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;
}
}
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();
}
}
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;
}
}
Aggregations