public static ForkProtocolStack getForkStack(Protocol prot) { while(prot != null && !(prot instanceof ForkProtocolStack)) prot=prot.getUpProtocol(); return prot instanceof ForkProtocolStack? (ForkProtocolStack)prot : null; }
protected <T extends Protocol> T findProtocolAbove(Class<? extends Protocol> clazz) { Protocol tmp=this; while(tmp != null) { Class<?> protClass=tmp.getClass(); if(clazz.isAssignableFrom(protClass)) return (T)tmp; tmp=tmp.getUpProtocol(); } return null; }
/** * Removes all events provided by the protocol above protocol from events * @param protocol * @param events */ protected static void removeProvidedDownServices(Protocol protocol, List<Integer> events) { if(protocol == null || events == null) return; for(Protocol prot=protocol.getUpProtocol(); prot != null && !events.isEmpty(); prot=prot.getUpProtocol()) { List<Integer> provided_down_services=prot.providedDownServices(); if(provided_down_services != null && !provided_down_services.isEmpty()) events.removeAll(provided_down_services); } }
public void init() throws Exception { super.init(); // sanity check: we cannot have any discovery protocols _above_ us for(Protocol p=up_prot; p != null; p=p.getUpProtocol()) if(p instanceof Discovery) throw new IllegalStateException(String.format("found %s above %s: this is invalid; all discovery " + "protocols must be placed below %s", p.getClass().getSimpleName(), getClass().getSimpleName(), getClass().getSimpleName())); // add all discovery protocols below us to the discovery_protocols list for(Protocol p=down_prot; p != null; p=p.getDownProtocol()) if(p instanceof Discovery) discovery_protocols.add((Discovery)p); }
prot=prot.getUpProtocol();
/** * Replaces one protocol instance with another. Should be done before the stack is connected * @param existing_prot * @param new_prot */ public void replaceProtocol(Protocol existing_prot, Protocol new_prot) throws Exception { Protocol up_neighbor=existing_prot.getUpProtocol(), down_neighbor=existing_prot.getDownProtocol(); new_prot.setUpProtocol(existing_prot.getUpProtocol()); new_prot.setDownProtocol(existing_prot.getDownProtocol()); up_neighbor.setDownProtocol(new_prot); if(down_neighbor != null) down_neighbor.setUpProtocol(new_prot); existing_prot.setDownProtocol(null); existing_prot.setUpProtocol(null); existing_prot.stop(); existing_prot.destroy(); if(new_prot.getUpProtocol() == this) top_prot=new_prot; callAfterCreationHook(new_prot, afterCreationHook()); new_prot.init(); }
public void insertProtocolInStack(Protocol prot, Protocol neighbor, Position position) { // connect to the protocol layer below and above if(position == Position.BELOW) { prot.setUpProtocol(neighbor); Protocol below=neighbor.getDownProtocol(); prot.setDownProtocol(below); if(below != null) below.setUpProtocol(prot); neighbor.setDownProtocol(prot); } else { // ABOVE is default Protocol above=neighbor.getUpProtocol(); checkAndSwitchTop(neighbor, prot); prot.setUpProtocol(above); if(above != null) above.setDownProtocol(prot); prot.setDownProtocol(neighbor); neighbor.setUpProtocol(prot); } }
public <T extends Protocol> T removeProtocol(T prot) { if(prot == null) return null; Protocol above=prot.getUpProtocol(), below=prot.getDownProtocol(); checkAndSwitchTop(prot, below); if(above != null) above.setDownProtocol(below); if(below != null) below.setUpProtocol(above); prot.setUpProtocol(null); prot.setDownProtocol(null); try { prot.stop(); } catch(Throwable t) { log.error(Util.getMessage("FailedStopping") + prot.getName() + ": " + t); } try { prot.destroy(); } catch(Throwable t) { log.error(Util.getMessage("FailedDestroying") + prot.getName() + ": " + t); } return prot; }
public static ForkProtocolStack getForkStack(Protocol prot) { while(prot != null && !(prot instanceof ForkProtocolStack)) prot=prot.getUpProtocol(); return prot instanceof ForkProtocolStack? (ForkProtocolStack)prot : null; }
protected <T extends Protocol> T findProtocolAbove(Class<? extends Protocol> clazz) { Protocol tmp=this; while(tmp != null) { Class<?> protClass=tmp.getClass(); if(clazz.isAssignableFrom(protClass)) return (T)tmp; tmp=tmp.getUpProtocol(); } return null; }
/** * Removes all events provided by the protocol above protocol from events * @param protocol * @param events */ protected static void removeProvidedDownServices(Protocol protocol, List<Integer> events) { if(protocol == null || events == null) return; for(Protocol prot=protocol.getUpProtocol(); prot != null && !events.isEmpty(); prot=prot.getUpProtocol()) { List<Integer> provided_down_services=prot.providedDownServices(); if(provided_down_services != null && !provided_down_services.isEmpty()) events.removeAll(provided_down_services); } }
public static void initProtocolStack(Protocol bottom_prot) throws Exception { while(bottom_prot != null) { bottom_prot.init(); bottom_prot=bottom_prot.getUpProtocol(); } }
public void init() throws Exception { super.init(); // sanity check: we cannot have any discovery protocols _above_ us for(Protocol p=up_prot; p != null; p=p.getUpProtocol()) if(p instanceof Discovery) throw new IllegalStateException(String.format("found %s above %s: this is invalid; all discovery " + "protocols must be placed below %s", p.getClass().getSimpleName(), getClass().getSimpleName(), getClass().getSimpleName())); // add all discovery protocols below us to the discovery_protocols list for(Protocol p=down_prot; p != null; p=p.getDownProtocol()) if(p instanceof Discovery) discovery_protocols.add((Discovery)p); }
public void run() { Vector responses=findInitialMembers(); thread_lock.lock(); try { thread=null; } finally { thread_lock.unlock(); } if(parent != null) { parent.getUpProtocol().up(new Event(Event.FIND_INITIAL_MBRS_OK, responses)); } }
/** * Replaces one protocol instance with another. Should be done before the stack is connected * @param existing_prot * @param new_prot */ public void replaceProtocol(Protocol existing_prot, Protocol new_prot) throws Exception { Protocol up_neighbor=existing_prot.getUpProtocol(), down_neighbor=existing_prot.getDownProtocol(); new_prot.setUpProtocol(existing_prot.getUpProtocol()); new_prot.setDownProtocol(existing_prot.getDownProtocol()); up_neighbor.setDownProtocol(new_prot); if(down_neighbor != null) down_neighbor.setUpProtocol(new_prot); existing_prot.setDownProtocol(null); existing_prot.setUpProtocol(null); existing_prot.stop(); existing_prot.destroy(); if(new_prot.getUpProtocol() == this) top_prot=new_prot; callAfterCreationHook(new_prot, afterCreationHook()); new_prot.init(); }
/** * Removes a protocol from the stack. Stops the protocol and readjusts the linked lists of * protocols. * @param prot_name The name of the protocol. Since all protocol names in a stack have to be unique * (otherwise the stack won't be created), the name refers to just 1 protocol. * @exception Exception Thrown if the protocol cannot be stopped correctly. */ public static Protocol removeProtocol(Protocol top_prot, String prot_name) throws Exception { if(prot_name == null) return null; Protocol prot=findProtocol(top_prot, prot_name); if(prot == null) return null; Protocol above=prot.getUpProtocol(), below=prot.getDownProtocol(); if(above != null) above.setDownProtocol(below); if(below != null) below.setUpProtocol(above); prot.setUpProtocol(null); prot.setDownProtocol(null); return prot; }
public void insertProtocolInStack(Protocol prot, Protocol neighbor, Position position) { // connect to the protocol layer below and above if(position == Position.BELOW) { prot.setUpProtocol(neighbor); Protocol below=neighbor.getDownProtocol(); prot.setDownProtocol(below); if(below != null) below.setUpProtocol(prot); neighbor.setDownProtocol(prot); } else { // ABOVE is default Protocol above=neighbor.getUpProtocol(); checkAndSwitchTop(neighbor, prot); prot.setUpProtocol(above); if(above != null) above.setDownProtocol(prot); prot.setDownProtocol(neighbor); neighbor.setUpProtocol(prot); } }
public <T extends Protocol> T removeProtocol(T prot) { if(prot == null) return null; Protocol above=prot.getUpProtocol(), below=prot.getDownProtocol(); checkAndSwitchTop(prot, below); if(above != null) above.setDownProtocol(below); if(below != null) below.setUpProtocol(above); prot.setUpProtocol(null); prot.setDownProtocol(null); try { prot.stop(); } catch(Throwable t) { log.error(Util.getMessage("FailedStopping") + prot.getName() + ": " + t); } try { prot.destroy(); } catch(Throwable t) { log.error(Util.getMessage("FailedDestroying") + prot.getName() + ": " + t); } return prot; }