Minor change, improved a bit logging messages quality
This commit is contained in:
+13
-7
@@ -78,11 +78,11 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
|
||||
}
|
||||
|
||||
void processConnect(ServerChannel session, ConnectMessage msg) {
|
||||
LOG.info("processConnect for client " + msg.getClientID());
|
||||
LOG.debug("processConnect for client " + msg.getClientID());
|
||||
if (msg.getProcotolVersion() != 0x03) {
|
||||
ConnAckMessage badProto = new ConnAckMessage();
|
||||
badProto.setReturnCode(ConnAckMessage.UNNACEPTABLE_PROTOCOL_VERSION);
|
||||
LOG.info("processConnect sent bad proto ConnAck");
|
||||
LOG.warn("processConnect sent bad proto ConnAck");
|
||||
session.write(badProto);
|
||||
session.close(false);
|
||||
return;
|
||||
@@ -153,8 +153,9 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
|
||||
|
||||
ConnAckMessage okResp = new ConnAckMessage();
|
||||
okResp.setReturnCode(ConnAckMessage.CONNECTION_ACCEPTED);
|
||||
LOG.info("processConnect sent OK ConnAck");
|
||||
LOG.debug("processConnect sent OK ConnAck");
|
||||
session.write(okResp);
|
||||
LOG.info(String.format("Connected client ID <%s> with clean session %s", msg.getClientID(), msg.isCleanSession()));
|
||||
|
||||
if (!msg.isCleanSession()) {
|
||||
//force the republish of stored QoS1 and QoS2
|
||||
@@ -166,10 +167,11 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
|
||||
LOG.debug("republishStored invoked");
|
||||
List<PublishEvent> publishedEvents = m_storageService.retrivePersistedPublishes(clientID);
|
||||
if (publishedEvents == null) {
|
||||
LOG.debug("republishStored, no stored publish events");
|
||||
LOG.info(String.format("No stored messages for client <%s>", clientID));
|
||||
return;
|
||||
}
|
||||
|
||||
LOG.info(String.format("republishing stored messages to client <%s>", clientID));
|
||||
for (PublishEvent pubEvt : publishedEvents) {
|
||||
sendPublish(pubEvt.getClientID(), pubEvt.getTopic(), pubEvt.getQos(),
|
||||
pubEvt.getMessage(), false, pubEvt.getMessageID());
|
||||
@@ -177,7 +179,7 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
|
||||
}
|
||||
|
||||
private void processRemoveAllSubscriptions(String clientID) {
|
||||
LOG.debug("processRemoveAllSubscriptions invoked");
|
||||
LOG.info(String.format("cleaning old saved subscriptions for client <%s>", clientID));
|
||||
subscriptions.removeForClient(clientID);
|
||||
|
||||
//remove also the messages stored of type QoS1/2
|
||||
@@ -375,6 +377,7 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
|
||||
//de-activate the subscriptions for this ClientID
|
||||
// String clientID = (String) evt.getSession().getAttribute(Constants.ATTR_CLIENTID);
|
||||
subscriptions.deactivate(clientID);
|
||||
LOG.info(String.format("Disconnected client <%s>", clientID));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -397,7 +400,7 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
|
||||
|
||||
|
||||
void processSubscribe(ServerChannel session, SubscribeMessage msg, String clientID, boolean cleanSession) {
|
||||
LOG.info(String.format("processSubscribe invoked from client %s with msgID %d", clientID, msg.getMessageID()));
|
||||
LOG.debug(String.format("processSubscribe invoked from client %s with msgID %d", clientID, msg.getMessageID()));
|
||||
|
||||
for (SubscribeMessage.Couple req : msg.subscriptions()) {
|
||||
AbstractMessage.QOSType qos = AbstractMessage.QOSType.values()[req.getQos()];
|
||||
@@ -413,11 +416,14 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
|
||||
for (int i = 0; i < msg.subscriptions().size(); i++) {
|
||||
ackMessage.addType(AbstractMessage.QOSType.MOST_ONE);
|
||||
}
|
||||
LOG.info("replying with SubAck to MSG ID " + msg.getMessageID());
|
||||
LOG.debug("replying with SubAck to MSG ID " + msg.getMessageID());
|
||||
session.write(ackMessage);
|
||||
}
|
||||
|
||||
private void subscribeSingleTopic(Subscription newSubscription, final String topic) {
|
||||
LOG.info(String.format("<%s> subscribed to topic <%s> with QoS %s",
|
||||
newSubscription.getClientId(), topic,
|
||||
AbstractMessage.QOSType.formatQoS(newSubscription.getRequestedQos())));
|
||||
subscriptions.add(newSubscription);
|
||||
|
||||
//scans retained messages to be published to the new subscription
|
||||
|
||||
@@ -25,6 +25,7 @@ public class Server {
|
||||
|
||||
final Server server = new Server();
|
||||
server.startServer();
|
||||
System.out.println("Server started, version 0.4-SNAPSHOT");
|
||||
//Bind a shutdown hook
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user