use of org.apache.catalina.tribes.ChannelException in project tomcat by apache.
the class McastService method broadcast.
@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);
}
}
use of org.apache.catalina.tribes.ChannelException in project tomcat by apache.
the class ParallelNioSender method sendMessage.
@Override
public synchronized void sendMessage(Member[] destination, ChannelMessage msg) throws ChannelException {
long start = System.currentTimeMillis();
this.setUdpBased((msg.getOptions() & Channel.SEND_OPTIONS_UDP) == Channel.SEND_OPTIONS_UDP);
byte[] data = XByteBuffer.createDataPackage((ChannelData) msg);
NioSender[] senders = setupForSend(destination);
connect(senders);
setData(senders, data);
int remaining = senders.length;
ChannelException cx = null;
try {
//loop until complete, an error happens, or we timeout
long delta = System.currentTimeMillis() - start;
boolean waitForAck = (Channel.SEND_OPTIONS_USE_ACK & msg.getOptions()) == Channel.SEND_OPTIONS_USE_ACK;
while ((remaining > 0) && (delta < getTimeout())) {
try {
remaining -= doLoop(selectTimeout, getMaxRetryAttempts(), waitForAck, msg);
} catch (Exception x) {
if (log.isTraceEnabled())
log.trace("Error sending message", x);
int faulty = (cx == null) ? 0 : cx.getFaultyMembers().length;
if (cx == null) {
if (x instanceof ChannelException)
cx = (ChannelException) x;
else
cx = new ChannelException(sm.getString("parallelNioSender.send.failed"), x);
} else {
if (x instanceof ChannelException) {
cx.addFaultyMember(((ChannelException) x).getFaultyMembers());
}
}
//count down the remaining on an error
if (faulty < cx.getFaultyMembers().length) {
remaining -= (cx.getFaultyMembers().length - faulty);
}
}
//bail out if all remaining senders are failing
if (cx != null && cx.getFaultyMembers().length == remaining)
throw cx;
delta = System.currentTimeMillis() - start;
}
if (remaining > 0) {
//timeout has occurred
ChannelException cxtimeout = new ChannelException(sm.getString("parallelNioSender.operation.timedout", Long.toString(getTimeout())));
if (cx == null) {
cx = new ChannelException(sm.getString("parallelNioSender.operation.timedout", Long.toString(getTimeout())));
}
for (int i = 0; i < senders.length; i++) {
if (!senders[i].isComplete()) {
cx.addFaultyMember(senders[i].getDestination(), cxtimeout);
}
}
throw cx;
} else if (cx != null) {
//there was an error
throw cx;
}
} catch (Exception x) {
try {
this.disconnect();
} catch (Exception e) {
/*Ignore*/
}
if (x instanceof ChannelException)
throw (ChannelException) x;
else
throw new ChannelException(x);
}
}
use of org.apache.catalina.tribes.ChannelException in project tomcat by apache.
the class ParallelNioSender method setupForSend.
private NioSender[] setupForSend(Member[] destination) throws ChannelException {
ChannelException cx = null;
NioSender[] result = new NioSender[destination.length];
for (int i = 0; i < destination.length; i++) {
NioSender sender = nioSenders.get(destination[i]);
try {
if (sender == null) {
sender = new NioSender();
AbstractSender.transferProperties(this, sender);
nioSenders.put(destination[i], sender);
}
sender.reset();
sender.setDestination(destination[i]);
sender.setSelector(selector);
sender.setUdpBased(isUdpBased());
result[i] = sender;
} catch (UnknownHostException x) {
if (cx == null)
cx = new ChannelException(sm.getString("parallelNioSender.unable.setup.NioSender"), x);
cx.addFaultyMember(destination[i], x);
}
}
if (cx != null)
throw cx;
else
return result;
}
use of org.apache.catalina.tribes.ChannelException in project tomcat by apache.
the class PooledParallelSender method sendMessage.
@Override
public void sendMessage(Member[] destination, ChannelMessage message) throws ChannelException {
if (!isConnected()) {
throw new ChannelException(sm.getString("pooledParallelSender.sender.disconnected"));
}
ParallelNioSender sender = (ParallelNioSender) getSender();
if (sender == null) {
ChannelException cx = new ChannelException(sm.getString("pooledParallelSender.unable.retrieveSender.timeout", Long.toString(getMaxWait())));
for (int i = 0; i < destination.length; i++) cx.addFaultyMember(destination[i], new NullPointerException(sm.getString("pooledParallelSender.unable.retrieveSender")));
throw cx;
} else {
try {
sender.sendMessage(destination, message);
sender.keepalive();
} catch (ChannelException x) {
sender.disconnect();
throw x;
} finally {
returnSender(sender);
}
}
}
use of org.apache.catalina.tribes.ChannelException in project tomcat by apache.
the class TestTcpFailureDetector method testTcpMcastFail.
@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);
}
Aggregations