/** * Subscribe. * * @param handler the handler * @param port the port * @throws ConfigurationException */ protected final <E extends KompicsEvent, P extends PortType> void subscribe( Handler<E> handler, Port<P> port) { if (port instanceof JavaPort) { JavaPort<P> p = (JavaPort<P>) port; p.doSubscribe(handler); } else { throw new ConfigurationException("Port (" + port.toString() + " is not an instance of JavaPort!" + "Handler subscription only works in Java"); } }
@Override public Negative<ControlPort> createControlPort() { negativeControl = new JavaPort<ControlPort>(false, PortType.getPortType(ControlPort.class), this); positiveControl = new JavaPort<ControlPort>(true, PortType.getPortType(ControlPort.class), parent); positiveControl.setPair(negativeControl); negativeControl.setPair(positiveControl); negativeControl.doSubscribe(handleStart); negativeControl.doSubscribe(handleStop); negativeControl.doSubscribe(handleKill); negativeControl.doSubscribe(handleStarted); negativeControl.doSubscribe(handleStopped); negativeControl.doSubscribe(handleKilled); negativeControl.doInternalSubscribe(handleFault); negativeControl.doInternalSubscribe(configHandler); return negativeControl; }
protected final void subscribe(MatchedHandler<?, ?, ?> handler, Port port) { if (port instanceof JavaPort) { JavaPort p = (JavaPort) port; if (p.owner.equals(this.core)) { p.doSubscribe(handler); } else { throw new ConfigurationException( "Cannot subscribe Handlers to other component's ports, " + "since the behaviour of this is unspecifed. " + "(The handler might be executed on the wrong thread)"); } } else { throw new ConfigurationException("Port (" + port.toString() + " is not an instance of JavaPort!" + "Handler subscription only works with matching ports and components"); } }