!(msg instanceof DoneMsg) &&
(msg.getDestination() == this.replicationServer.getServerId()))
{
if (msg instanceof ErrorMsg)
{
ErrorMsg errorMsg = (ErrorMsg) msg;
logError(ERR_ERROR_MSG_RECEIVED.get(
errorMsg.getDetails()));
} else if (msg instanceof MonitorRequestMsg)
{
// If the request comes from a Directory Server we need to
// build the full list of all servers in the topology
// and send back a MonitorMsg with the full list of all the servers
// in the topology.
if (senderHandler.isDataServer())
{
// Monitoring information requested by a DS
MonitorMsg monitorMsg =
createGlobalTopologyMonitorMsg(
msg.getDestination(), msg.getSenderID(), false);
if (monitorMsg != null)
{
try
{
senderHandler.send(monitorMsg);
} catch (IOException e)
{
// the connection was closed.
}
}
return;
} else
{
// Monitoring information requested by a RS
MonitorMsg monitorMsg =
createLocalTopologyMonitorMsg(msg.getDestination(),
msg.getSenderID());
if (monitorMsg != null)
{
try
{
senderHandler.send(monitorMsg);
} catch (Exception e)
{
// We log the error. The requestor will detect a timeout or
// any other failure on the connection.
logError(ERR_CHANGELOG_ERROR_SENDING_MSG.get(
Integer.toString((msg.getDestination()))));
}
}
}
} else if (msg instanceof MonitorMsg)
{
MonitorMsg monitorMsg =
(MonitorMsg) msg;
GlobalServerId globalServerId =
new GlobalServerId(baseDn, senderHandler.getServerId());
receivesMonitorDataResponse(monitorMsg, globalServerId);
} else
{
logError(NOTE_ERR_ROUTING_TO_SERVER.get(
msg.getClass().getCanonicalName()));
MessageBuilder mb1 = new MessageBuilder();
mb1.append(
NOTE_ERR_ROUTING_TO_SERVER.get(msg.getClass().getCanonicalName()));
mb1.append("serverID:" + msg.getDestination());
ErrorMsg errMsg = new ErrorMsg(
msg.getSenderID(), mb1.toMessage());
try
{
senderHandler.send(errMsg);
} catch (IOException ioe1)
{
// an error happened on the sender session trying to recover
// from an error on the receiver session.
// Not much more we can do at this point.
}
}
return;
}
List<ServerHandler> servers = getDestinationServers(msg, senderHandler);
if (servers.isEmpty())
{
MessageBuilder mb = new MessageBuilder();
mb.append(ERR_NO_REACHABLE_PEER_IN_THE_DOMAIN.get(
this.baseDn, Integer.toString(msg.getDestination())));
mb.append(" In Replication Server=" +
this.replicationServer.getMonitorInstanceName());
mb.append(" unroutable message =" + msg.getClass().getSimpleName());
mb.append(" Details:routing table is empty");
ErrorMsg errMsg = new ErrorMsg(
this.replicationServer.getServerId(),
msg.getSenderID(),
mb.toMessage());
logError(mb.toMessage());
try
{
senderHandler.send(errMsg);
} catch (IOException ioe)
{
// TODO Handle error properly (sender timeout in addition)
/*
* An error happened trying to send an error msg to this server.
* Log an error and close the connection to this server.
*/
MessageBuilder mb2 = new MessageBuilder();
mb2.append(ERR_CHANGELOG_ERROR_SENDING_ERROR.get(this.toString()));
mb2.append(stackTraceToSingleLineString(ioe));
logError(mb2.toMessage());
stopServer(senderHandler, false);
}
} else
{
for (ServerHandler targetHandler : servers)
{
try
{
targetHandler.send(msg);
} catch (IOException ioe)
{
/*
* An error happened trying the send a routable message
* to its destination server.
* Send back an error to the originator of the message.
*/
MessageBuilder mb1 = new MessageBuilder();
mb1.append(ERR_NO_REACHABLE_PEER_IN_THE_DOMAIN.get(
this.baseDn, Integer.toString(msg.getDestination())));
mb1.append(" unroutable message =" + msg.getClass().getSimpleName());
mb1.append(" Details: " + ioe.getLocalizedMessage());
ErrorMsg errMsg = new ErrorMsg(
msg.getSenderID(), mb1.toMessage());
logError(mb1.toMessage());
try
{
senderHandler.send(errMsg);