protected void shutdown() {}
public void run() {
Message msg = null;
Set servers = new HashSet();
try {
try {
nos = new NetworkOutputStream();
} catch (IOException exc) {
logmon.log(BasicLevel.FATAL, getName() + ", cannot start.");
return;
}
while (running) {
canStop = true;
try {
if (this.logmon.isLoggable(BasicLevel.DEBUG))
this.logmon.log(BasicLevel.DEBUG, this.getName() + ", waiting message");
msg = qout.get(WDActivationPeriod);
} catch (InterruptedException exc) {
if (this.logmon.isLoggable(BasicLevel.DEBUG))
this.logmon.log(BasicLevel.DEBUG, this.getName() + ", interrupted");
continue;
}
canStop = false;
if (! running) break;
if (msg != null) {
sendList.addMessage(msg);
qout.pop();
}
long currentTimeMillis = System.currentTimeMillis();
ServerDesc server = null;
Iterator iterator = sendList.toSendIterator();
while (iterator.hasNext()) {
msg = (Message) iterator.next();
short msgto = msg.getDest();
if (this.logmon.isLoggable(BasicLevel.DEBUG))
this.logmon.log(BasicLevel.DEBUG,
this.getName() +
", check msg#" + msg.getStamp() +
" from " + msg.from +
" to " + msg.to);
if (msg.not.expiration > 0L && msg.not.expiration < currentTimeMillis) {
// Remove the message.
AgentServer.getTransaction().begin();
if (msg.not.deadNotificationAgentId != null) {
if (logmon.isLoggable(BasicLevel.DEBUG)) {
logmon.log(BasicLevel.DEBUG, getName() + ": forward expired notification " + msg.from
+ ", " + msg.not + " to " + msg.not.deadNotificationAgentId);
}
ExpiredNot expiredNot = new ExpiredNot(msg.not, msg.from, msg.to);
Channel.post(Message.alloc(AgentId.localId, msg.not.deadNotificationAgentId, expiredNot));
Channel.validate();
} else {
if (logmon.isLoggable(BasicLevel.DEBUG)) {
logmon.log(BasicLevel.DEBUG, getName() + ": removes expired notification " + msg.from + ", "
+ msg.not);
}
}
// Deletes the processed notification
iterator.remove();
// AF: A reprendre.
// // send ack in JGroups to delete msg
// if (jgroups != null)
// jgroups.send(new JGroupsAckMsg(msg));
msg.delete();
msg.free();
AgentServer.getTransaction().commit(true);
continue;
}
try {
server = AgentServer.getServerDesc(msgto);
} catch (UnknownServerException exc) {
this.logmon.log(BasicLevel.ERROR,
this.getName() + ", can't send message: " + msg,
exc);
// Remove the message, may be we have to post an error
// notification to sender.
AgentServer.getTransaction().begin();
// Deletes the processed notification
iterator.remove();
// AF: A reprendre.
// // send ack in JGroups to delete msg
// if (jgroups != null)
// jgroups.send(new JGroupsAckMsg(msg));
msg.delete();
msg.free();
AgentServer.getTransaction().commit(true);
continue;
}
if (servers.contains(server)) {
// The server has already been tested during this round
continue;
}
this.logmon.log(BasicLevel.DEBUG,
this.getName() + server.active + ',' +
server.retry + ',' +
server.last + ',' +
currentTimeMillis);
if ((server.active) ||
((server.retry < WDNbRetryLevel1) &&
((server.last + WDRetryPeriod1) < currentTimeMillis)) ||
((server.retry < WDNbRetryLevel2) &&
((server.last + WDRetryPeriod2) < currentTimeMillis)) ||
((server.last + WDRetryPeriod3) < currentTimeMillis)) {
try {
if (this.logmon.isLoggable(BasicLevel.DEBUG))
this.logmon.log(BasicLevel.DEBUG,
this.getName() +
", send msg#" + msg.getStamp());
// Open the connection.
Socket socket = createSocket(server);
// The connection is ok, reset active and retry flags.
server.active = true;
server.retry = 0;
server.last = currentTimeMillis;
setSocketOption(socket);
send(socket, msg, currentTimeMillis);
} catch (SocketException exc) {
if (this.logmon.isLoggable(BasicLevel.WARN))
this.logmon.log(BasicLevel.WARN,
this.getName() + ", let msg in watchdog list",
exc);
server.active = false;
server.retry++;
server.last = currentTimeMillis;
// Do not send following messages to this server
servers.add(server);
// There is a connection problem, let the message in the
// waiting list.
continue;
} catch (Exception exc) {
this.logmon.log(BasicLevel.ERROR,
this.getName() + ", error", exc);
}
AgentServer.getTransaction().begin();
// Deletes the processed notification
iterator.remove();
// AF (TODO): To remove ?
// // send ack in JGroups to delete msg
// if (jgroups != null)
// jgroups.send(new JGroupsAckMsg(msg));
msg.delete();
msg.free();
AgentServer.getTransaction().commit(true);
} else {
// Do not send following messages to this server
servers.add(server);
}
}
servers.clear();
}
} catch (Exception exc) {
this.logmon.log(BasicLevel.FATAL,
this.getName() + ", unrecoverable exception", exc);
// There is an unrecoverable exception during the transaction