MatchedHandlerList getSubscribedMatchers(PatternExtractor event) { return handlers.getMatchers(event); }
HandlerList getSubscribedHandlers(KompicsEvent event) { return handlers.getSubscriptions(event); }
private boolean deliverToSubscribers(KompicsEvent event, int wid, Class<? extends KompicsEvent> eventType) { //Kompics.logger.debug("{}: trying to deliver {} to subscribers...", owner, event); if (handlers.hasSubscription(event)) { doDeliver(event, wid); return true; } //Kompics.logger.debug("{}: Couldn't deliver {}, no matching subscribers", owner.getComponent(), event); return false; }
@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(); } }
<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(); } }
boolean unsubscribe(MatchedHandler h) { Class<? extends PatternExtractor> eventType = h.getCxtType(); boolean found = false; int empties = 0; for (int i = 0; i < matchers.length; i++) { if (matchers[i].eventType.equals(eventType)) { if (matchers[i].remove(h)) { found = true; totalMatchers--; if (matchers[i].isEmpty()) { empties++; matchers[i] = null; } } } } if (empties > 0) { removeMatchers(empties); } return found; }
boolean unsubscribe(Handler h) { Class<? extends KompicsEvent> eventType = h.getEventType(); boolean found = false; int empties = 0; for (int i = 0; i < handlers.length; i++) { if (handlers[i].eventType.equals(eventType)) { if (handlers[i].remove(h)) { found = true; totalSubscriptions--; // might be wrong if the same handler was subscribed more than once...but how would that make any sense? if (handlers[i].isEmpty()) { empties++; handlers[i] = null; } } } } if (empties > 0) { removeHandlers(empties); } return found; }
<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(); } }
void doUnsubscribe(MatchedHandler handler) { Class cxtType = handler.getCxtType(); if (cxtType == null) { cxtType = reflectHandlerCxtType(handler); handler.setCxtType(cxtType); } rwLock.writeLock().lock(); try { if (!handlers.unsubscribe(handler)) { throw new RuntimeException("Handler " + handler + " is not subscribed to " + (isPositive ? "positive " : "negative ") + portType.getClass().getCanonicalName() + " for " + handler.getCxtType().getCanonicalName() + " events."); } } finally { rwLock.writeLock().unlock(); } }
@Override public void doSubscribe(MatchedHandler handler) { if (handler instanceof ClassMatchedHandler) { Object matchType = handler.pattern(); if (matchType == null) { ClassMatchedHandler cmh = (ClassMatchedHandler) handler; reflectCMHType(cmh); } } Class cxtType = handler.getCxtType(); if (cxtType == null) { cxtType = reflectHandlerCxtType(handler); handler.setCxtType(cxtType); } // check that the port type carries the event type in this direction if (!portType.hasEvent(isPositive, cxtType)) { throw new RuntimeException("Cannot subscribe handler " + handler + " to " + (isPositive ? "positive " : "negative ") + portType.getClass().getCanonicalName() + " for " + cxtType.getCanonicalName() + " events."); } rwLock.writeLock().lock(); try { handlers.subscribe(handler); } finally { rwLock.writeLock().unlock(); } }