@Override public void forwardToPositive(KompicsEvent event, int wid) { if (!destroyed) { positivePort.doTrigger(event, wid, this); } }
@Override public void disconnect() { this.destroy(); positivePort.removeChannel(this); negativePort.removeChannel(this); }
@Override public <P extends PortType> Channel<P> connect(PortCore<P> positivePort, PortCore<P> negativePort) { BiDirectionalChannel<P> c = new BiDirectionalChannel(positivePort, negativePort); positivePort.addChannel(c); negativePort.addChannel(c); return c; }
logger().debug("Slowly dying..."); state = Component.State.STOPPING; ((PortCore<ControlPort>) getControl().getPair()).cleanEvents(); // if multiple kills are queued up just ignore everything for (ComponentCore child : children) { if (child.state() != Component.State.ACTIVE) { ((PortCore<ControlPort>) child.getControl()).doTrigger( Kill.event, wid, component.getComponentCore()); logger().debug("dying..."); state = Component.State.PASSIVE; ((PortCore<ControlPort>) getControl().getPair()).cleanEvents(); // if multiple kills are queued up just ignore everything component.tearDown(); if (parent != null) { ((PortCore<ControlPort>) parent.getControl()).doTrigger(new Killed(component.getComponentCore()), wid, component.getComponentCore()); } else { synchronized (component.getComponentCore()) {
/** * * @param <P> * @param negative * @param positive * @deprecated Use {@link #disconnect(Channel)} or * {@link Channel.disconnect()} instead */ @Deprecated protected final <P extends PortType> void disconnect(Negative<P> negative, Positive<P> positive) { PortCore<P> pos = (PortCore<P>) positive; PortCore<P> neg = (PortCore<P>) negative; List<Channel<P>> channels = pos.findChannelsTo(neg); for (Channel<P> c : channels) { c.disconnect(); } }
@Override public Network getPortType() { return sourcePort.getPortType(); }
public void eventReceived(PortCore<?> port, KompicsEvent event, int wid) { //System.err.println("Received event " + event + " on " + port.getPortType().portTypeClass + " work " + workCount.get()); port.enqueue(event); readyPorts.offer(port); int wc = workCount.getAndIncrement(); if (wc == 0) { schedule(wid); } }
/** * * @param <P> * @param negative * @param positive * @deprecated Use {@link #disconnect(Channel)} or * {@link Channel.disconnect()} instead */ @Deprecated protected final <P extends PortType> void disconnect(Positive<P> positive, Negative<P> negative) { PortCore<P> pos = (PortCore<P>) positive; PortCore<P> neg = (PortCore<P>) negative; List<Channel<P>> channels = neg.findChannelsTo(pos); for (Channel<P> c : channels) { c.disconnect(); } }
@Override public void forwardToPositive(KompicsEvent event, int wid) { if (!destroyed && (direction == Direction.TO_POSITIVE)) { positivePort.doTrigger(event, wid, this); } }
@Override public void disconnect() { rwlock.writeLock().lock(); try { destroyed = true; // ATTENTION: Possible deadlock due to double locking (don't think it will happen, but if it does the fault is here!) sourcePort.removeChannel(this); deadLetterBox.removeChannel(this); for (Set<Negative<Network>> portSet : destinationPorts.values()) { for (Negative<Network> port : portSet) { PortCore<Network> p = (PortCore<Network>) port; p.removeChannel(this); } } destinationPorts.clear(); for (Negative<Network> port : hostPorts) { PortCore<Network> p = (PortCore<Network>) port; p.removeChannel(this); } hostPorts.clear(); } finally { rwlock.writeLock().unlock(); } }
@Override public <P extends PortType> Channel<P> connect(PortCore<P> positivePort, PortCore<P> negativePort) { UniDirectionalChannel<P> c = new UniDirectionalChannel(positivePort, negativePort, direction); positivePort.addChannel(c); negativePort.addChannel(c); return c; }
@Override public void forwardToNegative(KompicsEvent event, int wid) { if (!destroyed && (direction == Direction.TO_NEGATIVE)) { negativePort.doTrigger(event, wid, this); } }
@Override public <P extends PortType> Channel<P> connect(PortCore<P> positivePort, PortCore<P> negativePort, ChannelSelector selector) { BiDirectionalChannel<P> c = new BiDirectionalChannel(positivePort, negativePort); Class<? extends KompicsEvent> eventType = selector.getEventType(); if (selector.isPositive()) { if (!c.portType.hasPositive(eventType)) { throw new RuntimeException("Port type " + c.portType + " has no positive " + eventType); } positivePort.addChannel(c, selector); negativePort.addChannel(c); } else { if (!c.portType.hasNegative(eventType)) { throw new RuntimeException("Port type " + c.portType + " has no negative " + eventType); } positivePort.addChannel(c); negativePort.addChannel(c, selector); } return c; }
@Override public void forwardToPositive(KompicsEvent event, int wid) { if (destroyed) { return; } //log.debug("Forwarding Message down: " + event.toString()); sourcePort.doTrigger(event, wid, this); }
@Override public <P extends PortType> Channel<P> connect(PortCore<P> positivePort, PortCore<P> negativePort, ChannelSelector selector) { UniDirectionalChannel<P> c = new UniDirectionalChannel(positivePort, negativePort, direction); Class<? extends KompicsEvent> eventType = selector.getEventType(); if (selector.isPositive()) { if (!c.portType.hasPositive(eventType)) { throw new RuntimeException("Port type " + c.portType + " has no positive " + eventType); } if (this.direction != Direction.TO_NEGATIVE) { throw new RuntimeException("Selectors have to be added to the sending side of a one-way channel!"); } positivePort.addChannel(c, selector); negativePort.addChannel(c); } else { if (!c.portType.hasNegative(eventType)) { throw new RuntimeException("Port type " + c.portType + " has no negative " + eventType); } if (this.direction != Direction.TO_POSITIVE) { throw new RuntimeException("Selectors have to be added to the sending side of a one-way channel!"); } positivePort.addChannel(c); negativePort.addChannel(c, selector); } return c; }
@Override public void forwardToNegative(KompicsEvent event, int wid) { if (!destroyed) { negativePort.doTrigger(event, wid, this); } }
@Override public void handle(Started event) { logger().debug("Got Started event from {}", event.component); activeSet.add(event.component); logger().debug("Active set has {} members", activeSet.size()); try { childrenLock.readLock().lock(); if ((activeSet.size() == children.size()) && (state == Component.State.STARTING)) { logger().debug("Started!"); state = Component.State.ACTIVE; if (parent != null) { ((PortCore<ControlPort>) parent.getControl()).doTrigger(new Started(component.getComponentCore()), wid, component.getComponentCore()); } } } finally { childrenLock.readLock().unlock(); } }
@Override void doConfigUpdate(ConfigUpdate update) { Config.Impl impl = (Config.Impl) conf; impl.apply(update, ValueMerger.NONE); Update forwardedEvent = new Update(update, id()); // forward down for (Component child : children) { ((PortCore<ControlPort>) child.getControl()).doTrigger( forwardedEvent, wid, this); } // forward up if (parent != null) { ((PortCore<ControlPort>) parent.getControl()).doTrigger( forwardedEvent, wid, this); } component.postUpdate(); }
@Override public void handle(Stopped event) { logger().debug("Got Stopped event from {}", event.component); activeSet.remove(event.component); logger().debug("Active set has {} members", activeSet.size()); if (activeSet.isEmpty() && (state == Component.State.STOPPING)) { logger().debug("Stopped!"); state = Component.State.PASSIVE; component.tearDown(); if (parent != null) { ((PortCore<ControlPort>) parent.getControl()).doTrigger(new Stopped(component.getComponentCore()), wid, component.getComponentCore()); } else { synchronized (component.getComponentCore()) { component.getComponentCore().notifyAll(); } } } }
@Override public void handle(Start event) { if (state != Component.State.PASSIVE) { throw new KompicsException(JavaComponent.this + " received a Start event while in " + state + " state. " + "Duplicate Start events are not allowed!"); } try { childrenLock.readLock().lock(); if (!children.isEmpty()) { logger().debug("Starting..."); state = Component.State.STARTING; for (ComponentCore child : children) { logger().debug("Sending Start to child: {}", child); // start child ((PortCore<ControlPort>) child.getControl()).doTrigger( Start.event, wid, component.getComponentCore()); } } else { logger().debug("Started!"); state = Component.State.ACTIVE; if (parent != null) { ((PortCore<ControlPort>) parent.getControl()).doTrigger(new Started(component.getComponentCore()), wid, component.getComponentCore()); } } } finally { childrenLock.readLock().unlock(); } }