Commit 2a9f6e0b authored by Andre Freyssinet's avatar Andre Freyssinet

Adds monitoring informations.

parent 2bf4f176
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2016 ScalAgent Distributed Technologies
* Copyright (C) 2016 - 2020 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -74,13 +74,25 @@ public class ConsumerContext extends SessionContext {
messages.put(id, msg);
}
private int called = 0;
private int delivered = 0;
private int redelivered = 0;
public Message getMessage(long id) {
getClientCtx().setLastActivity(System.currentTimeMillis());
return messages.get(id);
}
synchronized Message receive(long timeout, long msgId) throws JMSException {
Message message = null;
called += 1;
getClientCtx().setLastActivity(System.currentTimeMillis());
Message message = getMessage(msgId);
if (message != null) {
redelivered += 1;
return message;
}
if (timeout > 0)
message = getConsumer().receive(timeout);
else if (timeout == 0)
......@@ -91,10 +103,11 @@ public class ConsumerContext extends SessionContext {
throw new JMSException("The consumer expire (timeout)");
}
//update activity
// update activity
getClientCtx().setLastActivity(System.currentTimeMillis());
if (message != null) {
delivered += 1;
if (getJmsContext().getSessionMode() == JMSContext.CLIENT_ACKNOWLEDGE) {
long id = msgId;
if (id == -1)
......@@ -115,4 +128,17 @@ public class ConsumerContext extends SessionContext {
public void clear() {
messages.clear();
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ConsumerContext [clientCtx=").append(getClientCtx().getClientId())
.append(", dest=").append(getDest())
.append(", lastId=").append(viewLastId())
.append(", called=").append(called)
.append(", delivered=").append(delivered)
.append(", redelivered=").append(redelivered)
.append("]");
return builder.toString();
}
}
......@@ -198,6 +198,8 @@ public class ProducerContext extends SessionContext {
}
}
private int sent = 0;
synchronized long send(
String type,
Map<String, Object> jmsHeaders,
......@@ -279,6 +281,7 @@ public class ProducerContext extends SessionContext {
// send the message
getProducer().setDeliveryMode(deliveryMode).setPriority(priority).setDeliveryDelay(deliveryDelay).setTimeToLive(timeToLive).send(getDest(), msg);
sent += 1;
// Increment the last id
incLastId();
//update activity
......@@ -287,4 +290,14 @@ public class ProducerContext extends SessionContext {
return getLastId();
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ProducerContext [clientCtx=").append(getClientCtx().getClientId())
.append(", dest=").append(getDest())
.append(", lastId=").append(viewLastId())
.append(", sent=").append(sent)
.append("]");
return builder.toString();
}
}
......@@ -23,6 +23,7 @@
package org.objectweb.joram.tools.rest.jms;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.jms.ConnectionFactory;
......@@ -129,4 +130,12 @@ public class RestClientContext {
this.idleTimeout = idleTimeout*1000;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("RestClientContext [clientId=").append(clientId)
.append(", lastActivity=").append(new Date(lastActivity))
.append(", idleTimeout=").append(idleTimeout).append("]");
return builder.toString();
}
}
......@@ -44,6 +44,11 @@ public abstract class SessionContext {
return dest;
}
/* Gets lastId without synchronization, avoids long pause */
public final long viewLastId() {
return lastId;
}
public synchronized long getLastId() {
return lastId;
}
......@@ -78,4 +83,13 @@ public abstract class SessionContext {
public RestClientContext getClientCtx() {
return clientCtx;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("SessionContext [clientCtx=").append(clientCtx.getClientId())
.append(", dest=").append(dest).append(", lastId=").append(lastId)
.append("]");
return builder.toString();
}
}
Markdown is supported
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