Implements the ServerILJMXService which is used to manage the JVM IL.
| Method from org.jboss.mq.il.oil.OILServerILService 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 int getReadTimeout() {
return readTimeout;
}
Gets the socket read timeout. |
public String getSecurityDomain() {
return this.securityDomain;
}
Get the security domain name to use with SSL aware socket factories |
public int getServerBindPort() {
return serverBindPort;
}
Get the OIL server listening port |
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();
}
catch (java.io.InterruptedIOException e)
{
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 e)
{
// do nothing
}
}
return;
}
try
{
socket.setSoTimeout(readTimeout);
new Thread(new Client(socket), "OIL Worker-" + threadNumber++).start();
}
catch(IOException ie)
{
if(log.isDebugEnabled())
{
log.debug("IOException processing client connection", ie);
log.debug("Dropping client connection, server will not terminate");
}
}
}
}
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 OILServerILService.");
}
catch (IOException e)
{
if (running)
log.warn("IOException occured. Cannot initialize the OILServerILService.");
}
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 setReadTimeout(int timeout) {
this.readTimeout = timeout;
}
|
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;
}
Set the OIL server listening port |
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();
if(log.isInfoEnabled())
log.info("JBossMQ OIL service available at : " + socketAddress + ":" + serverSocket.getLocalPort());
new Thread(server.getThreadGroup(), this, "OIL 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 OILServerIL(socketAddress, serverSocket.getLocalPort(),
clientSocketFactoryName, enableTcpNoDelay);
// Initialize the connection poperties using the base class.
connectionProperties = super.getClientConnectionProperties();
connectionProperties.setProperty(OILServerILFactory.CLIENT_IL_SERVICE_KEY, "org.jboss.mq.il.oil.OILClientILService");
connectionProperties.setProperty(OILServerILFactory.OIL_PORT_KEY, ""+serverSocket.getLocalPort());
connectionProperties.setProperty(OILServerILFactory.OIL_ADDRESS_KEY, ""+socketAddress.getHostAddress());
connectionProperties.setProperty(OILServerILFactory.OIL_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. |