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
}
Aggregations