org.apache.catalina.tribes.Channel Java Examples
The following examples show how to use
org.apache.catalina.tribes.Channel.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChannelCoordinator.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Send a message to one or more members in the cluster * @param destination Member[] - the destinations, null or zero length means all * @param msg ClusterMessage - the message to send * @param payload TBA */ @Override public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException { if ( destination == null ) destination = membershipService.getMembers(); if ((msg.getOptions()&Channel.SEND_OPTIONS_MULTICAST) == Channel.SEND_OPTIONS_MULTICAST) { membershipService.broadcast(msg); } else { clusterSender.sendMessage(msg,destination); } if ( Logs.MESSAGES.isTraceEnabled() ) { Logs.MESSAGES.trace("ChannelCoordinator - Sent msg:" + new UniqueId(msg.getUniqueId()) + " at " + new java.sql.Timestamp(System.currentTimeMillis()) + " to " + Arrays.toNameString(destination)); } }
Example #2
Source File: SimpleTcpCluster.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * send a cluster message to one member * * @param msg message to transfer * @param dest Receiver member * @see org.apache.catalina.ha.CatalinaCluster#send(org.apache.catalina.ha.ClusterMessage, * org.apache.catalina.tribes.Member) */ @Override public void send(ClusterMessage msg, Member dest) { try { msg.setAddress(getLocalMember()); int sendOptions = channelSendOptions; if (msg instanceof SessionMessage && ((SessionMessage)msg).getEventType() == SessionMessage.EVT_ALL_SESSION_DATA) { sendOptions = Channel.SEND_OPTIONS_SYNCHRONIZED_ACK|Channel.SEND_OPTIONS_USE_ACK; } if (dest != null) { if (!getLocalMember().equals(dest)) { channel.send(new Member[] {dest}, msg, sendOptions); } else log.error(sm.getString("simpleTcpCluster.unableSend.localMember", msg)); } else { Member[] destmembers = channel.getMembers(); if (destmembers.length>0) channel.send(destmembers,msg, sendOptions); else if (log.isDebugEnabled()) log.debug("No members in cluster, ignoring message:"+msg); } } catch (Exception x) { log.error(sm.getString("simpleTcpCluster.sendFailed"), x); } }
Example #3
Source File: MapDemo.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Main method * @param args * @throws Exception */ @SuppressWarnings("unused") public static void main(String[] args) throws Exception { long start = System.currentTimeMillis(); //create a channel object ManagedChannel channel = (ManagedChannel) ChannelCreator.createChannel(args); //define a map name, unless one is defined as a paramters String mapName = "MapDemo"; if ( args.length > 0 && (!args[args.length-1].startsWith("-"))) { mapName = args[args.length-1]; } //start the channel channel.start(Channel.DEFAULT); //listen for shutdown Runtime.getRuntime().addShutdownHook(new Shutdown(channel)); //create a map demo object new MapDemo(channel,mapName); //put the main thread to sleep until we are done System.out.println("System test complete, time to start="+(System.currentTimeMillis()-start)+" ms. Sleeping to let threads finish."); Thread.sleep(60 * 1000 * 60); }
Example #4
Source File: TestGroupChannelOptionFlag.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Test public void testOptionNoConflict() throws Exception { boolean error = false; channel.setOptionCheck(true); ChannelInterceptor i = new TestInterceptor(); i.setOptionFlag(128); channel.addInterceptor(i); i = new TestInterceptor(); i.setOptionFlag(64); channel.addInterceptor(i); i = new TestInterceptor(); i.setOptionFlag(256); channel.addInterceptor(i); try { channel.start(Channel.DEFAULT); }catch ( ChannelException x ) { if ( x.getMessage().indexOf("option flag conflict") >= 0 ) error = true; } assertFalse(error); }
Example #5
Source File: TestMulticastPackages.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { channel1 = new GroupChannel(); channel1.addInterceptor(new MessageDispatch15Interceptor()); channel2 = new GroupChannel(); channel2.addInterceptor(new MessageDispatch15Interceptor()); ThroughputInterceptor tint = new ThroughputInterceptor(); tint.setInterval(500); ThroughputInterceptor tint2 = new ThroughputInterceptor(); tint2.setInterval(500); //channel1.addInterceptor(tint); channel2.addInterceptor(tint2); listener1 = new Listener(); ReceiverBase rb1 = (ReceiverBase)channel1.getChannelReceiver(); ReceiverBase rb2 = (ReceiverBase)channel2.getChannelReceiver(); rb1.setUdpPort(50000); rb2.setUdpPort(50000); channel2.addChannelListener(listener1); TesterUtil.addRandomDomain(new ManagedChannel[] {channel1, channel2}); channel1.start(Channel.DEFAULT); channel2.start(Channel.DEFAULT); }
Example #6
Source File: TestTcpFailureDetector.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void testTcpSendFailureMemberDrop() throws Exception { System.out.println("testTcpSendFailureMemberDrop()"); clear(); channel1.start(Channel.DEFAULT); channel2.start(Channel.DEFAULT); //Thread.sleep(1000); Assert.assertEquals("Expecting member count to be equal",mbrlist1.members.size(),mbrlist2.members.size()); channel2.stop(Channel.SND_RX_SEQ); ByteMessage msg = new ByteMessage(new byte[1024]); try { channel1.send(channel1.getMembers(), msg, 0); Assert.fail("Message send should have failed."); } catch ( ChannelException x ) { // Ignore } Assert.assertEquals("Expecting member count to not be equal",mbrlist1.members.size()+1,mbrlist2.members.size()); channel1.stop(Channel.DEFAULT); channel2.stop(Channel.DEFAULT); }
Example #7
Source File: TestEncryptInterceptor.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void test192BitKey() throws Exception { Assume.assumeTrue("Skipping test192BitKey because the JVM does not support it", 192 <= Cipher.getMaxAllowedKeyLength("AES")); src.setEncryptionKey(encryptionKey192); dest.setEncryptionKey(encryptionKey192); src.start(Channel.SND_TX_SEQ); dest.start(Channel.SND_TX_SEQ); String testInput = "The quick brown fox jumps over the lazy dog."; Assert.assertEquals("Failed to set custom provider name", testInput, roundTrip(testInput, src, dest)); }
Example #8
Source File: MembersWithProperties.java From Tomcat8-Source-Read with MIT License | 6 votes |
@SuppressWarnings("unused") public static void main(String[] args) throws Exception { if (args.length==0) usage(); main = Thread.currentThread(); ManagedChannel channel = (ManagedChannel) ChannelCreator.createChannel(args); Properties props = new Properties(); props.setProperty("mydomainkey","mydomainvalue"); props.setProperty("someotherkey", Arrays.toString(UUIDGenerator.randomUUID(true))); new MembersWithProperties(channel, props); channel.start(Channel.DEFAULT); Runtime.getRuntime().addShutdownHook(new Shutdown(channel)); try { Thread.sleep(Long.MAX_VALUE); }catch(InterruptedException ix) { Thread.sleep(5000);//allow everything to shutdown } }
Example #9
Source File: CoordinationDemo.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
public void start() { try { if ( channel == null ) { channel = createChannel(); startstatus = "starting"; channel.start(Channel.DEFAULT); startstatus = "running"; } else { status = "Channel already started."; } } catch ( Exception x ) { synchronized (System.err) { System.err.println("Start failed:"); StackTraceElement[] els = x.getStackTrace(); for (int i = 0; i < els.length; i++) System.err.println(els[i].toString()); } status = "Start failed:"+x.getMessage(); error = x; startstatus = "failed"; try { channel.stop(Channel.DEFAULT);}catch(Exception ignore){ // Ignore } channel = null; interceptor = null; } }
Example #10
Source File: McastService.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Override public void broadcast(ChannelMessage message) throws ChannelException { if (impl==null || (impl.startLevel & Channel.MBR_TX_SEQ)!=Channel.MBR_TX_SEQ ) throw new ChannelException("Multicast send is not started or enabled."); byte[] data = XByteBuffer.createDataPackage((ChannelData)message); if (data.length>McastServiceImpl.MAX_PACKET_SIZE) { throw new ChannelException("Packet length["+data.length+"] exceeds max packet size of "+McastServiceImpl.MAX_PACKET_SIZE+" bytes."); } DatagramPacket packet = new DatagramPacket(data,0,data.length); try { impl.send(false, packet); } catch (Exception x) { throw new ChannelException(x); } }
Example #11
Source File: TestEncryptInterceptor.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void testPickup() throws Exception { File file = new File(MESSAGE_FILE); if(!file.exists()) { System.err.println("File message.bin does not exist. Skipping test."); return; } dest.start(Channel.SND_TX_SEQ); byte[] bytes = new byte[8192]; int read; try (FileInputStream in = new FileInputStream(file)) { read = in.read(bytes); } ChannelData msg = new ChannelData(false); XByteBuffer xbb = new XByteBuffer(read, false); xbb.append(bytes, 0, read); msg.setMessage(xbb); dest.messageReceived(msg); }
Example #12
Source File: McastService.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override public void broadcast(ChannelMessage message) throws ChannelException { if (impl==null || (impl.startLevel & Channel.MBR_TX_SEQ)!=Channel.MBR_TX_SEQ ) throw new ChannelException("Multicast send is not started or enabled."); byte[] data = XByteBuffer.createDataPackage((ChannelData)message); if (data.length>McastServiceImpl.MAX_PACKET_SIZE) { throw new ChannelException("Packet length["+data.length+"] exceeds max packet size of "+McastServiceImpl.MAX_PACKET_SIZE+" bytes."); } DatagramPacket packet = new DatagramPacket(data,0,data.length); try { impl.send(false, packet); } catch (Exception x) { throw new ChannelException(x); } }
Example #13
Source File: EchoRpcTest.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void run() { long counter = 0; while (counter<count) { String msg = message + " cnt="+(++counter); try { System.out.println("Sending ["+msg+"]"); long start = System.currentTimeMillis(); Response[] resp = rpc.send(channel.getMembers(),msg,options,Channel.SEND_OPTIONS_DEFAULT,timeout); System.out.println("Send of ["+msg+"] completed. Nr of responses="+resp.length+" Time:"+(System.currentTimeMillis()-start)+" ms."); for ( int i=0; i<resp.length; i++ ) { System.out.println("Received a response message from ["+resp[i].getSource().getName()+"] with data ["+resp[i].getMessage()+"]"); } Thread.sleep(pause); }catch(Exception x){ // Ignore } } }
Example #14
Source File: TestNonBlockingCoordinator.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testCoord2() throws Exception { Member member = coordinators[1].getCoordinator(); System.out.println("Coordinator[2a] is:" + member); int index = -1; for ( int i=0; i<CHANNEL_COUNT; i++ ) { if ( channels[i].getLocalMember(false).equals(member) ) { System.out.println("Shutting down:" + channels[i].getLocalMember(true).toString()); channels[i].stop(Channel.DEFAULT); index = i; } } int dead = index; Thread.sleep(1000); if (index == 0) { index = 1; } else { index = 0; } System.out.println("Member count:"+channels[index].getMembers().length); member = coordinators[index].getCoordinator(); for (int i = 1; i < CHANNEL_COUNT; i++) { if (i != dead) { Assert.assertEquals(member, coordinators[i].getCoordinator()); } } System.out.println("Coordinator[2b] is:" + member); }
Example #15
Source File: TestEncryptInterceptor.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testBasic() throws Exception { src.start(Channel.SND_TX_SEQ); dest.start(Channel.SND_TX_SEQ); String testInput = "The quick brown fox jumps over the lazy dog."; Assert.assertEquals("Basic roundtrip failed", testInput, roundTrip(testInput, src, dest)); }
Example #16
Source File: TestGroupChannelStartStop.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Test public void testUdpReceiverStart() throws Exception { ReceiverBase rb = (ReceiverBase)channel.getChannelReceiver(); rb.setUdpPort(udpPort); channel.start(Channel.DEFAULT); Thread.sleep(1000); channel.stop(Channel.DEFAULT); }
Example #17
Source File: McastServiceImpl.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Start the service * @param level 1 starts the receiver, level 2 starts the sender * @throws IOException if the service fails to start * @throws IllegalStateException if the service is already started */ public synchronized void start(int level) throws IOException { boolean valid = false; if ( (level & Channel.MBR_RX_SEQ)==Channel.MBR_RX_SEQ ) { if ( receiver != null ) throw new IllegalStateException(sm.getString("mcastServiceImpl.receive.running")); try { if ( sender == null ) socket.joinGroup(address); }catch (IOException iox) { log.error(sm.getString("mcastServiceImpl.unable.join")); throw iox; } doRunReceiver = true; receiver = new ReceiverThread(); receiver.setDaemon(true); receiver.start(); valid = true; } if ( (level & Channel.MBR_TX_SEQ)==Channel.MBR_TX_SEQ ) { if ( sender != null ) throw new IllegalStateException(sm.getString("mcastServiceImpl.send.running")); if ( receiver == null ) socket.joinGroup(address); //make sure at least one packet gets out there send(false); doRunSender = true; sender = new SenderThread(sendFrequency); sender.setDaemon(true); sender.start(); //we have started the receiver, but not yet waited for membership to establish valid = true; } if (!valid) { throw new IllegalArgumentException(sm.getString("mcastServiceImpl.invalid.startLevel")); } //pause, once or twice waitForMembers(level); startLevel = (startLevel | level); }
Example #18
Source File: McastServiceImpl.java From Tomcat8-Source-Read with MIT License | 5 votes |
public boolean startService() { try { parent.init(); parent.start(Channel.MBR_RX_SEQ | Channel.MBR_TX_SEQ); return true; } catch (Exception x) { log.warn(sm.getString("mcastServiceImpl.recovery.startFailed"), x); return false; } }
Example #19
Source File: TestDataIntegrity.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Test public void testDataSendSYNCACK() throws Exception { System.err.println("Starting SYNC_ACK"); for (int i=0; i<msgCount; i++) channel1.send(new Member[] {channel2.getLocalMember(false)},Data.createRandomData(),Channel.SEND_OPTIONS_SYNCHRONIZED_ACK|Channel.SEND_OPTIONS_USE_ACK); Thread.sleep(250); System.err.println("Finished SYNC_ACK"); assertEquals("Checking success messages.",msgCount,listener1.count); }
Example #20
Source File: TestUdpPackages.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Test public void testDataSendACK() throws Exception { System.err.println("Starting ACK"); for (int i=0; i<msgCount; i++) channel1.send(new Member[] {channel2.getLocalMember(false)},Data.createRandomData(1024),Channel.SEND_OPTIONS_USE_ACK|Channel.SEND_OPTIONS_UDP); Thread.sleep(250); System.err.println("Finished ACK"); assertEquals("Checking success messages.",msgCount,listener1.count.get()); }
Example #21
Source File: EchoRpcTest.java From tomcatsrc with Apache License 2.0 | 5 votes |
public EchoRpcTest(Channel channel, String name, int count, String message, long pause, int options, long timeout) { this.channel = channel; this.count = count; this.message = message; this.pause = pause; this.options = options; this.rpc = new RpcChannel(name.getBytes(),channel,this); this.timeout = timeout; this.name = name; }
Example #22
Source File: EchoRpcTest.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public void run() { System.out.println("Shutting down..."); SystemExit exit = new SystemExit(5000); exit.setDaemon(true); exit.start(); try { channel.stop(Channel.DEFAULT); }catch ( Exception x ) { x.printStackTrace(); } System.out.println("Channel stopped."); }
Example #23
Source File: TestTcpFailureDetector.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Test public void testTcpFailureMemberAdd() throws Exception { System.out.println("testTcpFailureMemberAdd()"); clear(); channel1.start(Channel.DEFAULT); channel2.start(Channel.SND_RX_SEQ); channel2.start(Channel.SND_TX_SEQ); channel2.start(Channel.MBR_RX_SEQ); channel2.stop(Channel.SND_RX_SEQ); channel2.start(Channel.MBR_TX_SEQ); //Thread.sleep(1000); assertEquals("Expecting member count to not be equal",mbrlist1.members.size()+1,mbrlist2.members.size()); channel1.stop(Channel.DEFAULT); channel2.stop(Channel.DEFAULT); }
Example #24
Source File: McastServiceImpl.java From tomcatsrc with Apache License 2.0 | 5 votes |
public boolean stopService() { try { parent.stop(Channel.MBR_RX_SEQ | Channel.MBR_TX_SEQ); return true; } catch (Exception x) { log.warn("Recovery thread failed to stop membership service.", x); return false; } }
Example #25
Source File: TestNonBlockingCoordinator.java From tomcatsrc with Apache License 2.0 | 5 votes |
@After public void tearDown() throws Exception { System.out.println("tearDown"); for ( int i=0; i<CHANNEL_COUNT; i++ ) { channels[i].stop(Channel.DEFAULT); } }
Example #26
Source File: TestEncryptInterceptor.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testMultipleMessages() throws Exception { src.start(Channel.SND_TX_SEQ); dest.start(Channel.SND_TX_SEQ); String testInput = "The quick brown fox jumps over the lazy dog."; Assert.assertEquals("Basic roundtrip failed", testInput, roundTrip(testInput, src, dest)); Assert.assertEquals("Second roundtrip failed", testInput, roundTrip(testInput, src, dest)); Assert.assertEquals("Third roundtrip failed", testInput, roundTrip(testInput, src, dest)); Assert.assertEquals("Fourth roundtrip failed", testInput, roundTrip(testInput, src, dest)); Assert.assertEquals("Fifth roundtrip failed", testInput, roundTrip(testInput, src, dest)); }
Example #27
Source File: RpcChannel.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Send a message and wait for the response. * @param destination Member[] - the destination for the message, and the members you request a reply from * @param message Serializable - the message you are sending out * @param rpcOptions int - FIRST_REPLY, MAJORITY_REPLY or ALL_REPLY * @param channelOptions channel sender options * @param timeout long - timeout in milliseconds, if no reply is received within this time null is returned * @return Response[] - an array of response objects. * @throws ChannelException */ public Response[] send(Member[] destination, Serializable message, int rpcOptions, int channelOptions, long timeout) throws ChannelException { if ( destination==null || destination.length == 0 ) return new Response[0]; //avoid dead lock int sendOptions = channelOptions & ~Channel.SEND_OPTIONS_SYNCHRONIZED_ACK; RpcCollectorKey key = new RpcCollectorKey(UUIDGenerator.randomUUID(false)); RpcCollector collector = new RpcCollector(key,rpcOptions,destination.length); try { synchronized (collector) { if ( rpcOptions != NO_REPLY ) responseMap.put(key, collector); RpcMessage rmsg = new RpcMessage(rpcId, key.id, message); channel.send(destination, rmsg, sendOptions); if ( rpcOptions != NO_REPLY ) collector.wait(timeout); } } catch ( InterruptedException ix ) { Thread.currentThread().interrupt(); } finally { responseMap.remove(key); } return collector.getResponses(); }
Example #28
Source File: TestNonBlockingCoordinator.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { System.out.println("Setup"); channels = new GroupChannel[CHANNEL_COUNT]; coordinators = new NonBlockingCoordinator[CHANNEL_COUNT]; Thread[] threads = new Thread[CHANNEL_COUNT]; for ( int i=0; i<CHANNEL_COUNT; i++ ) { channels[i] = new GroupChannel(); coordinators[i] = new NonBlockingCoordinator(); channels[i].addInterceptor(coordinators[i]); channels[i].addInterceptor(new TcpFailureDetector()); final int j = i; threads[i] = new Thread() { @Override public void run() { try { channels[j].start(Channel.DEFAULT); Thread.sleep(50); } catch (Exception x) { x.printStackTrace(); } } }; } TesterUtil.addRandomDomain(channels); for (int i = 0; i < CHANNEL_COUNT; i++) { threads[i].start(); } for (int i = 0; i < CHANNEL_COUNT; i++) { threads[i].join(); } Thread.sleep(1000); }
Example #29
Source File: TestMulticastPackages.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Test public void testDataSendSYNCACK() throws Exception { System.err.println("Starting SYNC_ACK"); for (int i=0; i<msgCount; i++) channel1.send(new Member[] {channel2.getLocalMember(false)},Data.createRandomData(1024),Channel.SEND_OPTIONS_SYNCHRONIZED_ACK|Channel.SEND_OPTIONS_USE_ACK|Channel.SEND_OPTIONS_MULTICAST); Thread.sleep(250); System.err.println("Finished SYNC_ACK"); assertEquals("Checking success messages.",msgCount,listener1.count.get()); }
Example #30
Source File: TestEncryptInterceptor.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testLargePayload() throws Exception { src.start(Channel.SND_TX_SEQ); dest.start(Channel.SND_TX_SEQ); byte[] bytes = new byte[1024*1024]; Assert.assertArrayEquals("Huge payload roundtrip failed", bytes, roundTrip(bytes, src, dest)); }