Hi Costin,

I was under the impression, as a convention, that we don't import using * (java.util.*). I find it more easier when all the classes are named....and from what I'm seeing, seems * is not used (at least on classes that I have worked on)

-- Jeanfrancois

[EMAIL PROTECTED] wrote:

costin 2003/01/09 11:09:33

Modified: catalina/src/share/org/apache/catalina/session
ManagerBase.java StandardManager.java
Log:
Few changes to give more info in the jmx console.
Switched StandardManager to c-l. There are still few dozens files that
need to be converted - and we need to find a naming scheme for the logs
that includes the host/path/component.
The additions provide info about detected duplicates, total number of
sessions that were generated, number of sessions that expired, number
of sessions that failed because of maxActive.
Also operations to show the sessions and get basic info ( expire ).
I think this would simplify some debugging and be more informative.
Revision Changes Path
1.11 +125 -46 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session/ManagerBase.java
Index: ManagerBase.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session/ManagerBase.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ManagerBase.java 1 Jan 2003 06:26:32 -0000 1.10
+++ ManagerBase.java 9 Jan 2003 19:09:33 -0000 1.11
@@ -1,7 +1,4 @@
/*
- * $Header$
- * $Revision$
- * $Date$
*
* ====================================================================
*
@@ -75,16 +72,16 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Random;
+import java.util.*;
+
import org.apache.catalina.Container;
import org.apache.catalina.DefaultContext;
import org.apache.catalina.Engine;
-import org.apache.catalina.Logger;
import org.apache.catalina.Manager;
import org.apache.catalina.Session;
import org.apache.catalina.util.StringManager;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
@@ -97,8 +94,7 @@
*/
public abstract class ManagerBase implements Manager {
- private static org.apache.commons.logging.Log log=
- org.apache.commons.logging.LogFactory.getLog( ManagerBase.class );
+ protected Log log = LogFactory.getLog(ManagerBase.class);
// ----------------------------------------------------- Instance Variables
@@ -211,6 +207,13 @@
*/
protected HashMap sessions = new HashMap();
+ // Number of sessions created by this manager
+ protected int sessionCounter=0;
+
+ protected int maxActive=0;
+
+ // number of duplicated session ids - anything >0 means we have problems
+ protected int duplicates=0;
/**
* The string manager for this package.
@@ -218,7 +221,6 @@
protected static StringManager sm =
StringManager.getManager(Constants.Package);
-
/**
* The property change support for this component.
*/
@@ -245,7 +247,6 @@
// ------------------------------------------------------------- Properties
-
/**
* Return the message digest algorithm for this Manager.
*/
@@ -290,7 +291,8 @@
Container oldContainer = this.container;
this.container = container;
support.firePropertyChange("container", oldContainer, this.container);
-
+ // TODO: find a good scheme for the log names
+ //log=LogFactory.getLog("tomcat.manager." + container.getName());
}
@@ -339,6 +341,12 @@
}
+ /** Returns the name of the implementation class.
+ */
+ public String getClassName() {
+ return this.getClass().getName();
+ }
+
/**
* Return the MessageDigest object to be used for calculating
@@ -515,6 +523,10 @@
}
}
+ public String getRandomFile() {
+ return devRandomSource;
+ }
+
/**
* Return the random number generator instance we should use for
@@ -594,8 +606,10 @@
synchronized (sessions) {
sessions.put(session.getId(), session);
+ if( sessions.size() > maxActive ) {
+ maxActive=sessions.size();
+ }
}
-
}
@@ -640,6 +654,7 @@
}
synchronized (sessions) {
while (sessions.get(sessionId) != null){ // Guarantee uniqueness
+ duplicates++;
sessionId = generateSessionId();
// @todo Move appending of jvmRoute generateSessionId()???
if (jvmRoute != null) {
@@ -649,6 +664,7 @@
}
session.setId(sessionId);
+ sessionCounter++;
return (session);
@@ -838,23 +854,10 @@
* Log a message on the Logger associated with our Container (if any).
*
* @param message Message to be logged
+ * @deprecated
*/
protected void log(String message) {
-
- Logger logger = null;
- if (container != null)
- logger = container.getLogger();
- if (logger != null)
- logger.log(getName() + "[" + container.getName() + "]: "
- + message);
- else {
- String containerName = null;
- if (container != null)
- containerName = container.getName();
- System.out.println(getName() + "[" + containerName
- + "]: " + message);
- }
-
+ log.info( message );
}
@@ -863,24 +866,10 @@
*
* @param message Message to be logged
* @param throwable Associated exception
+ * @deprecated
*/
protected void log(String message, Throwable throwable) {
-
- Logger logger = null;
- if (container != null)
- logger = container.getLogger();
- if (logger != null)
- logger.log(getName() + "[" + container.getName() + "] "
- + message, throwable);
- else {
- String containerName = null;
- if (container != null)
- containerName = container.getName();
- System.out.println(getName() + "[" + containerName
- + "]: " + message);
- throwable.printStackTrace(System.out);
- }
-
+ log.info(message,throwable);
}
@@ -890,11 +879,101 @@
* @param session Session to be recycled
*/
protected void recycle(Session session) {
-
synchronized (recycled) {
recycled.add(session);
}
+ }
+
+ public void setSessionCounter(int sessionCounter) {
+ this.sessionCounter = sessionCounter;
+ }
+ /** Total sessions created by this manager.
+ *
+ * @return sessions created
+ */
+ public int getSessionCounter() {
+ return sessionCounter;
+ }
+
+ /** Number of duplicated session IDs generated by the random source.
+ * Anything bigger than 0 means problems.
+ *
+ * @return
+ */
+ public int getDuplicates() {
+ return duplicates;
+ }
+
+ public void setDuplicates(int duplicates) {
+ this.duplicates = duplicates;
+ }
+
+ /** Returns the number of active sessions
+ *
+ * @return number of sessions active
+ */
+ public int getActiveSessions() {
+ return sessions.size();
+ }
+
+ /** Max number of concurent active sessions
+ *
+ * @return
+ */
+ public int getMaxActive() {
+ return maxActive;
+ }
+
+ public void setMaxActive(int maxActive) {
+ this.maxActive = maxActive;
+ }
+
+ /** For debugging: return a list of all session ids currently active
+ *
+ */
+ public String listSessionIds() {
+ StringBuffer sb=new StringBuffer();
+ Iterator keys=sessions.keySet().iterator();
+ while( keys.hasNext() ) {
+ sb.append(keys.next()).append(" ");
+ }
+ return sb.toString();
+ }
+
+ /** For debugging: get a session attribute
+ *
+ * @param sessionId
+ * @param key
+ * @return
+ */
+ public String getSessionAttribute( String sessionId, String key ) {
+ Session s=(Session)sessions.get(sessionId);
+ if( s==null ) {
+ log.info("Session not found " + sessionId);
+ return null;
+ }
+ Object o=s.getSession().getAttribute(key);
+ if( o==null ) return null;
+ return o.toString();
+ }
+
+ public void expireSession( String sessionId ) {
+ Session s=(Session)sessions.get(sessionId);
+ if( s==null ) {
+ log.info("Session not found " + sessionId);
+ return;
+ }
+ s.expire();
+ }
+
+ public String getLastAccessedTime( String sessionId ) {
+ Session s=(Session)sessions.get(sessionId);
+ if( s==null ) {
+ log.info("Session not found " + sessionId);
+ return "";
+ }
+ return new Date(s.getLastAccessedTime()).toString();
}
1.6 +89 -51 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session/StandardManager.java
Index: StandardManager.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/session/StandardManager.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- StandardManager.java 10 Dec 2002 07:46:37 -0000 1.5
+++ StandardManager.java 9 Jan 2003 19:09:33 -0000 1.6
@@ -212,6 +212,9 @@
*/
private String threadName = "StandardManager";
+ int rejectedSessions=0;
+ int expiredSessions=0;
+ long processingTime=0;
// ------------------------------------------------------------- Properties
@@ -290,6 +293,37 @@
}
+ /** Number of session creations that failed due to maxActiveSessions
+ *
+ * @return
+ */
+ public int getRejectedSessions() {
+ return rejectedSessions;
+ }
+
+ public void setRejectedSessions(int rejectedSessions) {
+ this.rejectedSessions = rejectedSessions;
+ }
+
+ /** Number of sessions that expired.
+ *
+ * @return
+ */
+ public int getExpiredSessions() {
+ return expiredSessions;
+ }
+
+ public void setExpiredSessions(int expiredSessions) {
+ this.expiredSessions = expiredSessions;
+ }
+
+ public long getProcessingTime() {
+ return processingTime;
+ }
+
+ public void setProcessingTime(long processingTime) {
+ this.processingTime = processingTime;
+ }
/**
* Set the maximum number of actives Sessions allowed, or -1 for
@@ -345,7 +379,6 @@
// --------------------------------------------------------- Public Methods
-
/**
* Construct and return a new session object, based on the default
* settings specified by this Manager's properties. The session
@@ -359,9 +392,11 @@
public Session createSession() {
if ((maxActiveSessions >= 0) &&
- (sessions.size() >= maxActiveSessions))
+ (sessions.size() >= maxActiveSessions)) {
+ rejectedSessions++;
throw new IllegalStateException
(sm.getString("standardManager.createSession.ise"));
+ }
return (super.createSession());
@@ -388,8 +423,8 @@
} else if (exception instanceof IOException){
throw (IOException)exception;
}
- if (debug >= 1)
- log("Unreported exception in load() "
+ if (log.isDebugEnabled())
+ log.debug("Unreported exception in load() "
+ exception); }
} else {
@@ -408,8 +443,8 @@
* @exception IOException if an input/output error occurs
*/
private void doLoad() throws ClassNotFoundException, IOException { - if (debug >= 1)
- log("Start: Loading persisted sessions");
+ if (log.isDebugEnabled())
+ log.debug("Start: Loading persisted sessions");
// Initialize our internal data structures
recycled.clear();
@@ -419,8 +454,8 @@
File file = file();
if (file == null)
return;
- if (debug >= 1)
- log(sm.getString("standardManager.loading", pathname));
+ if (log.isDebugEnabled())
+ log.debug(sm.getString("standardManager.loading", pathname));
FileInputStream fis = null;
ObjectInputStream ois = null;
Loader loader = null;
@@ -433,21 +468,21 @@
if (loader != null)
classLoader = loader.getClassLoader();
if (classLoader != null) {
- if (debug >= 1)
- log("Creating custom object input stream for class loader "
+ if (log.isDebugEnabled())
+ log.debug("Creating custom object input stream for class loader "
+ classLoader);
ois = new CustomObjectInputStream(bis, classLoader);
} else {
- if (debug >= 1)
- log("Creating standard object input stream");
+ if (log.isDebugEnabled())
+ log.debug("Creating standard object input stream");
ois = new ObjectInputStream(bis);
}
} catch (FileNotFoundException e) {
- if (debug >= 1)
- log("No persisted data file found");
+ if (log.isDebugEnabled())
+ log.debug("No persisted data file found");
return;
} catch (IOException e) {
- log(sm.getString("standardManager.loading.ioe", e), e);
+ log.error(sm.getString("standardManager.loading.ioe", e), e);
if (ois != null) {
try {
ois.close();
@@ -464,8 +499,8 @@
try {
Integer count = (Integer) ois.readObject();
int n = count.intValue();
- if (debug >= 1)
- log("Loading " + n + " persisted sessions");
+ if (log.isDebugEnabled())
+ log.debug("Loading " + n + " persisted sessions");
for (int i = 0; i < n; i++) {
StandardSession session = getNewSession();
session.readObjectData(ois);
@@ -474,7 +509,7 @@
session.activate();
}
} catch (ClassNotFoundException e) {
- log(sm.getString("standardManager.loading.cnfe", e), e);
+ log.error(sm.getString("standardManager.loading.cnfe", e), e);
if (ois != null) {
try {
ois.close();
@@ -485,7 +520,7 @@
}
throw e;
} catch (IOException e) {
- log(sm.getString("standardManager.loading.ioe", e), e);
+ log.error(sm.getString("standardManager.loading.ioe", e), e);
if (ois != null) {
try {
ois.close();
@@ -510,8 +545,8 @@
}
}
- if (debug >= 1)
- log("Finish: Loading persisted sessions");
+ if (log.isDebugEnabled())
+ log.debug("Finish: Loading persisted sessions");
}
@@ -531,8 +566,8 @@
if (exception instanceof IOException){
throw (IOException)exception;
}
- if (debug >= 1)
- log("Unreported exception in unLoad() "
+ if (log.isDebugEnabled())
+ log.debug("Unreported exception in unLoad() "
+ exception); } } else {
@@ -550,22 +585,22 @@
*/
private void doUnload() throws IOException { - if (debug >= 1)
- log("Unloading persisted sessions");
+ if (log.isDebugEnabled())
+ log.debug("Unloading persisted sessions");
// Open an output stream to the specified pathname, if any
File file = file();
if (file == null)
return;
- if (debug >= 1)
- log(sm.getString("standardManager.unloading", pathname));
+ if (log.isDebugEnabled())
+ log.debug(sm.getString("standardManager.unloading", pathname));
FileOutputStream fos = null;
ObjectOutputStream oos = null;
try {
fos = new FileOutputStream(file.getAbsolutePath());
oos = new ObjectOutputStream(new BufferedOutputStream(fos));
} catch (IOException e) {
- log(sm.getString("standardManager.unloading.ioe", e), e);
+ log.error(sm.getString("standardManager.unloading.ioe", e), e);
if (oos != null) {
try {
oos.close();
@@ -580,8 +615,8 @@
// Write the number of active sessions, followed by the details
ArrayList list = new ArrayList();
synchronized (sessions) {
- if (debug >= 1)
- log("Unloading " + sessions.size() + " sessions");
+ if (log.isDebugEnabled())
+ log.debug("Unloading " + sessions.size() + " sessions");
try {
oos.writeObject(new Integer(sessions.size()));
Iterator elements = sessions.values().iterator();
@@ -593,7 +628,7 @@
session.writeObjectData(oos);
}
} catch (IOException e) {
- log(sm.getString("standardManager.unloading.ioe", e), e);
+ log.error(sm.getString("standardManager.unloading.ioe", e), e);
if (oos != null) {
try {
oos.close();
@@ -624,8 +659,8 @@
}
// Expire all the sessions we just wrote
- if (debug >= 1)
- log("Expiring " + list.size() + " persisted sessions");
+ if (log.isDebugEnabled())
+ log.debug("Expiring " + list.size() + " persisted sessions");
Iterator expires = list.iterator();
while (expires.hasNext()) {
StandardSession session = (StandardSession) expires.next();
@@ -636,8 +671,8 @@
}
}
- if (debug >= 1)
- log("Unloading complete");
+ if (log.isDebugEnabled())
+ log.debug("Unloading complete");
}
@@ -690,8 +725,8 @@
*/
public void start() throws LifecycleException {
- if (debug >= 1)
- log("Starting");
+ if (log.isDebugEnabled())
+ log.debug("Starting");
// Validate and update our current component state
if (started)
@@ -701,17 +736,17 @@
started = true;
// Force initialization of the random number generator
- if (debug >= 1)
- log("Force random number initialization starting");
+ if (log.isDebugEnabled())
+ log.debug("Force random number initialization starting");
String dummy = generateSessionId();
- if (debug >= 1)
- log("Force random number initialization completed");
+ if (log.isDebugEnabled())
+ log.debug("Force random number initialization completed");
// Load unloaded sessions, if any
try {
load();
} catch (Throwable t) {
- log(sm.getString("standardManager.managerLoad"), t);
+ log.error(sm.getString("standardManager.managerLoad"), t);
}
// Start the background reaper thread
@@ -730,8 +765,8 @@
*/
public void stop() throws LifecycleException {
- if (debug >= 1)
- log("Stopping");
+ if (log.isDebugEnabled())
+ log.debug("Stopping");
// Validate and update our current component state
if (!started)
@@ -747,7 +782,7 @@
try {
unload();
} catch (IOException e) {
- log(sm.getString("standardManager.managerUnload"), e);
+ log.error(sm.getString("standardManager.managerUnload"), e);
}
// Expire all active sessions
@@ -790,7 +825,7 @@
setMaxInactiveInterval
( ((Integer) event.getNewValue()).intValue()*60 );
} catch (NumberFormatException e) {
- log(sm.getString("standardManager.sessionTimeout",
+ log.error(sm.getString("standardManager.sessionTimeout",
event.getNewValue().toString()));
}
}
@@ -846,12 +881,15 @@
(int) ((timeNow - session.getLastAccessedTime()) / 1000L);
if (timeIdle >= maxInactiveInterval) {
try {
+ expiredSessions++;
session.expire();
} catch (Throwable t) {
- log(sm.getString("standardManager.expireException"), t);
+ log.error(sm.getString("standardManager.expireException"), t);
}
}
}
+ long timeEnd=System.currentTimeMillis();
+ processingTime += ( timeEnd - timeNow );
}

--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to