/** * 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); }
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); } } }
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); }
/** * 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); }