Search in sources :

Example 1 with FaultyMember

use of org.apache.catalina.tribes.ChannelException.FaultyMember 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)

Aggregations

IOException (java.io.IOException)1 ChannelException (org.apache.catalina.tribes.ChannelException)1 FaultyMember (org.apache.catalina.tribes.ChannelException.FaultyMember)1 Member (org.apache.catalina.tribes.Member)1 Response (org.apache.catalina.tribes.group.Response)1