rmimanagedconnection.java
来自「OpenJMS是一个开源的Java Message Service API 1.」· Java 代码 · 共 441 行 · 第 1/2 页
JAVA
441 行
/** * 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: RMIManagedConnection.java,v 1.8 2006/12/16 12:37:17 tanderson Exp $ */package org.exolab.jms.net.rmi;import java.io.IOException;import java.rmi.AccessException;import java.rmi.MarshalException;import java.rmi.MarshalledObject;import java.rmi.NotBoundException;import java.rmi.RemoteException;import java.rmi.registry.LocateRegistry;import java.rmi.registry.Registry;import java.rmi.server.UnicastRemoteObject;import java.security.Principal;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.exolab.jms.common.uuid.UUIDGenerator;import org.exolab.jms.net.connector.AbstractManagedConnection;import org.exolab.jms.net.connector.Caller;import org.exolab.jms.net.connector.CallerImpl;import org.exolab.jms.net.connector.ConnectException;import org.exolab.jms.net.connector.Connection;import org.exolab.jms.net.connector.IllegalStateException;import org.exolab.jms.net.connector.InvocationHandler;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.SecurityException;import org.exolab.jms.net.connector.MarshalledInvocation;import org.exolab.jms.net.connector.ManagedConnectionListener;import org.exolab.jms.net.uri.InvalidURIException;import org.exolab.jms.net.uri.URI;import org.exolab.jms.net.uri.URIHelper;/** * <code>RMIManagedConnection</code> manages multiple <code>RMIConnection</code> * instances. * * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> * @version $Revision: 1.8 $ $Date: 2006/12/16 12:37:17 $ */class RMIManagedConnection extends AbstractManagedConnection { /** * The invoker for serving invocations from the remote managed connection. */ private RMIInvokerImpl _localInvoker; /** * The invoker for delegating invocations to the remote managed connection. */ private RMIInvoker _remoteInvoker; /** * The invocation handler. */ private InvocationHandler _invoker; /** * The remote address to which this is connected. */ private URI _remoteURI; /** * The the local address that this connection is bound to. */ private URI _localURI; /** * The security principal. */ private Principal _principal; /** * Cached caller instance. Non-null if this is a server-side instance. */ private Caller _caller; /** * The logger. */ private static final Log _log = LogFactory.getLog(RMIManagedConnection.class); /** * Construct a new client <code>RMIManagedConnection</code>. * * @param principal the security principal * @param info the connection request info * @throws ResourceException if a connection cannot be established */ protected RMIManagedConnection(Principal principal, RMIRequestInfo info) throws ResourceException { Registry registry; _remoteURI = URIHelper.convertHostToAddress(info.getURI()); _localURI = generateLocalURI(); try { registry = LocateRegistry.getRegistry(info.getHost(), info.getPort()); } catch (RemoteException exception) { throw new ConnectException("Failed to get registry" + ", host=" + info.getHost() + ", port=" + info.getPort(), exception); } String name = RegistryHelper.getName(_remoteURI); RMIInvokerFactory factory; try { factory = (RMIInvokerFactory) registry.lookup(name); } catch (RemoteException exception) { throw new ConnectException("Failed to lookup connection proxy" + ", host=" + info.getHost() + ", port=" + info.getPort(), exception); } catch (NotBoundException exception) { throw new ConnectException("Connection proxy=" + name + " not bound in " + "registry, host=" + info.getHost() + ", port=" + info.getPort(), exception); } _localInvoker = new RMIInvokerImpl(); _localInvoker.setConnection(this); try { UnicastRemoteObject.exportObject(_localInvoker); } catch (RemoteException exception) { throw new ResourceException("Failed to export invocation handler", exception); } try { _remoteInvoker = factory.createInvoker(principal, _localInvoker, _localURI.toString()); } catch (AccessException exception) { throw new SecurityException(exception.getMessage(), exception); } catch (RemoteException exception) { if (exception.detail instanceof AccessException) { throw new SecurityException(exception.getMessage(), exception.detail); } throw new ResourceException("Failed to create invocation handler", exception); } _principal = principal; } /** * Construct a new server <code>RMIManagedConnection</code>. This is * responsible for exporting the supplied local invoker on the port * specified by the URI. * * @param principal the security principal * @param localInvoker the invoker which delegates invocations to this * @param localURI the URI to export the connection proxy on * @param remoteInvoker the invoker which delegates invocations to the * remote managed connection * @param remoteURI the URI representing the remote connection * @throws RemoteException if the connection proxy can't be exported */ protected RMIManagedConnection(Principal principal, RMIInvokerImpl localInvoker, URI localURI, RMIInvoker remoteInvoker, URI remoteURI) throws RemoteException { localInvoker.setConnection(this); UnicastRemoteObject.exportObject(localInvoker, localURI.getPort()); _localInvoker = localInvoker; _localURI = localURI; _remoteInvoker = remoteInvoker; _remoteURI = remoteURI;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?