SocketOrChannelContactInfoImpl.java revision 608:7e06bf1dcb09
1/* 2 * Copyright (c) 2002, 2004, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26package com.sun.corba.se.impl.transport; 27 28import com.sun.corba.se.pept.transport.Connection; 29 30import com.sun.corba.se.spi.ior.IOR ; 31import com.sun.corba.se.spi.orb.ORB; 32import com.sun.corba.se.spi.transport.CorbaContactInfoList; 33import com.sun.corba.se.spi.transport.CorbaTransportManager; 34import com.sun.corba.se.spi.transport.SocketInfo; 35 36import com.sun.corba.se.impl.orbutil.ORBUtility; 37import com.sun.corba.se.impl.transport.CorbaContactInfoBase; 38 39/** 40 * @author Harold Carr 41 */ 42public class SocketOrChannelContactInfoImpl 43 extends CorbaContactInfoBase 44 implements SocketInfo 45{ 46 protected boolean isHashCodeCached = false; 47 protected int cachedHashCode; 48 49 protected String socketType; 50 protected String hostname; 51 protected int port; 52 53 // XREVISIT 54 // See SocketOrChannelAcceptorImpl.createMessageMediator 55 // See SocketFactoryContactInfoImpl.constructor() 56 // See SocketOrChannelContactInfoImpl.constructor() 57 protected SocketOrChannelContactInfoImpl() 58 { 59 } 60 61 protected SocketOrChannelContactInfoImpl( 62 ORB orb, 63 CorbaContactInfoList contactInfoList) 64 { 65 this.orb = orb; 66 this.contactInfoList = contactInfoList; 67 } 68 69 public SocketOrChannelContactInfoImpl( 70 ORB orb, 71 CorbaContactInfoList contactInfoList, 72 String socketType, 73 String hostname, 74 int port) 75 { 76 this(orb, contactInfoList); 77 this.socketType = socketType; 78 this.hostname = hostname; 79 this.port = port; 80 } 81 82 // XREVISIT 83 public SocketOrChannelContactInfoImpl( 84 ORB orb, 85 CorbaContactInfoList contactInfoList, 86 IOR effectiveTargetIOR, 87 short addressingDisposition, 88 String socketType, 89 String hostname, 90 int port) 91 { 92 this(orb, contactInfoList, socketType, hostname, port); 93 this.effectiveTargetIOR = effectiveTargetIOR; 94 this.addressingDisposition = addressingDisposition; 95 } 96 97 //////////////////////////////////////////////////// 98 // 99 // pept.transport.ContactInfo 100 // 101 102 public boolean isConnectionBased() 103 { 104 return true; 105 } 106 107 public boolean shouldCacheConnection() 108 { 109 return true; 110 } 111 112 public String getConnectionCacheType() 113 { 114 return CorbaTransportManager.SOCKET_OR_CHANNEL_CONNECTION_CACHE; 115 } 116 117 public Connection createConnection() 118 { 119 Connection connection = 120 new SocketOrChannelConnectionImpl(orb, this, 121 socketType, hostname, port); 122 return connection; 123 } 124 125 //////////////////////////////////////////////////// 126 // 127 // spi.transport.CorbaContactInfo 128 // 129 130 public String getMonitoringName() 131 { 132 return "SocketConnections"; 133 } 134 135 //////////////////////////////////////////////////// 136 // 137 // pept.transport.ContactInfo 138 // 139 140 public String getType() 141 { 142 return socketType; 143 } 144 145 public String getHost() 146 { 147 return hostname; 148 } 149 150 public int getPort() 151 { 152 return port; 153 } 154 155 //////////////////////////////////////////////////// 156 // 157 // java.lang.Object 158 // 159 160 public int hashCode() 161 { 162 if (! isHashCodeCached) { 163 cachedHashCode = socketType.hashCode() ^ hostname.hashCode() ^ port; 164 isHashCodeCached = true; 165 } 166 return cachedHashCode; 167 } 168 169 public boolean equals(Object obj) 170 { 171 if (obj == null) { 172 return false; 173 } else if (!(obj instanceof SocketOrChannelContactInfoImpl)) { 174 return false; 175 } 176 177 SocketOrChannelContactInfoImpl other = 178 (SocketOrChannelContactInfoImpl) obj; 179 180 if (port != other.port) { 181 return false; 182 } 183 if (!hostname.equals(other.hostname)) { 184 return false; 185 } 186 if (socketType == null) { 187 if (other.socketType != null) { 188 return false; 189 } 190 } else if (!socketType.equals(other.socketType)) { 191 return false; 192 } 193 return true; 194 } 195 196 public String toString() 197 { 198 return 199 "SocketOrChannelContactInfoImpl[" 200 + socketType + " " 201 + hostname + " " 202 + port 203 + "]"; 204 } 205 206 //////////////////////////////////////////////////// 207 // 208 // Implementation 209 // 210 211 protected void dprint(String msg) 212 { 213 ORBUtility.dprint("SocketOrChannelContactInfoImpl", msg); 214 } 215} 216 217// End of file. 218