| Method from org.jboss.invocation.pooled.server.PooledInvoker Detail: |
protected void destroyService() throws Exception {
// Unexport references to the bean
Registry.unbind(getServiceName());
}
|
public int getBacklog() {
return backlog;
}
|
public String getClientConnectAddress() {
return clientConnectAddress;
}
|
public int getClientConnectPort() {
return clientConnectPort;
}
|
public int getClientMaxPoolSize() {
return clientMaxPoolSize;
}
Getter for property maxPoolSize; |
public int getClientRetryCount() {
return clientRetryCount;
}
|
public SocketFactory getClientSocketFactory() {
return clientSocketFactory;
}
|
public String getClientSocketFactoryName() {
return clientSocketFactoryName;
}
|
public int getCurrentClientPoolSize() {
return clientpool.size();
}
|
public int getCurrentThreadPoolSize() {
return threadpool.size();
}
|
public int getMaxPoolSize() {
return maxPoolSize;
}
Getter for property maxPoolSize; |
public int getNumAcceptThreads() {
return numAcceptThreads;
}
Getter for property numAcceptThreads |
public PooledInvokerProxy getOptimizedInvokerProxy() {
return optimizedInvokerProxy;
}
|
public String getServerBindAddress() {
return serverBindAddress;
}
|
public int getServerBindPort() {
return serverBindPort;
}
Getter for property serverBindPort. |
public ServerSocket getServerSocket() {
return serverSocket;
}
|
public ServerSocketFactory getServerSocketFactory() {
return serverSocketFactory;
}
|
public String getServerSocketFactoryName() {
return serverSocketFactoryName;
}
|
public int getSocketTimeout() {
return timeout;
}
Getter for property timeout |
public String getSslDomain() {
return sslDomain;
}
|
public ObjectName getTransactionManagerService() {
return transactionManagerService;
}
mbean get-set pair for field transactionManagerService
Get the value of transactionManagerService |
protected Transaction importTPC(Object tpc) {
if (tpc != null)
return tpcImporter.importTransactionPropagationContext(tpc);
return null;
}
|
public Object invoke(Invocation invocation) throws Exception {
Thread currentThread = Thread.currentThread();
ClassLoader oldCl = currentThread.getContextClassLoader();
try
{
// Deserialize the transaction if it is there
PooledMarshalledInvocation mi = (PooledMarshalledInvocation) invocation;
invocation.setTransaction(importTPC(mi.getTransactionPropagationContext()));
ObjectName mbean = (ObjectName) Registry.lookup(invocation.getObjectName());
if( mbean == null )
{
System.err.println("NoSuchObjectException: "+invocation.getObjectName());
throw new NoSuchObjectException("Failed to find target for objectName: "+invocation.getObjectName());
}
// The cl on the thread should be set in another interceptor
Object obj = serverAction.invoke(mbean, "invoke",
new Object[] { invocation }, Invocation.INVOKE_SIGNATURE);
return obj;
}
catch (Exception e)
{
org.jboss.mx.util.JMXExceptionDecoder.rethrow(e);
// the compiler does not know an exception is thrown by the above
throw new org.jboss.util.UnreachableStatementException();
}
finally
{
currentThread.setContextClassLoader(oldCl);
}
}
The ServerProtocol will use this method to service an invocation
request. |
public boolean isEnableTcpNoDelay() {
return enableTcpNoDelay;
}
|
protected void jmxBind() {
////////////////////////////////////////////////////////////////////////
//
// The following methods Override the ServiceMBeanSupport base class
//
////////////////////////////////////////////////////////////////////////
Registry.bind(getServiceName(), optimizedInvokerProxy);
}
|
protected void loadCustomSocketFactories() {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
try
{
if( clientSocketFactoryName != null )
{
Class csfClass = loader.loadClass(clientSocketFactoryName);
clientSocketFactory = (SocketFactory) csfClass.newInstance();
}
}
catch (Exception e)
{
log.error("Failed to load client socket factory", e);
clientSocketFactory = null;
}
try
{
if( serverSocketFactory == null )
{
if( serverSocketFactoryName != null )
{
Class ssfClass = loader.loadClass(serverSocketFactoryName);
serverSocketFactory = (ServerSocketFactory) ssfClass.newInstance();
if( serverBindAddress != null )
{
// See if the server socket supports setBindAddress(String)
try
{
Class[] parameterTypes = {String.class};
Method m = ssfClass.getMethod("setBindAddress", parameterTypes);
Object[] args = {serverBindAddress};
m.invoke(serverSocketFactory, args);
}
catch (NoSuchMethodException e)
{
log.warn("Socket factory does not support setBindAddress(String)");
// Go with default address
}
catch (Exception e)
{
log.warn("Failed to setBindAddress="+serverBindAddress+" on socket factory", e);
// Go with default address
}
}
/* See if the server socket supports setSecurityDomain(SecurityDomain)
if an sslDomain was specified
*/
if( sslDomain != null )
{
try
{
InitialContext ctx = new InitialContext();
SecurityDomain domain = (SecurityDomain) ctx.lookup(sslDomain);
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="+sslDomain+" on socket factory", e);
}
}
}
// If a bind address was specified create a DefaultSocketFactory
else if( serverBindAddress != null )
{
DefaultSocketFactory defaultFactory = new DefaultSocketFactory(backlog);
serverSocketFactory = defaultFactory;
try
{
defaultFactory.setBindAddress(serverBindAddress);
}
catch (UnknownHostException e)
{
log.error("Failed to setBindAddress="+serverBindAddress+" on socket factory", e);
}
}
}
}
catch (Exception e)
{
log.error("operation failed", e);
serverSocketFactory = null;
}
}
Load and instantiate the clientSocketFactory, serverSocketFactory using
the TCL and set the bind address and SSL domain if the serverSocketFactory
supports it. |
public void run() {
while (running)
{
try
{
Socket socket = serverSocket.accept();
if( trace )
log.trace("Accepted: "+socket);
ServerThread thread = null;
boolean newThread = false;
while (thread == null)
{
synchronized(threadpool)
{
if (threadpool.size() > 0)
{
thread = (ServerThread)threadpool.removeFirst();
}
}
if (thread == null)
{
synchronized(clientpool)
{
if (clientpool.size() < maxPoolSize)
{
thread = new ServerThread(socket, this, clientpool, threadpool, timeout);
newThread = true;
}
if (thread == null)
{
clientpool.evict();
if( trace )
log.trace("Waiting for a thread...");
clientpool.wait();
if( trace )
log.trace("Notified of available thread");
}
}
}
}
synchronized(clientpool)
{
clientpool.insert(thread, thread);
}
if (newThread)
{
if( trace )
log.trace("Created a new thread, t="+thread);
thread.start();
}
else
{
if( trace )
log.trace("Reusing thread t="+thread);
thread.wakeup(socket, timeout);
}
}
catch (Throwable ex)
{
if (running)
log.error("Failed to accept socket connection", ex);
}
}
}
|
public void setBacklog(int backlog) {
this.backlog = backlog;
}
|
public void setClientConnectAddress(String clientConnectAddress) {
this.clientConnectAddress = clientConnectAddress;
}
|
public void setClientConnectPort(int clientConnectPort) {
this.clientConnectPort = clientConnectPort;
}
|
public void setClientMaxPoolSize(int clientMaxPoolSize) {
this.clientMaxPoolSize = clientMaxPoolSize;
}
Setter for property maxPoolSize. |
public void setClientRetryCount(int clientRetryCount) {
this.clientRetryCount = clientRetryCount;
}
|
public void setClientSocketFactory(SocketFactory clientSocketFactory) {
this.clientSocketFactory = clientSocketFactory;
}
|
public void setClientSocketFactoryName(String clientSocketFactoryName) {
this.clientSocketFactoryName = clientSocketFactoryName;
}
|
public void setEnableTcpNoDelay(boolean enableTcpNoDelay) {
this.enableTcpNoDelay = enableTcpNoDelay;
}
|
public void setMaxPoolSize(int maxPoolSize) {
this.maxPoolSize = maxPoolSize;
}
Setter for property maxPoolSize. |
public void setNumAcceptThreads(int size) {
this.numAcceptThreads = size;
}
Setter for property numAcceptThreads |
public void setServerBindAddress(String serverBindAddress) {
this.serverBindAddress = serverBindAddress;
}
|
public void setServerBindPort(int serverBindPort) {
this.serverBindPort = serverBindPort;
}
Setter for property serverBindPort. |
public void setServerSocket(ServerSocket serverSocket) {
this.serverSocket = serverSocket;
}
|
public void setServerSocketFactory(ServerSocketFactory serverSocketFactory) {
this.serverSocketFactory = serverSocketFactory;
}
|
public void setServerSocketFactoryName(String serverSocketFactoryName) {
this.serverSocketFactoryName = serverSocketFactoryName;
}
|
public void setSocketTimeout(int time) {
this.timeout = time;
}
Setter for property timeout |
public void setSslDomain(String sslDomain) {
this.sslDomain = sslDomain;
}
|
public void setTransactionManagerService(ObjectName transactionManagerService) {
this.transactionManagerService = transactionManagerService;
}
Set the value of transactionManagerService |
public void startService() throws Exception {
trace = log.isTraceEnabled();
///////////////////////////////////////////////////////////
// Setup the transaction stuff
///////////////////////////////////////////////////////////
InitialContext ctx = new InitialContext();
// Get the transaction propagation context factory
tpcFactory = TransactionPropagationContextUtil.getTPCFactory();
// and the transaction propagation context importer
tpcImporter = TransactionPropagationContextUtil.getTPCImporter();
// FIXME marcf: This should not be here
TransactionInterceptor.setTransactionManager((TransactionManager)ctx.lookup("java:/TransactionManager"));
///////////////////////////////////////////////////////////
// Setup the socket level stuff
///////////////////////////////////////////////////////////
InetAddress bindAddress =
(serverBindAddress == null || serverBindAddress.length() == 0)
? null
: InetAddress.getByName(serverBindAddress);
clientConnectAddress =
(clientConnectAddress == null || clientConnectAddress.length() == 0)
? InetAddress.getLocalHost().getHostName()
: clientConnectAddress;
/* We need to check the address against "0.0.0.0" as this is not a valid
address although some jdks will default to the host, while others fail
with java.net.BindException: Cannot assign requested address: connect
*/
clientConnectAddress = ServerConfigUtil.fixRemoteAddress(clientConnectAddress);
// Load any custom socket factories
loadCustomSocketFactories();
clientpool = new LRUPool(2, maxPoolSize);
clientpool.create();
threadpool = new LinkedList();
try
{
if( serverSocketFactory != null )
serverSocket = serverSocketFactory.createServerSocket(serverBindPort, backlog, bindAddress);
else
serverSocket = new ServerSocket(serverBindPort, backlog, bindAddress);
}
catch( java.net.BindException be)
{
throw new Exception("Port "+serverBindPort+" is already in use",be);
}
serverBindPort = serverSocket.getLocalPort();
clientConnectPort = (clientConnectPort == 0) ? serverSocket.getLocalPort() : clientConnectPort;
ServerAddress sa = new ServerAddress(clientConnectAddress, clientConnectPort,
enableTcpNoDelay, timeout, clientSocketFactory);
optimizedInvokerProxy = new PooledInvokerProxy(sa, clientMaxPoolSize, clientRetryCount);
///////////////////////////////////////////////////////////
// Register the service with the rest of the JBoss Kernel
///////////////////////////////////////////////////////////
// Export references to the bean
jmxBind();
log.debug("Bound invoker for JMX node");
ctx.close();
acceptThreads = new Thread[numAcceptThreads];
for (int i = 0; i < numAcceptThreads; i++)
{
String name = "PooledInvokerAcceptor#"+i+"-"+serverBindPort;
acceptThreads[i] = new Thread(this, name);
acceptThreads[i].start();
}
}
Starts this IL, and binds it to JNDI |
public void stopService() throws Exception {
running = false;
maxPoolSize = 0; // so ServerThreads don't reinsert themselves
for (int i = 0; i < acceptThreads.length; i++)
{
try
{
acceptThreads[i].interrupt();
}
catch (Exception ignored){}
}
clientpool.flush();
for (int i = 0; i < threadpool.size(); i++)
{
ServerThread thread = (ServerThread)threadpool.removeFirst();
thread.shutdown();
}
try
{
serverSocket.close();
}
catch(Exception e)
{
}
}
Stops this service, and unbinds it from JNDI. |