Commit f58d4117 authored by Andre Freyssinet's avatar Andre Freyssinet

Adds monitoring informations.

parent f4a39f12
/*
* 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
......@@ -73,6 +73,10 @@ public class ConsumerContext extends SessionContext {
setLastId(id);
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());
......@@ -80,21 +84,30 @@ public class ConsumerContext extends SessionContext {
}
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)
message = getConsumer().receiveNoWait();
else {
message = getConsumer().receive();
if (message == null)
throw new JMSException("The consumer expire (timeout)");
}
else if (timeout == 0)
message = getConsumer().receiveNoWait();
else {
message = getConsumer().receive();
if (message == null)
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();
}
}
......@@ -84,14 +84,16 @@ public class JmsContextService {
public static final String JMS_BODY = "body";
public static final String JMS_TYPE = "type";
private static boolean nologlink = ! Boolean.getBoolean("org.objectweb.joram.tools.rest.jms.loglink");
public static void logLinks(Response.ResponseBuilder builder) {
if ((builder == null) || !logger.isLoggable(BasicLevel.DEBUG))
if (nologlink || (builder == null) || !logger.isLoggable(BasicLevel.DEBUG))
return;
Response response = builder.build();
if (response != null) {
Set<Link> links = response.getLinks();
logger.log(BasicLevel.DEBUG, "links: ");
logger.log(BasicLevel.DEBUG, "links: " + nologlink);
for (Link link : links) {
logger.log(BasicLevel.DEBUG, "\t" + link.getRel() + ": " + link.getUri());
}
......
......@@ -197,6 +197,8 @@ public class ProducerContext extends SessionContext {
}
}
}
private int sent = 0;
synchronized long send(
String type,
......@@ -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
......@@ -286,5 +289,15 @@ 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;
......@@ -128,5 +129,13 @@ public class RestClientContext {
public void setIdleTimeout(long idleTimeout) {
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();
}
}
......@@ -26,7 +26,6 @@ import javax.jms.Destination;
import javax.jms.JMSContext;
public abstract class SessionContext {
private RestClientContext clientCtx;
private JMSContext jmsContext;
private Destination dest;
......@@ -44,6 +43,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 +82,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