org.apache.catalina.tribes.ChannelException Java Examples

The following examples show how to use org.apache.catalina.tribes.ChannelException. 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: TestGroupChannelOptionFlag.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Test
public void testOptionConflict() throws Exception {
    boolean error = false;
    channel.setOptionCheck(true);
    ChannelInterceptor i = new TestInterceptor();
    i.setOptionFlag(128);
    channel.addInterceptor(i);
    i = new TestInterceptor();
    i.setOptionFlag(128);
    channel.addInterceptor(i);
    try {
        channel.start(Channel.DEFAULT);
    }catch ( ChannelException x ) {
        if ( x.getMessage().indexOf("option flag conflict") >= 0 ) error = true;
    }
    assertTrue(error);
}
 
Example #2
Source File: ThroughputInterceptor.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@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() / (double) interval) >= lastCnt) {
            lastCnt++;
            report(timeTx);
        }
    }
    msgTxCnt.addAndGet(1);
}
 
Example #3
Source File: NonBlockingCoordinator.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Override
public void memberDisappeared(Member member) {
    try {
        
        membership.removeMember((MemberImpl)member);
        super.memberDisappeared(member);
        try {
            fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_MBR_DEL,this,"Member remove("+member.getName()+")"));
            if ( started && (isCoordinator() || isHighest()) ) 
                startElection(true); //to do, if a member disappears, only the coordinator can start
        }catch ( ChannelException x ) {
            log.error("Unable to start election when member was removed.",x);
        }
    }finally {
    }
}
 
Example #4
Source File: NonBlockingCoordinator.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@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 #5
Source File: NonBlockingCoordinator.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
protected void sendElectionMsgToNextInline(MemberImpl local, CoordinationMessage msg) throws ChannelException { 
    int next = Arrays.nextIndex(local,msg.getMembers());
    int current = next;
    msg.leader = msg.getMembers()[0];
    boolean sent =  false;
    while ( !sent && current >= 0 ) {
        try {
            sendElectionMsg(local, msg.getMembers()[current], msg);
            sent = true;
        }catch ( ChannelException x  ) {
            log.warn("Unable to send election message to:"+msg.getMembers()[current]);
            current = Arrays.nextIndex(msg.getMembers()[current],msg.getMembers());
            if ( current == next ) throw x;
        }
    }
}
 
Example #6
Source File: NonBlockingCoordinator.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void stop(int svc) throws ChannelException {
    try {
        halt();
        synchronized (electionMutex) {
            if (!started)return;
            started = false;
            fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_STOP, this, "Before stop"));
            super.stop(startsvc);
            this.view = null;
            this.viewId = null;
            this.suggestedView = null;
            this.suggestedviewId = null;
            this.membership.reset();
            fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_STOP, this, "After stop"));
        }
    }finally {
        release();
    }
}
 
Example #7
Source File: NonBlockingCoordinator.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
protected void handleViewConf(CoordinationMessage msg, Membership merged) throws ChannelException {
    if ( viewId != null && msg.getId().equals(viewId) ) return;//we already have this view
    view = new Membership(getLocalMember(false),AbsoluteOrder.comp,true);
    Arrays.fill(view,msg.getMembers());
    viewId = msg.getId();

    if ( viewId.equals(suggestedviewId) ) {
        suggestedView = null;
        suggestedviewId = null;
    }

    if (suggestedView != null && AbsoluteOrder.comp.compare(suggestedView.getMembers()[0],merged.getMembers()[0])<0 ) {
        suggestedView = null;
        suggestedviewId = null;
    }

    fireInterceptorEvent(new CoordinationEvent(CoordinationEvent.EVT_CONF_RX,this,"Accepted View"));

    if ( suggestedviewId == null && hasHigherPriority(merged.getMembers(),membership.getMembers()) ) {
        startElection(false);
    }
}
 
Example #8
Source File: EncryptInterceptor.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload)
        throws ChannelException {
    try {
        byte[] data = msg.getMessage().getBytes();

        // See #encrypt(byte[]) for an explanation of the return value
        byte[][] bytes = encryptionManager.encrypt(data);

        XByteBuffer xbb = msg.getMessage();

        // Completely replace the message
        xbb.clear();
        xbb.append(bytes[0], 0, bytes[0].length);
        xbb.append(bytes[1], 0, bytes[1].length);

        super.sendMessage(destination, msg, payload);

    } catch (GeneralSecurityException gse) {
        log.error(sm.getString("encryptInterceptor.encrypt.failed"));
        throw new ChannelException(gse);
    }
}
 
Example #9
Source File: TestTcpFailureDetector.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Test
public void testTcpSendFailureMemberDrop() throws Exception {
    System.out.println("testTcpSendFailureMemberDrop()");
    clear();
    channel1.start(Channel.DEFAULT);
    channel2.start(Channel.DEFAULT);
    //Thread.sleep(1000);
    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);
        fail("Message send should have failed.");
    } catch ( ChannelException x ) {
        // Ignore
    }
    assertEquals("Expecting member count to not be equal",mbrlist1.members.size()+1,mbrlist2.members.size());
    channel1.stop(Channel.DEFAULT);
    channel2.stop(Channel.DEFAULT);
}
 
Example #10
Source File: NonBlockingCoordinator.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
protected void handleMyToken(MemberImpl local, CoordinationMessage msg, Member sender,Membership merged) throws ChannelException {
    if ( local.equals(msg.getLeader()) ) {
        //no leadership change
        if ( Arrays.sameMembers(msg.getMembers(),merged.getMembers()) ) {
            msg.type = COORD_CONF;
            super.sendMessage(Arrays.remove(msg.getMembers(),local),createData(msg,local),null);
            handleViewConf(msg,local,merged);
        } else {
            //membership change
            suggestedView = new Membership(local,AbsoluteOrder.comp,true);
            suggestedviewId = msg.getId();
            Arrays.fill(suggestedView,merged.getMembers());
            msg.view = merged.getMembers();
            sendElectionMsgToNextInline(local,msg);
        }
    } else {
        //leadership change
        suggestedView = null;
        suggestedviewId = null;
        msg.view = merged.getMembers();
        sendElectionMsgToNextInline(local,msg);
    }
}
 
Example #11
Source File: TcpPingInterceptor.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void start(int svc) throws ChannelException {
    super.start(svc);
    running = true;
    if ( thread == null && useThread) {
        thread = new PingThread();
        thread.setDaemon(true);
        thread.setName("TcpPingInterceptor.PingThread-"+cnt.addAndGet(1));
        thread.start();
    }
    
    //acquire the interceptors to invoke on send ping events
    ChannelInterceptor next = getNext();
    while ( next != null ) {
        if ( next instanceof TcpFailureDetector ) 
            failureDetector = new WeakReference<TcpFailureDetector>((TcpFailureDetector)next);
        if ( next instanceof StaticMembershipInterceptor ) 
            staticMembers = new WeakReference<StaticMembershipInterceptor>((StaticMembershipInterceptor)next);
        next = next.getNext();
    }
    
}
 
Example #12
Source File: TestGroupChannelOptionFlag.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Test
public void testOptionConflict() throws Exception {
    boolean error = false;
    channel.setOptionCheck(true);
    ChannelInterceptor i = new TestInterceptor();
    i.setOptionFlag(128);
    channel.addInterceptor(i);
    i = new TestInterceptor();
    i.setOptionFlag(128);
    channel.addInterceptor(i);
    try {
        channel.start(Channel.DEFAULT);
    }catch ( ChannelException x ) {
        if ( x.getMessage().indexOf("option flag conflict") >= 0 ) error = true;
    }
    assertTrue(error);
}
 
Example #13
Source File: McastService.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@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 #14
Source File: TestTcpFailureDetector.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Test
public void testTcpMcastFail() throws Exception {
    System.out.println("testTcpMcastFail()");
    clear();
    channel1.start(Channel.DEFAULT);
    channel2.start(Channel.DEFAULT);
    //Thread.sleep(1000);
    assertEquals("Expecting member count to be equal",mbrlist1.members.size(),mbrlist2.members.size());
    channel2.stop(Channel.MBR_TX_SEQ);
    ByteMessage msg = new ByteMessage(new byte[1024]);
    try {
        Thread.sleep(5000);
        assertEquals("Expecting member count to be equal",mbrlist1.members.size(),mbrlist2.members.size());
        channel1.send(channel1.getMembers(), msg, 0);
    } catch ( ChannelException x ) {
        fail("Message send should have succeeded.");
    }
    channel1.stop(Channel.DEFAULT);
    channel2.stop(Channel.DEFAULT);
}
 
Example #15
Source File: McastService.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@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 #16
Source File: NonBlockingCoordinator.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@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, msg.getAddress());
        }catch ( ChannelException x ) {
            log.error("Error processing coordination message. Could be fatal.",x);
        }
    } else {
        super.messageReceived(msg);
    }
}
 
Example #17
Source File: NonBlockingCoordinator.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@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, msg.getAddress());
        }catch ( ChannelException x ) {
            log.error("Error processing coordination message. Could be fatal.",x);
        }
    } else {
        super.messageReceived(msg);
    }
}
 
Example #18
Source File: AbstractReplicatedMap.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public V put(K key, V value, boolean notify) {
    MapEntry<K,V> entry = new MapEntry<>(key, value);
    entry.setBackup(false);
    entry.setProxy(false);
    entry.setCopy(false);
    entry.setPrimary(channel.getLocalMember(false));

    V old = null;

    //make sure that any old values get removed
    if ( containsKey(key) ) old = remove(key);
    try {
        if ( notify ) {
            Member[] backup = publishEntryInfo(key, value);
            entry.setBackupNodes(backup);
        }
    } catch (ChannelException x) {
        log.error(sm.getString("abstractReplicatedMap.unable.put"), x);
    }
    innerMap.put(key,entry);
    return old;
}
 
Example #19
Source File: McastService.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@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 #20
Source File: TestTcpFailureDetector.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@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 #21
Source File: ThroughputInterceptor.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@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 #22
Source File: TestGroupChannelOptionFlag.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@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;
    }
    Assert.assertFalse(error);
}
 
Example #23
Source File: PooledParallelSender.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
public void sendMessage(Member[] destination, ChannelMessage message) throws ChannelException {
    if ( !connected ) throw new ChannelException("Sender not connected.");
    ParallelNioSender sender = (ParallelNioSender)getSender();
    if (sender == null) {
        ChannelException cx = new ChannelException("Unable to retrieve a data sender, time out("+getMaxWait()+" ms) error.");
        for (int i = 0; i < destination.length; i++) cx.addFaultyMember(destination[i], new NullPointerException("Unable to retrieve a sender from the sender pool"));
        throw cx;
    } else {
        try {
            sender.sendMessage(destination, message);
            sender.keepalive();
        } catch (ChannelException x) {
            sender.disconnect();
            throw x;
        } finally {
            returnSender(sender);
            if (!connected) disconnect();
        }
    }
}
 
Example #24
Source File: TestGroupChannelOptionFlag.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testOptionConflict() throws Exception {
    boolean error = false;
    channel.setOptionCheck(true);
    ChannelInterceptor i = new TestInterceptor();
    i.setOptionFlag(128);
    channel.addInterceptor(i);
    i = new TestInterceptor();
    i.setOptionFlag(128);
    channel.addInterceptor(i);
    try {
        channel.start(Channel.DEFAULT);
    }catch ( ChannelException x ) {
        if ( x.getMessage().indexOf("option flag conflict") >= 0 ) error = true;
    }
    Assert.assertTrue(error);
}
 
