Commit 10696f02 authored by ncampbell's avatar ncampbell

JMX intrumentation of SocketAccept. Increments an internal

counter for each socket accept that the jvm receives since it
was started.  Also shows how to register an mbean with the 
server.

git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/branches@2954 b35dd754-fafc-0310-a699-88a17e54d16e
parent 54287aea
......@@ -27,7 +27,7 @@ import java.net.UnknownHostException;
* Implements a network front end with a dedicated thread reading
* each incoming socket.
*/
public class SSLSocketAcceptThread extends Thread {
public class SSLSocketAcceptThread extends Thread implements SocketAcceptMBean {
/**
* The default Jabber socket
......@@ -63,6 +63,8 @@ public class SSLSocketAcceptThread extends Thread {
* to shutdown the SSL port.
*/
private static final int MAX_SSL_EXCEPTIONS = 10;
private long acceptCount = 0;
/**
* Creates an instance using the default port, TLS transport security, and
......@@ -143,6 +145,7 @@ public class SSLSocketAcceptThread extends Thread {
Socket sock = serverSocket.accept();
Log.debug("SSL Connect " + sock.toString());
connManager.addSocket(sock, true, serverPort);
this.acceptCount++;
}
catch (SSLException se) {
long exceptionTime = System.currentTimeMillis();
......@@ -185,4 +188,11 @@ public class SSLSocketAcceptThread extends Thread {
// we don't care, no matter what, the socket should be dead
}
}
/**
* @see org.jivesoftware.messenger.net.SocketAcceptMBean#getAcceptCount()
*/
public long getAcceptCount() {
return this.acceptCount;
}
}
/**
* Copyright Noah Campbell 2004
*/
package org.jivesoftware.messenger.net;
/**
* @author Noah Campbell
* @version 1.0
*/
public interface SocketAcceptMBean {
/**
* Return the total number of times this socket has accepted an incoming
* socket since the start of the JVM.
*
* @return acceptCount
*/
long getAcceptCount();
}
......@@ -27,7 +27,7 @@ import java.net.Socket;
*
* @author Iain Shigeoka
*/
public class SocketAcceptThread extends Thread {
public class SocketAcceptThread extends Thread implements SocketAcceptMBean {
/**
* The default XMPP port for clients.
......@@ -65,7 +65,16 @@ public class SocketAcceptThread extends Thread {
ServerSocket serverSocket;
private ConnectionManager connManager;
private long acceptCount = 0;
/**
* Construct a new <code>SocketAcceptThread</code>.
*
* @param connManager
* @param serverPort
* @throws IOException
*/
public SocketAcceptThread(ConnectionManager connManager, ServerPort serverPort)
throws IOException {
super("Socket Listener at port " + serverPort.getPort());
......@@ -122,6 +131,7 @@ public class SocketAcceptThread extends Thread {
* About as simple as it gets. The thread spins around an accept
* call getting sockets and handing them to the SocketManager.
*/
@Override
public void run() {
while (notTerminated) {
try {
......@@ -129,6 +139,7 @@ public class SocketAcceptThread extends Thread {
if (sock != null) {
Log.debug("Connect " + sock.toString());
connManager.addSocket(sock, false, serverPort);
acceptCount++;
}
}
catch (IOException ie) {
......@@ -153,4 +164,11 @@ public class SocketAcceptThread extends Thread {
// we don't care, no matter what, the socket should be dead
}
}
/**
* @see org.jivesoftware.messenger.net.SocketAcceptMBean#getAcceptCount()
*/
public long getAcceptCount() {
return this.acceptCount;
}
}
......@@ -19,15 +19,27 @@ import org.jivesoftware.util.Log;
import org.jivesoftware.util.JiveGlobals;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
import javax.management.StandardMBean;
public class ConnectionManagerImpl extends BasicModule implements ConnectionManager {
private MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
private SocketAcceptThread socketThread;
private SSLSocketAcceptThread sslSocketThread;
private SocketAcceptThread componentSocketThread;
......@@ -92,6 +104,8 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
serverSocketThread.setDaemon(true);
serverSocketThread.start();
register("serverListener", serverPort, serverSocketThread);
List params = new ArrayList();
params.add(Integer.toString(serverSocketThread.getPort()));
Log.info(LocaleUtils.getLocalizedString("startup.server", params));
......@@ -104,6 +118,26 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
}
}
private void register(String type, ServerPort serverPort, Object obj) throws MalformedObjectNameException, NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanRegistrationException {
Properties props = new Properties();
props.setProperty("port", Integer.toString(serverPort.getPort()));
//
// props.setProperty("interface", serverPort.getInterfaceName());
// props.setProperty("ipaddr", serverPort.getIPAddress());
if(serverPort.getSecurityType() != null) {
props.setProperty("securityType", serverPort.getSecurityType());
} else {
props.setProperty("securityType", "NONE");
}
props.setProperty("type", type);
ObjectName objectName = new ObjectName("org.jivesoftware.messenger", props);
StandardMBean mbean = new StandardMBean(obj, SocketAcceptMBean.class);
mbeanServer.registerMBean(mbean, objectName);
}
private void stopServerListener() {
if (serverSocketThread != null) {
serverSocketThread.shutdown();
......@@ -124,7 +158,8 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
ports.add(serverPort);
componentSocketThread.setDaemon(true);
componentSocketThread.start();
register("componentListener", serverPort, componentSocketThread);
List params = new ArrayList();
params.add(Integer.toString(componentSocketThread.getPort()));
Log.info(LocaleUtils.getLocalizedString("startup.component", params));
......@@ -158,6 +193,8 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
socketThread.setDaemon(true);
socketThread.start();
register("clientListener", serverPort, socketThread);
List params = new ArrayList();
params.add(Integer.toString(socketThread.getPort()));
Log.info(LocaleUtils.getLocalizedString("startup.plain", params));
......@@ -195,6 +232,7 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
sslSocketThread.setDaemon(true);
sslSocketThread.start();
register("SSLClientListner", serverPort, sslSocketThread);
List params = new ArrayList();
params.add(Integer.toString(sslSocketThread.getPort()));
Log.info(LocaleUtils.getLocalizedString("startup.ssl", params));
......
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