Commit 962879c6 authored by Andre Freyssinet's avatar Andre Freyssinet
Browse files

Logging and encoding enhancements.

parent 7a2c26ab
/*
* Copyright (C) 2001 - 2021 ScalAgent Distributed Technologies
* Copyright (C) 2001 - 2022 ScalAgent Distributed Technologies
* Copyright (C) 1996 - 2000 BULL
* Copyright (C) 1996 - 2000 INRIA
*
......@@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.Serializable;
import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Logger;
import fr.dyade.aaa.common.Debug;
import fr.dyade.aaa.common.Pool;
......@@ -47,6 +48,8 @@ public final class Message implements Serializable, Encodable {
/** define serialVersionUID for interoperability */
static final long serialVersionUID = 1L;
public static Logger logger = Debug.getLogger(Message.class.getName());
/** <code>AgentId</code> of sender. */
transient AgentId from;
/** <code>AgentId</code> of destination agent. */
......@@ -178,9 +181,7 @@ public final class Message implements Serializable, Encodable {
out.writeInt(stamp);
if (not == null) {
Debug.getLogger(getClass().getName()).log(BasicLevel.ERROR,
"Message.writeObject() -> null notification.");
logger.log(BasicLevel.ERROR, "Message.writeObject() -> null notification.");
out.write(NULL);
} else {
// Writes notification attributes
......@@ -189,8 +190,8 @@ public final class Message implements Serializable, Encodable {
// Writes notification object
out.writeObject(not);
} else {
Debug.getLogger(getClass().getName()).log(BasicLevel.DEBUG,
"Message.writeObject() -> detachable notification: " + not);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "Message.writeObject() -> detachable notification: " + not);
}
}
}
......@@ -220,9 +221,7 @@ public final class Message implements Serializable, Encodable {
int opt = in.read();
if (opt == NULL) {
Debug.getLogger(getClass().getName()).log(BasicLevel.ERROR,
"Message.readObject -> null notification.");
logger.log(BasicLevel.ERROR, "Message.readObject -> null notification.");
not = null;
} else {
// Reads notification attributes
......@@ -236,9 +235,8 @@ public final class Message implements Serializable, Encodable {
not.persistent = persistent;
not.detached = false;
} else {
Debug.getLogger(getClass().getName()).log(BasicLevel.DEBUG,
"Message.readObject -> " + opt);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "Message.readObject -> " + opt);
}
}
}
......@@ -381,7 +379,7 @@ public final class Message implements Serializable, Encodable {
private SerializableWrapper serializedNot;
public int getEncodedSize() throws Exception {
int encodedSize = 2 + 2 + 4 + 2 + 2 + 4 + 2 + 2 + 4 + 1;
int encodedSize = from.getEncodedSize() + to.getEncodedSize() + 2 + 2 + 4 + 1;
if (not != null) {
if (! not.detachable) {
......@@ -395,8 +393,8 @@ public final class Message implements Serializable, Encodable {
encodedSize += not.getEncodedSize();
}
} else {
Debug.getLogger(getClass().getName()).log(BasicLevel.DEBUG,
"Message.writeObject() -> detachable notification: " + not);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "Message.writeObject() -> detachable notification: " + not);
}
}
return encodedSize;
......@@ -404,13 +402,9 @@ public final class Message implements Serializable, Encodable {
public void encode(Encoder encoder) throws Exception {
// Writes sender's AgentId
encoder.encode16(from.from);
encoder.encode16(from.to);
encoder.encode32(from.stamp);
from.encode(encoder);
// Writes adressee's AgentId
encoder.encode16(to.from);
encoder.encode16(to.to);
encoder.encode32(to.stamp);
to.encode(encoder);
// Writes source server id of message
encoder.encode16(source);
// Writes destination server id of message
......@@ -419,8 +413,7 @@ public final class Message implements Serializable, Encodable {
encoder.encode32(stamp);
if (not == null) {
Debug.getLogger(getClass().getName()).log(BasicLevel.ERROR,
"Message.writeObject() -> null notification.");
logger.log(BasicLevel.ERROR, "Message.writeObject() -> null notification.");
encoder.encodeByte(NULL);
} else {
// Writes notification attributes
......@@ -440,17 +433,17 @@ public final class Message implements Serializable, Encodable {
not.encode(encoder);
}
} else {
Debug.getLogger(getClass().getName()).log(BasicLevel.DEBUG,
"Message.writeObject() -> detachable notification: " + not);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "Message.writeObject() -> detachable notification: " + not);
}
}
}
public void decode(Decoder decoder) throws Exception {
// Reads sender's AgentId
from = new AgentId(decoder.decode16(), decoder.decode16(), decoder.decode32());
from = new AgentId(decoder.decode16(), decoder.decode16(), decoder.decode32()); // TODO (AF): Should use AgentId.decode
// Reads adressee's AgentId
to = new AgentId(decoder.decode16(), decoder.decode16(), decoder.decode32());
to = new AgentId(decoder.decode16(), decoder.decode16(), decoder.decode32()); // TODO (AF): Should use AgentId.decode
// Reads source server id of message
source = decoder.decode16();
// Reads destination server id of message
......@@ -460,8 +453,7 @@ public final class Message implements Serializable, Encodable {
int opt = decoder.decodeByte();
if (opt == NULL) {
Debug.getLogger(getClass().getName()).log(BasicLevel.ERROR,
"Message.readObject -> null notification.");
logger.log(BasicLevel.ERROR, "Message.readObject -> null notification.");
not = null;
} else {
// Reads notification attributes
......@@ -475,14 +467,8 @@ public final class Message implements Serializable, Encodable {
int classId = decoder.decodeUnsignedInt();
EncodableFactory factory = EncodableFactoryRepository.getFactory(classId);
if (factory == null) {
Debug.getLogger(getClass().getName()).log(BasicLevel.ERROR,
"from=" + from) ;
Debug.getLogger(getClass().getName()).log(BasicLevel.ERROR,
"to=" + to) ;
Debug.getLogger(getClass().getName()).log(BasicLevel.ERROR,
"dest=" + dest) ;
Debug.getLogger(getClass().getName()).log(BasicLevel.ERROR,
"stamp=" + stamp) ;
logger.log(BasicLevel.ERROR,
"Notification factory not found:" + classId + ", from=" + from + ", to=" + to + ", dest=" + dest + ", stamp=" + stamp) ;
throw new Exception("Notification factory not found: " + classId);
}
not = (Notification) factory.createEncodable();
......@@ -496,18 +482,15 @@ public final class Message implements Serializable, Encodable {
not.persistent = persistent;
not.detached = false;
} else {
Debug.getLogger(getClass().getName()).log(BasicLevel.DEBUG,
"Message.readObject -> " + opt);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "Message.readObject -> " + opt);
}
}
}
static class Factory implements EncodableFactory {
public Encodable createEncodable() {
return new Message();
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment