Search in sources :

Example 16 with ChannelException

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

the class ChannelCoordinator method internalStart.

/**
     * Starts up the channel. This can be called multiple times for individual services to start
     * The svc parameter can be the logical or value of any constants
     * @param svc int value of <BR>
     * DEFAULT - will start 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 internalStart(int svc) throws ChannelException {
    try {
        boolean valid = false;
        //make sure we don't pass down any flags that are unrelated to the bottom layer
        svc = svc & Channel.DEFAULT;
        //we have already started up all components
        if (startLevel == Channel.DEFAULT)
            return;
        //nothing to start
        if (svc == 0)
            return;
        if (svc == (svc & startLevel)) {
            throw new ChannelException(sm.getString("channelCoordinator.alreadyStarted", Integer.toString(svc)));
        }
        //listens to with the local membership settings
        if (Channel.SND_RX_SEQ == (svc & Channel.SND_RX_SEQ)) {
            clusterReceiver.setMessageListener(this);
            clusterReceiver.setChannel(getChannel());
            clusterReceiver.start();
            //synchronize, big time FIXME
            Member localMember = getChannel().getLocalMember(false);
            if (localMember instanceof StaticMember) {
                // static member
                StaticMember staticMember = (StaticMember) localMember;
                staticMember.setHost(getClusterReceiver().getHost());
                staticMember.setPort(getClusterReceiver().getPort());
                staticMember.setSecurePort(getClusterReceiver().getSecurePort());
            } else {
                // multicast member
                membershipService.setLocalMemberProperties(getClusterReceiver().getHost(), getClusterReceiver().getPort(), getClusterReceiver().getSecurePort(), getClusterReceiver().getUdpPort());
            }
            valid = true;
        }
        if (Channel.SND_TX_SEQ == (svc & Channel.SND_TX_SEQ)) {
            clusterSender.setChannel(getChannel());
            clusterSender.start();
            valid = true;
        }
        if (Channel.MBR_RX_SEQ == (svc & Channel.MBR_RX_SEQ)) {
            membershipService.setMembershipListener(this);
            membershipService.setChannel(getChannel());
            if (membershipService instanceof McastService) {
                ((McastService) membershipService).setMessageListener(this);
            }
            membershipService.start(MembershipService.MBR_RX);
            valid = true;
        }
        if (Channel.MBR_TX_SEQ == (svc & Channel.MBR_TX_SEQ)) {
            membershipService.setChannel(getChannel());
            membershipService.start(MembershipService.MBR_TX);
            valid = true;
        }
        if (!valid) {
            throw new IllegalArgumentException(sm.getString("channelCoordinator.invalid.startLevel"));
        }
        startLevel = (startLevel | svc);
    } catch (ChannelException cx) {
        throw cx;
    } catch (Exception x) {
        throw new ChannelException(x);
    }
}
Also used : StaticMember(org.apache.catalina.tribes.membership.StaticMember) Member(org.apache.catalina.tribes.Member) StaticMember(org.apache.catalina.tribes.membership.StaticMember) ChannelException(org.apache.catalina.tribes.ChannelException) ChannelException(org.apache.catalina.tribes.ChannelException) McastService(org.apache.catalina.tribes.membership.McastService)

Example 17 with ChannelException

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

the class AbstractReplicatedMap method ping.

/**
     * Sends a ping out to all the members in the cluster, not just map members
     * that this map is alive.
     * @param timeout long
     * @throws ChannelException Send error
     */
protected void ping(long timeout) throws ChannelException {
    MapMessage msg = new MapMessage(this.mapContextName, MapMessage.MSG_PING, false, null, null, null, channel.getLocalMember(false), null);
    if (channel.getMembers().length > 0) {
        try {
            //send a ping, wait for all nodes to reply
            Response[] resp = rpcChannel.send(channel.getMembers(), msg, RpcChannel.ALL_REPLY, (channelSendOptions), (int) accessTimeout);
            for (int i = 0; i < resp.length; i++) {
                MapMessage mapMsg = (MapMessage) resp[i].getMessage();
                try {
                    mapMsg.deserialize(getExternalLoaders());
                    State state = (State) mapMsg.getValue();
                    if (state.isAvailable()) {
                        memberAlive(resp[i].getSource());
                    } else {
                        if (log.isInfoEnabled())
                            log.info(sm.getString("abstractReplicatedMap.mapMember.unavailable", resp[i].getSource()));
                    }
                } catch (ClassNotFoundException | IOException e) {
                    log.error(sm.getString("abstractReplicatedMap.unable.deserialize.MapMessage"), e);
                }
            }
        } catch (ChannelException ce) {
            // Handle known failed members
            FaultyMember[] faultyMembers = ce.getFaultyMembers();
            for (FaultyMember faultyMember : faultyMembers) {
                memberDisappeared(faultyMember.getMember());
            }
            throw ce;
        }
    }
    //update our map of members, expire some if we didn't receive a ping back
    synchronized (mapMembers) {
        Member[] members = mapMembers.keySet().toArray(new Member[mapMembers.size()]);
        long now = System.currentTimeMillis();
        for (Member member : members) {
            long access = mapMembers.get(member).longValue();
            if ((now - access) > timeout) {
                log.warn(sm.getString("abstractReplicatedMap.ping.timeout", member, mapname));
                memberDisappeared(member);
            }
        }
    }
//synch
}
Also used : IOException(java.io.IOException) Response(org.apache.catalina.tribes.group.Response) FaultyMember(org.apache.catalina.tribes.ChannelException.FaultyMember) FaultyMember(org.apache.catalina.tribes.ChannelException.FaultyMember) Member(org.apache.catalina.tribes.Member) ChannelException(org.apache.catalina.tribes.ChannelException)

