org.apache.catalina.tribes.transport.Constants Java Examples

The following examples show how to use org.apache.catalina.tribes.transport.Constants. 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: BioSender.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Wait for Acknowledgement from other server.
 * FIXME Please, not wait only for three characters, better control that the wait ack message is correct.
 * @throws IOException An IO error occurred
 */
protected void waitForAck() throws java.io.IOException {
    try {
        boolean ackReceived = false;
        boolean failAckReceived = false;
        ackbuf.clear();
        int bytesRead = 0;
        int i = soIn.read();
        while ((i != -1) && (bytesRead < Constants.ACK_COMMAND.length)) {
            bytesRead++;
            byte d = (byte)i;
            ackbuf.append(d);
            if (ackbuf.doesPackageExist() ) {
                byte[] ackcmd = ackbuf.extractDataPackage(true).getBytes();
                ackReceived = Arrays.equals(ackcmd,org.apache.catalina.tribes.transport.Constants.ACK_DATA);
                failAckReceived = Arrays.equals(ackcmd,org.apache.catalina.tribes.transport.Constants.FAIL_ACK_DATA);
                ackReceived = ackReceived || failAckReceived;
                break;
            }
            i = soIn.read();
        }
        if (!ackReceived) {
            if (i == -1) throw new IOException(sm.getString("bioSender.ack.eof",getAddress(), Integer.valueOf(socket.getLocalPort())));
            else throw new IOException(sm.getString("bioSender.ack.wrong",getAddress(), Integer.valueOf(socket.getLocalPort())));
        } else if ( failAckReceived && getThrowOnFailedAck()) {
            throw new RemoteProcessException(sm.getString("bioSender.fail.AckReceived"));
        }
    } catch (IOException x) {
        String errmsg = sm.getString("bioSender.ack.missing", getAddress(), Integer.valueOf(socket.getLocalPort()), Long.valueOf(getTimeout()));
        if ( SenderState.getSenderState(getDestination()).isReady() ) {
            SenderState.getSenderState(getDestination()).setSuspect();
            if ( log.isWarnEnabled() ) log.warn(errmsg, x);
        } else {
            if ( log.isDebugEnabled() )log.debug(errmsg, x);
        }
        throw x;
    } finally {
        ackbuf.clear();
    }
}
 
Example #2
Source File: BioReplicationTask.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
protected void execute(ObjectReader reader) throws Exception{
    int pkgcnt = reader.count();

    if ( pkgcnt > 0 ) {
        ChannelMessage[] msgs = reader.execute();
        for ( int i=0; i<msgs.length; i++ ) {
            /**
             * Use send ack here if you want to ack the request to the remote
             * server before completing the request
             * This is considered an asynchronous request
             */
            if (ChannelData.sendAckAsync(msgs[i].getOptions())) sendAck(Constants.ACK_COMMAND);
            try {
                //process the message
                getCallback().messageDataReceived(msgs[i]);
                /**
                 * Use send ack here if you want the request to complete on this
                 * server before sending the ack to the remote server
                 * This is considered a synchronized request
                 */
                if (ChannelData.sendAckSync(msgs[i].getOptions())) sendAck(Constants.ACK_COMMAND);
            }catch  ( Exception x ) {
                if (ChannelData.sendAckSync(msgs[i].getOptions())) sendAck(Constants.FAIL_ACK_COMMAND);
                log.error(sm.getString("bioReplicationTask.messageDataReceived.error"),x);
            }
            if ( getUseBufferPool() ) {
                BufferPool.getBufferPool().returnBuffer(msgs[i].getMessage());
                msgs[i].setMessage(null);
            }
        }
    }


}
 
Example #3
Source File: BioSender.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Wait for Acknowledgement from other server.
 * FIXME Please, not wait only for three characters, better control that the wait ack message is correct.
 * @throws java.io.IOException
 * @throws java.net.SocketTimeoutException
 */
protected void waitForAck() throws java.io.IOException {
    try {
        boolean ackReceived = false;
        boolean failAckReceived = false;
        ackbuf.clear();
        int bytesRead = 0;
        int i = soIn.read();
        while ((i != -1) && (bytesRead < Constants.ACK_COMMAND.length)) {
            bytesRead++;
            byte d = (byte)i;
            ackbuf.append(d);
            if (ackbuf.doesPackageExist() ) {
                byte[] ackcmd = ackbuf.extractDataPackage(true).getBytes();
                ackReceived = Arrays.equals(ackcmd,org.apache.catalina.tribes.transport.Constants.ACK_DATA);
                failAckReceived = Arrays.equals(ackcmd,org.apache.catalina.tribes.transport.Constants.FAIL_ACK_DATA);
                ackReceived = ackReceived || failAckReceived;
                break;
            }
            i = soIn.read();
        }
        if (!ackReceived) {
            if (i == -1) throw new IOException(sm.getString("IDataSender.ack.eof",getAddress(), Integer.valueOf(socket.getLocalPort())));
            else throw new IOException(sm.getString("IDataSender.ack.wrong",getAddress(), Integer.valueOf(socket.getLocalPort())));
        } else if ( failAckReceived && getThrowOnFailedAck()) {
            throw new RemoteProcessException("Received a failed ack:org.apache.catalina.tribes.transport.Constants.FAIL_ACK_DATA");
        }
    } catch (IOException x) {
        String errmsg = sm.getString("IDataSender.ack.missing", getAddress(), Integer.valueOf(socket.getLocalPort()), Long.valueOf(getTimeout()));
        if ( SenderState.getSenderState(getDestination()).isReady() ) {
            SenderState.getSenderState(getDestination()).setSuspect();
            if ( log.isWarnEnabled() ) log.warn(errmsg, x);
        } else {
            if ( log.isDebugEnabled() )log.debug(errmsg, x);
        }
        throw x;
    } finally {
        ackbuf.clear();
    }
}
 
