2 * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.cluster.example;
11 import akka.actor.ActorRef;
12 import org.opendaylight.controller.cluster.example.messages.KeyValue;
14 import java.util.HashMap;
16 import java.util.Random;
19 * Created by kramesha on 7/16/14.
21 public class LogGenerator {
22 private Map<ActorRef, LoggingThread> clientToLoggingThread = new HashMap<>();
24 public void startLoggingForClient(ActorRef client) {
25 LoggingThread lt = new LoggingThread(client);
26 clientToLoggingThread.put(client, lt);
27 Thread t = new Thread(lt);
31 public void stopLoggingForClient(ActorRef client) {
32 clientToLoggingThread.get(client).stopLogging();
33 clientToLoggingThread.remove(client);
36 public class LoggingThread implements Runnable {
38 private ActorRef clientActor;
39 private volatile boolean stopLogging = false;
41 public LoggingThread(ActorRef clientActor) {
42 this.clientActor = clientActor;
46 Random r = new Random();
49 System.out.println("Logging stopped for client:" + clientActor.path());
52 String key = clientActor.path().name();
53 int random = r.nextInt(100);
54 clientActor.tell(new KeyValue(key+"-key-" + random, "value-" + random), null);
56 Thread.sleep((random%10) * 1000);
57 } catch (InterruptedException e) {
63 public void stopLogging() {
67 public void startLogging() {