Madan Jampani

Netty bug fix: Do not use weakValues in a cache where we track outstanding responses.

......@@ -8,7 +8,7 @@ export ONOS_ROOT=${ONOS_ROOT:-~/onos-next}
# Setup some environmental context for developers
if [ -z "${JAVA_HOME}" ]; then
if [ -x /usr/libexec/java_home ]; then
export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
elif [ -d /usr/lib/jvm/java-7-openjdk-amd64 ]; then
export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
fi
......
......@@ -55,8 +55,8 @@ public class Endpoint {
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("port", port)
.add("host", host)
.add("port", port)
.toString();
}
......
......@@ -26,7 +26,7 @@ import java.io.IOException;
*/
public final class InternalMessage implements Message {
public static final String REPLY_MESSAGE_TYPE = "NETTY_MESSAGIG_REQUEST_REPLY";
public static final String REPLY_MESSAGE_TYPE = "NETTY_MESSAGING_REQUEST_REPLY";
private long id;
private Endpoint sender;
......
......@@ -67,7 +67,6 @@ public class NettyMessagingService implements MessagingService {
private final AtomicLong messageIdGenerator = new AtomicLong(0);
private final Cache<Long, SettableFuture<byte[]>> responseFutures = CacheBuilder.newBuilder()
.maximumSize(100000)
.weakValues()
// TODO: Once the entry expires, notify blocking threads (if any).
.expireAfterWrite(10, TimeUnit.MINUTES)
.build();
......@@ -174,7 +173,12 @@ public class NettyMessagingService implements MessagingService {
.withType(type)
.withPayload(payload)
.build();
sendAsync(ep, message);
try {
sendAsync(ep, message);
} catch (IOException e) {
responseFutures.invalidate(messageId);
throw e;
}
return futureResponse;
}
......@@ -293,7 +297,8 @@ public class NettyMessagingService implements MessagingService {
if (futureResponse != null) {
futureResponse.set(message.payload());
} else {
log.warn("Received a reply. But was unable to locate the request handle");
log.warn("Received a reply for message id:[{}]. "
+ "But was unable to locate the request handle", message.id());
}
} finally {
NettyMessagingService.this.responseFutures.invalidate(message.id());
......