iiopconnection.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,000 行 · 第 1/3 页
JAVA
1,000 行
/* * @(#)IIOPConnection.java 1.124 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. *//* * Licensed Materials - Property of IBM * RMI-IIOP v1.0 * Copyright IBM Corp. 1998 1999 All Rights Reserved * * US Government Users Restricted Rights - Use, duplication or * disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */package com.sun.corba.se.internal.iiop;import java.util.Hashtable;import java.util.Enumeration;import java.util.Vector;import java.util.*; // Once we get beyond 5 does it make sense to do otherwise?import java.net.ServerSocket;import java.net.Socket;import java.net.InetAddress;import java.net.SocketException;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import org.omg.CORBA.SystemException;import org.omg.CORBA.CompletionStatus;import org.omg.CORBA.COMM_FAILURE;import org.omg.CORBA.INTERNAL;import org.omg.CORBA.Object;import com.sun.org.omg.SendingContext.CodeBase;import com.sun.org.omg.CORBA.ValueDefPackage.FullValueDescription;import com.sun.corba.se.internal.core.ServerGIOP;import com.sun.corba.se.internal.core.EndPoint;import com.sun.corba.se.internal.core.RequestHandler;import com.sun.corba.se.internal.core.IOR;import com.sun.corba.se.internal.core.ServerRequest;import com.sun.corba.se.internal.core.MarshalOutputStream;import com.sun.corba.se.internal.orbutil.MinorCodes;import com.sun.corba.se.internal.core.GIOPVersion;import com.sun.corba.se.internal.orbutil.Condition;import com.sun.corba.se.internal.orbutil.Lock;import com.sun.corba.se.internal.iiop.messages.Message;import com.sun.corba.se.internal.iiop.messages.MessageBase;import com.sun.corba.se.internal.iiop.messages.RequestMessage;import com.sun.corba.se.internal.iiop.messages.ReplyMessage;import com.sun.corba.se.internal.iiop.messages.FragmentMessage;import java.security.AccessController;import java.security.PrivilegedAction;/** * A network connection which processes IIOP messages. */public final class IIOPConnection extends Connection { final static class OutCallDesc { java.lang.Object done = new java.lang.Object(); Thread thd; SystemException exc; IIOPInputStream s; } final static class DeleteConn extends java.lang.Throwable { int minorCode; DeleteConn (int code) { minorCode = code; } } // // Connection status // private static final int OPENING = 1; private static final int ESTABLISHED = 2; private static final int CLOSE_SENT = 3; private static final int CLOSE_RECVD = 4; private static final int ABORT = 5; // // Table of pending invocations on this connection indexed by // Integer(requestId). These are only relevant if this is // a client. // // The clientReplyMap maps request ID to an IIOPInputStream. // The out_calls map request ID to an OutCallDesc. // This is so the client thread can start unmarshaling // the reply and remove it from the out_calls map while the // ReaderThread can still obtain the input stream to give // new fragments. Only the ReaderThread touches the clientReplyMap, // so it doesn't incur synchronization overhead. // Hashtable out_calls = null; ClientResponseImpl theOnly1_1ClientResponseImpl = null; Map clientReplyMap = null; // This map allows the ORB to ask "have any fragments // been sent?" if it catches an exception after already // sending at least one fragment and before the last is sent. // This can happen on both the client and server side. // We want a synchronized Hashtable. Hashtable idToFragmentedOutputStream; private MessageMediator mediator; // // Remote address that we're talking to. // private String threadName; protected EndPoint endpoint; protected int requestCount = 0; private ServerGIOP server; // Server request map: used on the server side of Connection // Maps request ID to IIOPInputStream. Map serverRequestMap = null; ServerRequestImpl theOnly1_1ServerRequestImpl = null; // This is a flag associated per connection telling us if the initial set of // sending contexts were sent to the receiver already... private boolean postInitialContexts = false; // Remote reference to CodeBase server (supplies FullValueDescription, among other things) private IOR codeBaseServerIOR; // CodeBase cache for this connection. This will cache remote operations, // handle connecting, and ensure we don't do any remote operations until // necessary. private CachedCodeBase cachedCodeBase = new CachedCodeBase(this); private String getStateString( int state ) { synchronized ( stateEvent ){ switch (state) { case OPENING : return "OPENING" ; case ESTABLISHED : return "ESTABLISHED" ; case CLOSE_SENT : return "CLOSE_SENT" ; case CLOSE_RECVD : return "CLOSE_RECVD" ; case ABORT : return "ABORT" ; default : return "???" ; } } } public String toString() { synchronized ( stateEvent ){ return "Connection[" + "type=" + endpoint.getType() + " remote_host=" + endpoint.getHostName() + " remote_port=" + endpoint.getPort() + " state=" + getStateString( state ) + "]" ; } } // // Various connection state. // Thread reader; int state; private java.lang.Object stateEvent = new java.lang.Object(); private java.lang.Object writeEvent = new java.lang.Object(); private boolean writeLocked; // These I/O streams are the ONLY ONES that should be used. // i.e. Do not directly use the input/output streams that socket gives. // This restriction is to allow connections to service multiple // protocols (e.g. http for tunneling), which may require the // socket's streams to be wrapped in other streams. InputStream inputStream; OutputStream outputStream; /** * Called after client creates a connection to server * or after server accepts an incoming connection. * @param host The remote host pointed to by this connection. * @param port The remote port used by this connection. */ public IIOPConnection(ORB orb, ServerGIOP server, ConnectionTable ctab, EndPoint ep) { this.orb = orb; this.server = server; this.connectionTable = ctab; this.endpoint = ep; this.codeBaseServerIOR = null; String host = endpoint.getHostName(); int port = endpoint.getPort(); threadName = "JavaIDL Reader for " + host + ":" + port; mediator = new MessageMediator(this); // Only do the next two because we're a client clientReplyMap = new HashMap(); out_calls = new Hashtable(); // Both client and servers. idToFragmentedOutputStream = new Hashtable(); final ThreadGroup finalThreadGroup = orb.threadGroup; final String finalThreadName = threadName; final IIOPConnection finalThis = this; final boolean finalTransportDebugFlag = orb.transportDebugFlag; try { AccessController.doPrivileged(new PrivilegedAction() { public java.lang.Object run() { reader = new ReaderThread(finalThreadGroup, finalThis, finalThreadName, finalTransportDebugFlag); return null; } }); } catch (SecurityException e) { // // For some reason we're not allowed to create a new thread // in the same thread group that the ORB was initialized in. // Fall back on creating the thread in the calling thread's // group. // AccessController.doPrivileged(new PrivilegedAction() { public java.lang.Object run() { reader = new ReaderThread(finalThis, finalThreadName, finalTransportDebugFlag); return null; } }); } synchronized ( stateEvent ){ state = OPENING; } } /** * Called only from ConnectionTable.get() after server accepts an * incoming connection. * @param sock The socket for this connection. * @param inputStream The inputstream to use. It may be different * from a socket's inputstream. * @param outputStream The outputstream to use. It may be different * from a socket's outputstream. */ public IIOPConnection(ORB orb, ServerGIOP server, EndPoint ep, Socket sock, InputStream inputStream, OutputStream outputStream, ConnectionTable ct) { this(orb, server, ct, ep); mediator = new MessageMediator(this); this.socket = sock; this.inputStream = inputStream; this.outputStream = outputStream; this.connectionTable = ct; isServer = true; // Only create the serverRequestMap for servers serverRequestMap = Collections.synchronizedMap(new HashMap()); // Both client and servers. idToFragmentedOutputStream = new Hashtable(); state = ESTABLISHED; // Catch exceptions since setDaemon can cause a // security exception to be thrown under netscape // in the Applet mode try { AccessController.doPrivileged(new PrivilegedAction() { public java.lang.Object run() { reader.setDaemon(true); return null; } }); } catch (Exception e) {} reader.start(); } public synchronized boolean isPostInitialContexts() { return postInitialContexts; } // Can never be unset... public synchronized void setPostInitialContexts(){ postInitialContexts = true; } public java.io.InputStream getInputStream() { return inputStream; } public ServerGIOP getServerGIOP() { return server; } String getHost() { return endpoint.getHostName(); } int getPort() { return endpoint.getPort(); } EndPoint getEndpoint() { return endpoint; } /** * Read in the IIOP message from the network's InputStream and * create an IIOPInputStream object. * Called from ReaderThread only. * * The protocol of use by ReaderThread has been changed * so that non-null return values are not expected * for Fragment message types. * */ public final void processInput() throws Exception
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?