listenSniffTemplate = MessageTemplate.MatchConversationId(getName() + "-event");
}
public void action() {
ACLMessage current = receive(listenSniffTemplate);
if(current != null) {
try {
Occurred o = (Occurred)getContentManager().extractContent(current);
EventRecord er = o.getWhat();
Event ev = er.getWhat();
String content = null;
Envelope env = null;
AID unicastReceiver = null;
if(ev instanceof SentMessage) {
content = ((SentMessage)ev).getMessage().getPayload();
env = ((SentMessage)ev).getMessage().getEnvelope();
unicastReceiver = ((SentMessage)ev).getReceiver();
} else if(ev instanceof PostedMessage) {
content = ((PostedMessage)ev).getMessage().getPayload();
env = ((PostedMessage)ev).getMessage().getEnvelope();
unicastReceiver = ((PostedMessage)ev).getReceiver();
AID sender = ((PostedMessage)ev).getSender();
// If the sender is currently under sniff, then the message was already
// displayed when the 'sent-message' event occurred --> just skip this message.
if(agentsUnderSniff.contains(new Agent(sender))) {
return;
}
} else {
return;
}
ACLCodec codec = new StringACLCodec();
String charset = null;
if ((env == null) || ((charset = env.getPayloadEncoding()) == null)) {
charset = ACLCodec.DEFAULT_CHARSET;
}
ACLMessage tmp = codec.decode(content.getBytes(charset),charset);
tmp.setEnvelope(env);
Message msg = new Message(tmp, unicastReceiver);
/* If this is a 'posted-message' event and the sender is
// currently under sniff, then the message was already
// displayed when the 'sent-message' event occurred. In that