Search in sources :

Example 11 with ChannelException

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

the class MultipointBioSender method setupForSend.

protected BioSender[] setupForSend(Member[] destination) throws ChannelException {
    ChannelException cx = null;
    BioSender[] result = new BioSender[destination.length];
    for (int i = 0; i < destination.length; i++) {
        try {
            BioSender sender = bioSenders.get(destination[i]);
            if (sender == null) {
                sender = new BioSender();
                AbstractSender.transferProperties(this, sender);
                sender.setDestination(destination[i]);
                bioSenders.put(destination[i], sender);
            }
            result[i] = sender;
            if (!result[i].isConnected())
                result[i].connect();
            result[i].keepalive();
        } catch (Exception x) {
            if (cx == null)
                cx = new ChannelException(x);
            cx.addFaultyMember(destination[i], x);
        }
    }
    if (cx != null)
        throw cx;
    else
        return result;
}
Also used : ChannelException(org.apache.catalina.tribes.ChannelException) IOException(java.io.IOException) ChannelException(org.apache.catalina.tribes.ChannelException)

Example 12 with ChannelException

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

the class PooledMultiSender method sendMessage.

@Override
public void sendMessage(Member[] destination, ChannelMessage msg) throws ChannelException {
    MultiPointSender sender = null;
    try {
        sender = (MultiPointSender) getSender();
        if (sender == null) {
            ChannelException cx = new ChannelException(sm.getString("pooledMultiSender.unable.retrieve.sender", Long.toString(getMaxWait())));
            for (int i = 0; i < destination.length; i++) cx.addFaultyMember(destination[i], new NullPointerException(sm.getString("pooledMultiSender.retrieve.fail")));
            throw cx;
        } else {
            sender.sendMessage(destination, msg);
        }
        sender.keepalive();
    } finally {
        if (sender != null)
            returnSender(sender);
    }
}
Also used : MultiPointSender(org.apache.catalina.tribes.transport.MultiPointSender) ChannelException(org.apache.catalina.tribes.ChannelException)

Example 13 with ChannelException

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

the class ParallelNioSender method doLoop.

private int doLoop(long selectTimeOut, int maxAttempts, boolean waitForAck, ChannelMessage msg) throws IOException, ChannelException {
    int completed = 0;
    int selectedKeys = selector.select(selectTimeOut);
    if (selectedKeys == 0) {
        return 0;
    }
    Iterator<SelectionKey> it = selector.selectedKeys().iterator();
    while (it.hasNext()) {
        SelectionKey sk = it.next();
        it.remove();
        int readyOps = sk.readyOps();
        sk.interestOps(sk.interestOps() & ~readyOps);
        NioSender sender = (NioSender) sk.attachment();
        try {
            if (sender.process(sk, waitForAck)) {
                completed++;
                sender.setComplete(true);
                if (Logs.MESSAGES.isTraceEnabled()) {
                    Logs.MESSAGES.trace("ParallelNioSender - Sent msg:" + new UniqueId(msg.getUniqueId()) + " at " + new java.sql.Timestamp(System.currentTimeMillis()) + " to " + sender.getDestination().getName());
                }
                SenderState.getSenderState(sender.getDestination()).setReady();
            }
        //end if
        } catch (Exception x) {
            if (log.isTraceEnabled()) {
                log.trace("Error while processing send to " + sender.getDestination().getName(), x);
            }
            SenderState state = SenderState.getSenderState(sender.getDestination());
            int attempt = sender.getAttempt() + 1;
            boolean retry = (sender.getAttempt() <= maxAttempts && maxAttempts > 0);
            synchronized (state) {
                //sk.cancel();
                if (state.isSuspect())
                    state.setFailing();
                if (state.isReady()) {
                    state.setSuspect();
                    if (retry)
                        log.warn(sm.getString("parallelNioSender.send.fail.retrying", sender.getDestination().getName()));
                    else
                        log.warn(sm.getString("parallelNioSender.send.fail", sender.getDestination().getName()), x);
                }
            }
            if (!isConnected()) {
                log.warn(sm.getString("parallelNioSender.sender.disconnected.notRetry", sender.getDestination().getName()));
                ChannelException cx = new ChannelException(sm.getString("parallelNioSender.sender.disconnected.sendFailed"), x);
                cx.addFaultyMember(sender.getDestination(), x);
                throw cx;
            }
            byte[] data = sender.getMessage();
            if (retry) {
                try {
                    sender.disconnect();
                    sender.connect();
                    sender.setAttempt(attempt);
                    sender.setMessage(data);
                } catch (Exception ignore) {
                    state.setFailing();
                }
            } else {
                ChannelException cx = new ChannelException(sm.getString("parallelNioSender.sendFailed.attempt", Integer.toString(sender.getAttempt()), Integer.toString(maxAttempts)), x);
                cx.addFaultyMember(sender.getDestination(), x);
                throw cx;
            }
        //end if
        }
    }
    return completed;
}
Also used : SelectionKey(java.nio.channels.SelectionKey) UniqueId(org.apache.catalina.tribes.UniqueId) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ChannelException(org.apache.catalina.tribes.ChannelException) SenderState(org.apache.catalina.tribes.transport.SenderState) ChannelException(org.apache.catalina.tribes.ChannelException)

