org.apache.catalina.tribes.group.InterceptorPayload Java Examples

The following examples show how to use org.apache.catalina.tribes.group.InterceptorPayload. 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: 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 #2
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 #3
Source File: ThroughputInterceptor.java    From tomcatsrc 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 #4
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 #5
Source File: FragmentationInterceptor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    int size = msg.getMessage().getLength();
    boolean frag = (size>maxSize) && okToProcess(msg.getOptions());
    if ( frag ) {
        frag(destination, msg, payload);
    } else {
        msg.getMessage().append(frag);
        super.sendMessage(destination, msg, payload);
    }
}
 
Example #6
Source File: GzipInterceptor.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    try {
        byte[] data = compress(msg.getMessage().getBytes());
        msg.getMessage().trim(msg.getMessage().getLength());
        msg.getMessage().append(data,0,data.length);
        getNext().sendMessage(destination, msg, payload);
    } catch ( IOException x ) {
        log.error("Unable to compress byte contents");
        throw new ChannelException(x);
    }
}
 
Example #7
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 #8
Source File: FragmentationInterceptor.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    int size = msg.getMessage().getLength();
    boolean frag = (size>maxSize) && okToProcess(msg.getOptions());
    if ( frag ) {
        frag(destination, msg, payload);
    } else {
        msg.getMessage().append(frag);
        super.sendMessage(destination, msg, payload);
    }
}
 
Example #9
Source File: MessageDispatch15Interceptor.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@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 #10
Source File: OrderInterceptor.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@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 #11
Source File: TcpFailureDetector.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@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: GzipInterceptor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    try {
        byte[] data = compress(msg.getMessage().getBytes());
        msg.getMessage().trim(msg.getMessage().getLength());
        msg.getMessage().append(data,0,data.length);
        getNext().sendMessage(destination, msg, payload);
    } catch ( IOException x ) {
        log.error("Unable to compress byte contents");
        throw new ChannelException(x);
    }
}
 
Example #13
Source File: FragmentationInterceptor.java    From Tomcat7.0.67 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 #14
Source File: MessageDispatchInterceptor.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public boolean addToQueue(final ChannelMessage msg, final Member[] destination,
        final InterceptorPayload payload) {
    Runnable r = new Runnable() {
        @Override
        public void run() {
            sendAsyncData(msg, destination, payload);
        }
    };
    executor.execute(r);
    return true;
}
 
Example #15
Source File: MessageDispatch15Interceptor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@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 #16
Source File: OrderInterceptor.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@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 #17
Source File: TcpFailureDetector.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@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 #18
Source File: TestEncryptInterceptor.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload)
        throws ChannelException {
    synchronized(messages) {
        messages.add(msg.getMessage().getBytes());
    }
}
 
Example #19
Source File: TcpFailureDetector.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@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 #20
Source File: OrderInterceptor.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@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;
            outLock.writeLock().lock();
            try {
                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 #21
Source File: FragmentationInterceptor.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    int size = msg.getMessage().getLength();
    boolean frag = (size>maxSize) && okToProcess(msg.getOptions());
    if ( frag ) {
        frag(destination, msg, payload);
    } else {
        msg.getMessage().append(frag);
        super.sendMessage(destination, msg, payload);
    }
}
 
Example #22
Source File: FragmentationInterceptor.java    From Tomcat8-Source-Read with MIT License 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 #23
Source File: GzipInterceptor.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    try {
        byte[] data = compress(msg.getMessage().getBytes());
        msg.getMessage().trim(msg.getMessage().getLength());
        msg.getMessage().append(data,0,data.length);
        super.sendMessage(destination, msg, payload);
    } catch ( IOException x ) {
        log.error(sm.getString("gzipInterceptor.compress.failed"));
        throw new ChannelException(x);
    }
}
 
Example #24
Source File: MessageDispatchInterceptor.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public boolean addToQueue(ChannelMessage msg, Member[] destination, InterceptorPayload payload) {
    return queue.add(msg,destination,payload);
}
 
Example #25
Source File: FastQueue.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * Add new data to the queue.
 * 
 * FIXME extract some method
 */
public boolean add(ChannelMessage msg, Member[] destination, InterceptorPayload payload) {
    boolean ok = true;

    if (!enabled) {
        if (log.isInfoEnabled())
            log.info("FastQueue.add: queue disabled, add aborted");
        return false;
    }

    lock.lockAdd();
    try {
        if (log.isTraceEnabled()) {
            log.trace("FastQueue.add: starting with size " + size);
        }
        if (checkLock) {
            if (inAdd)
                log.warn("FastQueue.add: Detected other add");
            inAdd = true;
            if (inMutex)
                log.warn("FastQueue.add: Detected other mutex in add");
            inMutex = true;
        }

        if ((maxQueueLength > 0) && (size >= maxQueueLength)) {
            ok = false;
            if (log.isTraceEnabled()) {
                log.trace("FastQueue.add: Could not add, since queue is full (" + size + ">=" + maxQueueLength + ")");
            }
        } else {
            LinkObject element = new LinkObject(msg,destination, payload);
            if (size == 0) {
                first = last = element;
                size = 1;
            } else {
                if (last == null) {
                    ok = false;
                    log.error("FastQueue.add: Could not add, since last is null although size is "+ size + " (>0)");
                } else {
                    last.append(element);
                    last = element;
                    size++;
                }
            }
        }

        if (first == null) {
            log.error("FastQueue.add: first is null, size is " + size + " at end of add");
        }
        if (last == null) {
            log.error("FastQueue.add: last is null, size is " + size+ " at end of add");
        }

        if (checkLock) {
            if (!inMutex) log.warn("FastQueue.add: Cancelled by other mutex in add");
            inMutex = false;
            if (!inAdd) log.warn("FastQueue.add: Cancelled by other add");
            inAdd = false;
        }
        if (log.isTraceEnabled()) log.trace("FastQueue.add: add ending with size " + size);

    } finally {
        lock.unlockAdd(true);
    }
    return ok;
}
 
Example #26
Source File: NonBlockingCoordinator.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    waitForRelease();
    super.sendMessage(destination, msg, payload);
}
 
Example #27
Source File: NonBlockingCoordinator.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    waitForRelease();
    super.sendMessage(destination, msg, payload);
}
 
Example #28
Source File: LinkObject.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public InterceptorPayload getPayload() {
    return payload;
}
 
Example #29
Source File: NonBlockingCoordinator.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    waitForRelease();
    super.sendMessage(destination, msg, payload);
}
 
Example #30
Source File: LinkObject.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
public InterceptorPayload getPayload() {
    return payload;
}