use of com.b2international.snowowl.eventbus.net4j.IEventBusProtocol in project snow-owl by b2ihealthcare.
the class EventBus method unregisterHandler.
@Override
public IEventBus unregisterHandler(String address, IHandler<IMessage> handler) {
if (isActive()) {
MessageFactory.checkAddress(address);
if (handler != null) {
final ConcurrentMap<String, ChoosableList<Handler>> map = handler instanceof IEventBusProtocol ? protocolMap : handlerMap;
final ChoosableList<Handler> handlers = map.get(address);
if (handlers != null) {
synchronized (handlers) {
final int size = handlers.list.size();
// we need fast ordered traversal for the round robin
for (int i = 0; i < size; i++) {
final Handler entry = handlers.list.get(i);
if (entry.handler == handler) {
handlers.list.remove(i);
if (handlers.list.isEmpty()) {
map.remove(address);
// if this was the last non protocol based handler, send unregistration event
if (!entry.isReplyHandler && !(handler instanceof IEventBusProtocol)) {
addressBook.remove(address);
fireEvent(new HandlerChangedEvent(this, address, false));
}
}
LOG.trace("Unregistered handler {} from address {}", entry.handler, address);
return this;
}
}
}
}
}
}
return this;
}
use of com.b2international.snowowl.eventbus.net4j.IEventBusProtocol in project snow-owl by b2ihealthcare.
the class TransportClient method openCustomProtocols.
@SuppressWarnings("unchecked")
private void openCustomProtocols() {
// other client protocols
final List<ClientProtocolFactory> protocolFactories = getRegisteredClientProtocolFactories();
for (final ClientProtocolFactory clientProtocolFactory : protocolFactories) {
final SignalProtocol<Object> protocol = (SignalProtocol<Object>) clientProtocolFactory.create("");
openProtocol(protocol);
}
// also set up the RPC client...
final RpcProtocol rpcProtocol = RpcUtil.getRpcClientProtocol(IPluginContainer.INSTANCE);
openProtocol(rpcProtocol);
if (!env.isServer()) {
// ...the event bus, too.
final IEventBusProtocol eventBusProtocol = EventBusNet4jUtil.getClientProtocol(IPluginContainer.INSTANCE);
openProtocol(eventBusProtocol);
}
}
use of com.b2international.snowowl.eventbus.net4j.IEventBusProtocol in project snow-owl by b2ihealthcare.
the class EventBus method registerHandler.
private void registerHandler(String address, IHandler<IMessage> handler, boolean replyHandler, boolean localOnly) {
checkActive();
MessageFactory.checkAddress(address);
if (handler != null) {
ChoosableList<Handler> handlers = null;
if (handler instanceof IEventBusProtocol) {
handlers = protocolMap.get(address);
if (handlers == null) {
handlers = new ChoosableList<Handler>();
final ChoosableList<Handler> previousHandlers = protocolMap.putIfAbsent(address, handlers);
if (previousHandlers != null) {
handlers = previousHandlers;
}
}
} else {
handlers = handlerMap.get(address);
if (handlers == null) {
handlers = new ChoosableList<Handler>();
final ChoosableList<Handler> previousHandlers = handlerMap.putIfAbsent(address, handlers);
if (previousHandlers != null) {
handlers = previousHandlers;
}
}
}
final Handler h = new Handler(address, handler, executorService, replyHandler);
if (!handlers.list.contains(h)) {
handlers.list.add(h);
LOG.trace("Registered handler {} to address {}", handler, address);
if (!replyHandler && handlers.list.size() == 1 && !(handler instanceof IEventBusProtocol)) {
addressBook.add(address);
fireEvent(new HandlerChangedEvent(this, address, true));
}
}
}
}
Aggregations