KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)SocketOrChannelContactInfoImpl.java 1.59 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 com.sun.corba.se.pept.transport.Connection;
11
12 import com.sun.corba.se.spi.ior.IOR ;
13 import com.sun.corba.se.spi.orb.ORB;
14 import com.sun.corba.se.spi.transport.CorbaContactInfoList;
15 import com.sun.corba.se.spi.transport.CorbaTransportManager;
16 import com.sun.corba.se.spi.transport.SocketInfo;
17
18 import com.sun.corba.se.impl.orbutil.ORBUtility;
19 import com.sun.corba.se.impl.transport.CorbaContactInfoBase;
20
21 /**
22  * @author Harold Carr
23  */

24 public class SocketOrChannelContactInfoImpl
25     extends CorbaContactInfoBase
26     implements SocketInfo
27 {
28     protected boolean isHashCodeCached = false;
29     protected int cachedHashCode;
30
31     protected String JavaDoc socketType;
32     protected String JavaDoc hostname;
33     protected int port;
34
35     // XREVISIT
36
// See SocketOrChannelAcceptorImpl.createMessageMediator
37
// See SocketFactoryContactInfoImpl.constructor()
38
// See SocketOrChannelContactInfoImpl.constructor()
39
protected SocketOrChannelContactInfoImpl()
40     {
41     }
42
43     protected SocketOrChannelContactInfoImpl(
44         ORB orb,
45     CorbaContactInfoList contactInfoList)
46     {
47     this.orb = orb;
48     this.contactInfoList = contactInfoList;
49     }
50
51     public SocketOrChannelContactInfoImpl(
52         ORB orb,
53     CorbaContactInfoList contactInfoList,
54     String JavaDoc socketType,
55     String JavaDoc hostname,
56     int port)
57     {
58     this(orb, contactInfoList);
59     this.socketType = socketType;
60     this.hostname = hostname;
61     this.port = port;
62     }
63
64     // XREVISIT
65
public SocketOrChannelContactInfoImpl(
66         ORB orb,
67     CorbaContactInfoList contactInfoList,
68     IOR effectiveTargetIOR,
69     short addressingDisposition,
70     String JavaDoc socketType,
71     String JavaDoc hostname,
72     int port)
73     {
74     this(orb, contactInfoList, socketType, hostname, port);
75     this.effectiveTargetIOR = effectiveTargetIOR;
76     this.addressingDisposition = addressingDisposition;
77     }
78
79     ////////////////////////////////////////////////////
80
//
81
// pept.transport.ContactInfo
82
//
83

84     public boolean isConnectionBased()
85     {
86     return true;
87     }
88
89     public boolean shouldCacheConnection()
90     {
91     return true;
92     }
93
94     public String JavaDoc getConnectionCacheType()
95     {
96     return CorbaTransportManager.SOCKET_OR_CHANNEL_CONNECTION_CACHE;
97     }
98
99     public Connection createConnection()
100     {
101     Connection connection =
102         new SocketOrChannelConnectionImpl(orb, this,
103                           socketType, hostname, port);
104     return connection;
105     }
106
107     ////////////////////////////////////////////////////
108
//
109
// spi.transport.CorbaContactInfo
110
//
111

112     public String JavaDoc getMonitoringName()
113     {
114     return "SocketConnections";
115     }
116
117     ////////////////////////////////////////////////////
118
//
119
// pept.transport.ContactInfo
120
//
121

122     public String JavaDoc getType()
123     {
124     return socketType;
125     }
126
127     public String JavaDoc getHost()
128     {
129     return hostname;
130     }
131
132     public int getPort()
133     {
134     return port;
135     }
136
137     ////////////////////////////////////////////////////
138
//
139
// java.lang.Object
140
//
141

142     public int hashCode()
143     {
144     if (! isHashCodeCached) {
145         cachedHashCode = socketType.hashCode() ^ hostname.hashCode() ^ port;
146         isHashCodeCached = true;
147     }
148     return cachedHashCode;
149     }
150     
151     public boolean equals(Object JavaDoc obj)
152     {
153     if (obj == null) {
154         return false;
155     } else if (!(obj instanceof SocketOrChannelContactInfoImpl)) {
156         return false;
157     }
158
159     SocketOrChannelContactInfoImpl other =
160         (SocketOrChannelContactInfoImpl) obj;
161
162         if (port != other.port) {
163             return false;
164     }
165         if (!hostname.equals(other.hostname)) {
166             return false;
167         }
168     if (socketType == null) {
169         if (other.socketType != null) {
170         return false;
171         }
172     } else if (!socketType.equals(other.socketType)) {
173         return false;
174     }
175         return true;
176     }
177
178     public String JavaDoc toString()
179     {
180     return
181         "SocketOrChannelContactInfoImpl["
182         + socketType + " "
183         + hostname + " "
184         + port
185         + "]";
186     }
187
188     ////////////////////////////////////////////////////
189
//
190
// Implementation
191
//
192

193     protected void dprint(String JavaDoc msg)
194     {
195     ORBUtility.dprint("SocketOrChannelContactInfoImpl", msg);
196     }
197 }
198
199 // End of file.
200
Popular Tags