/** * Creates a new FORK protocol, or returns the existing one, or throws an exception. Never returns null. */ protected static FORK getFORK(JChannel ch, ProtocolStack.Position position, Class<? extends Protocol> neighbor, boolean create_fork_if_absent) throws Exception { ProtocolStack stack=ch.getProtocolStack(); FORK fork=stack.findProtocol(FORK.class); if(fork == null) { if(!create_fork_if_absent) throw new IllegalArgumentException("FORK not found in main stack"); fork = new FORK(); fork.setProtocolStack(stack); stack.insertProtocol(fork, position, neighbor); } return fork; }
public Object up(Message msg) { ForkHeader hdr=msg.getHeader(id); if(hdr == null) return up_prot.up(msg); if(hdr.fork_stack_id == null) throw new IllegalArgumentException("header has a null fork_stack_id"); Protocol bottom_prot=get(hdr.fork_stack_id); return bottom_prot != null? bottom_prot.up(msg) : this.unknownForkHandler.handleUnknownForkStack(msg, hdr.fork_stack_id); }
@Override public synchronized void destroy() { if(--inits == 0) { super.destroy(); this.protocols.clear(); FORK fork=findProtocol(FORK.class); fork.remove(this.fork_stack_id); } }
protected void createForkStacks(Map<String,List<ProtocolConfiguration>> protocols) throws Exception { for(Map.Entry<String,List<ProtocolConfiguration>> entry: protocols.entrySet()) { String fork_stack_id=entry.getKey(); if(get(fork_stack_id) != null) continue; List<Protocol> prots=createProtocols(null,entry.getValue()); createForkStack(fork_stack_id, prots, false); } }
protected void createForkStacks(String config) throws Exception { InputStream in=getForkStream(config); if(in == null) throw new FileNotFoundException("fork stacks config " + config + " not found"); Map<String,List<ProtocolConfiguration>> protocols=ForkConfig.parse(in); createForkStacks(protocols); }
@Override public JChannel createChannel(String id) throws Exception { FORK fork = new FORK(); fork.enableStats(this.configuration.isStatisticsEnabled()); fork.setUnknownForkHandler(new UnknownForkHandler() { private final short id = ClassConfigurator.getProtocolId(RequestCorrelator.class);
FORK fork = new FORK(); fork.setUnknownForkHandler(unknownForkHandler); stack.addProtocol(fork); fork.init();
gcb.transport().distributedSyncTimeout(30, TimeUnit.SECONDS); FORK fork = new FORK(); fork.setUnknownForkHandler(new UnknownForkHandler() { @Override public Object handleUnknownForkStack(Message message, String forkStackId) {
/** * 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 parse(Node node) throws Exception { Map<String,List<ProtocolConfiguration>> protocols=ForkConfig.parse(node); createForkStacks(protocols); }
prot_stack=fork.createForkStack(fork_stack_id, protocols == null? null : Arrays.asList(protocols), true); flush_supported=main_channel.flushSupported(); state=State.OPEN;
@Override public JChannel createChannel(String id) throws Exception { FORK fork = new FORK(); fork.enableStats(this.configuration.isStatisticsEnabled()); fork.setUnknownForkHandler(new UnknownForkHandler() { private final short id = ClassConfigurator.getProtocolId(RequestCorrelator.class);
protected void createForkStacks(Map<String,List<ProtocolConfiguration>> protocols) throws Exception { for(Map.Entry<String,List<ProtocolConfiguration>> entry: protocols.entrySet()) { String fork_stack_id=entry.getKey(); if(get(fork_stack_id) != null) continue; List<Protocol> prots=createProtocols(null,entry.getValue()); createForkStack(fork_stack_id, prots, false); } }
/** * 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; }
protected void createForkStacks(String config) throws Exception { InputStream in=getForkStream(config); if(in == null) throw new FileNotFoundException("fork stacks config " + config + " not found"); Map<String,List<ProtocolConfiguration>> protocols=ForkConfig.parse(in); createForkStacks(protocols); }
public void init() throws Exception { super.init(); if(config != null) createForkStacks(config); }
prot_stack=fork.createForkStack(fork_stack_id, protocols == null? null : Arrays.asList(protocols), true); flush_supported=main_channel.flushSupported(); state=State.OPEN;
/** * Creates a new FORK protocol, or returns the existing one, or throws an exception. Never returns null. */ protected static FORK getFORK(JChannel ch, ProtocolStack.Position position, Class<? extends Protocol> neighbor, boolean create_fork_if_absent) throws Exception { ProtocolStack stack=ch.getProtocolStack(); FORK fork=stack.findProtocol(FORK.class); if(fork == null) { if(!create_fork_if_absent) throw new IllegalArgumentException("FORK not found in main stack"); fork = new FORK(); fork.setProtocolStack(stack); stack.insertProtocol(fork, position, neighbor); } return fork; }
String fork_stack_id=entry.getKey(); List<Message> list=entry.getValue(); Protocol bottom_prot=get(fork_stack_id); if(bottom_prot == null) { for(Message m: list)
@Override public void accept(ChannelFactory factory) { ProtocolStack stack = this.parentChannel.get().getProtocolStack(); FORK fork = (FORK) stack.findProtocol(FORK.class); fork.remove(this.address.getLastElement().getValue()); }