Commit 3f4e162b authored by Andre Freyssinet's avatar Andre Freyssinet

JORAM-341: Improvement of JMS/TCP connector.

- Adds methods for stopping and starting the connector, as well as a
method to force the closing of all active connections.
- Adds attribute to monitor the state of the connector, the number of
active, initiated and errors connections.
parent a3b73ab4
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2001 - 2013 ScalAgent Distributed Technologies
* Copyright (C) 2001 - 2019 ScalAgent Distributed Technologies
* Copyright (C) 1996 - 2000 Dyade
*
* This library is free software; you can redistribute it and/or
......@@ -283,10 +283,19 @@ public class TcpProxyService implements TcpProxyServiceMBean {
logger.log(BasicLevel.DEBUG, "TcpProxyService.stoped.");
}
/**
* Activates the TcpProxyService (TCP/JMS connector), creates the socket and starts listeners.
*/
@Override
public void activate() {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "TcpProxyService.activate()");
if (activated) {
logger.log(BasicLevel.WARN, "TcpProxyService.activate(): Already active, do nothing.");
return;
}
try {
if (cnxWithNoAckedQueue && executorService == null) {
createExecutors();
......@@ -295,6 +304,9 @@ public class TcpProxyService implements TcpProxyServiceMBean {
if (serverSocket == null)
serverSocket = createServerSocket(port, backlog, address);
// Note: If there is a failure during socket initialization, an exception is thrown, serverSocket is
// null and activated is false.
for (int i = 0; i < connectionListeners.length; i++) {
if (!connectionListeners[i].isRunning())
connectionListeners[i].start();
......@@ -302,7 +314,6 @@ public class TcpProxyService implements TcpProxyServiceMBean {
activated = true;
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "TcpProxyService.activated.");
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
logger.log(BasicLevel.ERROR, "TcpProxyService.activate()", exc);
......@@ -339,6 +350,10 @@ public class TcpProxyService implements TcpProxyServiceMBean {
}
}
/**
* Closes all active connections.
*/
@Override
public void closeAllConnections() {
Vector stopList = (Vector) connections.clone();
for (int i = 0; i < stopList.size(); i++) {
......@@ -347,7 +362,16 @@ public class TcpProxyService implements TcpProxyServiceMBean {
}
}
/**
* Deactivates the TcpProxyService (TCP/JMS connector), stops all listeners.
*/
@Override
public void deactivate() {
if (! activated) {
logger.log(BasicLevel.WARN, "TcpProxyService.deactivate(): Already stopped, do nothing.");
return;
}
for (int i = 0; i < connectionListeners.length; i++) {
connectionListeners[i].stop();
}
......@@ -360,26 +384,61 @@ public class TcpProxyService implements TcpProxyServiceMBean {
logger.log(BasicLevel.DEBUG, "TcpProxyService.activated = false");
}
/**
* Returns true if the TcpProxyService (TCP/JMS connector) is started.
* @return true if the TcpProxyService is started.
*/
@Override
public boolean isActivated() {
return activated;
}
/**
* Gets the number of active connections.
*
* @return the number of active connections.
*/
@Override
public int getRunningConnectionsCount() {
return connections.size();
}
/**
* Gets the number of threads listening for incoming tcp connections.
*
* @return the tcp listeners pool size.
*/
@Override
public int getTcpListenersPoolSize() {
return connectionListeners.length;
}
/**
* Gets the listen port of the server.
*
* @return the listen port of the server.
*/
@Override
public int getListenPort() {
return port;
}
/**
* Gets the socket address of the server.
*
* @return the server socket address.
*/
@Override
public String getServerAddress() {
return address;
}
/**
* Gets the number of failed login.
*
* @return the number of failed login.
*/
@Override
public int getFailedLoginCount() {
int failedCount = 0;
for (int i = 0; i < connectionListeners.length; i++) {
......@@ -388,6 +447,12 @@ public class TcpProxyService implements TcpProxyServiceMBean {
return failedCount;
}
/**
* Gets the number of connections initiated since boot time.
*
* @return the number of connections initiated since boot time.
*/
@Override
public int getInitiatedConnectionCount() {
int initCount = 0;
for (int i = 0; i < connectionListeners.length; i++) {
......@@ -396,6 +461,12 @@ public class TcpProxyService implements TcpProxyServiceMBean {
return initCount;
}
/**
* Gets the number of connections rejected due to a wrong protocol header.
*
* @return the number of connections rejected due to a wrong protocol header.
*/
@Override
public int getProtocolErrorCount() {
int errorCount = 0;
for (int i = 0; i < connectionListeners.length; i++) {
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2009 ScalAgent Distributed Technologies
* Copyright (C) 2009 - 2019 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -47,7 +47,34 @@ public interface TcpProxyServiceMBean extends ConnectionManagerMBean {
* @return the tcp listeners pool size.
*/
public int getTcpListenersPoolSize();
/**
* Returns true if the TcpProxyService (TCP/JMS connector) is started.
* @return true if the TcpProxyService is started.
*/
public boolean isActivated();
/**
* Gets the number of connections initiated since boot time.
*
* @return the number of connections initiated since boot time.
*/
public int getInitiatedConnectionCount();
/**
* Gets the number of active connections.
*
* @return the number of active connections.
*/
public int getRunningConnectionsCount();
/**
* Gets the number of failed login.
*
* @return the number of failed login.
*/
public int getFailedLoginCount();
/**
* Gets the number of connections rejected due to a wrong protocol header.
*
......@@ -55,4 +82,18 @@ public interface TcpProxyServiceMBean extends ConnectionManagerMBean {
*/
public int getProtocolErrorCount();
/**
* Activates the TcpProxyService (TCP/JMS connector), creates the socket and starts listeners.
*/
public void activate();
/**
* Closes all active connections.
*/
public void closeAllConnections();
/**
* Deactivates the TcpProxyService (TCP/JMS connector), stops all listeners.
*/
public void deactivate();
}
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