defaultorb.java
来自「OpenJMS是一个开源的Java Message Service API 1.」· Java 代码 · 共 611 行 · 第 1/2 页
JAVA
611 行
/** * Redistribution and use of this software and associated documentation * ("Software"), with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain copyright * statements and notices. Redistributions must also contain a * copy of this document. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * * 3. The name "Exolab" must not be used to endorse or promote * products derived from this Software without prior written * permission of Exoffice Technologies. For written permission, * please contact info@exolab.org. * * 4. Products derived from this Software may not be called "Exolab" * nor may "Exolab" appear in their names without prior written * permission of Exoffice Technologies. Exolab is a registered * trademark of Exoffice Technologies. * * 5. Due credit should be given to the Exolab Project * (http://www.exolab.org/). * * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * Copyright 2003-2005 (C) Exoffice Technologies Inc. All Rights Reserved. * * $Id: DefaultORB.java,v 1.13 2006/02/23 11:17:40 tanderson Exp $ */package org.exolab.jms.net.orb;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.rmi.ConnectException;import java.rmi.NoSuchObjectException;import java.rmi.RemoteException;import java.rmi.StubNotFoundException;import java.rmi.server.ExportException;import java.security.Principal;import java.util.Map;import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.exolab.jms.common.security.BasicPrincipal;import org.exolab.jms.common.threads.DefaultThreadPoolFactory;import org.exolab.jms.net.connector.AbstractConnectionManager;import org.exolab.jms.net.connector.Authenticator;import org.exolab.jms.net.connector.Caller;import org.exolab.jms.net.connector.CallerListener;import org.exolab.jms.net.connector.Connection;import org.exolab.jms.net.connector.Invocation;import org.exolab.jms.net.connector.InvocationHandler;import org.exolab.jms.net.connector.MulticastCallerListener;import org.exolab.jms.net.connector.Request;import org.exolab.jms.net.connector.ResourceException;import org.exolab.jms.net.connector.Response;import org.exolab.jms.net.proxy.Proxy;import org.exolab.jms.net.registry.LocalRegistry;import org.exolab.jms.net.registry.Registry;import org.exolab.jms.net.uri.InvalidURIException;import org.exolab.jms.net.uri.URI;import org.exolab.jms.common.threads.ThreadPoolFactory;import org.exolab.jms.net.util.MethodHelper;import org.exolab.jms.net.util.Properties;/** * The <code>DefaultORB</code> class manages exported objects. * * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> * @version $Revision: 1.13 $ $Date: 2006/02/23 11:17:40 $ */class DefaultORB extends AbstractORB { /** * The registry. */ private LocalRegistry _registry; /** * The connection manager. */ private AbstractConnectionManager _manager; /** * The caller event listeners. */ private MulticastCallerListener _listeners; /** * The thread pool factory. */ private ThreadPoolFactory _factory; /** * The thread pool for scheduling invocation requests. */ private PooledExecutor _pool; /** * The maximum no. of threads to use in the thread pool. */ private int _maxThreads; /** * Synchronization helper for accessing _pool. */ private final Object _poolLock = new Object(); /** * Current caller. */ private final ThreadLocal _caller = new ThreadLocal(); /** * Constant that holds the name of the connection property for specifying * the maximum no. of threads to use for servicing invocations. */ private static final String MAX_THREADS_NAME = "org.exolab.jms.net.orb.threads.max"; /** * Constant that holds the name of the connection property for specifying * the thread pool factory. */ private static final String THREAD_POOL_FACTORY = "org.exolab.jms.net.orb.threads.factory"; /** * Default max no. of threads to service invocations, if none is specified. */ private static final int MAX_THREADS = Integer.MAX_VALUE; /** * The logger. */ private static final Log _log = LogFactory.getLog(DefaultORB.class); /** * Construct a new <code>DefaultORB</code> with the connection * authenticator. All proxies will be loaded using this instance's class * loader. * * @param authenticator the connection authenticator * @throws RemoteException for any error */ public DefaultORB(Authenticator authenticator) throws RemoteException { this(authenticator, DefaultORB.class.getClassLoader(), null); } /** * Construct a new <code>DefaultORB</code> with the connection * authenticator, and properties to configure the ORB. All proxies will be * loaded using this instance's class loader. * * @param authenticator the connection authenticator * @param properties properties to configure the ORB. May be * <code>null</code> * @throws RemoteException for any error */ public DefaultORB(Authenticator authenticator, Map properties) throws RemoteException { this(authenticator, DefaultORB.class.getClassLoader(), properties); } /** * Construct a new <code>DefaultORB</code> with properties to configure the * ORB. Connections will be unauthenticated. All proxies will be loaded * using this instance's class loader. * * @throws RemoteException for any error */ public DefaultORB(Map properties) throws RemoteException { this(new DummyAuthenticator(), DefaultORB.class.getClassLoader(), properties); } /** * Construct a new <code>DefaultORB</code>. Connections will be * unauthenticated. All proxies will be loaded using this instance's class * loader. * * @throws RemoteException for any error */ public DefaultORB() throws RemoteException { this(new DummyAuthenticator(), DefaultORB.class.getClassLoader(), null); } /** * Construct a new <code>DefaultORB</code> with the connection * authenticator, the class loader used to load proxies, and properties to * configure the ORB. * * @param authenticator the connection authenticator * @param loader the class loader to load proxies * @param properties properties to configure the ORB. May be * <code>null</code> * @throws RemoteException for any error */ public DefaultORB(Authenticator authenticator, ClassLoader loader, Map properties) throws RemoteException { super(loader, properties); if (authenticator == null) { throw new IllegalArgumentException( "Argument 'authenticator' is null"); } Properties helper = new Properties(properties, null); try { _maxThreads = helper.getInt(MAX_THREADS_NAME, MAX_THREADS); } catch (ResourceException exception) { throw new RemoteException("Failed to construct thread pool", exception); } _factory = (ThreadPoolFactory) helper.getProperties().get( THREAD_POOL_FACTORY); if (_factory == null) { _factory = new DefaultThreadPoolFactory(null); } try { _manager = createConnectionManager(new Handler(), authenticator); } catch (ResourceException exception) { throw new RemoteException("Failed to construct connection manager", exception); } } /** * Returns a reference to the registry service. * * @return the registry service * @throws RemoteException if the service cannot be exported */ public synchronized LocalRegistry getRegistry() throws RemoteException { if (_registry == null) { _registry = new RegistryService(this); } return _registry; } /** * Returns a reference to a remote registry service. * * @param properties the connection properties. * @return the registry service * @throws RemoteException for any error */ public Registry getRegistry(Map properties) throws RemoteException { if (properties == null || properties.get(PROVIDER_URI) == null) { throw new ConnectException(PROVIDER_URI + " not specified"); } Registry registry; String uri = (String) properties.get(PROVIDER_URI); String principal = (String) properties.get(SECURITY_PRINCIPAL); String credentials = (String) properties.get(SECURITY_CREDENTIALS); Principal subject = null; if (principal != null) { subject = new BasicPrincipal(principal, credentials); } try { registry = Locator.getRegistry(subject, uri, _manager, getProxyClassLoader(), properties); } catch (InvalidURIException exception) { throw new RemoteException("Invalid URI: " + uri, exception); } return registry; } /** * Export an object to the current remote caller. Only the remote caller may * perform invocations. * * @param object the object to export * @return a proxy which may be used to invoke methods on the object * @throws ExportException if the object cannot be exported * @throws StubNotFoundException if the proxy class cannot be found */ public Proxy exportObjectTo(Object object) throws ExportException, StubNotFoundException { Caller caller = (Caller) _caller.get(); if (caller == null) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?