KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > legacy > connection > LegacyServerSocketManagerImpl


1 /*
2  * @(#)LegacyServerSocketManagerImpl.java 1.94 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.legacy.connection;
9
10 import java.net.ServerSocket JavaDoc;
11 import java.util.ArrayList JavaDoc;
12 import java.util.Collection JavaDoc;
13 import java.util.Iterator JavaDoc;
14
15 import org.omg.CORBA.INITIALIZE JavaDoc;
16 import org.omg.CORBA.INTERNAL JavaDoc;
17 import org.omg.CORBA.CompletionStatus JavaDoc;
18
19 import com.sun.corba.se.pept.transport.Acceptor;
20 import com.sun.corba.se.pept.transport.ByteBufferPool;
21 import com.sun.corba.se.pept.transport.ContactInfo;
22 import com.sun.corba.se.pept.transport.Selector;
23
24 import com.sun.corba.se.spi.ior.IOR;
25 import com.sun.corba.se.spi.ior.iiop.IIOPProfile ;
26 import com.sun.corba.se.spi.ior.ObjectKeyTemplate;
27 import com.sun.corba.se.spi.ior.ObjectId ;
28 import com.sun.corba.se.spi.orb.ORB;
29 import com.sun.corba.se.spi.transport.CorbaTransportManager;
30 import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketEndPointInfo;
31 import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketManager;
32 import com.sun.corba.se.spi.transport.SocketOrChannelAcceptor;
33 import com.sun.corba.se.spi.logging.CORBALogDomains;
34
35 import com.sun.corba.se.impl.encoding.EncapsOutputStream;
36 import com.sun.corba.se.impl.legacy.connection.SocketFactoryAcceptorImpl;
37 import com.sun.corba.se.impl.legacy.connection.USLPort;
38 import com.sun.corba.se.impl.orbutil.ORBUtility;
39 import com.sun.corba.se.impl.transport.SocketOrChannelAcceptorImpl;
40 import com.sun.corba.se.impl.logging.ORBUtilSystemException;
41
42 public class LegacyServerSocketManagerImpl
43     implements
44     LegacyServerSocketManager
45 {
46     protected ORB orb;
47     private ORBUtilSystemException wrapper ;
48     
49     public LegacyServerSocketManagerImpl(ORB orb)
50     {
51     this.orb = orb;
52     wrapper = ORBUtilSystemException.get( orb,
53         CORBALogDomains.RPC_TRANSPORT ) ;
54     }
55
56     ////////////////////////////////////////////////////
57
//
58
// LegacyServerSocketManager
59
//
60

61     // Only used in ServerManagerImpl.
62
public int legacyGetTransientServerPort(String JavaDoc type)
63     {
64     return legacyGetServerPort(type, false);
65     }
66
67     // Only used by POAPolicyMediatorBase.
68
public synchronized int legacyGetPersistentServerPort(String JavaDoc socketType)
69     {
70     if (orb.getORBData().getServerIsORBActivated()) {
71         // this server is activated by orbd
72
return legacyGetServerPort(socketType, true);
73     } else if (orb.getORBData().getPersistentPortInitialized()) {
74         // this is a user-activated server
75
return orb.getORBData().getPersistentServerPort();
76     } else {
77         throw wrapper.persistentServerportNotSet(
78         CompletionStatus.COMPLETED_MAYBE);
79     }
80     }
81
82     // Only used by PI IORInfoImpl.
83
public synchronized int legacyGetTransientOrPersistentServerPort(
84         String JavaDoc socketType)
85     {
86         return legacyGetServerPort(socketType,
87                        orb.getORBData()
88                        .getServerIsORBActivated());
89     }
90
91     // Used in RepositoryImpl, ServerManagerImpl, POAImpl,
92
// POAPolicyMediatorBase, TOAImpl.
93
// To get either default or bootnaming endpoint.
94
public synchronized LegacyServerSocketEndPointInfo legacyGetEndpoint(
95         String JavaDoc name)
96     {
97     Iterator JavaDoc iterator = getAcceptorIterator();
98     while (iterator.hasNext()) {
99         LegacyServerSocketEndPointInfo endPoint = cast(iterator.next());
100         if (endPoint != null && name.equals(endPoint.getName())) {
101         return endPoint;
102         }
103     }
104     throw new INTERNAL JavaDoc("No acceptor for: " + name);
105     }
106
107     // Check to see if the given port is equal to any of the ORB Server Ports.
108
// XXX Does this need to change for the multi-homed case?
109
// Used in IIOPProfileImpl, ORBImpl.
110
public boolean legacyIsLocalServerPort(int port)
111     {
112     Iterator JavaDoc iterator = getAcceptorIterator();
113     while (iterator.hasNext()) {
114         LegacyServerSocketEndPointInfo endPoint = cast(iterator.next());
115         if (endPoint != null && endPoint.getPort() == port) {
116         return true;
117         }
118     }
119         return false;
120     }
121
122     ////////////////////////////////////////////////////
123
//
124
// Implementation.
125
//
126

127     private int legacyGetServerPort (String JavaDoc socketType, boolean isPersistent)
128     {
129     Iterator JavaDoc endpoints = getAcceptorIterator();
130     while (endpoints.hasNext()) {
131         LegacyServerSocketEndPointInfo ep = cast(endpoints.next());
132         if (ep != null && ep.getType().equals(socketType)) {
133         if (isPersistent) {
134             return ep.getLocatorPort();
135         } else {
136             return ep.getPort();
137         }
138         }
139     }
140     return -1;
141     }
142
143     private Iterator JavaDoc getAcceptorIterator()
144     {
145         Collection JavaDoc acceptors =
146         orb.getCorbaTransportManager().getAcceptors(null, null);
147         if (acceptors != null) {
148             return acceptors.iterator();
149     }
150
151     throw wrapper.getServerPortCalledBeforeEndpointsInitialized() ;
152     }
153
154     private LegacyServerSocketEndPointInfo cast(Object JavaDoc o)
155     {
156     if (o instanceof LegacyServerSocketEndPointInfo) {
157         return (LegacyServerSocketEndPointInfo) o;
158     }
159     return null;
160     }
161
162     protected void dprint(String JavaDoc msg)
163     {
164     ORBUtility.dprint("LegacyServerSocketManagerImpl", msg);
165     }
166 }
167
168 // End of file.
169

170
171
Popular Tags