Implements the ServerILJMXService which is used to manage the OIL2 IL.
| Method from org.jboss.mq.il.oil2.OIL2ServerILService Detail: |
public String getBindAddress() {
String addr = "0.0.0.0";
if (bindAddress != null)
addr = bindAddress.getHostName();
return addr;
}
Get the interface address the OIL server bind its listening port on. |
public Properties getClientConnectionProperties() {
return connectionProperties;
}
Used to construct the GenericConnectionFactory (bindJNDIReferences()
builds it) Sets up the connection properties need by a client to use this
IL |
public String getClientSocketFactory() {
return clientSocketFactoryName;
}
Get the javax.net.SocketFactory implementation class to use on the
client. |
public boolean getEnableTcpNoDelay() {
return enableTcpNoDelay;
}
Gets the enableTcpNoDelay. |
public String getName() {
return "JBossMQ-OILServerIL";
}
Gives this JMX service a name. |
public String getSecurityDomain() {
return this.securityDomain;
}
Get the security domain name to use with SSL aware socket factories |
public int getServerBindPort() {
return serverBindPort;
}
Getter for property serverBindPort. |
public ServerIL getServerIL() {
return serverIL;
}
Used to construct the GenericConnectionFactory (bindJNDIReferences()
builds it) |
public String getServerSocketFactory() {
String name = null;
if( serverSocketFactory != null )
name = serverSocketFactory.getClass().getName();
return name;
}
Get the javax.net.ServerSocketFactory implementation class to use to
create the service SocketFactory. |
public void run() {
try
{
while (running)
{
Socket socket = null;
try
{
socket = serverSocket.accept();
if( log.isTraceEnabled() )
log.trace("Accepted connection: "+socket);
}
catch (java.io.InterruptedIOException e)
{
// It's ok, this is due to the SO_TIME_OUT
continue;
}
// it's possible that the service is no longer
// running but it got a connection, no point in
// starting up a thread!
//
if (!running)
{
if (socket != null)
{
try
{
socket.close();
}
catch (Exception ignore)
{
}
}
return;
}
try
{
if( log.isTraceEnabled() )
log.trace("Initializing RequestListner for socket: "+socket);
RequestListner requestListner = new RequestListner(socket);
OIL2SocketHandler socketHandler =
new OIL2SocketHandler(
requestListner.in,
requestListner.out,
Thread.currentThread().getThreadGroup());
requestListner.socketHandler = socketHandler;
socketHandler.setRequestListner(requestListner);
socketHandler.start();
}
catch (IOException ie)
{
log.debug("Client connection could not be accepted: ", ie);
}
}
}
catch (SocketException e)
{
// There is no easy way (other than string comparison) to
// determine if the socket exception is caused by connection
// reset by peer. In this case, it's okay to ignore both
// SocketException and IOException.
if (running)
log.warn("SocketException occured (Connection reset by peer?). Cannot initialize the OIL2ServerILService.");
}
catch (IOException e)
{
if (running)
log.warn("IOException occured. Cannot initialize the OIL2ServerILService.");
}
finally
{
try
{
serverSocket.close();
}
catch (Exception e)
{
log.debug("error closing server socket", e);
}
return;
}
}
Main processing method for the OILServerILService object |
public void setBindAddress(String host) throws UnknownHostException {
// If host is null or empty use any address
if (host == null || host.length() == 0)
bindAddress = null;
else
bindAddress = InetAddress.getByName(host);
}
Set the interface address the OIL server bind its listening port on. |
public void setClientSocketFactory(String name) {
this.clientSocketFactoryName = name;
}
Set the javax.net.SocketFactory implementation class to use on the
client. |
public void setEnableTcpNoDelay(boolean enableTcpNoDelay) {
this.enableTcpNoDelay = enableTcpNoDelay;
}
Sets the enableTcpNoDelay. |
public void setSecurityDomain(String domainName) {
this.securityDomain = domainName;
}
Set the security domain name to use with SSL aware socket factories |
public void setServerBindPort(int serverBindPort) {
this.serverBindPort = serverBindPort;
}
Setter for property serverBindPort. |
public void setServerSocketFactory(String name) throws Exception {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Class ssfClass = loader.loadClass(name);
serverSocketFactory = (ServerSocketFactory) ssfClass.newInstance();
}
Set the javax.net.ServerSocketFactory implementation class to use to
create the service SocketFactory. |
public void startService() throws Exception {
super.startService();
running = true;
this.server = lookupJMSServer();
// Use the default javax.net.ServerSocketFactory if none was set
if( serverSocketFactory == null )
serverSocketFactory = ServerSocketFactory.getDefault();
/* See if the server socket supports setSecurityDomain(SecurityDomain)
if an securityDomain was specified
*/
if( securityDomain != null )
{
try
{
InitialContext ctx = new InitialContext();
Class ssfClass = serverSocketFactory.getClass();
SecurityDomain domain = (SecurityDomain) ctx.lookup(securityDomain);
Class[] parameterTypes = {SecurityDomain.class};
Method m = ssfClass.getMethod("setSecurityDomain", parameterTypes);
Object[] args = {domain};
m.invoke(serverSocketFactory, args);
}
catch(NoSuchMethodException e)
{
log.error("Socket factory does not support setSecurityDomain(SecurityDomain)");
}
catch(Exception e)
{
log.error("Failed to setSecurityDomain="+securityDomain+" on socket factory");
}
}
// Create the server socket using the socket factory
serverSocket = serverSocketFactory.createServerSocket(serverBindPort, 50, bindAddress);
serverSocket.setSoTimeout(SO_TIMEOUT);
InetAddress socketAddress = serverSocket.getInetAddress();
log.info("JBossMQ OIL2 service available at : " + socketAddress + ":" + serverSocket.getLocalPort());
new Thread(server.getThreadGroup(), this, "OIL2 Worker Server").start();
/* We need to check the socketAddress against "0.0.0.0/0.0.0.0"
because this is not a valid address on Win32 while it is for
*NIX. See BugParade bug #4343286.
*/
if (socketAddress.toString().equals("0.0.0.0/0.0.0.0"))
socketAddress = InetAddress.getLocalHost();
serverIL = new OIL2ServerIL(socketAddress.getHostAddress(), serverSocket.getLocalPort(),
clientSocketFactoryName, enableTcpNoDelay);
// Initialize the connection poperties using the base class.
connectionProperties = super.getClientConnectionProperties();
connectionProperties.setProperty(OIL2ServerILFactory.CLIENT_IL_SERVICE_KEY, "org.jboss.mq.il.oil2.OIL2ClientILService");
connectionProperties.setProperty(OIL2ServerILFactory.OIL2_PORT_KEY, "" + serverSocket.getLocalPort());
connectionProperties.setProperty(OIL2ServerILFactory.OIL2_ADDRESS_KEY, "" + socketAddress.getHostAddress());
connectionProperties.setProperty(OIL2ServerILFactory.OIL2_TCPNODELAY_KEY, enableTcpNoDelay ? "yes" : "no");
bindJNDIReferences();
}
Starts this IL, and binds it to JNDI |
public void stopService() {
try
{
unbindJNDIReferences();
}
catch (Exception e)
{
log.error("Exception unbinding from JNDI", e);
}
try
{
running = false;
if (serverSocket != null)
serverSocket.close();
}
catch (Exception e)
{
log.debug("Exception stopping server thread", e);
}
}
Stops this IL, and unbinds it from JNDI. |