Example #25
Source File: NonBlockingCoordinator.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
protected void handleOtherToken(Member local, CoordinationMessage msg, Membership merged) throws ChannelException {
    if ( local.equals(msg.getLeader()) ) {
        //I am the new leader
        //startElection(false);
    } else {
        msg.view = merged.getMembers();
        sendElectionMsgToNextInline(local,msg);
    }
}
 
Example #26
Source File: AbstractReplicatedMap.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public void mapMemberAdded(Member member) {
    if ( member.equals(getChannel().getLocalMember(false)) ) return;
    boolean memberAdded = false;
    //select a backup node if we don't have one
    Member mapMember = getChannel().getMember(member);
    if (mapMember == null) {
        log.warn("Notified member is not registered in the membership:" + member);
        return;
    }
    synchronized (mapMembers) {
        if (!mapMembers.containsKey(mapMember) ) {
            if (log.isInfoEnabled()) log.info("Map member added:" + mapMember);
            mapMembers.put(mapMember, Long.valueOf(System.currentTimeMillis()));
            memberAdded = true;
        }
    }
    if ( memberAdded ) {
        synchronized (stateMutex) {
            Iterator<Map.Entry<K,MapEntry<K,V>>> i = innerMap.entrySet().iterator();
            while (i.hasNext()) {
                Map.Entry<K,MapEntry<K,V>> e = i.next();
                MapEntry<K,V> entry = innerMap.get(e.getKey());
                if ( entry == null ) continue;
                if (entry.isPrimary() && (entry.getBackupNodes() == null || entry.getBackupNodes().length == 0)) {
                    try {
                        Member[] backup = publishEntryInfo(entry.getKey(), entry.getValue());
                        entry.setBackupNodes(backup);
                        entry.setPrimary(channel.getLocalMember(false));
                    } catch (ChannelException x) {
                        log.error("Unable to select backup node.", x);
                    } //catch
                } //end if
            } //while
        } //synchronized
    }//end if
}
 
Example #27
Source File: TcpPingInterceptor.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void stop(int svc) throws ChannelException {
    running = false;
    if ( thread != null ) {
        thread.interrupt();
        thread = null;
    }
    super.stop(svc);
}
 
Example #28
Source File: GroupChannel.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Validates the option flags that each interceptor is using and reports
 * an error if two interceptor share the same flag.
 * @throws ChannelException
 */
protected void checkOptionFlags() throws ChannelException {
    StringBuilder conflicts = new StringBuilder();
    ChannelInterceptor first = interceptors;
    while ( first != null ) {
        int flag = first.getOptionFlag();
        if ( flag != 0 ) {
            ChannelInterceptor next = first.getNext();
            while ( next != null ) {
                int nflag = next.getOptionFlag();
                if (nflag!=0 && (((flag & nflag) == flag ) || ((flag & nflag) == nflag)) ) {
                    conflicts.append("[");
                    conflicts.append(first.getClass().getName());
                    conflicts.append(":");
                    conflicts.append(flag);
                    conflicts.append(" == ");
                    conflicts.append(next.getClass().getName());
                    conflicts.append(":");
                    conflicts.append(nflag);
                    conflicts.append("] ");
                }//end if
                next = next.getNext();
            }//while
        }//end if
        first = first.getNext();
    }//while
    if ( conflicts.length() > 0 ) throw new ChannelException("Interceptor option flag conflict: "+conflicts.toString());

}
 
Example #29
Source File: FragmentationInterceptor.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
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 #30
Source File: StaticMembershipInterceptor.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
protected void sendMemberMessage(Member[] members, byte[] message) throws ChannelException {
    if ( members == null || members.length == 0 ) return;
    ChannelData data = new ChannelData(true);
    data.setAddress(getLocalMember(false));
    data.setTimestamp(System.currentTimeMillis());
    data.setOptions(getOptionFlag());
    data.setMessage(new XByteBuffer(message, false));
    super.sendMessage(members, data, null);
}