Example 14 with ChannelException

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

the class ParallelNioSender method close.

private synchronized void close() throws ChannelException {
    ChannelException x = null;
    Object[] members = nioSenders.keySet().toArray();
    for (int i = 0; i < members.length; i++) {
        Member mbr = (Member) members[i];
        try {
            NioSender sender = nioSenders.get(mbr);
            sender.disconnect();
        } catch (Exception e) {
            if (x == null)
                x = new ChannelException(e);
            x.addFaultyMember(mbr, e);
        }
        nioSenders.remove(mbr);
    }
    if (x != null)
        throw x;
}
Also used : Member(org.apache.catalina.tribes.Member) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ChannelException(org.apache.catalina.tribes.ChannelException) ChannelException(org.apache.catalina.tribes.ChannelException)

Example 15 with ChannelException

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

the class ChannelCoordinator method internalStop.

/**
     * Shuts down the channel. This can be called multiple times for individual services to shutdown
     * The svc parameter can be the logical or value of any constants
     * @param svc int value of <BR>
     * DEFAULT - will shutdown all services <BR>
     * MBR_RX_SEQ - starts the membership receiver <BR>
     * MBR_TX_SEQ - starts the membership broadcaster <BR>
     * SND_TX_SEQ - starts the replication transmitter<BR>
     * SND_RX_SEQ - starts the replication receiver<BR>
     * @throws ChannelException if a startup error occurs or the service is already started.
     */
protected synchronized void internalStop(int svc) throws ChannelException {
    try {
        //make sure we don't pass down any flags that are unrelated to the bottom layer
        svc = svc & Channel.DEFAULT;
        //we have already stopped up all components
        if (startLevel == 0)
            return;
        //nothing to stop
        if (svc == 0)
            return;
        boolean valid = false;
        if (Channel.SND_RX_SEQ == (svc & Channel.SND_RX_SEQ)) {
            clusterReceiver.stop();
            clusterReceiver.setMessageListener(null);
            valid = true;
        }
        if (Channel.SND_TX_SEQ == (svc & Channel.SND_TX_SEQ)) {
            clusterSender.stop();
            valid = true;
        }
        if (Channel.MBR_RX_SEQ == (svc & Channel.MBR_RX_SEQ)) {
            membershipService.stop(MembershipService.MBR_RX);
            membershipService.setMembershipListener(null);
            valid = true;
        }
        if (Channel.MBR_TX_SEQ == (svc & Channel.MBR_TX_SEQ)) {
            valid = true;
            membershipService.stop(MembershipService.MBR_TX);
        }
        if (!valid) {
            throw new IllegalArgumentException(sm.getString("channelCoordinator.invalid.startLevel"));
        }
        startLevel = (startLevel & (~svc));
        setChannel(null);
    } catch (Exception x) {
        throw new ChannelException(x);
    }
}
Also used : ChannelException(org.apache.catalina.tribes.ChannelException) ChannelException(org.apache.catalina.tribes.ChannelException)

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