public void addConnection(byte[] id, Negative<Network> destinationPort) { rwlock.writeLock().lock(); try { if (id == null) { hostPorts.add(destinationPort); } else { Set<Negative<Network>> ports = destinationPorts.get(ByteBuffer.wrap(id)); if (ports != null) { ports.add(destinationPort); } else { ports = new HashSet<Negative<Network>>(); ports.add(destinationPort); destinationPorts.put(ByteBuffer.wrap(id), ports); } } } finally { rwlock.writeLock().unlock(); } destinationPort.addChannel(this); }
public final void suicide() { if (core.state == Component.State.ACTIVE || core.state == Component.State.STARTING) { trigger(Kill.event, control.getPair()); } else { logger.warn("Could not commit suicide as state is non-active"); } }
public void removeConnection(byte[] id, Negative<Network> destinationPort) { rwlock.writeLock().lock(); try { if (id == null) { hostPorts.remove(destinationPort); } else { Set<Negative<Network>> ports = destinationPorts.get(ByteBuffer.wrap(id)); if (ports != null) { ports.remove(destinationPort); } } } finally { rwlock.writeLock().unlock(); } destinationPort.removeChannel(this); }
protected ComponentDefinition(Class<? extends ComponentCore> coreClass) { try { Constructor[] constrs = coreClass.getConstructors(); for (Constructor constr : constrs) { Class[] paramTypes = constr.getParameterTypes(); if ((paramTypes.length) == 1 && paramTypes[0].isInstance(this)) { core = (ComponentCore) constr.newInstance(this); } } if (core == null) { core = coreClass.newInstance(); } } catch (Exception e) { //e.printStackTrace(); //System.out.println(e + ": " + e.getMessage()); throw new ConfigurationException(e); } control = core.createControlPort(); loopback = core.createNegativePort(LoopbackPort.class); onSelf = loopback.getPair(); loggingCtxInit(); } }
public static VirtualNetworkChannel connect(Positive<Network> sourcePort, Negative<Network> deadLetterBox, ChannelSelector<?, ?> selector) { VirtualNetworkChannel vnc = new VirtualNetworkChannel(sourcePort, deadLetterBox); sourcePort.addChannel(vnc, selector); deadLetterBox.addChannel(vnc); return vnc; }
@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(); } }
/** * Instantiates a new component definition. */ protected ComponentDefinition() { core = new JavaComponent(this); control = core.createControlPort(); loopback = core.createNegativePort(LoopbackPort.class); onSelf = loopback.getPair(); loggingCtxInit(); }
public static VirtualNetworkChannel connect(Positive<Network> sourcePort, Negative<Network> deadLetterBox) { VirtualNetworkChannel vnc = new VirtualNetworkChannel(sourcePort, deadLetterBox); sourcePort.addChannel(vnc); deadLetterBox.addChannel(vnc); return vnc; }