<E extends KompicsEvent> void doUnsubscribe(Handler<E> handler) { Class<E> eventType = handler.getEventType(); if (eventType == null) { eventType = reflectHandlerEventType(handler); handler.setEventType(eventType); } rwLock.writeLock().lock(); try { if (!handlers.unsubscribe(handler)) { throw new RuntimeException("Handler " + handler + " is not subscribed to " + (isPositive ? "positive " : "negative ") + portType.getClass().getCanonicalName() + " for " + eventType.getCanonicalName() + " events."); } } finally { rwLock.writeLock().unlock(); } }
<E extends KompicsEvent> void doInternalSubscribe(Handler<E> handler) { Class<E> eventType = handler.getEventType(); if (eventType == null) { eventType = reflectHandlerEventType(handler); handler.setEventType(eventType); } // check that the port type carries the event type in this direction if (!portType.hasEvent(isPositive, eventType)) { throw new RuntimeException("Cannot subscribe handler " + handler + " to " + (isPositive ? "positive " : "negative ") + portType.getClass().getCanonicalName() + " for " + eventType.getCanonicalName() + " events."); } rwLock.writeLock().lock(); try { handlers.subscribe(handler); } finally { rwLock.writeLock().unlock(); } }
@Override public <E extends KompicsEvent> void doSubscribe(Handler<E> handler) { Class<E> eventType = handler.getEventType(); if (eventType == null) { eventType = reflectHandlerEventType(handler); if (Fault.class.isAssignableFrom(eventType)) { throw new RuntimeException("Custom Fault handlers are not support anymore! Please override ComponentDefinition.handleFault() instead, for custom Fault handling."); } handler.setEventType(eventType); } // check that the port type carries the event type in this direction if (!portType.hasEvent(isPositive, eventType)) { throw new RuntimeException("Cannot subscribe handler " + handler + " to " + (isPositive ? "positive " : "negative ") + portType.getClass().getCanonicalName() + " for " + eventType.getCanonicalName() + " events."); } rwLock.writeLock().lock(); try { handlers.subscribe(handler); } finally { rwLock.writeLock().unlock(); } }