/**
* Handle an incoming JICP packet received by the MediatorManager
*/
public JICPPacket handleJICPPacket(Connection c, JICPPacket pkt, InetAddress addr, int port) throws ICPException {
JICPPacket response = null;
if ((status == ACTIVE) && (frontEndStatus != TERMINATED)) {
if (myLogger.isLoggable(Logger.FINE)) {
myLogger.log(Logger.FINE, myID+" - Incoming packet. Type = "+pkt.getType()+", SID = "+pkt.getSessionID()+", terminated-info = "+((pkt.getInfo() & JICPProtocol.TERMINATED_INFO) != 0));
}
String from = " [" + addr + ":" + port + "]";
if (pkt.getType() == JICPProtocol.COMMAND_TYPE) {
// COMMAND
if ((pkt.getInfo() & JICPProtocol.TERMINATED_INFO) != 0) {
// PEER TERMINATION NOTIFICATION
// The remote FrontEnd terminated spontaneously --> Terminate and notify up.
myLogger.log(Logger.INFO, myID+" - Peer termination notification received");
handlePeerSelfTermination();
// Since we return null the MediatorManager would keep the connection open --> close it explicitly
return createTerminationNotificationAck();
} else {
// NORMAL COMMAND
// Serve the incoming command and send back the response
byte sid = pkt.getSessionID();
if (sid == lastIncomingCommandSid) {
myLogger.log(Logger.WARNING, myID+" - Duplicated command received. SID = " + sid);
response = lastResponse;
} else {
if (myLogger.isLoggable(Logger.FINE)) {
myLogger.log(Logger.FINE, myID+" - Incoming command received. SID = " + sid);
}
byte[] rspData = mySkel.handleCommand(pkt.getData());
if (myLogger.isLoggable(Logger.FINE)) {
myLogger.log(Logger.FINE, myID+" - Incoming command served. SID = " + sid);
}
response = new JICPPacket(JICPProtocol.RESPONSE_TYPE, JICPProtocol.DEFAULT_INFO, rspData);
response.setSessionID(sid);
lastIncomingCommandSid = sid;
lastResponse = response;
}
}
} else {