Search in sources :

Example 6 with RemoteProcessException

use of org.apache.catalina.tribes.RemoteProcessException in project tomcat by apache.

the class NioSender method read.

protected boolean read() throws IOException {
    //if there is no message here, we are done
    if (current == null)
        return true;
    int read = isUdpBased() ? dataChannel.read(readbuf) : socketChannel.read(readbuf);
    //end of stream
    if (read == -1)
        throw new IOException(sm.getString("nioSender.unable.receive.ack"));
    else //no data read
    if (read == 0)
        return false;
    readbuf.flip();
    ackbuf.append(readbuf, read);
    readbuf.clear();
    if (ackbuf.doesPackageExist()) {
        byte[] ackcmd = ackbuf.extractDataPackage(true).getBytes();
        boolean ack = Arrays.equals(ackcmd, org.apache.catalina.tribes.transport.Constants.ACK_DATA);
        boolean fack = Arrays.equals(ackcmd, org.apache.catalina.tribes.transport.Constants.FAIL_ACK_DATA);
        if (fack && getThrowOnFailedAck())
            throw new RemoteProcessException(sm.getString("nioSender.receive.failedAck"));
        return ack || fack;
    } else {
        return false;
    }
}
Also used : IOException(java.io.IOException) RemoteProcessException(org.apache.catalina.tribes.RemoteProcessException)

Example 7 with RemoteProcessException

use of org.apache.catalina.tribes.RemoteProcessException in project tomcat by apache.

the class BioSender method waitForAck.

/**
     * 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();
    }
}
Also used : IOException(java.io.IOException) RemoteProcessException(org.apache.catalina.tribes.RemoteProcessException)

Example 8 with RemoteProcessException

use of org.apache.catalina.tribes.RemoteProcessException in project tomcat70 by apache.

the class NioSender method read.

protected boolean read(SelectionKey key) throws IOException {
    // if there is no message here, we are done
    if (current == null)
        return true;
    int read = isUdpBased() ? dataChannel.read(readbuf) : socketChannel.read(readbuf);
    // end of stream
    if (read == -1)
        throw new IOException("Unable to receive an ack message. EOF on socket channel has been reached.");
    else // no data read
    if (read == 0)
        return false;
    readbuf.flip();
    ackbuf.append(readbuf, read);
    readbuf.clear();
    if (ackbuf.doesPackageExist()) {
        byte[] ackcmd = ackbuf.extractDataPackage(true).getBytes();
        boolean ack = Arrays.equals(ackcmd, org.apache.catalina.tribes.transport.Constants.ACK_DATA);
        boolean fack = Arrays.equals(ackcmd, org.apache.catalina.tribes.transport.Constants.FAIL_ACK_DATA);
        if (fack && getThrowOnFailedAck())
            throw new RemoteProcessException("Received a failed ack:org.apache.catalina.tribes.transport.Constants.FAIL_ACK_DATA");
        return ack || fack;
    } else {
        return false;
    }
}
Also used : IOException(java.io.IOException) RemoteProcessException(org.apache.catalina.tribes.RemoteProcessException)

Aggregations

RemoteProcessException (org.apache.catalina.tribes.RemoteProcessException)8 IOException (java.io.IOException)7 UniqueId (org.apache.catalina.tribes.UniqueId)4 Serializable (java.io.Serializable)2 SocketAddress (java.net.SocketAddress)2 CancelledKeyException (java.nio.channels.CancelledKeyException)2 DatagramChannel (java.nio.channels.DatagramChannel)2 ReadableByteChannel (java.nio.channels.ReadableByteChannel)2 SocketChannel (java.nio.channels.SocketChannel)2 WritableByteChannel (java.nio.channels.WritableByteChannel)2 ByteMessage (org.apache.catalina.tribes.ByteMessage)2 ChannelException (org.apache.catalina.tribes.ChannelException)2 ChannelListener (org.apache.catalina.tribes.ChannelListener)2 ChannelMessage (org.apache.catalina.tribes.ChannelMessage)2 Member (org.apache.catalina.tribes.Member)2 ExecutionException (java.util.concurrent.ExecutionException)1