User: starksm
Date: 01/11/25 22:33:12
Modified: src/main/org/jboss/mq/server ClientConsumer.java
JMSServer.java MessageReference.java
Log:
Clean up the execessive logging by introducing trace level messages
Revision Changes Path
1.9 +169 -108 jbossmq/src/main/org/jboss/mq/server/ClientConsumer.java
Index: ClientConsumer.java
===================================================================
RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/server/ClientConsumer.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ClientConsumer.java 2001/10/28 01:27:01 1.8
+++ ClientConsumer.java 2001/11/26 06:33:12 1.9
@@ -16,12 +16,16 @@
import javax.jms.Destination;
import javax.jms.JMSException;
-import org.jboss.mq.*;
-import org.jboss.mq.xml.XElement;
-
+import org.jboss.logging.Logger;
+import org.jboss.mq.AcknowledgementRequest;
+import org.jboss.mq.ConnectionToken;
+import org.jboss.mq.ReceiveRequest;
+import org.jboss.mq.SpyMessage;
+import org.jboss.mq.Subscription;
import org.jboss.mq.threadpool.ThreadPool;
import org.jboss.mq.threadpool.Work;
+import org.jboss.mq.xml.XElement;
/**
* This represent the clients queue which consumes messages from the
@@ -29,9 +33,11 @@
*
* @author Hiram Chirino ([EMAIL PROTECTED])
* @created August 16, 2001
- * @version $Revision: 1.8 $
+ * @version $Revision: 1.9 $
*/
-public class ClientConsumer implements Work {
+public class ClientConsumer implements Work
+{
+ private Logger log;
//The JMSServer object
JMSServer server;
//The connection this queue will send messages over
@@ -44,52 +50,58 @@
HashMap subscriptions = new HashMap();
//Maps a subscription id to a Subscription for subscriptions that have finished
receiving
HashMap removedSubscriptions = new HashMap();
-
+
LinkedList blockedSubscriptions = new LinkedList();
-
- org.apache.log4j.Category cat;
-
+
//List of messages waiting to be transmitted to the client
private LinkedList messages = new LinkedList();
//LinkedList of the the temporary destinations that this client created
// public LinkedList temporaryDestinations = new LinkedList();
-
+
/**
* Flags that I am enqueued as work on my thread pool.
*/
private boolean enqueued = false;
-
+
// Static ---------------------------------------------------
-
+
/**
* The {@link org.jboss.mq.threadpool.ThreadPool ThreadPool} that
* does the actual message pushing for us.
*/
private static ThreadPool threadPool = null;
-
+
// Constructor ---------------------------------------------------
-
- public ClientConsumer(JMSServer server, ConnectionToken dc) throws JMSException {
+
+ public ClientConsumer(JMSServer server, ConnectionToken dc) throws JMSException
+ {
this.server = server;
this.dc = dc;
- cat = org.apache.log4j.Category.getInstance(ClientConsumer.class.getName() +
":" + dc.getClientID());
+ log = Logger.getLogger(ClientConsumer.class.getName() + ":" +
dc.getClientID());
// Create thread pool
- synchronized (ClientConsumer.class) {
+ synchronized (ClientConsumer.class)
+ {
if (threadPool == null)
threadPool = new ThreadPool("Message Pushers", server.threadGroup, 10,
true);
}
}
-
- public void setEnabled(boolean enabled) throws JMSException {
- cat.debug("" + this +"->setEnabled(enabled=" + enabled + ")");
+
+ public void setEnabled(boolean enabled) throws JMSException
+ {
+ if( log.isTraceEnabled() )
+ log.trace("" + this +"->setEnabled(enabled=" + enabled + ")");
this.enabled = enabled;
- if (enabled) {
+ if (enabled)
+ {
// queues might be waiting for messages.
- synchronized (blockedSubscriptions) {
- for (Iterator it = blockedSubscriptions.iterator(); it.hasNext();) {
+ synchronized (blockedSubscriptions)
+ {
+ for (Iterator it = blockedSubscriptions.iterator(); it.hasNext();)
+ {
Subscription sub = (Subscription) it.next();
JMSDestination dest = server.getJMSDestination(sub.destination);
- if (dest != null) {
+ if (dest != null)
+ {
dest.addReceiver(sub);
}
}
@@ -97,128 +109,161 @@
}
}
}
-
- public void queueMessageForSending(RoutedMessage r) {
- synchronized (messages) {
+
+ public void queueMessageForSending(RoutedMessage r)
+ {
+ synchronized (messages)
+ {
if (closed)
return; // Wouldn't be delivered anyway
-
+
messages.add(r);
- if (!enqueued) {
+ if (!enqueued)
+ {
threadPool.enqueueWork(this);
enqueued = true;
}
}
}
-
- public void addSubscription(Subscription req) throws JMSException {
- cat.debug("Adding subscription for: " + req);
+
+ public void addSubscription(Subscription req) throws JMSException
+ {
+ if( log.isTraceEnabled() )
+ log.trace("Adding subscription for: " + req);
req.dc = dc;
req.clientConsumer = this;
-
+
JMSDestination jmsdest = (JMSDestination)
server.getJMSDestination(req.destination);
- if (jmsdest == null) {
+ if (jmsdest == null)
+ {
throw new JMSException("The destination " + req.destination + " does not
exist !");
}
-
+
jmsdest.addSubscriber(req);
-
- synchronized (subscriptions) {
+
+ synchronized (subscriptions)
+ {
HashMap subscriptionsClone = (HashMap) subscriptions.clone();
subscriptionsClone.put(new Integer(req.subscriptionId), req);
subscriptions = subscriptionsClone;
}
}
-
- public void close() {
- cat.debug("" + this +"->close()");
-
- synchronized (messages) {
+
+ public void close()
+ {
+ boolean trace = log.isTraceEnabled();
+ if( trace )
+ log.trace("" + this +"->close()");
+
+ synchronized (messages)
+ {
closed = true;
- if (enqueued) {
- cat.debug("" + this +"->close(): Cancelling work in progress.");
+ if (enqueued)
+ {
+ if( trace )
+ log.trace("" + this +"->close(): Cancelling work in progress.");
threadPool.cancelWork(this);
enqueued = false;
}
}
-
- synchronized (subscriptions) {
+
+ synchronized (subscriptions)
+ {
Iterator i = subscriptions.keySet().iterator();
- while (i.hasNext()) {
+ while (i.hasNext())
+ {
Integer subscriptionId = (Integer) i.next();
- try {
+ try
+ {
removeSubscription(subscriptionId.intValue());
- } catch (JMSException ignore) {
+ }
+ catch(JMSException ignore)
+ {
}
}
}
-
+
}
- public SpyMessage receive(int subscriberId, long wait) throws JMSException {
-
+ public SpyMessage receive(int subscriberId, long wait) throws JMSException
+ {
+
Subscription req = (Subscription) subscriptions.get(new
Integer(subscriberId));
- if (req == null) {
+ if (req == null)
+ {
throw new JMSException("The provided subscription does not exist");
}
-
+
JMSDestination queue = server.getJMSDestination(req.destination);
- if (queue == null) {
+ if (queue == null)
+ {
throw new JMSException("The subscription's destination " + req.destination
+ " does not exist");
}
-
- if (enabled) {
+
+ if (enabled)
+ {
return queue.receive(req, (wait != -1));
- } else
- if (wait != -1) {
- addBlockedSubscription(req);
- }
-
+ }
+ else if (wait != -1)
+ {
+ addBlockedSubscription(req);
+ }
+
return null;
}
-
- public void removeSubscription(int subscriptionId) throws JMSException {
- cat.debug("" + this +"->removeSubscription(subscriberId=" + subscriptionId +
")");
-
+
+ public void removeSubscription(int subscriptionId) throws JMSException
+ {
+ if( log.isTraceEnabled() )
+ log.trace("" + this +"->removeSubscription(subscriberId=" + subscriptionId
+ ")");
+
Integer subId = new Integer(subscriptionId);
Subscription req;
- synchronized (subscriptions) {
+ synchronized (subscriptions)
+ {
HashMap subscriptionsClone = (HashMap) subscriptions.clone();
req = (Subscription) subscriptionsClone.remove(subId);
subscriptions = subscriptionsClone;
- if (req != null) {
+ if (req != null)
+ {
removedSubscriptions.put(subId, req);
}
}
-
- if (req == null) {
+
+ if (req == null)
+ {
throw new JMSException("The subscription had not been previously
registered");
}
-
+
JMSDestination queue = (JMSDestination)
server.getJMSDestination(req.destination);
- if (queue == null) {
+ if (queue == null)
+ {
throw new JMSException("The subscription was registed with a destination
that does not exist !");
}
-
+
queue.removeSubscriber(req);
-
+
}
-
+
/**
* Push some messages.
*/
- public void doWork() {
- try {
-
+ public void doWork()
+ {
+ try
+ {
+
ReceiveRequest[] job;
-
- synchronized (messages) {
+
+ synchronized (messages)
+ {
if (closed)
return;
-
+
job = new ReceiveRequest[messages.size()];
Iterator iter = messages.iterator();
- for (int i = 0; iter.hasNext(); i++) {
+ for (int i = 0; iter.hasNext(); i++)
+ {
RoutedMessage rm = (RoutedMessage) iter.next();
job[i] = rm.toReceiveRequest();
iter.remove();
@@ -226,60 +271,76 @@
enqueued = false;
}
-
+
dc.clientIL.receive(job);
- } catch (Exception e) {
- cat.warn("Could not send messages to a receiver.", e);
- try {
+ }
+ catch(Exception e)
+ {
+ log.warn("Could not send messages to a receiver.", e);
+ try
+ {
server.connectionFailure(dc);
- } catch (Throwable ignore) {
- cat.warn("Could not close the client connection..", ignore);
}
+ catch(Throwable ignore)
+ {
+ log.warn("Could not close the client connection..", ignore);
+ }
}
}
-
- public String toString() {
+
+ public String toString()
+ {
return "ClientConsumer:" + dc.getClientID();
}
-
- public void acknowledge(AcknowledgementRequest request, org.jboss.mq.pm.Tx txId)
throws JMSException {
+
+ public void acknowledge(AcknowledgementRequest request, org.jboss.mq.pm.Tx txId)
throws JMSException
+ {
Subscription sub = (Subscription) subscriptions.get(new
Integer(request.subscriberId));
-
- if (sub == null) {
+
+ if (sub == null)
+ {
//might be in removed subscriptions
- synchronized (subscriptions) {
+ synchronized (subscriptions)
+ {
sub = (Subscription) removedSubscriptions.get(new
Integer(request.subscriberId));
}
}
-
- if (sub == null) {
+
+ if (sub == null)
+ {
throw new JMSException("The provided subscription does not exist");
}
-
+
JMSDestination queue = server.getJMSDestination(sub.destination);
- if (queue == null) {
+ if (queue == null)
+ {
throw new JMSException("The subscription's destination " + sub.destination
+ " does not exist");
}
-
+
queue.acknowledge(request, sub, txId);
}
-
- void addBlockedSubscription(Subscription sub) {
- synchronized (blockedSubscriptions) {
+
+ void addBlockedSubscription(Subscription sub)
+ {
+ synchronized (blockedSubscriptions)
+ {
blockedSubscriptions.add(sub);
}
}
-
- void removeRemovedSubscription(int subId) {
+
+ void removeRemovedSubscription(int subId)
+ {
Subscription sub = null;
- synchronized (subscriptions) {
+ synchronized (subscriptions)
+ {
sub = (Subscription) removedSubscriptions.remove(new Integer(subId));
}
- if (sub != null) {
+ if (sub != null)
+ {
JMSDestination topic = server.getJMSDestination(sub.destination);
if (topic instanceof JMSTopic)
- ((JMSTopic) topic).cleanupSubscription(sub);
+ ((JMSTopic) topic).cleanupSubscription(sub);
}
}
}
1.11 +19 -17 jbossmq/src/main/org/jboss/mq/server/JMSServer.java
Index: JMSServer.java
===================================================================
RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/server/JMSServer.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- JMSServer.java 2001/11/10 21:38:05 1.10
+++ JMSServer.java 2001/11/26 06:33:12 1.11
@@ -20,10 +20,11 @@
import javax.jms.TemporaryTopic;
import javax.jms.Topic;
import javax.jms.TransactionRolledBackException;
-
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
+
+import org.jboss.logging.Logger;
import org.jboss.mq.*;
import org.jboss.mq.pm.*;
@@ -36,10 +37,11 @@
* @author Norbert Lataille ([EMAIL PROTECTED])
* @author Hiram Chirino ([EMAIL PROTECTED])
* @author David Maplesden ([EMAIL PROTECTED])
- * @version $Revision: 1.10 $
+ * @version $Revision: 1.11 $
*/
public class JMSServer
{
+ static Logger log = Logger.getLogger(JMSServer.class);
/**
* Description of the Field
@@ -52,7 +54,6 @@
*/
protected static JMSServer theInstance = null;
- static org.apache.log4j.Category cat =
org.apache.log4j.Category.getInstance(JMSServer.class);
/////////////////////////////////////////////////////////////////////
// Attributes
@@ -537,7 +538,8 @@
*/
public synchronized void connectionClosing(ConnectionToken dc) throws
JMSException
{
- cat.debug("JMSServer->connectionClosing(dc=" + dc + ")");
+ if( log.isTraceEnabled() )
+ log.trace("JMSServer->connectionClosing(dc=" + dc + ")");
if (dc == null)
{
return;
@@ -583,11 +585,8 @@
*/
public void connectionFailure(ConnectionToken dc) throws JMSException
{
- cat.debug("JMSServer->connectionFailure(dc=" + dc + ")");
-
//We should try again :) This behavior should under control of a
Failure-Plugin
- cat.error("The connection to client " + dc.getClientID() + " failed.");
-
+ log.error("The connection to client " + dc.getClientID() + " failed.");
connectionClosing(dc);
}
@@ -603,13 +602,14 @@
{
try
{
- cat.debug("Server: subscribe(dest=" + sub.destination + ",idConnection=" +
dc.getClientID() + ")");
+ if( log.isTraceEnabled() )
+ log.trace("Server: subscribe(dest=" + sub.destination +
",idConnection=" + dc.getClientID() + ")");
ClientConsumer ClientConsumer = getClientConsumer(dc);
ClientConsumer.addSubscription(sub);
}
catch (JMSException e)
{
- cat.debug("Exception:", e);
+ log.debug("Exception:", e);
throw e;
}
@@ -624,7 +624,8 @@
*/
public void unsubscribe(ConnectionToken dc, int subscriptionId) throws
JMSException
{
- cat.debug("Server: unsubscribe(idConnection=" + dc.getClientID() + ")");
+ if( log.isTraceEnabled() )
+ log.trace("Server: unsubscribe(idConnection=" + dc.getClientID() + ")");
ClientConsumer ClientConsumer = getClientConsumer(dc);
ClientConsumer.removeSubscription(subscriptionId);
}
@@ -690,7 +691,7 @@
*/
public synchronized Queue createQueue(ConnectionToken dc, String name) throws
JMSException
{
- cat.debug("createQueue(" + name + ")");
+ log.debug("createQueue(" + name + ")");
SpyQueue newQueue = new SpyQueue(name);
if (!destinations.containsKey(newQueue))
@@ -710,7 +711,7 @@
*/
public synchronized Topic createTopic(ConnectionToken dc, String name) throws
JMSException
{
- cat.debug("createTopic(" + name + ")");
+ log.debug("createTopic(" + name + ")");
SpyTopic newTopic = new SpyTopic(name);
if (!destinations.containsKey(newTopic))
@@ -728,7 +729,7 @@
*/
public synchronized void deleteTemporaryDestination(ConnectionToken dc,
SpyDestination dest)
{
- cat.debug("deleteDestination(dest=" + dest.toString() + ")");
+ log.debug("deleteDestination(dest=" + dest.toString() + ")");
synchronized (destinations)
{
@@ -764,7 +765,7 @@
*/
public void addDestination(SpyDestination topic, JMSDestination queue) throws
JMSException
{
- cat.debug("addDestination: " + topic + ", " + queue);
+ log.debug("addDestination: " + topic + ", " + queue);
if (destinations.containsKey(topic))
{
throw new JMSException("This destination already exists !");
@@ -817,7 +818,8 @@
{
try
{
- cat.debug("PING");
+ if( log.isTraceEnabled() )
+ log.trace("PING");
dc.clientIL.pong(System.currentTimeMillis());
}
catch (Exception e)
@@ -825,7 +827,7 @@
throw new SpyJMSException("Could not pong", e);
}
}
-
+
/**
* Gets the messageCache
* @return Returns a MessageCache
1.6 +102 -62 jbossmq/src/main/org/jboss/mq/server/MessageReference.java
Index: MessageReference.java
===================================================================
RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/server/MessageReference.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MessageReference.java 2001/11/14 04:23:27 1.5
+++ MessageReference.java 2001/11/26 06:33:12 1.6
@@ -11,7 +11,7 @@
import javax.jms.JMSException;
-import org.apache.log4j.Category;
+import org.jboss.logging.Logger;
import org.jboss.mq.SpyMessage;
import org.jboss.mq.SpyMessage.Header;
@@ -25,37 +25,42 @@
* </ul>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Hiram Chirino</a>
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
-public class MessageReference implements Comparable {
- org.apache.log4j.Category cat =
org.apache.log4j.Category.getInstance(MessageReference.class);
-
- static class MessageSoftReference extends SoftReference {
+public class MessageReference implements Comparable
+{
+ Logger log = Logger.getLogger(MessageReference.class);
+
+ static class MessageSoftReference extends SoftReference
+ {
MessageReference parent;
- public MessageSoftReference(MessageReference parent, Object message,
ReferenceQueue rq) {
+ public MessageSoftReference(MessageReference parent, Object message,
ReferenceQueue rq)
+ {
super(message, rq);
this.parent = parent;
}
}
-
+
public Long referenceId;
public MessageCache messageCache;
public SpyMessage hardReference;
public MessageSoftReference softReference;
boolean isStored;
-
+
// These fields are copied over from the messae itself..
// they are used too often to not have them handy.
public byte jmsPriority;
public long messageId;
// This object could be used by the PM to associate some info
public transient Object persistData = null;
-
- MessageReference() {
+
+ MessageReference()
+ {
}
-
+
//init and reset methods for use by object pool
- void init(MessageCache messageCache, Long referenceId, SpyMessage message) {
+ void init(MessageCache messageCache, Long referenceId, SpyMessage message)
+ {
this.messageCache = messageCache;
this.hardReference = message;
this.referenceId = referenceId;
@@ -63,28 +68,37 @@
this.messageId = message.header.messageId;
this.isStored = false;
}
-
- void reset() {
+
+ void reset()
+ {
//clear refs so gc can collect unused objects
this.messageCache = null;
this.hardReference = null;
-
+
this.softReference = null;
this.persistData = null;
}
-
- public SpyMessage getMessage() throws JMSException {
- cat.debug("getMessage lock aquire");
- synchronized (this) {
- if (hardReference == null) {
+
+ public SpyMessage getMessage() throws JMSException
+ {
+ boolean trace = log.isTraceEnabled();
+ if( trace )
+ log.trace("getMessage lock aquire");
+
+ synchronized (this)
+ {
+ if (hardReference == null)
+ {
makeHard();
messageCache.messageReferenceUsedEvent(this, false);
- } else {
+ }
+ else
+ {
messageCache.cacheHits++;
messageCache.messageReferenceUsedEvent(this, true);
}
-
- cat.debug("getMessage lock released");
+ if( trace )
+ log.trace("getMessage lock released");
return hardReference;
}
}
@@ -96,101 +110,127 @@
*
* For now just return the message.
*/
- public SpyMessage.Header getHeaders() throws javax.jms.JMSException {
+ public SpyMessage.Header getHeaders() throws javax.jms.JMSException
+ {
return getMessage().header;
}
-
- void clear() throws JMSException {
- cat.debug("clear lock aquire");
- synchronized (this) {
- if (isStored) {
+
+ void clear() throws JMSException
+ {
+ boolean trace = log.isTraceEnabled();
+ if( trace )
+ log.trace("clear lock aquire");
+ synchronized (this)
+ {
+ if (isStored)
+ {
messageCache.removeFromStorage(this);
isStored = false;
}
- cat.debug("clear lock relased");
+ if( trace )
+ log.trace("clear lock relased");
}
}
-
- public synchronized void invalidate() throws JMSException {
+
+ public synchronized void invalidate() throws JMSException
+ {
clear(); // Clear out the disk copy
}
- synchronized void makeSoft() throws JMSException {
- cat.debug("makeSoft lock aquire");
- synchronized (this) {
+ synchronized void makeSoft() throws JMSException
+ {
+ boolean trace = log.isTraceEnabled();
+ if( trace )
+ log.trace("makeSoft lock aquire");
+ synchronized (this)
+ {
if (softReference != null)
return;
-
- if (!isStored) {
+
+ if (!isStored)
+ {
messageCache.saveToStorage(this, hardReference);
isStored = true;
}
-
+
softReference = new MessageSoftReference(this, hardReference,
messageCache.referenceQueue);
-
+
//I am undecided about whether to release this message back to the message
pool or not
//the whole point of this caching business is to release the memory this
message is using up
//if we are going to do it then this is the place...
//MessagePool.releaseMessage(hardReference);
-
+
// We don't need the hard ref anymore..
hardReference = null;
-
+
messageCache.softRefCacheSize++;
- cat.debug("makeSoft lock released");
+ if( trace )
+ log.trace("makeSoft lock released");
}
}
- synchronized void makeHard() throws JMSException {
- cat.debug("makeHard lock aquire");
- synchronized (this) {
+ synchronized void makeHard() throws JMSException
+ {
+ boolean trace = log.isTraceEnabled();
+ if( trace )
+ log.trace("makeHard lock aquire");
+ synchronized (this)
+ {
// allready hard
if (hardReference != null)
return;
-
+
// Get the object via the softref
hardReference = (SpyMessage) softReference.get();
-
+
// It might have been removed from the cache due to memory constraints
- if (hardReference == null) {
+ if (hardReference == null)
+ {
// load it from disk.
hardReference = messageCache.loadFromStorage(this);
messageCache.cacheMisses++;
- } else {
+ } else
+ {
messageCache.cacheHits++;
messageCache.softRefCacheSize--;
}
-
+
// Since we have hard ref, we do not need the soft one.
softReference = null;
-
- cat.debug("makeHard lock released");
+ if( trace )
+ log.trace("makeHard lock released");
}
}
-
- public boolean equals(Object o) {
- try {
+
+ public boolean equals(Object o)
+ {
+ try
+ {
return referenceId.equals(((MessageReference) o).referenceId);
- } catch (Throwable e) {
+ } catch (Throwable e)
+ {
return false;
}
}
-
+
/**
* This method allows message to be order on the server queues
* by priority and the order that they came in on.
*
* @see Comparable#compareTo(Object)
*/
- public int compareTo(Object o) {
+ public int compareTo(Object o)
+ {
MessageReference sm = (MessageReference) o;
- if (jmsPriority > sm.jmsPriority) {
+ if (jmsPriority > sm.jmsPriority)
+ {
return -1;
}
- if (jmsPriority < sm.jmsPriority) {
+ if (jmsPriority < sm.jmsPriority)
+ {
return 1;
}
return (int) (messageId - sm.messageId);
}
-
+
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development