Example #4
Source File: BioReplicationTask.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
protected void execute(ObjectReader reader) throws Exception{
    int pkgcnt = reader.count();

    if ( pkgcnt > 0 ) {
        ChannelMessage[] msgs = reader.execute();
        for ( int i=0; i<msgs.length; i++ ) {
            /**
             * Use send ack here if you want to ack the request to the remote 
             * server before completing the request
             * This is considered an asynchronized request
             */
            if (ChannelData.sendAckAsync(msgs[i].getOptions())) sendAck(Constants.ACK_COMMAND);
            try {
                //process the message
                getCallback().messageDataReceived(msgs[i]);
                /**
                 * Use send ack here if you want the request to complete on this
                 * server before sending the ack to the remote server
                 * This is considered a synchronized request
                 */
                if (ChannelData.sendAckSync(msgs[i].getOptions())) sendAck(Constants.ACK_COMMAND);
            }catch  ( Exception x ) {
                if (ChannelData.sendAckSync(msgs[i].getOptions())) sendAck(Constants.FAIL_ACK_COMMAND);
                log.error("Error thrown from messageDataReceived.",x);
            }
            if ( getUseBufferPool() ) {
                BufferPool.getBufferPool().returnBuffer(msgs[i].getMessage());
                msgs[i].setMessage(null);
            }
        }                       
    }

   
}
 
Example #5
Source File: BioSender.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Wait for Acknowledgement from other server.
 * FIXME Please, not wait only for three characters, better control that the wait ack message is correct.
 * @throws java.io.IOException
 * @throws java.net.SocketTimeoutException
 */
protected void waitForAck() throws java.io.IOException {
    try {
        boolean ackReceived = false;
        boolean failAckReceived = false;
        ackbuf.clear();
        int bytesRead = 0;
        int i = soIn.read();
        while ((i != -1) && (bytesRead < Constants.ACK_COMMAND.length)) {
            bytesRead++;
            byte d = (byte)i;
            ackbuf.append(d);
            if (ackbuf.doesPackageExist() ) {
                byte[] ackcmd = ackbuf.extractDataPackage(true).getBytes();
                ackReceived = Arrays.equals(ackcmd,org.apache.catalina.tribes.transport.Constants.ACK_DATA);
                failAckReceived = Arrays.equals(ackcmd,org.apache.catalina.tribes.transport.Constants.FAIL_ACK_DATA);
                ackReceived = ackReceived || failAckReceived;
                break;
            }
            i = soIn.read();
        }
        if (!ackReceived) {
            if (i == -1) throw new IOException(sm.getString("IDataSender.ack.eof",getAddress(), Integer.valueOf(socket.getLocalPort())));
            else throw new IOException(sm.getString("IDataSender.ack.wrong",getAddress(), Integer.valueOf(socket.getLocalPort())));
        } else if ( failAckReceived && getThrowOnFailedAck()) {
            throw new RemoteProcessException("Received a failed ack:org.apache.catalina.tribes.transport.Constants.FAIL_ACK_DATA");
        }
    } catch (IOException x) {
        String errmsg = sm.getString("IDataSender.ack.missing", getAddress(), Integer.valueOf(socket.getLocalPort()), Long.valueOf(getTimeout()));
        if ( SenderState.getSenderState(getDestination()).isReady() ) {
            SenderState.getSenderState(getDestination()).setSuspect();
            if ( log.isWarnEnabled() ) log.warn(errmsg, x);
        } else {
            if ( log.isDebugEnabled() )log.debug(errmsg, x);
        }
        throw x;
    } finally {
        ackbuf.clear();
    }
}
 
Example #6
Source File: BioReplicationTask.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
protected void execute(ObjectReader reader) throws Exception{
    int pkgcnt = reader.count();

    if ( pkgcnt > 0 ) {
        ChannelMessage[] msgs = reader.execute();
        for ( int i=0; i<msgs.length; i++ ) {
            /**
             * Use send ack here if you want to ack the request to the remote 
             * server before completing the request
             * This is considered an asynchronized request
             */
            if (ChannelData.sendAckAsync(msgs[i].getOptions())) sendAck(Constants.ACK_COMMAND);
            try {
                //process the message
                getCallback().messageDataReceived(msgs[i]);
                /**
                 * Use send ack here if you want the request to complete on this
                 * server before sending the ack to the remote server
                 * This is considered a synchronized request
                 */
                if (ChannelData.sendAckSync(msgs[i].getOptions())) sendAck(Constants.ACK_COMMAND);
            }catch  ( Exception x ) {
                if (ChannelData.sendAckSync(msgs[i].getOptions())) sendAck(Constants.FAIL_ACK_COMMAND);
                log.error("Error thrown from messageDataReceived.",x);
            }
            if ( getUseBufferPool() ) {
                BufferPool.getBufferPool().returnBuffer(msgs[i].getMessage());
                msgs[i].setMessage(null);
            }
        }                       
    }

   
}