corba/src/share/classes/com/sun/corba/se/impl/transport/BufferConnectionImpl.sjava
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 4 02bb8761fcce
child 5555 b2b5ed3f0d0d
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
02bb8761fcce Initial load
duke
parents:
diff changeset
     2
 * Copyright 2004 Sun Microsystems, Inc.  All Rights Reserved.
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
02bb8761fcce Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
02bb8761fcce Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
02bb8761fcce Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
02bb8761fcce Initial load
duke
parents:
diff changeset
    23
 * have any questions.
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
package com.sun.corba.se.impl.transport;
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
import java.net.InetSocketAddress;
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
import java.net.Socket;
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
import java.nio.ByteBuffer;
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
import java.nio.channels.SelectableChannel;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
import java.nio.channels.SelectionKey;
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import java.nio.channels.SocketChannel;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import java.security.AccessController;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import java.security.PrivilegedAction;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import java.util.Collections;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import java.util.Hashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import java.util.HashMap;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import java.util.Map;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import org.omg.CORBA.COMM_FAILURE;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import org.omg.CORBA.CompletionStatus;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import org.omg.CORBA.DATA_CONVERSION;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import org.omg.CORBA.INTERNAL;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import org.omg.CORBA.MARSHAL;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import org.omg.CORBA.OBJECT_NOT_EXIST;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import org.omg.CORBA.SystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
import com.sun.org.omg.SendingContext.CodeBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
import com.sun.corba.se.pept.broker.Broker;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
import com.sun.corba.se.pept.encoding.InputObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
import com.sun.corba.se.pept.encoding.OutputObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
import com.sun.corba.se.pept.protocol.MessageMediator;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
import com.sun.corba.se.pept.transport.Acceptor;
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
import com.sun.corba.se.pept.transport.Connection;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
import com.sun.corba.se.pept.transport.ConnectionCache;
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
import com.sun.corba.se.pept.transport.ContactInfo;
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
import com.sun.corba.se.pept.transport.EventHandler;
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
import com.sun.corba.se.pept.transport.InboundConnectionCache;
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
import com.sun.corba.se.pept.transport.OutboundConnectionCache;
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
import com.sun.corba.se.pept.transport.ResponseWaitingRoom;
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
import com.sun.corba.se.pept.transport.Selector;
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
import com.sun.corba.se.spi.ior.IOR;
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
import com.sun.corba.se.spi.logging.CORBALogDomains;
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
import com.sun.corba.se.spi.orb.ORB ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
import com.sun.corba.se.spi.orbutil.threadpool.Work;
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
import com.sun.corba.se.spi.transport.CorbaContactInfo;
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
import com.sun.corba.se.spi.transport.CorbaConnection;
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
import com.sun.corba.se.spi.transport.CorbaResponseWaitingRoom;
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
import com.sun.corba.se.impl.encoding.CachedCodeBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
import com.sun.corba.se.impl.encoding.CDRInputStream_1_0;
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
import com.sun.corba.se.impl.encoding.CDROutputObject;
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
import com.sun.corba.se.impl.encoding.CDROutputStream_1_0;
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
import com.sun.corba.se.impl.encoding.CodeSetComponentInfo;
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry;
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
import com.sun.corba.se.impl.logging.ORBUtilSystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
import com.sun.corba.se.impl.orbutil.ORBConstants;
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
import com.sun.corba.se.impl.orbutil.ORBUtility;
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
import com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
import com.sun.corba.se.impl.transport.CorbaResponseWaitingRoomImpl;
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
 * @author Ken Cavanaugh
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
public class BufferConnectionImpl
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
    extends
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
	EventHandlerBase
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
    implements
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
        CorbaConnection,
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
	Work
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
    // New transport.
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
    protected long enqueueTime;
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
    public SocketChannel getSocketChannel()
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
	return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
    // REVISIT:
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
    // protected for test: genericRPCMSGFramework.IIOPConnection constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
    // From iiop.Connection.java
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
    protected long timeStamp = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
    protected boolean isServer = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
    // Start at some value other than zero since this is a magic
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
    // value in some protocols.
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
    protected int requestId = 5;
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
    protected CorbaResponseWaitingRoom responseWaitingRoom;
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
    protected int state;
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
    protected java.lang.Object stateEvent = new java.lang.Object();
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
    protected java.lang.Object writeEvent = new java.lang.Object();
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
    protected boolean writeLocked;
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
    protected int serverRequestCount = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
    
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
    // Server request map: used on the server side of Connection
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
    // Maps request ID to IIOPInputStream.
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
    Map serverRequestMap = new HashMap() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
    // This is a flag associated per connection telling us if the
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
    // initial set of sending contexts were sent to the receiver
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
    // already...
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
    protected boolean postInitialContexts = false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
 
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
    // Remote reference to CodeBase server (supplies
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
    // FullValueDescription, among other things)
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
    protected IOR codeBaseServerIOR;
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
    // CodeBase cache for this connection.  This will cache remote operations,
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
    // handle connecting, and ensure we don't do any remote operations until
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
    // necessary.
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
    protected CachedCodeBase cachedCodeBase = new CachedCodeBase(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
    protected ORBUtilSystemException wrapper ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
    List buffers ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
    public BufferConnectionImpl(ORB orb, byte[][] data )
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
	this.orb = orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
	wrapper = ORBUtilSystemException.get( orb,
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
	    CORBALogDomains.RPC_TRANSPORT ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
	buffers = new ArrayList() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
    ////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
    // framework.transport.Connection
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
    public boolean shouldRegisterReadEvent()
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
	return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
    public boolean shouldRegisterServerReadEvent()
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
	return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
    public boolean read()
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
	return true ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
    protected CorbaMessageMediator readBits()
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
	return null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
    protected boolean dispatch(CorbaMessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
    public boolean shouldUseDirectByteBuffers()
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
	return false ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
    // Only called from readGIOPMessage with (12, 0, 12) as arguments
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
    // size is size of buffer to create
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
    // offset is offset from start of message in buffer
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
    // length is length to read
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
    public ByteBuffer read(int size, int offset, int length)
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
	throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
	byte[] buf = new byte[size];
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
	readFully( buf, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
	ByteBuffer byteBuffer = ByteBuffer.wrap(buf);
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
	byteBuffer.limit(size);
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
	return byteBuffer;
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
    // Only called as read( buf, 12, msgsize-12 ) in readGIOPMessage
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
    // We can ignore the byteBuffer parameter
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
    // offset is the starting position to place data in the result
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
    // length is the length of the data to read
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
    public ByteBuffer read(ByteBuffer byteBuffer, int offset, int length)
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
	throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
	int size = offset + length;
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
	byte[] buf = new byte[size];
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
	readFully(buf, offset, length);
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
	return ByteBuffer.wrap(buf);
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
    // Read size bytes from buffer list and place the data
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
    // starting at offset in buf.
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
    public void readFully(byte[] buf, int offset, int size) 
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
	throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
	int remaining = size ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
	int position = offset ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
	while (remaining > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
	    ByteBuffer buff = (ByteBuffer)buffers.get(0) ; 
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
	    int dataSize = buff.remaining() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
	    int xferSize = dataSize ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
	    if (dataSize >= remaining) :
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
		xferSize = remaining ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
		buffers.remove(0) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
	    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
	    
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
	    buff.get( buf, offset, xferSize ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
	    offset += xferSize ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
	    remaining -= xferSize ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
	}
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
    }    
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
    public void write(ByteBuffer byteBuffer)
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
	throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
	buffers.add( byteBuffer ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
     * Note:it is possible for this to be called more than once
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
    public synchronized void close() 
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
    public Acceptor getAcceptor()
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
	return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
    public ContactInfo getContactInfo()
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
	return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
    public EventHandler getEventHandler()
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
	return this;
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
    public OutputObject createOutputObject(MessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
	// REVISIT - remove this method from Connection and all it subclasses.
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
	throw new RuntimeException("*****SocketOrChannelConnectionImpl.createOutputObject - should not be called.");
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
    // This is used by the GIOPOutputObject in order to
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
    // throw the correct error when handling code sets.
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
    // Can we determine if we are on the server side by
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
    // other means?  XREVISIT
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
    public boolean isServer()
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
        return isServer;
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
    public boolean isBusy()
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
	return false ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
    public long getTimeStamp()
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
	return timeStamp;
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
    public void setTimeStamp(long time)
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
	timeStamp = time;
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
    public void setState(String stateString)
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
	synchronized (stateEvent) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
	    if (stateString.equals("ESTABLISHED")) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
		state =  ESTABLISHED;
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
		stateEvent.notifyAll();
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
	    } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
		// REVISIT: ASSERT
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
	    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
	}
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
    public void writeLock()
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
    public void writeUnlock()
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
    public void sendWithoutLock(OutputObject outputObject)
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
    public void registerWaiter(MessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
    public void unregisterWaiter(MessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
    public InputObject waitForResponse(MessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
	return null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
    public void setConnectionCache(ConnectionCache connectionCache)
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
    public ConnectionCache getConnectionCache()
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
	return null;	
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
    ////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
    // EventHandler methods
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
    public SelectableChannel getChannel()
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
	return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
    public int getInterestOps()
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
	return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
    //    public Acceptor getAcceptor() - already defined above.
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
    public Connection getConnection()
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
	return this;
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
    ////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
    // Work methods.
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
    public String getName()
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
	return this.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
    public void doWork()
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
    public void setEnqueueTime(long timeInMillis)
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
	enqueueTime = timeInMillis;
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
    public long getEnqueueTime()
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
	return enqueueTime;
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
    ////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
    // spi.transport.CorbaConnection.
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
    public ResponseWaitingRoom getResponseWaitingRoom()
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
	return null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
    // REVISIT - inteface defines isServer but already defined in 
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
    // higher interface.
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
    public void serverRequestMapPut(int requestId, 
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
				    CorbaMessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
	serverRequestMap.put(new Integer(requestId), messageMediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
    public CorbaMessageMediator serverRequestMapGet(int requestId)
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
	return (CorbaMessageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
	    serverRequestMap.get(new Integer(requestId));
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
    public void serverRequestMapRemove(int requestId)
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   422
	serverRequestMap.remove(new Integer(requestId));
02bb8761fcce Initial load
duke
parents:
diff changeset
   423
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   424
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
    // REVISIT: this is also defined in:
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
    // com.sun.corba.se.spi.legacy.connection.Connection
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
    public java.net.Socket getSocket()
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
	return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
    /** It is possible for a Close Connection to have been
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
     ** sent here, but we will not check for this. A "lazy"
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
     ** Exception will be thrown in the Worker thread after the
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
     ** incoming request has been processed even though the connection
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
     ** is closed before the request is processed. This is o.k because
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
     ** it is a boundary condition. To prevent it we would have to add
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
     ** more locks which would reduce performance in the normal case.
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
     **/
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
    public synchronized void serverRequestProcessingBegins()
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
        serverRequestCount++;
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
    public synchronized void serverRequestProcessingEnds()
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
        serverRequestCount--;
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
    public synchronized int getNextRequestId() 
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
	return requestId++;
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
    // Negotiated code sets for char and wchar data
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
    protected CodeSetComponentInfo.CodeSetContext codeSetContext = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
    public ORB getBroker() 
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
        return orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
    public CodeSetComponentInfo.CodeSetContext getCodeSetContext() 
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
        // Needs to be synchronized for the following case when the client
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
        // doesn't send the code set context twice, and we have two threads
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
        // in ServerRequestDispatcher processCodeSetContext.
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
        //
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
        // Thread A checks to see if there is a context, there is none, so
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
        //     it calls setCodeSetContext, getting the synch lock.
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
        // Thread B checks to see if there is a context.  If we didn't synch,
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
        //     it might decide to outlaw wchar/wstring.
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
        if (codeSetContext == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
            synchronized(this) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
                return codeSetContext;
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
        return codeSetContext;
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
    public synchronized void setCodeSetContext(CodeSetComponentInfo.CodeSetContext csc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
        // Double check whether or not we need to do this
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
        if (codeSetContext == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
            
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
            if (OSFCodeSetRegistry.lookupEntry(csc.getCharCodeSet()) == null ||
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
                OSFCodeSetRegistry.lookupEntry(csc.getWCharCodeSet()) == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
                // If the client says it's negotiated a code set that
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
                // isn't a fallback and we never said we support, then
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
                // it has a bug.
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
		throw wrapper.badCodesetsFromClient() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
            codeSetContext = csc;
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
    // from iiop.IIOPConnection.java
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
    // Map request ID to an InputObject.
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
    // This is so the client thread can start unmarshaling
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
    // the reply and remove it from the out_calls map while the
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
    // ReaderThread can still obtain the input stream to give
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
    // new fragments.  Only the ReaderThread touches the clientReplyMap,
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
    // so it doesn't incur synchronization overhead.
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
    public MessageMediator clientRequestMapGet(int requestId)
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
	return null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
    protected MessageMediator clientReply_1_1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
    public void clientReply_1_1_Put(MessageMediator x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
	clientReply_1_1 = x;
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
    public MessageMediator clientReply_1_1_Get()
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
	return 	clientReply_1_1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
    public void clientReply_1_1_Remove()
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
	clientReply_1_1 = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
    protected MessageMediator serverRequest_1_1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
    public void serverRequest_1_1_Put(MessageMediator x)
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
	serverRequest_1_1 = x;
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
    public MessageMediator serverRequest_1_1_Get()
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
	return 	serverRequest_1_1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
    public void serverRequest_1_1_Remove()
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
	serverRequest_1_1 = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
    protected String getStateString( int state ) 
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
        synchronized ( stateEvent ){
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
            switch (state) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
            case OPENING : return "OPENING" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
            case ESTABLISHED : return "ESTABLISHED" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
            case CLOSE_SENT : return "CLOSE_SENT" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
            case CLOSE_RECVD : return "CLOSE_RECVD" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
            case ABORT : return "ABORT" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
            default : return "???" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
    
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
    public synchronized boolean isPostInitialContexts() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
        return postInitialContexts;
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
    // Can never be unset...
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
    public synchronized void setPostInitialContexts(){
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
        postInitialContexts = true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
    
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
     * Wake up the outstanding requests on the connection, and hand them
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
     * COMM_FAILURE exception with a given minor code.
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
     * Also, delete connection from connection table and
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
     * stop the reader thread.
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
     * Note that this should only ever be called by the Reader thread for
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
     * this connection.
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
     * 
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
     * @param minor_code The minor code for the COMM_FAILURE major code.
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
     * @param die Kill the reader thread (this thread) before exiting.
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
    public void purgeCalls(SystemException systemException,
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
			   boolean die, boolean lockHeld)
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
    /*************************************************************************
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
    * The following methods are for dealing with Connection cleaning for
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
    * better scalability of servers in high network load conditions.
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
    **************************************************************************/
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
    public void sendCloseConnection(GIOPVersion giopVersion)
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
	throws IOException 
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
        Message msg = MessageBase.createCloseConnection(giopVersion);
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
	sendHelper(giopVersion, msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
    public void sendMessageError(GIOPVersion giopVersion)
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
	throws IOException 
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
        Message msg = MessageBase.createMessageError(giopVersion);
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
	sendHelper(giopVersion, msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
     * Send a CancelRequest message. This does not lock the connection, so the
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
     * caller needs to ensure this method is called appropriately.
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
     * @exception IOException - could be due to abortive connection closure.
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
    public void sendCancelRequest(GIOPVersion giopVersion, int requestId)
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
	throws IOException 
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
        Message msg = MessageBase.createCancelRequest(giopVersion, requestId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
	sendHelper(giopVersion, msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
    protected void sendHelper(GIOPVersion giopVersion, Message msg)
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
	throws IOException
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
	// REVISIT: See comments in CDROutputObject constructor.
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
        CDROutputObject outputObject = 
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
	    new CDROutputObject((ORB)orb, null, giopVersion, this, msg,
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
				ORBConstants.STREAM_FORMAT_VERSION_1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
        msg.write(outputObject);
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
	outputObject.writeTo(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
    public void sendCancelRequestWithLock(GIOPVersion giopVersion,
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
					  int requestId)
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
	throws IOException 
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
	writeLock();
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
	try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
	    sendCancelRequest(giopVersion, requestId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
	} finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   646
	    writeUnlock();
02bb8761fcce Initial load
duke
parents:
diff changeset
   647
	}
02bb8761fcce Initial load
duke
parents:
diff changeset
   648
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   649
02bb8761fcce Initial load
duke
parents:
diff changeset
   650
    // Begin Code Base methods ---------------------------------------
02bb8761fcce Initial load
duke
parents:
diff changeset
   651
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   652
    // Set this connection's code base IOR.  The IOR comes from the
02bb8761fcce Initial load
duke
parents:
diff changeset
   653
    // SendingContext.  This is an optional service context, but all
02bb8761fcce Initial load
duke
parents:
diff changeset
   654
    // JavaSoft ORBs send it.
02bb8761fcce Initial load
duke
parents:
diff changeset
   655
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   656
    // The set and get methods don't need to be synchronized since the
02bb8761fcce Initial load
duke
parents:
diff changeset
   657
    // first possible get would occur during reading a valuetype, and
02bb8761fcce Initial load
duke
parents:
diff changeset
   658
    // that would be after the set.
02bb8761fcce Initial load
duke
parents:
diff changeset
   659
02bb8761fcce Initial load
duke
parents:
diff changeset
   660
    // Sets this connection's code base IOR.  This is done after
02bb8761fcce Initial load
duke
parents:
diff changeset
   661
    // getting the IOR out of the SendingContext service context.
02bb8761fcce Initial load
duke
parents:
diff changeset
   662
    // Our ORBs always send this, but it's optional in CORBA.
02bb8761fcce Initial load
duke
parents:
diff changeset
   663
02bb8761fcce Initial load
duke
parents:
diff changeset
   664
    public final void setCodeBaseIOR(IOR ior) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   665
        codeBaseServerIOR = ior;
02bb8761fcce Initial load
duke
parents:
diff changeset
   666
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   667
02bb8761fcce Initial load
duke
parents:
diff changeset
   668
    public final IOR getCodeBaseIOR() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   669
        return codeBaseServerIOR;
02bb8761fcce Initial load
duke
parents:
diff changeset
   670
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   671
02bb8761fcce Initial load
duke
parents:
diff changeset
   672
    // Get a CodeBase stub to use in unmarshaling.  The CachedCodeBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   673
    // won't connect to the remote codebase unless it's necessary.
02bb8761fcce Initial load
duke
parents:
diff changeset
   674
    public final CodeBase getCodeBase() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   675
        return cachedCodeBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
   676
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   677
02bb8761fcce Initial load
duke
parents:
diff changeset
   678
    // End Code Base methods -----------------------------------------
02bb8761fcce Initial load
duke
parents:
diff changeset
   679
02bb8761fcce Initial load
duke
parents:
diff changeset
   680
    // Can be overridden in subclass for different options.
02bb8761fcce Initial load
duke
parents:
diff changeset
   681
    protected void setSocketOptions(Socket socket)
02bb8761fcce Initial load
duke
parents:
diff changeset
   682
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   683
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   684
02bb8761fcce Initial load
duke
parents:
diff changeset
   685
    public String toString()
02bb8761fcce Initial load
duke
parents:
diff changeset
   686
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   687
        synchronized ( stateEvent ){
02bb8761fcce Initial load
duke
parents:
diff changeset
   688
            return 
02bb8761fcce Initial load
duke
parents:
diff changeset
   689
		"BufferConnectionImpl[" + " "
02bb8761fcce Initial load
duke
parents:
diff changeset
   690
		+ getStateString( state ) + " "
02bb8761fcce Initial load
duke
parents:
diff changeset
   691
		+ shouldUseSelectThreadToWait() + " "
02bb8761fcce Initial load
duke
parents:
diff changeset
   692
		+ shouldUseWorkerThreadForEvent()
02bb8761fcce Initial load
duke
parents:
diff changeset
   693
		+ "]" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   694
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   695
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   696
    
02bb8761fcce Initial load
duke
parents:
diff changeset
   697
    // Must be public - used in encoding.
02bb8761fcce Initial load
duke
parents:
diff changeset
   698
    public void dprint(String msg) 
02bb8761fcce Initial load
duke
parents:
diff changeset
   699
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   700
	ORBUtility.dprint("SocketOrChannelConnectionImpl", msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   701
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   702
02bb8761fcce Initial load
duke
parents:
diff changeset
   703
    protected void dprint(String msg, Throwable t)
02bb8761fcce Initial load
duke
parents:
diff changeset
   704
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   705
	dprint(msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   706
	t.printStackTrace(System.out);
02bb8761fcce Initial load
duke
parents:
diff changeset
   707
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   708
}
02bb8761fcce Initial load
duke
parents:
diff changeset
   709
02bb8761fcce Initial load
duke
parents:
diff changeset
   710
// End of file.