org.apache.catalina.tribes.ChannelMessage Java Examples
The following examples show how to use
org.apache.catalina.tribes.ChannelMessage.
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: 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 #2
Source File: ThroughputInterceptor.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Override public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException { if ( access.addAndGet(1) == 1 ) txStart = System.currentTimeMillis(); long bytes = XByteBuffer.getDataPackageLength(((ChannelData)msg).getDataPackageLength()); try { super.sendMessage(destination, msg, payload); }catch ( ChannelException x ) { msgTxErr.addAndGet(1); if ( access.get() == 1 ) access.addAndGet(-1); throw x; } mbTx += (bytes*destination.length)/(1024d*1024d); mbAppTx += bytes/(1024d*1024d); if ( access.addAndGet(-1) == 0 ) { long stop = System.currentTimeMillis(); timeTx += (stop - txStart) / 1000d; if ((msgTxCnt.get() / interval) >= lastCnt) { lastCnt++; report(timeTx); } } msgTxCnt.addAndGet(1); }
Example #3
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 #4
Source File: EncryptInterceptor.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void messageReceived(ChannelMessage msg) { try { byte[] data = msg.getMessage().getBytes(); data = encryptionManager.decrypt(data); XByteBuffer xbb = msg.getMessage(); // Completely replace the message with the decrypted one xbb.clear(); xbb.append(data, 0, data.length); super.messageReceived(msg); } catch (GeneralSecurityException gse) { log.error(sm.getString("encryptInterceptor.decrypt.failed"), gse); } }
Example #5
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 #6
Source File: NonBlockingCoordinator.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override public void messageReceived(ChannelMessage msg) { if ( Arrays.contains(msg.getMessage().getBytesDirect(),0,COORD_ALIVE,0,COORD_ALIVE.length) ) { //ignore message, its an alive message fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_MSG_ARRIVE,this,"Alive Message")); } else if ( Arrays.contains(msg.getMessage().getBytesDirect(),0,COORD_HEADER,0,COORD_HEADER.length) ) { try { CoordinationMessage cmsg = new CoordinationMessage(msg.getMessage()); Member[] cmbr = cmsg.getMembers(); fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_MSG_ARRIVE,this,"Coord Msg Arrived("+Arrays.toNameString(cmbr)+")")); processCoordMessage(cmsg); }catch ( ChannelException x ) { log.error(sm.getString("nonBlockingCoordinator.processCoordinationMessage.failed"),x); } } else { super.messageReceived(msg); } }
Example #7
Source File: ThroughputInterceptor.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException { if ( access.addAndGet(1) == 1 ) txStart = System.currentTimeMillis(); long bytes = XByteBuffer.getDataPackageLength(((ChannelData)msg).getDataPackageLength()); try { super.sendMessage(destination, msg, payload); }catch ( ChannelException x ) { msgTxErr.addAndGet(1); if ( access.get() == 1 ) access.addAndGet(-1); throw x; } mbTx += (bytes*destination.length)/(1024d*1024d); mbAppTx += bytes/(1024d*1024d); if ( access.addAndGet(-1) == 0 ) { long stop = System.currentTimeMillis(); timeTx += (stop - txStart) / 1000d; if ((msgTxCnt.get() / interval) >= lastCnt) { lastCnt++; report(timeTx); } } msgTxCnt.addAndGet(1); }
Example #8
Source File: OrderInterceptor.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Override public void messageReceived(ChannelMessage msg) { if ( !okToProcess(msg.getOptions()) ) { super.messageReceived(msg); return; } int msgnr = XByteBuffer.toInt(msg.getMessage().getBytesDirect(),msg.getMessage().getLength()-4); msg.getMessage().trim(4); MessageOrder order = new MessageOrder(msgnr,(ChannelMessage)msg.deepclone()); try { inLock.writeLock().lock(); if ( processIncoming(order) ) processLeftOvers(msg.getAddress(),false); }finally { inLock.writeLock().unlock(); } }
Example #9
Source File: McastService.java From Tomcat8-Source-Read with MIT License | 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(sm.getString("mcastService.noStart")); byte[] data = XByteBuffer.createDataPackage((ChannelData)message); if (data.length>McastServiceImpl.MAX_PACKET_SIZE) { throw new ChannelException(sm.getString("mcastService.exceed.maxPacketSize", Integer.toString(data.length) , Integer.toString(McastServiceImpl.MAX_PACKET_SIZE))); } DatagramPacket packet = new DatagramPacket(data,0,data.length); try { impl.send(false, packet); } catch (Exception x) { throw new ChannelException(x); } }
Example #10
Source File: SocketNioReceive.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Override public void messageReceived(ChannelMessage msg) { if (first) { first = false; start = System.currentTimeMillis(); } mb += ( (double) len) / 1024 / 1024; synchronized (this) {count++;} if ( ( (count) % 10000) == 0) { long time = System.currentTimeMillis(); seconds = ( (double) (time - start)) / 1000; System.out.println("Throughput " + df.format(mb / seconds) + " MB/seconds, messages "+count+", total "+mb+" MB."); } }
Example #11
Source File: TcpFailureDetector.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException { try { super.sendMessage(destination, msg, payload); }catch ( ChannelException cx ) { FaultyMember[] mbrs = cx.getFaultyMembers(); for ( int i=0; i<mbrs.length; i++ ) { if ( mbrs[i].getCause()!=null && (!(mbrs[i].getCause() instanceof RemoteProcessException)) ) {//RemoteProcessException's are ok this.memberDisappeared(mbrs[i].getMember()); }//end if }//for throw cx; } }
Example #12
Source File: ThroughputInterceptor.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public void messageReceived(ChannelMessage msg) { if ( rxStart == 0 ) rxStart = System.currentTimeMillis(); long bytes = XByteBuffer.getDataPackageLength(((ChannelData)msg).getDataPackageLength()); mbRx += bytes/(1024d*1024d); msgRxCnt.addAndGet(1); if ( msgRxCnt.get() % interval == 0 ) report(timeTx); super.messageReceived(msg); }
Example #13
Source File: TcpFailureDetector.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public void messageReceived(ChannelMessage msg) { //catch incoming boolean process = true; if ( okToProcess(msg.getOptions()) ) { //check to see if it is a testMessage, if so, process = false process = ( (msg.getMessage().getLength() != TCP_FAIL_DETECT.length) || (!Arrays.equals(TCP_FAIL_DETECT,msg.getMessage().getBytes()) ) ); }//end if //ignore the message, it doesnt have the flag set if ( process ) super.messageReceived(msg); else if ( log.isDebugEnabled() ) log.debug("Received a failure detector packet:"+msg); }
Example #14
Source File: FragmentationInterceptor.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public void messageReceived(ChannelMessage msg) { boolean isFrag = XByteBuffer.toBoolean(msg.getMessage().getBytesDirect(),msg.getMessage().getLength()-1); msg.getMessage().trim(1); if ( isFrag ) { defrag(msg); } else { super.messageReceived(msg); } }
Example #15
Source File: DomainFilterInterceptor.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public void messageReceived(ChannelMessage msg) { if (Arrays.equals(domain, msg.getAddress().getDomain())) { super.messageReceived(msg); } else { if (log.isWarnEnabled()) log.warn("Received message from cluster["+msg.getAddress()+"] was refused."); } }
Example #16
Source File: FragmentationInterceptor.java From tomcatsrc with Apache License 2.0 | 5 votes |
public void frag(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException { int size = msg.getMessage().getLength(); int count = ((size / maxSize )+(size%maxSize==0?0:1)); ChannelMessage[] messages = new ChannelMessage[count]; int remaining = size; for ( int i=0; i<count; i++ ) { ChannelMessage tmp = (ChannelMessage)msg.clone(); int offset = (i*maxSize); int length = Math.min(remaining,maxSize); tmp.getMessage().clear(); tmp.getMessage().append(msg.getMessage().getBytesDirect(),offset,length); //add the msg nr //tmp.getMessage().append(XByteBuffer.toBytes(i),0,4); tmp.getMessage().append(i); //add the total nr of messages //tmp.getMessage().append(XByteBuffer.toBytes(count),0,4); tmp.getMessage().append(count); //add true as the frag flag //byte[] flag = XByteBuffer.toBytes(true); //tmp.getMessage().append(flag,0,flag.length); tmp.getMessage().append(true); messages[i] = tmp; remaining -= length; } for ( int i=0; i<messages.length; i++ ) { super.sendMessage(destination,messages[i],payload); } }
Example #17
Source File: MessageDispatch15Interceptor.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public boolean addToQueue(ChannelMessage msg, Member[] destination, InterceptorPayload payload) { final LinkObject obj = new LinkObject(msg,destination,payload); Runnable r = new Runnable() { @Override public void run() { sendAsyncData(obj); } }; executor.execute(r); return true; }
Example #18
Source File: FragmentationInterceptor.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
public FragCollection getFragCollection(FragKey key, ChannelMessage msg) { FragCollection coll = fragpieces.get(key); if ( coll == null ) { synchronized (fragpieces) { coll = fragpieces.get(key); if ( coll == null ) { coll = new FragCollection(msg); fragpieces.put(key, coll); } } } return coll; }
Example #19
Source File: OrderInterceptor.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException { if ( !okToProcess(msg.getOptions()) ) { super.sendMessage(destination, msg, payload); return; } ChannelException cx = null; for (int i=0; i<destination.length; i++ ) { try { int nr = 0; try { outLock.writeLock().lock(); nr = incCounter(destination[i]); } finally { outLock.writeLock().unlock(); } //reduce byte copy msg.getMessage().append(nr); try { getNext().sendMessage(new Member[] {destination[i]}, msg, payload); } finally { msg.getMessage().trim(4); } }catch ( ChannelException x ) { if ( cx == null ) cx = x; cx.addFaultyMember(x.getFaultyMembers()); } }//for if ( cx != null ) throw cx; }
Example #20
Source File: FragmentationInterceptor.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
public void addMessage(ChannelMessage msg) { //remove the total messages msg.getMessage().trim(4); //get the msg nr int nr = XByteBuffer.toInt(msg.getMessage().getBytesDirect(),msg.getMessage().getLength()-4); //remove the msg nr msg.getMessage().trim(4); frags[nr] = msg.getMessage(); }
Example #21
Source File: ChannelCoordinator.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public void messageReceived(ChannelMessage msg) { if ( Logs.MESSAGES.isTraceEnabled() ) { Logs.MESSAGES.trace("ChannelCoordinator - Received msg:" + new UniqueId(msg.getUniqueId()) + " at " +new java.sql.Timestamp(System.currentTimeMillis())+ " from "+msg.getAddress().getName()); } super.messageReceived(msg); }
Example #22
Source File: TcpPingInterceptor.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Override public void messageReceived(ChannelMessage msg) { //catch incoming boolean process = true; if ( okToProcess(msg.getOptions()) ) { //check to see if it is a ping message, if so, process = false process = ( (msg.getMessage().getLength() != TCP_PING_DATA.length) || (!Arrays.equals(TCP_PING_DATA,msg.getMessage().getBytes()) ) ); }//end if //ignore the message, it doesnt have the flag set if ( process ) super.messageReceived(msg); else if ( log.isDebugEnabled() ) log.debug("Received a TCP ping packet:"+msg); }
Example #23
Source File: TestEncryptInterceptor.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException { synchronized(messages) { messages.add(msg.getMessage().getBytes()); } }
Example #24
Source File: SocketNioReceive.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public void messageReceived(ChannelMessage msg) { if (first) { first = false; start = System.currentTimeMillis(); } mb += ( (double) len) / 1024 / 1024; synchronized (this) {count++;} if ( ( (count) % 10000) == 0) { long time = System.currentTimeMillis(); seconds = ( (double) (time - start)) / 1000; System.out.println("Throughput " + df.format(mb / seconds) + " MB/seconds, messages "+count+", total "+mb+" MB."); } }
Example #25
Source File: ChannelCoordinator.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Override public void messageReceived(ChannelMessage msg) { if ( Logs.MESSAGES.isTraceEnabled() ) { Logs.MESSAGES.trace("ChannelCoordinator - Received msg:" + new UniqueId(msg.getUniqueId()) + " at " +new java.sql.Timestamp(System.currentTimeMillis())+ " from "+msg.getAddress().getName()); } super.messageReceived(msg); }
Example #26
Source File: GzipInterceptor.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Override public void messageReceived(ChannelMessage msg) { try { byte[] data = decompress(msg.getMessage().getBytes()); msg.getMessage().trim(msg.getMessage().getLength()); msg.getMessage().append(data,0,data.length); getPrevious().messageReceived(msg); } catch ( IOException x ) { log.error("Unable to decompress byte contents",x); } }
Example #27
Source File: OrderInterceptor.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Override public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException { if ( !okToProcess(msg.getOptions()) ) { super.sendMessage(destination, msg, payload); return; } ChannelException cx = null; for (int i=0; i<destination.length; i++ ) { try { int nr = 0; try { outLock.writeLock().lock(); nr = incCounter(destination[i]); } finally { outLock.writeLock().unlock(); } //reduce byte copy msg.getMessage().append(nr); try { getNext().sendMessage(new Member[] {destination[i]}, msg, payload); } finally { msg.getMessage().trim(4); } }catch ( ChannelException x ) { if ( cx == null ) cx = x; cx.addFaultyMember(x.getFaultyMembers()); } }//for if ( cx != null ) throw cx; }
Example #28
Source File: FragmentationInterceptor.java From tomcatsrc with Apache License 2.0 | 5 votes |
public void addMessage(ChannelMessage msg) { //remove the total messages msg.getMessage().trim(4); //get the msg nr int nr = XByteBuffer.toInt(msg.getMessage().getBytesDirect(),msg.getMessage().getLength()-4); //remove the msg nr msg.getMessage().trim(4); frags[nr] = msg.getMessage(); }
Example #29
Source File: ChannelCoordinator.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public void messageReceived(ChannelMessage msg) { if ( Logs.MESSAGES.isTraceEnabled() ) { Logs.MESSAGES.trace("ChannelCoordinator - Received msg:" + new UniqueId(msg.getUniqueId()) + " at " + new java.sql.Timestamp(System.currentTimeMillis()) + " from " + msg.getAddress().getName()); } super.messageReceived(msg); }
Example #30
Source File: FragmentationInterceptor.java From tomcatsrc with Apache License 2.0 | 5 votes |
public FragCollection getFragCollection(FragKey key, ChannelMessage msg) { FragCollection coll = fragpieces.get(key); if ( coll == null ) { synchronized (fragpieces) { coll = fragpieces.get(key); if ( coll == null ) { coll = new FragCollection(msg); fragpieces.put(key, coll); } } } return coll; }