ClusterMessagingProtocolServer: add null check + trace
Change-Id: If10a2f98a8e2ef098f770196de1bdc81500fd0c0
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/ClusterMessagingProtocolServer.java b/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/ClusterMessagingProtocolServer.java
index e2c06c7..53c3f63 100644
--- a/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/ClusterMessagingProtocolServer.java
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/service/impl/ClusterMessagingProtocolServer.java
@@ -67,6 +67,24 @@
@Override
public void handle(ClusterMessage message) {
T request = ClusterMessagingProtocol.SERIALIZER.decode(message.payload());
+ if (handler == null) {
+ // there is a slight window of time during state transition,
+ // where handler becomes null
+ for (int i = 0; i < 10; ++i) {
+ if (handler != null) {
+ break;
+ }
+ try {
+ Thread.sleep(1);
+ } catch (InterruptedException e) {
+ log.trace("Exception", e);
+ }
+ }
+ if (handler == null) {
+ log.error("There was no handler for registered!");
+ return;
+ }
+ }
if (request.getClass().equals(PingRequest.class)) {
handler.ping((PingRequest) request).whenComplete(new PostExecutionTask<PingResponse>(message));
} else if (request.getClass().equals(PollRequest.class)) {
@@ -94,6 +112,7 @@
log.error("Processing for " + message.subject() + " failed.", t);
} else {
try {
+ log.trace("responding to {}", message.subject());
message.respond(ClusterMessagingProtocol.SERIALIZER.encode(response));
} catch (Exception e) {
log.error("Failed to respond to " + response.getClass().getName(), e);