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 java.util.HashMap;
14 import java.util.Random;
15 import org.opendaylight.controller.cluster.example.messages.KeyValue;
18 * Created by kramesha on 7/16/14.
20 public class LogGenerator {
21 private final Map<ActorRef, LoggingThread> clientToLoggingThread = new HashMap<>();
23 public void startLoggingForClient(ActorRef client) {
24 LoggingThread lt = new LoggingThread(client);
25 clientToLoggingThread.put(client, lt);
26 new Thread(lt).start();
29 public void stopLoggingForClient(ActorRef client) {
30 clientToLoggingThread.get(client).stopLogging();
31 clientToLoggingThread.remove(client);
34 public static class LoggingThread implements Runnable {
36 private final ActorRef clientActor;
37 private volatile boolean stopLogging = false;
39 public LoggingThread(ActorRef clientActor) {
40 this.clientActor = clientActor;
44 @SuppressWarnings("checkstyle:RegexpSingleLineJava")
46 Random random = new Random();
49 System.out.println("Logging stopped for client:" + clientActor.path());
52 String key = clientActor.path().name();
53 int randomInt = random.nextInt(100);
54 clientActor.tell(new KeyValue(key + "-key-" + randomInt, "value-" + randomInt), null);
56 Thread.sleep(randomInt % 10 * 1000L);
57 } catch (InterruptedException e) {
63 public void stopLogging() {
67 public void startLogging() {