KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > transport > CorbaContactInfoBase


1 /*
2  * @(#)CorbaContactInfoBase.java 1.14 04/06/21
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.transport;
9
10 import java.io.InputStream JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.nio.ByteBuffer JavaDoc;
13
14 import org.omg.CORBA.INTERNAL JavaDoc;
15
16 import com.sun.corba.se.pept.broker.Broker;
17 import com.sun.corba.se.pept.encoding.InputObject;
18 import com.sun.corba.se.pept.encoding.OutputObject;
19 import com.sun.corba.se.pept.protocol.ClientRequestDispatcher;
20 import com.sun.corba.se.pept.protocol.MessageMediator;
21 import com.sun.corba.se.pept.transport.ByteBufferPool;
22 import com.sun.corba.se.pept.transport.ContactInfo;
23 import com.sun.corba.se.pept.transport.ContactInfoList;
24 import com.sun.corba.se.pept.transport.Connection;
25 import com.sun.corba.se.pept.transport.EventHandler;
26 import com.sun.corba.se.pept.transport.OutboundConnectionCache;
27
28 import com.sun.corba.se.spi.orb.ORB;
29 import com.sun.corba.se.spi.ior.IOR;
30 import com.sun.corba.se.spi.ior.ObjectKeyTemplate;
31 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
32 import com.sun.corba.se.spi.ior.iiop.IIOPAddress ;
33 import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate;
34 import com.sun.corba.se.spi.ior.iiop.IIOPProfile;
35 import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
36 import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry;
37 import com.sun.corba.se.spi.transport.CorbaConnection;
38 import com.sun.corba.se.spi.transport.CorbaContactInfoList;
39 import com.sun.corba.se.spi.transport.CorbaContactInfo;
40
41 import com.sun.corba.se.impl.encoding.ByteBufferWithInfo;
42 import com.sun.corba.se.impl.encoding.CDRInputObject;
43 import com.sun.corba.se.impl.encoding.CDRInputStream_1_0;
44 import com.sun.corba.se.impl.encoding.CDROutputObject;
45 import com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl;
46 import com.sun.corba.se.impl.protocol.giopmsgheaders.KeyAddr;
47 import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
48 import com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase;
49 import com.sun.corba.se.impl.orbutil.ORBUtility;
50
51 /**
52  * @author Harold Carr
53  */

