Commit 09d288b0 authored by ncampbell's avatar ncampbell

JMX for SocketReaders. Shows the number of connections and

collectes the statistics for each connection.

git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/branches/pampero@2958 b35dd754-fafc-0310-a699-88a17e54d16e
parent 650d9ef8
...@@ -32,5 +32,7 @@ ...@@ -32,5 +32,7 @@
<classpathentry kind="lib" path="build/lib/merge/standard.jar"/> <classpathentry kind="lib" path="build/lib/merge/standard.jar"/>
<classpathentry kind="lib" path="build/lib/merge/whack.jar"/> <classpathentry kind="lib" path="build/lib/merge/whack.jar"/>
<classpathentry kind="lib" path="build/lib/merge/xpp3.jar"/> <classpathentry kind="lib" path="build/lib/merge/xpp3.jar"/>
<classpathentry kind="lib" path="build/lib/merge/commons-math-1.0.jar"/>
<classpathentry kind="lib" path="build/lib/merge/sitemesh.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>
/** /**
* Copyright Noah Campbell 2004 * Copyright Noah Campbell 2005
*/ */
package org.jivesoftware.messenger.net; package org.jivesoftware.messenger.net;
......
...@@ -31,6 +31,8 @@ import java.io.InputStreamReader; ...@@ -31,6 +31,8 @@ import java.io.InputStreamReader;
import java.io.Writer; import java.io.Writer;
import java.net.Socket; import java.net.Socket;
import java.net.SocketException; import java.net.SocketException;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
/** /**
* A SocketReader creates the appropriate {@link Session} based on the defined namespace in the * A SocketReader creates the appropriate {@link Session} based on the defined namespace in the
...@@ -84,6 +86,47 @@ public abstract class SocketReader implements Runnable { ...@@ -84,6 +86,47 @@ public abstract class SocketReader implements Runnable {
this.router = router; this.router = router;
this.connection = connection; this.connection = connection;
this.socket = socket; this.socket = socket;
SocketReader.concurrent++;
this.connectedTimestamp = System.currentTimeMillis();
}
/** The connectedTimestamp. */
private long connectedTimestamp;
/** The disconnectedTimestamp. */
private long disconnectedTimestamp = -1;
/**
* The total concurrent StreamReaders in memory.
*
* @see SocketReaderObserver
*/
static volatile int concurrent;
/**
* The statsOutboundQueue. Sends the amount of time that the socket reader
* is connected to the <code>SocketReaderObserver</code> so it can calculate
* the appropriate.
*
* @see SocketReaderObserver
*/
static Queue<Long> statsOutboundQueue = new ConcurrentLinkedQueue<Long>();
/**
* @see java.lang.Object#finalize()
*/
@Override
protected void finalize() throws Throwable {
super.finalize();
if(disconnectedTimestamp <= -1) {
this.disconnectedTimestamp = System.currentTimeMillis();
}
SocketReader.concurrent--;
statsOutboundQueue.offer(disconnectedTimestamp - connectedTimestamp);
} }
/** /**
...@@ -569,6 +612,7 @@ public abstract class SocketReader implements Runnable { ...@@ -569,6 +612,7 @@ public abstract class SocketReader implements Runnable {
* for releasing any resource they might need. * for releasing any resource they might need.
*/ */
protected void shutdown() { protected void shutdown() {
this.disconnectedTimestamp = System.currentTimeMillis();
} }
/** /**
...@@ -582,4 +626,5 @@ public abstract class SocketReader implements Runnable { ...@@ -582,4 +626,5 @@ public abstract class SocketReader implements Runnable {
*/ */
abstract boolean createSession(String namespace) throws UnauthorizedException, abstract boolean createSession(String namespace) throws UnauthorizedException,
XmlPullParserException, IOException; XmlPullParserException, IOException;
} }
/**
*
*/
package org.jivesoftware.messenger.net;
/**
* @author Noah Campbell
* @version 1.0
*/
public interface SocketReaderMBean {
/**
* The total SocketReaders in this jvm.
* @return total
*/
int getConcurrent();
/**
* The aver connection time for this socket reader
* @return avgConnTime
*/
double getMeanConnectionTime();
/**
* Return the min connection time.
*
* @return min
*/
public double getMinConnectionTime();
/**
* Return the max connection time.
*
* @return max
*/
public double getMaxConnectionTime();
/**
* Return the 95th percentile connection time (trims out spurrious data).
*
* @return value
*/
public double get95thPercentile();
}
/**
*
*/
package org.jivesoftware.messenger.net;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.apache.commons.math.stat.descriptive.DescriptiveStatistics;
/**
* @author Noah Campbell
* @version 1.0
*/
public class SocketReaderObserver implements SocketReaderMBean, Runnable {
/** The ds. */
private DescriptiveStatistics ds = DescriptiveStatistics.newInstance();
/** The des. */
private ScheduledExecutorService des = Executors.newScheduledThreadPool(1);
/**
* Construct a new <code>SocketReaderObserver</code>.
*
*/
private SocketReaderObserver() {
des.scheduleAtFixedRate(this, 0, 500, TimeUnit.MILLISECONDS);
}
/** The INSTANCE. */
private static final SocketReaderObserver INSTANCE = new SocketReaderObserver();
/**
* @return observer
*/
public static SocketReaderObserver getInstance() {
return INSTANCE;
}
/**
* @see org.jivesoftware.messenger.net.SocketReaderMBean#getConcurrent()
*/
public int getConcurrent() {
return SocketReader.concurrent;
}
/**
* @see org.jivesoftware.messenger.net.SocketReaderMBean#getMeanConnectionTime()
*/
public double getMeanConnectionTime() {
return ds.getMean();
}
/**
* @return
*/
public double getMinConnectionTime() {
return ds.getMin();
}
/**
* @return
*/
public double getMaxConnectionTime() {
return ds.getMax();
}
/**
* @return
*/
public double get95thPercentile() {
return ds.getPercentile(95);
}
/**
* @see java.lang.Runnable#run()
*/
public void run() {
if(SocketReader.statsOutboundQueue.peek() != null) {
Long l = SocketReader.statsOutboundQueue.poll();
ds.addValue(l.doubleValue());
}
}
}
...@@ -290,6 +290,18 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -290,6 +290,18 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
router = server.getPacketRouter(); router = server.getPacketRouter();
deliverer = server.getPacketDeliverer(); deliverer = server.getPacketDeliverer();
sessionManager = server.getSessionManager(); sessionManager = server.getSessionManager();
Properties props = new Properties();
props.put("name","ServerReader");
try {
ObjectName objectName = new ObjectName("org.jivesoftware.messenger", props);
StandardMBean mbean = new StandardMBean(SocketReaderObserver.getInstance(), SocketReaderMBean.class);
mbeanServer.registerMBean(mbean, objectName);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
public void enableClientListener(boolean enabled) { public void enableClientListener(boolean enabled) {
......
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