Example 18 with ChannelException

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

the class LazyReplicatedMap method publishEntryInfo.

/**
     * publish info about a map pair (key/value) to other nodes in the cluster
     * @param key Object
     * @param value Object
     * @return Member - the backup node
     * @throws ChannelException Cluster error
     */
@Override
protected Member[] publishEntryInfo(Object key, Object value) throws ChannelException {
    if (!(key instanceof Serializable && value instanceof Serializable))
        return new Member[0];
    Member[] members = getMapMembers();
    int firstIdx = getNextBackupIndex();
    int nextIdx = firstIdx;
    Member[] backup = new Member[0];
    //there are no backups
    if (members.length == 0 || firstIdx == -1)
        return backup;
    boolean success = false;
    do {
        //select a backup node
        Member next = members[nextIdx];
        //increment for the next round of back up selection
        nextIdx = nextIdx + 1;
        if (nextIdx >= members.length)
            nextIdx = 0;
        if (next == null) {
            continue;
        }
        MapMessage msg = null;
        try {
            Member[] tmpBackup = wrap(next);
            //publish the backup data to one node
            msg = new MapMessage(getMapContextName(), MapMessage.MSG_BACKUP, false, (Serializable) key, (Serializable) value, null, channel.getLocalMember(false), tmpBackup);
            if (log.isTraceEnabled())
                log.trace("Publishing backup data:" + msg + " to: " + next.getName());
            UniqueId id = getChannel().send(tmpBackup, msg, getChannelSendOptions());
            if (log.isTraceEnabled())
                log.trace("Data published:" + msg + " msg Id:" + id);
            //we published out to a backup, mark the test success
            success = true;
            backup = tmpBackup;
        } catch (ChannelException x) {
            log.error(sm.getString("lazyReplicatedMap.unableReplicate.backup", key, next, x.getMessage()), x);
            continue;
        }
        try {
            //publish the data out to all nodes
            Member[] proxies = excludeFromSet(backup, getMapMembers());
            if (success && proxies.length > 0) {
                msg = new MapMessage(getMapContextName(), MapMessage.MSG_PROXY, false, (Serializable) key, null, null, channel.getLocalMember(false), backup);
                if (log.isTraceEnabled())
                    log.trace("Publishing proxy data:" + msg + " to: " + Arrays.toNameString(proxies));
                getChannel().send(proxies, msg, getChannelSendOptions());
            }
        } catch (ChannelException x) {
            //log the error, but proceed, this should only happen if a node went down,
            //and if the node went down, then it can't receive the message, the others
            //should still get it.
            log.error(sm.getString("lazyReplicatedMap.unableReplicate.proxy", key, next, x.getMessage()), x);
        }
    } while (!success && (firstIdx != nextIdx));
    return backup;
}
Also used : UniqueId(org.apache.catalina.tribes.UniqueId) Serializable(java.io.Serializable) Member(org.apache.catalina.tribes.Member) ChannelException(org.apache.catalina.tribes.ChannelException)

Example 19 with ChannelException

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

the class OrderInterceptor method sendMessage.

@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    if (!okToProcess(msg.getOptions())) {
        super.sendMessage(destination, msg, payload);
        return;
    }
    ChannelException cx = null;
    for (int i = 0; i < destination.length; i++) {
        try {
            int nr = 0;
            outLock.writeLock().lock();
            try {
                nr = incCounter(destination[i]);
            } finally {
                outLock.writeLock().unlock();
            }
            //reduce byte copy
            msg.getMessage().append(nr);
            try {
                getNext().sendMessage(new Member[] { destination[i] }, msg, payload);
            } finally {
                msg.getMessage().trim(4);
            }
        } catch (ChannelException x) {
            if (cx == null)
                cx = x;
            cx.addFaultyMember(x.getFaultyMembers());
        }
    }
    //for
    if (cx != null)
        throw cx;
}
Also used : ChannelException(org.apache.catalina.tribes.ChannelException)

Example 20 with ChannelException

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

the class GzipInterceptor method sendMessage.

@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    try {
        byte[] data = compress(msg.getMessage().getBytes());
        msg.getMessage().trim(msg.getMessage().getLength());
        msg.getMessage().append(data, 0, data.length);
        super.sendMessage(destination, msg, payload);
    } catch (IOException x) {
        log.error(sm.getString("gzipInterceptor.compress.failed"));
        throw new ChannelException(x);
    }
}
Also used : IOException(java.io.IOException) 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