/** * 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); }
@Override public ModelNode execute(ExpressionResolver expressionResolver, ModelNode operation, ChannelFactory factory) throws OperationFailedException { // Create a temporary channel, but don't connect it try (JChannel channel = factory.createChannel(UUID.randomUUID().toString())) { // ProtocolStack.printProtocolSpecAsXML() is very hacky and only works on an uninitialized stack List<Protocol> protocols = channel.getProtocolStack().getProtocols(); Collections.reverse(protocols); ProtocolStack stack = new ProtocolStack(); stack.addProtocols(protocols); return new ModelNode(stack.printProtocolSpecAsXML()); } catch (Exception e) { throw new OperationFailedException(e); } } },
public void init() throws Exception { super.init(); if(site == null || site.isEmpty()) throw new IllegalArgumentException("\"site\" must be set"); timer=getTransport().getTimer(); JChannel channel=getProtocolStack().getChannel(); if(channel == null) throw new IllegalStateException("channel must be set"); channel.addAddressGenerator(() -> ExtendedUUID.randomUUID().put(SITE_ID, Util.stringToBytes(site))); }
public <T extends Protocol> T removeProtocol(Class<? extends Protocol> prot) { if(prot == null) return null; return removeProtocol((T)findProtocol(prot)); }
/** * Start all layers. The {@link Protocol#start()} method is called in each protocol, * <em>from top to bottom</em>. * Each layer can perform some initialization, e.g. create a multicast socket */ public void startStack() throws Exception { if(!stopped) return; for(Protocol prot: getProtocols()) prot.start(); TP transport=getTransport(); transport.registerProbeHandler(props_handler); stopped=false; }
public void insertProtocol(Protocol prot, Position position, Class<? extends Protocol> neighbor_prot) throws Exception { if(neighbor_prot == null) throw new IllegalArgumentException("neighbor_prot is null"); Protocol neighbor=findProtocol(neighbor_prot); if(neighbor == null) throw new IllegalArgumentException("protocol \"" + neighbor_prot + "\" not found in " + stack.printProtocolSpec(false)); if(position == Position.BELOW && neighbor instanceof TP) throw new IllegalArgumentException("\"" + prot + "\" cannot be inserted below the transport (" + neighbor + ")"); insertProtocolInStack(prot, neighbor, position); }
List<Address> members = new ArrayList<>(); members.add(new UUID(0, 0));// TODO open a JGroups JIRA for GEODE-3034 View jgv = new View(vid, members); this.myChannel.down(new Event(Event.VIEW_CHANGE, jgv)); UUID logicalAddress = (UUID) myChannel.getAddress(); if (logicalAddress instanceof JGAddress) { ((JGAddress) logicalAddress).setVmViewId(-1); myChannel = new JChannel(is); StatRecorder sr = (StatRecorder) myChannel.getProtocolStack().findProtocol(StatRecorder.class); if (sr != null) { sr.setServices(services); Transport transport = (Transport) myChannel.getProtocolStack().getTransport(); transport.setMessenger(this);
final JChannel ch=new JChannel(props); if(name != null) ch.setName(name); ch.setReceiver(new ReceiverAdapter() { public void receive(Message msg) { Address sender=msg.getSrc(); RELAY2 relay=ch.getProtocolStack().findProtocol(RELAY2.class); relay.setRouteStatusListener(new RouteStatusListener() { public void sitesUp(String... sites) { String line=Util.readStringFromStdin(": "); ch.send(null, line);
public void init(String props, String name, AddressGenerator generator, int bind_port) throws Throwable { channel=new JChannel(props).addAddressGenerator(generator).setName(name); if(bind_port > 0) { TP transport=channel.getProtocolStack().getTransport(); transport.setBindPort(bind_port); } disp=new RpcDispatcher(channel, this).setMembershipListener(this).setMethodLookup(id -> METHODS[id]) .setMarshaller(new UPerfMarshaller()); channel.connect(groupname); local_addr=channel.getAddress(); try { MBeanServer server=Util.getMBeanServer(); JmxConfigurator.registerChannel(channel, server, "jgroups", channel.getClusterName(), true); } catch(Throwable ex) { System.err.println("registering the channel in JMX failed: " + ex); } if(members.size() < 2) return; Address coord=members.get(0); Config config=disp.callRemoteMethod(coord, new MethodCall(GET_CONFIG), new RequestOptions(ResponseMode.GET_ALL, 5000)); if(config != null) { applyConfig(config); System.out.println("Fetched config from " + coord + ": " + config + "\n"); } else System.err.println("failed to fetch config from " + coord); }
@ManagedOperation public void start() throws Exception { if(hash_function_factory != null) { hash_function=hash_function_factory.create(); } if(hash_function == null) hash_function=new ConsistentHashFunction<>(); ch=new JChannel(props); disp=new RpcDispatcher(ch, this).setMethodLookup(methods::get).setMembershipListener(this); Marshaller marshaller=new CustomMarshaller(); disp.setMarshaller(marshaller); ch.connect(cluster_name); local_addr=ch.getAddress(); view=ch.getView(); timer=ch.getProtocolStack().getTransport().getTimer(); l2_cache.addChangeListener(this); }
public void start(String ... options) throws Exception { String props="udp.xml", name=null; options(options); if(options !=null) { for(int i=0; i < options.length; i++) { if(options[i].startsWith("-props")) { props=options[++i]; continue; } if(options[i].startsWith("-name")) { name=options[++i]; } } } ch=new JChannel(props).name(name).receiver(this); TP transport=ch.getProtocolStack().getTransport(); // uncomment below to disable the regular and OOB thread pools // transport.setOOBThreadPool(new DirectExecutor()); // transport.setDefaultThreadPool(new DirectExecutor()); //ThreadPoolExecutor thread_pool=new ThreadPoolExecutor(4, 4, 30000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(5000)); //transport.setDefaultThreadPool(thread_pool); //transport.setOOBThreadPool(thread_pool); //transport.setInternalThreadPool(thread_pool); ch.connect("rt"); View v=ch.getView(); if(v.size() > 2) throw new IllegalStateException(String.format("More than 2 members found (%s); terminating\n", v)); }
throw new IllegalArgumentException("operation " + operation + " is missing the protocol name"); String prot_name=operation.substring(0, index); Protocol prot=ch.getProtocolStack().findProtocol(prot_name); if(prot == null) return; // less drastic than throwing an exception... if(end_index == -1) throw new IllegalArgumentException("] not found"); List<String> str_args=Util.parseCommaDelimitedStrings(operation.substring(args_index + 1, end_index)); Object[] strings=str_args.toArray(); args=new String[strings.length]; log.warn(Util.getMessage("MethodNotFound"), ch.getAddress(), target.getClass().getSimpleName(), method_name); return; Class<?>[] types=method.getParameterTypes(); for(int i=0; i < args.length; i++) converted_args[i]=Util.convert(args[i], types[i]);
public Map<String, String> handleProbe(String... keys) { for(String key: keys) { if(Objects.equals(key, "props")) { String tmp=printProtocolSpec(true); HashMap<String, String> map=new HashMap<>(1); map.put("props", tmp); List<Protocol> prots=getProtocols(); Collections.reverse(prots); StringBuilder sb=new StringBuilder(); for(Protocol prot: prots) sb.append(prot.getName()).append("\n"); HashMap<String, String> map=new HashMap<>(1); map.put("protocols", sb.toString()); String rest=key.substring(index +1); if(rest != null && !rest.isEmpty()) { List<String> prots=Util.parseCommaDelimitedStrings(rest); if(!prots.isEmpty()) { for(String p: prots) { List<Protocol> protocols=findProtocols(p); if(protocols != null && !protocols.isEmpty()) { for(Protocol prot_to_remove: protocols) { try { Protocol removed=removeProtocol(prot_to_remove); if(removed != null) log.debug("removed protocol %s from stack", prot_to_remove.getName()); if(findProtocol(prot_name) != null) { log.error("Protocol %s cannot be inserted as it is already present", prot_name);
@ManagedOperation(description="Inject a view (example of view string format: A=A/B/C;B=B/C;C=C)") public synchronized void injectView(String newView) { try { log.info("Received request to inject view %s", newView); String[] perNode = newView.split(NODE_VIEWS_SEPARATOR); String thisNodeAddress = getProtocolStack().getChannel().getAddressAsString(); log.info("[channel: %s] Injecting a new view: %s", thisNodeAddress, nodeView); long viewId = getProtocolStack().getChannel().getView().getViewId().getId()+1; List<Address> nodes = new ArrayList<>(); for( Map.Entry<Address, String> entry : NameCache.getContents().entrySet() ) { if( nodeName.equals(entry.getValue()) ){ log.debug("[channel: %s] Found name: <%s> for address: <%s>", entry.getValue(), entry.getKey().toString()); nodes.add( entry.getKey() ); break; View view = new View( nodes.get(0), viewId, nodes); GMS gms = getProtocolStack().findProtocol(GMS.class); gms.installView(view); log.info("[channel: %s] Injection finished of view: %s", thisNodeAddress, nodeView);
public <X extends MessageDispatcher> X start() { if(corr == null) corr=createRequestCorrelator(prot_adapter, this, local_addr) .asyncDispatching(async_dispatching).wrapExceptions(this.wrap_exceptions); correlatorStarted(); corr.start(); if(channel != null) { List<Address> tmp_mbrs=channel.getView() != null ? channel.getView().getMembers() : null; setMembers(tmp_mbrs); if(channel instanceof JChannel) { TP transport=channel.getProtocolStack().getTransport(); corr.registerProbeHandler(transport); } } return (X)this; }
protocol_name=protocol_name.substring(0, index); String attrs=rest.substring(index +1); // e.g. "num_sent,msgs,num_received_msgs" list=Util.parseStringList(attrs, ","); String attrname=tmp.substring(0, index); String attrvalue=tmp.substring(index+1); Object target=ch.getProtocolStack().findProtocol(protocol_name); Field field=target != null? Util.getField(target.getClass(), attrname) : null; if(field == null && target instanceof AdditionalJmxObjects) { Object[] objs=((AdditionalJmxObjects)target).getJmxObjects(); if(objs != null && objs.length > 0) { for(Object o: objs) { field=o != null? Util.getField(o.getClass(), attrname) : null; if(field != null) { target=o; log.error("unable to invoke %s() on %s: %s", setter, protocol_name, e); log.warn(Util.getMessage("FieldNotFound"), attrname, protocol_name); setter=new ResourceDMBean.NoopAccessor(); tmp_stats=ch.dumpStats(protocol_name, list); if(tmp_stats != null) { for(Map.Entry<String,Object> entry : tmp_stats.entrySet()) { tmp_stats=ch.dumpStats(); if(tmp_stats != null) { for(Map.Entry<String,Object> entry : tmp_stats.entrySet()) {
protected void loop() { for(;;) { int key=Util.keyPress("[1] Send multicast message [2] Send unicast message " + "[3] Set message size [4] Print credits MFC [5] Print credits UFC [q] quit"); switch(key) { Message msg=new Message(null, buf); try { ch.send(msg); msg=new Message(target, buf); try { ch.send(msg); case '3': try { int msg_size=Util.readIntFromStdin("New message size: "); buf=new byte[msg_size]; MFC mfc=ch.getProtocolStack().findProtocol(MFC.class); if(mfc == null) { System.err.println("MFC not found"); break; case '5': UFC ufc=ch.getProtocolStack().findProtocol(UFC.class); if(ufc == null) { System.err.println("UFC not found");
@Override public JChannel get() { try { JChannel channel = this.factory.get().createChannel(this.name); if (JGroupsLogger.ROOT_LOGGER.isTraceEnabled()) { JGroupsLogger.ROOT_LOGGER.tracef("JGroups channel %s created with configuration:%n %s", this.name, channel.getProtocolStack().printProtocolSpec(true)); } channel.stats(this.statisticsEnabled); if (this.server != null) { try { JmxConfigurator.registerChannel(channel, this.server.get(), this.name); } catch (Exception e) { JGroupsLogger.ROOT_LOGGER.debug(e.getLocalizedMessage(), e); } } channel.connect(this.cluster.get()); return channel; } catch (Exception e) { throw new IllegalStateException(e); } }
public void configure() throws Exception { timer=getTransport().getTimer(); if(site == null) throw new IllegalArgumentException("site cannot be null"); TP tp=getTransport(); if(tp.getUseIpAddresses()) throw new IllegalArgumentException(String.format("%s cannot be used if %s.use_ip_addrs is true", RELAY2.class.getSimpleName(), tp.getClass().getSimpleName())); if(max_site_masters < 1) { log.warn("max_size_masters was " + max_site_masters + ", changed to 1"); max_site_masters=1; Class<SiteMasterPicker> clazz=Util.loadClass(site_master_picker_impl, (Class)null); this.site_master_picker=clazz.newInstance(); if(site_config == null) throw new Exception("site configuration for \"" + site + "\" not found in " + config); log.trace(local_addr + ": site configuration:\n" + site_config); log.warn(local_addr + ": forwarding routes are currently not supported and will be ignored. This will change " + "with hierarchical routing (https://issues.jboss.org/browse/JGRP-1506)"); JChannel ch=getProtocolStack().getChannel(); ch.addAddressGenerator(() -> { ExtendedUUID retval=ExtendedUUID.randomUUID(); if(can_become_site_master)
public void setChannel(JChannel ch) { this.ch=ch; counter_prot=ch.getProtocolStack().findProtocol(COUNTER.class); if(counter_prot == null) throw new IllegalStateException("channel configuration must include the COUNTER protocol"); }