/** * 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; }
insertProtocol(prot, position, neighbor.getClass());
/** * Drops messages to/from other members and then closes the channel. Note that this member won't get excluded from * the view until failure detection has kicked in and the new coord installed the new view */ public static void shutdown(JChannel ch) throws Exception { DISCARD discard=new DISCARD(); discard.setLocalAddress(ch.getAddress()); discard.setDiscardAll(true); ProtocolStack stack=ch.getProtocolStack(); TP transport=stack.getTransport(); stack.insertProtocol(discard,ProtocolStack.Position.ABOVE,transport.getClass()); //abruptly shutdown FD_SOCK just as in real life when member gets killed non gracefully FD_SOCK fd=ch.getProtocolStack().findProtocol(FD_SOCK.class); if(fd != null) fd.stopServerSocket(false); View view=ch.getView(); if(view != null) { ViewId vid=view.getViewId(); List<Address> members=Collections.singletonList(ch.getAddress()); ViewId new_vid=new ViewId(ch.getAddress(),vid.getId() + 1); View new_view=new View(new_vid,members); // inject view in which the shut down member is the only element GMS gms=stack.findProtocol(GMS.class); gms.installView(new_view); } Util.close(ch); }
/** * 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; }
insertProtocol(prot, position, neighbor.getClass());
private void discardOtherMembers() { List<Address> outsideMembers = new ArrayList<>(); for (Address a : allMembers) { boolean inThisPartition = false; for (JChannel c : channels) { if (c.getAddress().equals(a)) inThisPartition = true; } if (!inThisPartition) outsideMembers.add(a); } for (JChannel c : channels) { DISCARD discard = new DISCARD(); for (Address a : outsideMembers) discard.addIgnoreMember(a); try { c.getProtocolStack().insertProtocol(discard, ProtocolStack.Position.ABOVE, TP.class); } catch (Exception e) { throw new RuntimeException(e); } } }
stack.insertProtocol(fork, ProtocolStack.ABOVE, topProtocol.getClass());
stack.insertProtocol(fork, ProtocolStack.ABOVE, topProtocol.getClass());
public static DISCARD getDiscardForCache(EmbeddedCacheManager cacheManager) throws Exception { JGroupsTransport jgt = (JGroupsTransport) TestingUtil.extractGlobalComponent(cacheManager, Transport.class); JChannel ch = jgt.getChannel(); ProtocolStack ps = ch.getProtocolStack(); DISCARD discard = new DISCARD(); discard.setExcludeItself(false); ps.insertProtocol(discard, ProtocolStack.Position.ABOVE, TP.class); return discard; }
/** * Drops messages to/from other members and then closes the channel. Note that this member won't get excluded from * the view until failure detection has kicked in and the new coord installed the new view */ public static void shutdown(JChannel ch) throws Exception { DISCARD discard=new DISCARD(); discard.setLocalAddress(ch.getAddress()); discard.setDiscardAll(true); ProtocolStack stack=ch.getProtocolStack(); TP transport=stack.getTransport(); stack.insertProtocol(discard,ProtocolStack.Position.ABOVE,transport.getClass()); //abruptly shutdown FD_SOCK just as in real life when member gets killed non gracefully FD_SOCK fd=ch.getProtocolStack().findProtocol(FD_SOCK.class); if(fd != null) fd.stopServerSocket(false); View view=ch.getView(); if(view != null) { ViewId vid=view.getViewId(); List<Address> members=Collections.singletonList(ch.getAddress()); ViewId new_vid=new ViewId(ch.getAddress(),vid.getId() + 1); View new_view=new View(new_vid,members); // inject view in which the shut down member is the only element GMS gms=stack.findProtocol(GMS.class); gms.installView(new_view); } Util.close(ch); }
Configurator.resolveAndAssignFields(sasl, props); Configurator.resolveAndInvokePropertyMethods(sasl, props); channel.getProtocolStack().insertProtocol(sasl, ProtocolStack.Position.BELOW, GMS.class); sasl.init();
/** * Inserts a DELAY protocol in the JGroups stack used by the cache, and returns it. * The DELAY protocol can then be used to inject delays in milliseconds both at receiver * and sending side. * @param cache * @param in_delay_millis * @param out_delay_millis * @return a reference to the DELAY instance being used by the JGroups stack * @throws Exception */ public static DELAY setDelayForCache(Cache<?, ?> cache, int in_delay_millis, int out_delay_millis) throws Exception { JGroupsTransport jgt = (JGroupsTransport) TestingUtil.extractComponent(cache, Transport.class); JChannel ch = jgt.getChannel(); ProtocolStack ps = ch.getProtocolStack(); DELAY delay = ps.findProtocol(DELAY.class); if (delay==null) { delay = new DELAY(); ps.insertProtocol(delay, ProtocolStack.Position.ABOVE, TP.class); } delay.setInDelay(in_delay_millis); delay.setOutDelay(out_delay_millis); return delay; }
/** * Simulates a node crash, discarding all the messages from/to this node and then stopping the caches. */ public static void crashCacheManagers(EmbeddedCacheManager... cacheManagers) { for (EmbeddedCacheManager cm : cacheManagers) { JGroupsTransport t = (JGroupsTransport) cm.getGlobalComponentRegistry().getComponent(Transport.class); JChannel channel = t.getChannel(); try { DISCARD discard = new DISCARD(); discard.setDiscardAll(true); channel.getProtocolStack().insertProtocol(discard, ProtocolStack.Position.ABOVE, TP.class); } catch (Exception e) { log.warn("Problems inserting discard", e); throw new RuntimeException(e); } View view = View.create(channel.getAddress(), 100, channel.getAddress()); ((GMS) channel.getProtocolStack().findProtocol(GMS.class)).installView(view); } killCacheManagers(cacheManagers); }