public void setUnknownForkHandler(UnknownForkHandler unknownForkHandler) { this.unknownForkHandler = unknownForkHandler; fork_stacks.values().forEach(p -> { if(p instanceof ForkProtocol) { ForkProtocolStack st=getForkStack(p); if(st != null) st.setUnknownForkHandler(unknownForkHandler); } }); }
protected void getStateFromMainAndForkChannels(Event evt) { final OutputStream out=evt.getArg(); try(DataOutputStream dos=new DataOutputStream(out)) { getStateFrom(null, up_prot, null, null, dos); // now fetch state from all fork channels for(Map.Entry<String,Protocol> entry: fork_stacks.entrySet()) { String stack_name=entry.getKey(); Protocol prot=entry.getValue(); ForkProtocolStack fork_stack=getForkStack(prot); for(Map.Entry<String,JChannel> en: fork_stack.getForkChannels().entrySet()) { String fc_name=en.getKey(); JChannel fc=en.getValue(); getStateFrom(fc, null, stack_name, fc_name, dos); } } } catch(Throwable ex) { log.error("%s: failed fetching state from main channel", local_addr, ex); } }
continue; ForkProtocolStack fork_stack=getForkStack(prot); JChannel fork_ch=fork_stack.get(ch_name); if(fork_ch == null) {
/** * Returns the fork stack for fork_stack_id (if exitstent), or creates a new fork-stack from protocols and adds it * into the hashmap of fork-stack (key is fork_stack_id). * Method init() will be called on each protocol, from bottom to top. * @param fork_stack_id The key under which the new fork-stack should be added to the fork-stacks hashmap * @param protocols A list of protocols from <em>bottom to top</em> to be inserted. They will be sandwiched * between ForkProtocolStack (top) and ForkProtocol (bottom). The list can be empty (or null) in * which case we won't create any protocols, but still have a separate fork-stack inserted. * @param initialize If false, the ref count 'inits' will not get incremented and init() won't be called. This is * needed when creating a fork stack from an XML config inside of the FORK protocol. The protocols * in the fork stack will only get initialized on the first ForkChannel creation * @return The new {@link ForkProtocolStack}, or the existing stack (if present) */ public synchronized ProtocolStack createForkStack(String fork_stack_id, List<Protocol> protocols, boolean initialize) throws Exception { Protocol bottom; if((bottom=get(fork_stack_id)) != null) { ForkProtocolStack retval=getForkStack(bottom); return initialize? retval.incrInits() : retval; } List<Protocol> prots=new ArrayList<>(); prots.add(bottom=new ForkProtocol(fork_stack_id).setDownProtocol(this)); // add a ForkProtocol as bottom protocol if(protocols != null) prots.addAll(protocols); ForkProtocolStack fork_stack=(ForkProtocolStack)new ForkProtocolStack(getUnknownForkHandler(), prots, fork_stack_id).setChannel(this.stack.getChannel()); fork_stack.init(); if(initialize) fork_stack.incrInits(); fork_stacks.put(fork_stack_id, bottom); return fork_stack; }
public void setUnknownForkHandler(UnknownForkHandler unknownForkHandler) { this.unknownForkHandler = unknownForkHandler; fork_stacks.values().forEach(p -> { if(p instanceof ForkProtocol) { ForkProtocolStack st=getForkStack(p); if(st != null) st.setUnknownForkHandler(unknownForkHandler); } }); }
protected void getStateFromMainAndForkChannels(Event evt) { final OutputStream out=evt.getArg(); try(DataOutputStream dos=new DataOutputStream(out)) { getStateFrom(null, up_prot, null, null, dos); // now fetch state from all fork channels for(Map.Entry<String,Protocol> entry: fork_stacks.entrySet()) { String stack_name=entry.getKey(); Protocol prot=entry.getValue(); ForkProtocolStack fork_stack=getForkStack(prot); for(Map.Entry<String,JChannel> en: fork_stack.getForkChannels().entrySet()) { String fc_name=en.getKey(); JChannel fc=en.getValue(); getStateFrom(fc, null, stack_name, fc_name, dos); } } } catch(Throwable ex) { log.error("%s: failed fetching state from main channel", local_addr, ex); } }
continue; ForkProtocolStack fork_stack=getForkStack(prot); JChannel fork_ch=fork_stack.get(ch_name); if(fork_ch == null) {
/** * Returns the fork stack for fork_stack_id (if exitstent), or creates a new fork-stack from protocols and adds it * into the hashmap of fork-stack (key is fork_stack_id). * Method init() will be called on each protocol, from bottom to top. * @param fork_stack_id The key under which the new fork-stack should be added to the fork-stacks hashmap * @param protocols A list of protocols from <em>bottom to top</em> to be inserted. They will be sandwiched * between ForkProtocolStack (top) and ForkProtocol (bottom). The list can be empty (or null) in * which case we won't create any protocols, but still have a separate fork-stack inserted. * @param initialize If false, the ref count 'inits' will not get incremented and init() won't be called. This is * needed when creating a fork stack from an XML config inside of the FORK protocol. The protocols * in the fork stack will only get initialized on the first ForkChannel creation * @return The new {@link ForkProtocolStack}, or the existing stack (if present) */ public synchronized ProtocolStack createForkStack(String fork_stack_id, List<Protocol> protocols, boolean initialize) throws Exception { Protocol bottom; if((bottom=get(fork_stack_id)) != null) { ForkProtocolStack retval=getForkStack(bottom); return initialize? retval.incrInits() : retval; } List<Protocol> prots=new ArrayList<>(); prots.add(bottom=new ForkProtocol(fork_stack_id).setDownProtocol(this)); // add a ForkProtocol as bottom protocol if(protocols != null) prots.addAll(protocols); ForkProtocolStack fork_stack=(ForkProtocolStack)new ForkProtocolStack(getUnknownForkHandler(), prots, fork_stack_id).setChannel(this.stack.getChannel()); fork_stack.init(); if(initialize) fork_stack.incrInits(); fork_stacks.put(fork_stack_id, bottom); return fork_stack; }