We are getting flagged in SonarCloud for this example, clean it up.
Change-Id: I9665e444857f6fb5b67a1bcb064d10b0ada8069b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.controller.cluster.example;
import akka.actor.ActorRef;
package org.opendaylight.controller.cluster.example;
import akka.actor.ActorRef;
import java.util.Map;
import java.util.Random;
import org.opendaylight.controller.cluster.example.messages.KeyValue;
import java.util.Map;
import java.util.Random;
import org.opendaylight.controller.cluster.example.messages.KeyValue;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Created by kramesha on 7/16/14.
*/
public class LogGenerator {
/**
* Created by kramesha on 7/16/14.
*/
public class LogGenerator {
+ private static final Logger LOG = LoggerFactory.getLogger(LogGenerator.class);
+
private final Map<ActorRef, LoggingThread> clientToLoggingThread = new HashMap<>();
private final Map<ActorRef, LoggingThread> clientToLoggingThread = new HashMap<>();
- public void startLoggingForClient(ActorRef client) {
+ public void startLoggingForClient(final ActorRef client) {
LoggingThread lt = new LoggingThread(client);
clientToLoggingThread.put(client, lt);
new Thread(lt).start();
}
LoggingThread lt = new LoggingThread(client);
clientToLoggingThread.put(client, lt);
new Thread(lt).start();
}
- public void stopLoggingForClient(ActorRef client) {
+ public void stopLoggingForClient(final ActorRef client) {
clientToLoggingThread.get(client).stopLogging();
clientToLoggingThread.remove(client);
}
clientToLoggingThread.get(client).stopLogging();
clientToLoggingThread.remove(client);
}
private final ActorRef clientActor;
private volatile boolean stopLogging = false;
private final ActorRef clientActor;
private volatile boolean stopLogging = false;
- public LoggingThread(ActorRef clientActor) {
+ public LoggingThread(final ActorRef clientActor) {
this.clientActor = clientActor;
}
@Override
this.clientActor = clientActor;
}
@Override
- @SuppressWarnings("checkstyle:RegexpSingleLineJava")
public void run() {
Random random = new Random();
while (true) {
if (stopLogging) {
public void run() {
Random random = new Random();
while (true) {
if (stopLogging) {
- System.out.println("Logging stopped for client:" + clientActor.path());
+ LOG.info("Logging stopped for client: {}", clientActor.path());
break;
}
String key = clientActor.path().name();
int randomInt = random.nextInt(100);
clientActor.tell(new KeyValue(key + "-key-" + randomInt, "value-" + randomInt), null);
break;
}
String key = clientActor.path().name();
int randomInt = random.nextInt(100);
clientActor.tell(new KeyValue(key + "-key-" + randomInt, "value-" + randomInt), null);
try {
Thread.sleep(randomInt % 10 * 1000L);
} catch (InterruptedException e) {
try {
Thread.sleep(randomInt % 10 * 1000L);
} catch (InterruptedException e) {
+ LOG.info("Interrupted while sleeping", e);