54 public abstract class CorbaContactInfoBase
55     implements
56     CorbaContactInfo
57 {
58     protected ORB orb;
59     protected CorbaContactInfoList contactInfoList;
60     // NOTE: This may be different from same named one in CorbaContactInfoList.
61
protected IOR effectiveTargetIOR;
62     protected short addressingDisposition;
63     protected OutboundConnectionCache connectionCache;
64
65     ////////////////////////////////////////////////////
66
//
67
// pept.transport.ContactInfo
68
//
69

70     public Broker getBroker()
71     {
72     return orb;
73     }
74
75     public ContactInfoList getContactInfoList()
76     {
77     return contactInfoList;
78     }
79
80     public ClientRequestDispatcher getClientRequestDispatcher()
81     {
82     int scid =
83         getEffectiveProfile().getObjectKeyTemplate().getSubcontractId() ;
84     RequestDispatcherRegistry scr = orb.getRequestDispatcherRegistry() ;
85     return scr.getClientRequestDispatcher( scid ) ;
86     }
87
88     // Note: not all derived classes will use a connection cache.
89
// These are convenience methods that may not be used.
90
public void setConnectionCache(OutboundConnectionCache connectionCache)
91     {
92     this.connectionCache = connectionCache;
93     }
94
95     public OutboundConnectionCache getConnectionCache()
96     {
97     return connectionCache;
98     }
99
100     // Called when client making an invocation.
101
public MessageMediator createMessageMediator(Broker broker,
102                          ContactInfo contactInfo,
103                          Connection connection,
104                          String JavaDoc methodName,
105                          boolean isOneWay)
106     {
107     // REVISIT: Would like version, ior, requestid, etc., decisions
108
// to be in client subcontract. Cannot pass these to this
109
// factory method because it breaks generic abstraction.
110
// Maybe set methods on mediator called from subcontract
111
// after creation?
112
CorbaMessageMediator messageMediator =
113         new CorbaMessageMediatorImpl(
114             (ORB) broker,
115         contactInfo,
116         connection,
117         GIOPVersion.chooseRequestVersion( (ORB)broker,
118              effectiveTargetIOR),
119         effectiveTargetIOR,
120         ((CorbaConnection)connection).getNextRequestId(),
121         getAddressingDisposition(),
122         methodName,
123         isOneWay);
124
125     return messageMediator;
126     }
127
128     // Called when connection handling a read event.
129
public MessageMediator createMessageMediator(Broker broker,Connection conn)
130     {
131     ORB orb = (ORB) broker;
132     CorbaConnection connection = (CorbaConnection) conn;
133
134         if (orb.transportDebugFlag) {
135         if (connection.shouldReadGiopHeaderOnly()) {
136         dprint(
137         ".createMessageMediator: waiting for message header on connection: "
138         + connection);
139         } else {
140         dprint(
141         ".createMessageMediator: waiting for message on connection: "
142         + connection);
143         }
144     }
145
146     Message msg = null;
147
148     if (connection.shouldReadGiopHeaderOnly()) {
149         // read giop header only
150
msg = MessageBase.readGIOPHeader(orb, connection);
151     } else {
152         // read entire giop message
153
msg = MessageBase.readGIOPMessage(orb, connection);
154     }
155
156     ByteBuffer JavaDoc byteBuffer = msg.getByteBuffer();
157     msg.setByteBuffer(null);
158     CorbaMessageMediator messageMediator =
159         new CorbaMessageMediatorImpl(orb, connection, msg, byteBuffer);
160
161     return messageMediator;
162     }
163
164     // Called when connection reading message body
165
public MessageMediator finishCreatingMessageMediator(Broker broker,
166                                Connection conn, MessageMediator messageMediator)
167     {
168     ORB orb = (ORB) broker;
169     CorbaConnection connection = (CorbaConnection) conn;
170     CorbaMessageMediator corbaMessageMediator =
171                   (CorbaMessageMediator)messageMediator;
172
173         if (orb.transportDebugFlag) {
174         dprint(
175         ".finishCreatingMessageMediator: waiting for message body on connection: "
176         + connection);
177     }
178
179     Message msg = corbaMessageMediator.getDispatchHeader();
180     msg.setByteBuffer(corbaMessageMediator.getDispatchBuffer());
181
182     // read giop body only
183
msg = MessageBase.readGIOPBody(orb, connection, msg);
184
185     ByteBuffer JavaDoc byteBuffer = msg.getByteBuffer();
186     msg.setByteBuffer(null);
187     corbaMessageMediator.setDispatchHeader(msg);
188     corbaMessageMediator.setDispatchBuffer(byteBuffer);
189
190     return corbaMessageMediator;
191     }
192
193     public OutputObject createOutputObject(MessageMediator messageMediator)
194     {
195     CorbaMessageMediator corbaMessageMediator = (CorbaMessageMediator)
196         messageMediator;
197     
198     OutputObject outputObject =
199         new CDROutputObject(orb, messageMediator,
200                 corbaMessageMediator.getRequestHeader(),
201                 corbaMessageMediator.getStreamFormatVersion());
202
203     messageMediator.setOutputObject(outputObject);
204     return outputObject;
205     }
206
207     public InputObject createInputObject(Broker broker,
208                      MessageMediator messageMediator)
209     {
210     // REVISIT: Duplicate of acceptor code.
211
CorbaMessageMediator corbaMessageMediator = (CorbaMessageMediator)
212         messageMediator;
213     return new CDRInputObject((ORB)broker,
214                   (CorbaConnection)messageMediator.getConnection(),
215                   corbaMessageMediator.getDispatchBuffer(),
216                   corbaMessageMediator.getDispatchHeader());
217     }
218
219     ////////////////////////////////////////////////////
220
//
221
// spi.transport.CorbaContactInfo
222
//
223

224     public short getAddressingDisposition()
225     {
226     return addressingDisposition;
227     }
228
229     public void setAddressingDisposition(short addressingDisposition)
230     {
231         this.addressingDisposition = addressingDisposition;
232     }
233
234     // REVISIT - remove this.
235
public IOR getTargetIOR()
236     {
237     return contactInfoList.getTargetIOR();
238     }
239
240     public IOR getEffectiveTargetIOR()
241     {
242     return effectiveTargetIOR ;
243     }
244
245     public IIOPProfile getEffectiveProfile()
246     {
247     return effectiveTargetIOR.getProfile();
248     }
249
250     ////////////////////////////////////////////////////
251
//
252
// java.lang.Object
253
//
254

255     public String JavaDoc toString()
256     {
257     return
258         "CorbaContactInfoBase["
259         + "]";
260     }
261
262
263     ////////////////////////////////////////////////////
264
//
265
// Implementation
266
//
267

268     protected void dprint(String JavaDoc msg)
269     {
270     ORBUtility.dprint("CorbaContactInfoBase", msg);
271     }
272 }
273
274 // End of file.
275
Popular Tags