public void start() throws Exception { int c; channel = new JChannel(); channel.connect("PullPushTestMux"); adapter = new PullPushAdapter(channel); adapter.setListener(this); listeners = new MyListener[10]; for (int i = 0; i < listeners.length; i++) { listeners[i] = new MyListener(i, adapter); } while ((c = choice()) != 'q') { c -= 48; if (c < 0 || c > 9) { System.err.println("Choose between 0 and 9"); continue; } if (c == 0) adapter.send(new Message(null, null, "Message from default message listener")); else listeners[c].sendMessage(); } channel.close(); System.exit(0); }
@Override public void stop() { try { if (stopChannel && channel != null && channel.isOpen()) { log.disconnectAndCloseJGroups(); // Unregistering before disconnecting/closing because // after that the cluster name is null if (globalStatsEnabled) { JmxConfigurator.unregisterChannel( (JChannel) channel, mbeanServer, domain, channel.getClusterName()); } channel.disconnect(); channel.close(); } } catch (Exception toLog) { log.problemClosingChannel(toLog); } channel = null; if (dispatcher != null) { log.stoppingRpcDispatcher(); dispatcher.stop(); } members = Collections.emptyList(); coordinator = null; isCoordinator = false; dispatcher = null; }
@Override public void channelConnected(Channel channel) { // Validate view String localName = channel.getName(); Address localAddress = channel.getAddress(); for (Address address : channel.getView()) { String name = channel.getName(address); if ((name != null) && name.equals(localName) && !address.equals(localAddress)) { channel.close(); throw JGroupsLogger.ROOT_LOGGER.duplicateNodeName( this.factory.getValue().getProtocolStackConfiguration().getEnvironment().getNodeName()); } } }
@Override public synchronized void shutdown() { if (channel != null) { // Mark this as not accepting any more ... isOpen.set(false); try { // Disconnect from the channel and close it ... channel.removeChannelListener(listener); channel.setReceiver(null); channel.close(); } finally { channel = null; // Now that we're not receiving any more messages, shut down the delegate delegate.shutdown(); } } }
@AfterClass protected void tearDown() throws Exception { disp.stop(); channel.close(); }