1 package org.opendaylight.controller.cluster.example;
3 import akka.actor.ActorRef;
4 import org.opendaylight.controller.cluster.example.messages.KeyValue;
6 import java.util.HashMap;
8 import java.util.Random;
11 * Created by kramesha on 7/16/14.
13 public class LogGenerator {
14 private Map<ActorRef, LoggingThread> clientToLoggingThread = new HashMap<ActorRef, LoggingThread>();
16 public void startLoggingForClient(ActorRef client) {
17 LoggingThread lt = new LoggingThread(client);
18 clientToLoggingThread.put(client, lt);
19 Thread t = new Thread(lt);
23 public void stopLoggingForClient(ActorRef client) {
24 clientToLoggingThread.get(client).stopLogging();
25 clientToLoggingThread.remove(client);
28 public class LoggingThread implements Runnable {
30 private ActorRef clientActor;
31 private volatile boolean stopLogging = false;
33 public LoggingThread(ActorRef clientActor) {
34 this.clientActor = clientActor;
38 Random r = new Random();
41 System.out.println("Logging stopped for client:" + clientActor.path());
44 String key = clientActor.path().name();
45 int random = r.nextInt(100);
46 clientActor.tell(new KeyValue(key+"-key-" + random, "value-" + random), null);
48 Thread.sleep((random%10) * 1000);
49 } catch (InterruptedException e) {
55 public void stopLogging() {
59 public void startLogging() {