defaultorb.java
来自「一个java方面的消息订阅发送的源码」· Java 代码 · 共 499 行 · 第 1/2 页
JAVA
499 行
/**
* 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.9 2005/06/04 14:43:59 tanderson Exp $
*/
package org.exolab.jms.net.orb;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
import java.rmi.StubNotFoundException;
import java.rmi.ConnectException;
import java.rmi.server.ExportException;
import java.security.Principal;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.exolab.jms.common.security.BasicPrincipal;
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.connector.AbstractConnectionManager;
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.net.util.MethodHelper;
/**
* The <code>DefaultORB</code> class manages exported objects.
*
* @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
* @version $Revision: 1.9 $ $Date: 2005/06/04 14:43:59 $
*/
class DefaultORB extends AbstractORB {
/**
* The registry.
*/
private LocalRegistry _registry;
/**
* The connection manager.
*/
private AbstractConnectionManager _manager;
/**
* The caller event listeners.
*/
private MulticastCallerListener _listeners;
/**
* Current caller.
*/
private final ThreadLocal _caller = new ThreadLocal();
/**
* 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");
}
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) {
throw new ExportException("Cannot export - no current caller");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?