boolean replyHandler, boolean localOnly) {
checkStarted();
if (address == null) {
throw new NullPointerException("address");
}
DefaultContext context = vertx.getContext();
boolean hasContext = context != null;
if (!hasContext) {
context = vertx.createEventLoopContext();
}
Handlers handlers = handlerMap.get(address);
if (handlers == null) {
handlers = new Handlers();
Handlers prevHandlers = handlerMap.putIfAbsent(address, handlers);
if (prevHandlers != null) {
handlers = prevHandlers;
}
if (completionHandler == null) {
completionHandler = new Handler<AsyncResult<Void>>() {
public void handle(AsyncResult<Void> event) {
if (event.failed()) {
log.error("Failed to remove entry", event.cause());
}
}
};
}
handlers.list.add(new HandlerHolder(handler, replyHandler, localOnly, context));
if (subs != null && !replyHandler && !localOnly) {
// Propagate the information
subs.put(address, serverID, completionHandler);
} else {
callCompletionHandler(completionHandler);
}
} else {
handlers.list.add(new HandlerHolder(handler, replyHandler, localOnly, context));
if (completionHandler != null) {
callCompletionHandler(completionHandler);
}
}
if (hasContext) {
HandlerEntry entry = new HandlerEntry(address, handler);
context.addCloseHook(entry);
}
}