User: starksm
Date: 01/11/25 22:33:11
Modified: src/main/org/jboss/mq Connection.java
Log:
Clean up the execessive logging by introducing trace level messages
Revision Changes Path
1.13 +206 -187 jbossmq/src/main/org/jboss/mq/Connection.java
Index: Connection.java
===================================================================
RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/Connection.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Connection.java 2001/11/12 05:27:35 1.12
+++ Connection.java 2001/11/26 06:33:11 1.13
@@ -14,23 +14,21 @@
import java.io.IOException;
import java.io.Serializable;
import java.util.Collection;
-
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
-
import java.util.LinkedList;
import java.util.Properties;
import javax.jms.ConnectionMetaData;
-
import javax.jms.Destination;
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.Topic;
+
+import org.jboss.logging.Logger;
import org.jboss.mq.il.ClientIL;
import org.jboss.mq.il.ClientILService;
-
import org.jboss.mq.il.ServerIL;
/**
@@ -38,7 +36,7 @@
*
* @author Norbert Lataille ([EMAIL PROTECTED])
* @author Hiram Chirino ([EMAIL PROTECTED])
- * @version $Revision: 1.12 $
+ * @version $Revision: 1.13 $
* @created August 16, 2001
*/
public class Connection implements java.io.Serializable, javax.jms.Connection
@@ -47,8 +45,8 @@
* Description of the Field
*/
public static ThreadGroup threadGroup = new ThreadGroup("JBossMQ Client
Threads");
-
- static org.apache.log4j.Category cat =
org.apache.log4j.Category.getInstance(Connection.class);
+
+ static Logger log = Logger.getLogger(Connection.class);
/**
* Maps a destination to a LinkedList of Subscriptions
@@ -66,7 +64,7 @@
//////////////////////////////////////////////////////////////
// Attributes
//////////////////////////////////////////////////////////////
-
+
/**
* This is our connection to the JMS server
*/
@@ -80,12 +78,12 @@
* The connection token is used to identify our connection to the server.
*/
protected ConnectionToken connectionToken;
-
+
/**
* The object that sets up the client IL
*/
protected ClientILService clientILService;
-
+
/**
* Manages the thread that pings the connection to see if it is 'alive'
*/
@@ -115,7 +113,7 @@
* Set a soon as close() is called on the connection.
*/
protected volatile boolean closing = false;
-
+
//LinkedList of all created sessions by this connection
HashSet createdSessions;
// Numbers subscriptions
@@ -124,60 +122,67 @@
boolean closed;
// Used to control tranactions
SpyXAResourceManager spyXAResourceManager;
-
+
//The class that created this connection
GenericConnectionFactory genericConnectionFactory;
//Last message ID returned
private int lastMessageID;
-
+
//the exceptionListener
private ExceptionListener exceptionListener;
-
+
//Get a new messageID (creation of a new message)
private StringBuffer sb = new StringBuffer();
private char[] charStack = new char[22];
-
+
/**
* Static class initializer..
*/
- static {
- cat.debug("Setting the clockDaemon's thread factory");
+ static
+ {
+ log.debug("Setting the clockDaemon's thread factory");
clockDaemon.setThreadFactory(
- new ThreadFactory () {
- public Thread newThread(Runnable r) {
+ new ThreadFactory()
+ {
+ public Thread newThread(Runnable r)
+ {
Thread t = new Thread(threadGroup, r, "Connection Monitor Thread");
t.setDaemon(true);
return t;
}
- }
-
+ }
);
}
-
+
//////////////////////////////////////////////////////////////
// Constructors
//////////////////////////////////////////////////////////////
-
+
Connection(String userName, String password, GenericConnectionFactory
genericConnectionFactory)
- throws JMSException
+ throws JMSException
{
-
- cat.debug("Connection Initializing");
-
+ boolean trace = log.isTraceEnabled();
+ if( trace )
+ log.trace("Connection Initializing");
+
//Set the attributes
createdSessions = new HashSet();
connectionToken = null;
closed = false;
lastMessageID = 0;
modeStop = true;
-
+
// Connect to the server
- cat.debug("Getting the serverIL");
+ if( trace )
+ log.trace("Getting the serverIL");
this.genericConnectionFactory = genericConnectionFactory;
serverIL = genericConnectionFactory.createServerIL();
- cat.debug("serverIL="+serverIL);
+ if( trace )
+ {
+ log.trace("serverIL="+serverIL);
+ log.trace("Authenticating");
+ }
- cat.debug("Authenticating");
// Authenticate with the server
if (userName != null)
{
@@ -190,28 +195,29 @@
// Setup the ClientIL service so that the Server can
// push messages to us
- cat.debug("Starting the clientIL service");
+ if( trace )
+ log.trace("Starting the clientIL service");
startILService();
-
+
// Setup the XA Resource manager,
spyXAResourceManager = new SpyXAResourceManager(this);
-
+
// Used to monitor the connection.
startPingThread();
-
- cat.debug("Connection establishment successful");
+ if( trace )
+ log.trace("Connection establishment successful");
}
//////////////////////////////////////////////////////////////
// Constructors
//////////////////////////////////////////////////////////////
-
+
Connection(GenericConnectionFactory genericConnectionFactory)
- throws JMSException
+ throws JMSException
{
this(null, null, genericConnectionFactory);
}
-
+
/**
* Sets the ClientID attribute of the Connection object
*
@@ -219,7 +225,7 @@
* @exception JMSException Description of Exception
*/
public void setClientID(String cID)
- throws JMSException
+ throws JMSException
{
if (closed)
{
@@ -229,8 +235,8 @@
{
throw new IllegalStateException("The connection has already a clientID");
}
-
- cat.debug("SetClientID(" + clientID + ")");
+ if( log.isTraceEnabled() )
+ log.trace("SetClientID(" + clientID + ")");
try
{
@@ -244,10 +250,10 @@
{
throw new SpyJMSException("Cannot connect to the JMSServer", e);
}
-
+
clientID = cID;
}
-
+
/**
* Sets the ExceptionListener attribute of the Connection object
*
@@ -255,20 +261,20 @@
* @exception JMSException Description of Exception
*/
public void setExceptionListener(ExceptionListener listener)
- throws JMSException
+ throws JMSException
{
if (closed)
{
throw new IllegalStateException("The connection is closed");
}
-
+
exceptionListener = listener;
}
-
+
//////////////////////////////////////////////////////////////
// Public Methods
//////////////////////////////////////////////////////////////
-
+
/**
* Gets the ClientID attribute of the Connection object
*
@@ -276,7 +282,7 @@
* @exception JMSException Description of Exception
*/
public String getClientID()
- throws JMSException
+ throws JMSException
{
if (closed)
{
@@ -284,7 +290,7 @@
}
return clientID;
}
-
+
/**
* Gets the ExceptionListener attribute of the Connection object
*
@@ -292,16 +298,16 @@
* @exception JMSException Description of Exception
*/
public ExceptionListener getExceptionListener()
- throws JMSException
+ throws JMSException
{
if (closed)
{
throw new IllegalStateException("The connection is closed");
}
-
+
return exceptionListener;
}
-
+
/**
* Gets the MetaData attribute of the Connection object
*
@@ -309,16 +315,16 @@
* @exception JMSException Description of Exception
*/
public ConnectionMetaData getMetaData()
- throws JMSException
+ throws JMSException
{
if (closed)
{
throw new IllegalStateException("The connection is closed");
}
-
+
return new SpyConnectionMetaData();
}
-
+
/**
* Gets the ServerIL attribute of the Connection object
*
@@ -328,14 +334,14 @@
{
return serverIL;
}
-
+
/**
* #Description of the Method
*/
public void asynchClose()
{
}
-
+
//called by a TemporaryDestination which is going to be deleted()
/**
* #Description of the Method
@@ -352,9 +358,9 @@
{
asynchFailure(e.getMessage(), e.getLinkedException());
}
-
+
}
-
+
//Gets the first consumer that is listening to a destination.
/**
* #Description of the Method
@@ -363,22 +369,22 @@
*/
public void asynchDeliver(ReceiveRequest requests[])
{
-
+
try
{
for (int i = 0; i < requests.length; i++)
{
-
+
SpyConsumer consumer =
(SpyConsumer)subscriptions.get(requests[i].subscriptionId);
requests[i].message.createAcknowledgementRequest(requests[i].subscriptionId.intValue());
-
+
if (consumer == null)
{
send(requests[i].message.getAcknowledgementRequest(false));
- cat.debug("WARNING: NACK issued due to non existent subscription");
+ log.debug("WARNING: NACK issued due to non existent subscription");
continue;
}
-
+
consumer.addMessage(requests[i].message);
}
}
@@ -387,7 +393,7 @@
asynchFailure(e.getMessage(), e.getLinkedException());
}
}
-
+
/**
* #Description of the Method
*
@@ -396,16 +402,16 @@
*/
public void asynchFailure(String reason, Exception e)
{
-
+
// Exceptions due to closing will be ignored.
if (closing)
{
return;
}
-
+
JMSException excep = new SpyJMSException(reason, e);
excep.fillInStackTrace();
-
+
if (exceptionListener != null)
{
synchronized (exceptionListener)
@@ -415,10 +421,10 @@
}
else
{
- cat.warn("Connection failure: ", excep);
+ log.warn("Connection failure: ", excep);
}
}
-
+
/**
* #Description of the Method
*
@@ -426,8 +432,8 @@
*/
public void asynchPong(long serverTime)
{
- cat.debug("PONG");
- cat.debug("serverIL="+serverIL);
+ if( log.isTraceEnabled() )
+ log.trace("PONG, serverIL="+serverIL);
ponged = true;
}
@@ -437,30 +443,34 @@
* @exception JMSException Description of Exception
*/
public synchronized void close()
- throws JMSException
+ throws JMSException
{
if (closed)
{
return;
}
-
- cat.debug("Closing sessions, ClientID=" + connectionToken.getClientID());
+ boolean trace = log.isTraceEnabled();
+ if( trace )
+ log.trace("Closing sessions, ClientID=" + connectionToken.getClientID());
closing = true;
//notify his sessions
synchronized (createdSessions)
{
-
+
Object[] vect = createdSessions.toArray();
for (int i = 0; i < vect.length; i++)
{
((SpySession)vect[i]).close();
}
-
+
+ }
+ if( trace )
+ {
+ log.trace("Closed sessions");
+ log.debug("Notifiying the server of close");
}
- cat.debug("Closed sessions");
- cat.debug("Notifiying the server of close");
//Notify the JMSServer that I am closing
try
{
@@ -470,19 +480,21 @@
{
throw new SpyJMSException("Cannot close properly the connection", e);
}
-
+
// Clean up after the ping thread..
stopPingThread();
- cat.debug("Stoping the ClientIL service");
+ if( trace )
+ log.trace("Stoping the ClientIL service");
stopILService();
- cat.debug("Disconnected from server");
+ if( trace )
+ log.trace("Disconnected from server");
// Only set the closed flag after all the objects that depend
// on this connection have been closed.
closed = true;
}
-
+
//called by a TemporaryDestination which is going to be deleted()
/**
* #Description of the Method
@@ -491,69 +503,69 @@
* @exception JMSException Description of Exception
*/
public void deleteTemporaryDestination(SpyDestination dest)
- throws JMSException
+ throws JMSException
{
if (closed)
{
throw new IllegalStateException("The connection is closed");
}
-
- cat.debug("SpyConnection: deleteDestination(dest=" + dest.toString() + ")");
-
+
+ log.debug("SpyConnection: deleteDestination(dest=" + dest.toString() + ")");
try
{
-
+
//Remove it from the destinations list
synchronized (subscriptions)
{
destinationSubscriptions.remove(dest);
}
-
+
//Notify its sessions that this TemporaryDestination is going to be
deleted()
//We could do that only on the Sessions "linked" to this Destination
synchronized (createdSessions)
{
-
+
Iterator i = createdSessions.iterator();
while (i.hasNext())
{
((SpySession)i.next()).deleteTemporaryDestination(dest);
}
-
+
}
-
+
//Ask the broker to delete() this TemporaryDestination
serverIL.deleteTemporaryDestination(connectionToken, dest);
-
+
}
catch (Exception e)
{
throw new SpyJMSException("Cannot delete the TemporaryDestination", e);
}
-
+
}
-
+
/**
* #Description of the Method
*
* @exception JMSException Description of Exception
*/
public void start()
- throws JMSException
+ throws JMSException
{
if (closed)
{
throw new IllegalStateException("The connection is closed");
}
-
+
if (!modeStop)
{
return;
}
modeStop = false;
-
- cat.debug("Starting connection, ClientID=" + connectionToken.getClientID());
+ if( log.isTraceEnabled() )
+ log.trace("Starting connection, ClientID=" +
connectionToken.getClientID());
+
try
{
serverIL.setEnabled(connectionToken, true);
@@ -563,28 +575,28 @@
throw new SpyJMSException("Cannot enable the connection with the JMS
server", e);
}
}
-
+
/**
* #Description of the Method
*
* @exception JMSException Description of Exception
*/
public void stop()
- throws JMSException
+ throws JMSException
{
if (closed)
{
throw new IllegalStateException("The connection is closed");
}
-
+
if (modeStop)
{
return;
}
modeStop = true;
-
- cat.debug("Stoping connection, ClientID=" + connectionToken.getClientID());
-
+ if( log.isTraceEnabled() )
+ log.trace("Stoping connection, ClientID=" + connectionToken.getClientID());
+
try
{
serverIL.setEnabled(connectionToken, false);
@@ -594,7 +606,7 @@
throw new SpyJMSException("Cannot disable the connection with the JMS
server", e);
}
}
-
+
//ask the JMS server for a new ID
/**
* #Description of the Method
@@ -602,7 +614,7 @@
* @exception JMSException Description of Exception
*/
protected void askForAnID()
- throws JMSException
+ throws JMSException
{
try
{
@@ -610,11 +622,11 @@
}
catch (Exception e)
{
- cat.debug("Server Exception: ", e);
+ log.debug("Cannot get a client ID:", e);
throw new SpyJMSException("Cannot get a client ID: " + e.getMessage(), e);
}
}
-
+
//ask the JMS server for a new ID
/**
* #Description of the Method
@@ -624,7 +636,7 @@
* @exception JMSException Description of Exception
*/
protected void askForAnID(String userName, String password)
- throws JMSException
+ throws JMSException
{
try
{
@@ -635,7 +647,7 @@
throw new SpyJMSException("Cannot get a client ID", e);
}
}
-
+
// used to acknowledge a message
/**
* #Description of the Method
@@ -644,7 +656,7 @@
* @exception JMSException Description of Exception
*/
protected void send(AcknowledgementRequest item)
- throws JMSException
+ throws JMSException
{
if (closed)
{
@@ -659,7 +671,7 @@
throw new SpyJMSException("Cannot acknowlege a message", e);
}
}
-
+
// Used to commit/rollback a transaction.
/**
* #Description of the Method
@@ -668,13 +680,13 @@
* @exception JMSException Description of Exception
*/
protected void send(TransactionRequest transaction)
- throws JMSException
+ throws JMSException
{
if (closed)
{
throw new IllegalStateException("The connection is closed");
}
-
+
try
{
serverIL.transact(connectionToken, transaction);
@@ -683,13 +695,13 @@
{
throw new SpyJMSException("Cannot process a transaction", e);
}
-
+
}
-
+
////////////////////////////////////////////////////////////////////
// Protected
////////////////////////////////////////////////////////////////////
-
+
//create a new Distributed object which receives the messages for this connection
/**
* #Description of the Method
@@ -697,28 +709,28 @@
* @exception JMSException Description of Exception
*/
protected void startILService()
- throws JMSException
+ throws JMSException
{
try
{
-
+
clientILService = genericConnectionFactory.createClientILService(this);
clientILService.start();
connectionToken = new ConnectionToken(clientID,
clientILService.getClientIL());
serverIL.setConnectionToken(connectionToken);
-
+
}
catch (Exception e)
{
- cat.debug(e);
+ log.debug("Cannot start a the client IL service", e);
throw new SpyJMSException("Cannot start a the client IL service", e);
}
}
-
+
////////////////////////////////////////////////////////////////////
// Protected
////////////////////////////////////////////////////////////////////
-
+
//create a new Distributed object which receives the messages for this connection
/**
* #Description of the Method
@@ -726,32 +738,32 @@
* @exception JMSException Description of Exception
*/
protected void stopILService()
- throws JMSException
+ throws JMSException
{
try
{
-
+
clientILService.stop();
-
+
}
catch (Exception e)
{
throw new SpyJMSException("Cannot stop a the client IL service", e);
}
}
-
+
//all longs are less than 22 digits long
-
+
//Note that in this routine we assume that System.currentTimeMillis() is
non-negative
//always be non-negative (so don't set lastMessageID to a positive for a start).
String getNewMessageID()
- throws JMSException
+ throws JMSException
{
if (closed)
{
throw new IllegalStateException("The connection is closed");
}
-
+
synchronized (sb)
{
sb.setLength(0);
@@ -792,50 +804,50 @@
return sb.toString();
}
}
-
+
//A new Consumer has been created for the Destination dest
void addConsumer(SpyConsumer consumer)
- throws JMSException
+ throws JMSException
{
if (closed)
{
throw new IllegalStateException("The connection is closed");
}
-
+
Subscription req = consumer.getSubscription();
req.subscriptionId = subscriptionCounter++;
req.dc = connectionToken;
-
- cat.debug("Connection: addConsumer(dest=" + req.destination.toString() + ")");
-
+ if( log.isTraceEnabled() )
+ log.trace("Connection: addConsumer(dest=" + req.destination.toString() +
")");
+
try
{
-
+
synchronized (subscriptions)
{
-
+
subscriptions.put(new Integer(req.subscriptionId), consumer);
-
+
LinkedList ll =
(LinkedList)destinationSubscriptions.get(req.destination);
if (ll == null)
{
ll = new LinkedList();
destinationSubscriptions.put(req.destination, ll);
}
-
+
ll.add(consumer);
}
-
+
serverIL.subscribe(connectionToken, req);
-
+
}
catch (Exception e)
{
throw new SpyJMSException("Cannot subscribe to this Destination: " +
e.getMessage(), e);
}
-
+
}
-
+
/**
* @param queue Description of Parameter
* @param selector Description of Parameter
@@ -843,13 +855,13 @@
* @exception JMSException Description of Exception
*/
SpyMessage[] browse(Queue queue, String selector)
- throws JMSException
+ throws JMSException
{
if (closed)
{
throw new IllegalStateException("The connection is closed");
}
-
+
try
{
return serverIL.browse(connectionToken, queue, selector);
@@ -859,30 +871,30 @@
throw new SpyJMSException("Cannot browse the Queue", e);
}
}
-
+
//Send a message to the serverIL
void pingServer(long clientTime)
- throws JMSException
+ throws JMSException
{
-
+
if (closed)
{
throw new IllegalStateException("The connection is closed");
}
-
+
try
{
-
- cat.debug("PING");
+ if( log.isTraceEnabled() )
+ log.trace("PING");
serverIL.ping(connectionToken, clientTime);
-
+
}
catch (Exception e)
{
throw new SpyJMSException("Cannot ping the JMS server", e);
}
}
-
+
/**
* @param sub Description of Parameter
* @param wait Description of Parameter
@@ -890,13 +902,13 @@
* @exception JMSException Description of Exception
*/
SpyMessage receive(Subscription sub, long wait)
- throws JMSException
+ throws JMSException
{
if (closed)
{
throw new IllegalStateException("The connection is closed");
}
-
+
try
{
SpyMessage message = serverIL.receive(connectionToken, sub.subscriptionId,
wait);
@@ -911,29 +923,30 @@
throw new SpyJMSException("Cannot create a ConnectionReceiver", e);
}
}
-
+
//A consumer does not need to recieve the messages from a Destination
void removeConsumer(SpyConsumer consumer)
- throws JMSException
+ throws JMSException
{
if (closed)
{
throw new IllegalStateException("The connection is closed");
}
-
+
Subscription req = consumer.getSubscription();
- cat.debug("Connection: removeSession(dest=" + req.destination + ")");
+ if( log.isTraceEnabled() )
+ log.debug("Connection: removeSession(dest=" + req.destination + ")");
try
{
-
+
serverIL.unsubscribe(connectionToken, req.subscriptionId);
-
+
synchronized (subscriptions)
{
-
+
subscriptions.remove(new Integer(req.subscriptionId));
-
+
LinkedList ll =
(LinkedList)destinationSubscriptions.get(req.destination);
if (ll != null)
{
@@ -944,36 +957,36 @@
}
}
}
-
+
}
catch (Exception e)
{
throw new SpyJMSException("Cannot unsubscribe to this destination", e);
}
-
+
}
//Send a message to the serverIL
void sendToServer(SpyMessage mes)
- throws JMSException
+ throws JMSException
{
if (closed)
{
throw new IllegalStateException("The connection is closed");
}
-
+
try
{
-
+
serverIL.addMessage(connectionToken, mes);
-
+
}
catch (Exception e)
{
throw new SpyJMSException("Cannot send a message to the JMS server", e);
}
}
-
+
//Called by a session when it is closing
void sessionClosing(SpySession who)
{
@@ -981,13 +994,13 @@
{
createdSessions.remove(who);
}
-
+
//This session should not be in the "destinations" object anymore.
//We could check this, though
}
-
+
void unsubscribe(DurableSubcriptionID id)
- throws JMSException
+ throws JMSException
{
try
{
@@ -998,7 +1011,7 @@
throw new SpyJMSException("Cannot destroy durable subscription " + id, e);
}
}
-
+
/**
* #Description of the Class
*/
@@ -1009,33 +1022,38 @@
*/
public void run()
{
- try {
+ try
+ {
pingTaskSemaphore.acquire();
- } catch ( InterruptedException e ) {
+ } catch ( InterruptedException e )
+ {
return;
}
- try {
+ try
+ {
if (ponged == false)
{
// Server did not pong use with in the timeout
// period.. Assuming the connection is dead.
throw new SpyJMSException("", new IOException("ping timeout."));
}
-
+
ponged = false;
pingServer(System.currentTimeMillis());
}
catch (JMSException e)
{
asynchFailure("Connection Failed", e.getLinkedException());
- } finally {
+ } finally
+ {
pingTaskSemaphore.release();}
- }
+ }
}
-
- private void startPingThread() {
+
+ private void startPingThread()
+ {
- // Ping thread does not need to be running if the
+ // Ping thread does not need to be running if the
// ping period is 0.
if( pingPeriod == 0 )
return;
@@ -1043,7 +1061,8 @@
}
- private void stopPingThread() {
+ private void stopPingThread()
+ {
// Ping thread was not running if ping period is 0.
if( pingPeriod == 0 )
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development