Search in sources :

Example 21 with ChannelException

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);
    }
}
Also used : DatagramPacket(java.net.DatagramPacket) IOException(java.io.IOException) ChannelException(org.apache.catalina.tribes.ChannelException) ChannelException(org.apache.catalina.tribes.ChannelException)

Example 22 with ChannelException

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);
    }
}
Also used : IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ChannelException(org.apache.catalina.tribes.ChannelException) ChannelException(org.apache.catalina.tribes.ChannelException)

Example 23 with ChannelException

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;
}
Also used : UnknownHostException(java.net.UnknownHostException) ChannelException(org.apache.catalina.tribes.ChannelException)

Example 24 with ChannelException

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);
        }
    }
}
Also used : ChannelException(org.apache.catalina.tribes.ChannelException)

Example 25 with ChannelException

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);
}
Also used : ByteMessage(org.apache.catalina.tribes.ByteMessage) ChannelException(org.apache.catalina.tribes.ChannelException) Test(org.junit.Test)

Aggregations

ChannelException (org.apache.catalina.tribes.ChannelException)27 IOException (java.io.IOException)10 Member (org.apache.catalina.tribes.Member)8 UnknownHostException (java.net.UnknownHostException)4 UniqueId (org.apache.catalina.tribes.UniqueId)4 Test (org.junit.Test)4 ByteMessage (org.apache.catalina.tribes.ByteMessage)3 FaultyMember (org.apache.catalina.tribes.ChannelException.FaultyMember)3 ChannelInterceptor (org.apache.catalina.tribes.ChannelInterceptor)3 Serializable (java.io.Serializable)2 Response (org.apache.catalina.tribes.group.Response)2 ChannelData (org.apache.catalina.tribes.io.ChannelData)2 XByteBuffer (org.apache.catalina.tribes.io.XByteBuffer)2 DatagramPacket (java.net.DatagramPacket)1 SelectionKey (java.nio.channels.SelectionKey)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1