1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4 
5 package IceInternal;
6 
7 public class FixedReference extends Reference
8 {
9     public
FixedReference(Instance instance, Ice.Communicator communicator, Ice.Identity identity, String facet, int mode, boolean secure, Ice.ProtocolVersion protocol, Ice.EncodingVersion encoding, Ice.ConnectionI connection, int invocationTimeout, java.util.Map<String, String> context, Ice.BooleanOptional compress)10     FixedReference(Instance instance,
11                    Ice.Communicator communicator,
12                    Ice.Identity identity,
13                    String facet,
14                    int mode,
15                    boolean secure,
16                    Ice.ProtocolVersion protocol,
17                    Ice.EncodingVersion encoding,
18                    Ice.ConnectionI connection,
19                    int invocationTimeout,
20                    java.util.Map<String, String> context,
21                    Ice.BooleanOptional compress)
22     {
23         super(instance, communicator, identity, facet, mode, secure, protocol, encoding, invocationTimeout, context);
24         _fixedConnection = connection;
25         if(compress.isSet())
26         {
27             _overrideCompress = true;
28             _compress = compress.get();
29         }
30     }
31 
32     @Override
33     public EndpointI[]
getEndpoints()34     getEndpoints()
35     {
36         return _emptyEndpoints;
37     }
38 
39     @Override
40     public String
getAdapterId()41     getAdapterId()
42     {
43         return "";
44     }
45 
46     @Override
47     public LocatorInfo
getLocatorInfo()48     getLocatorInfo()
49     {
50         return null;
51     }
52 
53     @Override
54     public RouterInfo
getRouterInfo()55     getRouterInfo()
56     {
57         return null;
58     }
59 
60     @Override
61     public boolean
getCollocationOptimized()62     getCollocationOptimized()
63     {
64         return false;
65     }
66 
67     @Override
68     public final boolean
getCacheConnection()69     getCacheConnection()
70     {
71         return true;
72     }
73 
74     @Override
75     public boolean
getPreferSecure()76     getPreferSecure()
77     {
78         return false;
79     }
80 
81     @Override
82     public final Ice.EndpointSelectionType
getEndpointSelection()83     getEndpointSelection()
84     {
85         return Ice.EndpointSelectionType.Random;
86     }
87 
88     @Override
89     public int
getLocatorCacheTimeout()90     getLocatorCacheTimeout()
91     {
92         return 0;
93     }
94 
95     @Override
96     public String
getConnectionId()97     getConnectionId()
98     {
99         return "";
100     }
101 
102     @Override
103     public Ice.IntOptional
getTimeout()104     getTimeout()
105     {
106         return new Ice.IntOptional();
107     }
108 
109     @Override
110     public Reference
changeEndpoints(EndpointI[] newEndpoints)111     changeEndpoints(EndpointI[] newEndpoints)
112     {
113         throw new Ice.FixedProxyException();
114     }
115 
116     @Override
117     public Reference
changeAdapterId(String newAdapterId)118     changeAdapterId(String newAdapterId)
119     {
120         throw new Ice.FixedProxyException();
121     }
122 
123     @Override
124     public Reference
changeLocator(Ice.LocatorPrx newLocator)125     changeLocator(Ice.LocatorPrx newLocator)
126     {
127         throw new Ice.FixedProxyException();
128     }
129 
130     @Override
131     public Reference
changeRouter(Ice.RouterPrx newRouter)132     changeRouter(Ice.RouterPrx newRouter)
133     {
134         throw new Ice.FixedProxyException();
135     }
136 
137     @Override
138     public Reference
changeCollocationOptimized(boolean newCollocationOptimized)139     changeCollocationOptimized(boolean newCollocationOptimized)
140     {
141         throw new Ice.FixedProxyException();
142     }
143 
144     @Override
145     public final Reference
changeCacheConnection(boolean newCache)146     changeCacheConnection(boolean newCache)
147     {
148         throw new Ice.FixedProxyException();
149     }
150 
151     @Override
152     public Reference
changePreferSecure(boolean prefSec)153     changePreferSecure(boolean prefSec)
154     {
155         throw new Ice.FixedProxyException();
156     }
157 
158     @Override
159     public final Reference
changeEndpointSelection(Ice.EndpointSelectionType newType)160     changeEndpointSelection(Ice.EndpointSelectionType newType)
161     {
162         throw new Ice.FixedProxyException();
163     }
164 
165     @Override
166     public Reference
changeLocatorCacheTimeout(int newTimeout)167     changeLocatorCacheTimeout(int newTimeout)
168     {
169         throw new Ice.FixedProxyException();
170     }
171 
172     @Override
173     public Reference
changeTimeout(int newTimeout)174     changeTimeout(int newTimeout)
175     {
176         throw new Ice.FixedProxyException();
177     }
178 
179     @Override
180     public Reference
changeConnectionId(String connectionId)181     changeConnectionId(String connectionId)
182     {
183         throw new Ice.FixedProxyException();
184     }
185 
186     @Override
187     public Reference
changeConnection(Ice.ConnectionI connection)188     changeConnection(Ice.ConnectionI connection)
189     {
190         if(_fixedConnection == connection)
191         {
192             return this;
193         }
194         FixedReference r = (FixedReference)getInstance().referenceFactory().copy(this);
195         r._fixedConnection = connection;
196         return r;
197     }
198 
199     @Override
200     public boolean
isIndirect()201     isIndirect()
202     {
203         return false;
204     }
205 
206     @Override
207     public boolean
isWellKnown()208     isWellKnown()
209     {
210         return false;
211     }
212 
213     @Override
214     public void
streamWrite(Ice.OutputStream s)215     streamWrite(Ice.OutputStream s)
216         throws Ice.MarshalException
217     {
218         throw new Ice.FixedProxyException();
219     }
220 
221     @Override
222     public java.util.Map<String, String>
toProperty(String prefix)223     toProperty(String prefix)
224     {
225         throw new Ice.FixedProxyException();
226     }
227 
228     @Override
229     public RequestHandler
getRequestHandler(Ice.ObjectPrxHelperBase proxy)230     getRequestHandler(Ice.ObjectPrxHelperBase proxy)
231     {
232         switch(getMode())
233         {
234         case Reference.ModeTwoway:
235         case Reference.ModeOneway:
236         case Reference.ModeBatchOneway:
237         {
238             if(_fixedConnection.endpoint().datagram())
239             {
240                 throw new Ice.NoEndpointException(toString());
241             }
242             break;
243         }
244 
245         case Reference.ModeDatagram:
246         case Reference.ModeBatchDatagram:
247         {
248             if(!_fixedConnection.endpoint().datagram())
249             {
250                 throw new Ice.NoEndpointException(toString());
251             }
252             break;
253         }
254         }
255 
256         //
257         // If a secure connection is requested or secure overrides is set,
258         // check if the connection is secure.
259         //
260         boolean secure;
261         DefaultsAndOverrides defaultsAndOverrides = getInstance().defaultsAndOverrides();
262         if(defaultsAndOverrides.overrideSecure)
263         {
264             secure = defaultsAndOverrides.overrideSecureValue;
265         }
266         else
267         {
268             secure = getSecure();
269         }
270         if(secure && !_fixedConnection.endpoint().secure())
271         {
272             throw new Ice.NoEndpointException(toString());
273         }
274 
275         _fixedConnection.throwException(); // Throw in case our connection is already destroyed.
276 
277         boolean compress = false;
278         if(defaultsAndOverrides.overrideCompress)
279         {
280             compress = defaultsAndOverrides.overrideCompressValue;
281         }
282         else if(_overrideCompress)
283         {
284             compress = _compress;
285         }
286 
287         RequestHandler handler = new ConnectionRequestHandler(this, _fixedConnection, compress);
288         if(getInstance().queueRequests())
289         {
290             handler = new QueueRequestHandler(getInstance(), handler);
291         }
292         return proxy._setRequestHandler(handler);
293     }
294 
295     @Override
296     public BatchRequestQueue
getBatchRequestQueue()297     getBatchRequestQueue()
298     {
299         return _fixedConnection.getBatchRequestQueue();
300     }
301 
302     @Override
303     public boolean
equals(java.lang.Object obj)304     equals(java.lang.Object obj)
305     {
306         if(this == obj)
307         {
308             return true;
309         }
310         if(!(obj instanceof FixedReference))
311         {
312             return false;
313         }
314         FixedReference rhs = (FixedReference)obj;
315         if(!super.equals(rhs))
316         {
317             return false;
318         }
319         return _fixedConnection.equals(rhs._fixedConnection);
320     }
321 
322     @Override
323     public int
hashCode()324     hashCode()
325     {
326         return super.hashCode();
327     }
328 
329     private Ice.ConnectionI _fixedConnection;
330     private static EndpointI[] _emptyEndpoints = new EndpointI[0];
331 }
332