40 |
|
|
41 |
import java.util.Iterator; |
import java.util.Iterator; |
42 |
import java.util.Map; |
import java.util.Map; |
43 |
|
import java.util.Set; |
44 |
import java.util.TreeMap; |
import java.util.TreeMap; |
45 |
|
|
46 |
/** |
/** |
53 |
public class Connected_objects |
public class Connected_objects |
54 |
{ |
{ |
55 |
/** |
/** |
56 |
|
* The reference data about the connected object. |
57 |
|
*/ |
58 |
|
public class cObject |
59 |
|
{ |
60 |
|
/** |
61 |
|
* Create an initialised instance. |
62 |
|
*/ |
63 |
|
cObject(org.omg.CORBA.Object _object, int _port, byte[] _key) |
64 |
|
{ |
65 |
|
object = _object; |
66 |
|
port = _port; |
67 |
|
key = _key; |
68 |
|
} |
69 |
|
|
70 |
|
/** |
71 |
|
* The object. |
72 |
|
*/ |
73 |
|
public final org.omg.CORBA.Object object; |
74 |
|
|
75 |
|
/** |
76 |
|
* The port on that the object is connected. |
77 |
|
*/ |
78 |
|
public final int port; |
79 |
|
|
80 |
|
/** |
81 |
|
* The object key. |
82 |
|
*/ |
83 |
|
public final byte[] key; |
84 |
|
|
85 |
|
public boolean equals(java.lang.Object other) |
86 |
|
{ |
87 |
|
if (other instanceof cObject) |
88 |
|
{ |
89 |
|
cObject o = (cObject) other; |
90 |
|
return o.object.equals(object) && o.port == port; |
91 |
|
} |
92 |
|
else |
93 |
|
return false; |
94 |
|
} |
95 |
|
} |
96 |
|
|
97 |
|
/** |
98 |
* The free number to give for the next instance. |
* The free number to give for the next instance. |
99 |
* This field is incremented each time the |
* This field is incremented each time the |
100 |
* new collection of the connected objects is created. |
* new collection of the connected objects is created. |
109 |
private Map objects = new TreeMap(new ByteArrayComparator()); |
private Map objects = new TreeMap(new ByteArrayComparator()); |
110 |
|
|
111 |
/** |
/** |
112 |
* Get the key of the stored object. |
* Get the record of the stored object. |
113 |
* |
* |
114 |
* @param object the stored object |
* @param object the stored object |
115 |
* |
* |
116 |
* @return the key of the stored object, null if |
* @return the record about the stored object, null if |
117 |
* this object is not stored here. |
* this object is not stored here. |
118 |
*/ |
*/ |
119 |
public byte[] getKey(org.omg.CORBA.Object stored_object) |
public cObject getKey(org.omg.CORBA.Object stored_object) |
120 |
{ |
{ |
121 |
Map.Entry item; |
Map.Entry item; |
122 |
Iterator iter = objects.entrySet().iterator(); |
Iterator iter = objects.entrySet().iterator(); |
123 |
|
cObject ref; |
124 |
|
|
125 |
while (iter.hasNext()) |
while (iter.hasNext()) |
126 |
{ |
{ |
127 |
item = (Map.Entry) iter.next(); |
item = (Map.Entry) iter.next(); |
128 |
if (stored_object._is_equivalent((org.omg.CORBA.Object) item.getValue()) |
ref = (cObject) item.getValue(); |
129 |
) |
if (stored_object.equals(ref.object)) |
130 |
return (byte[]) item.getKey(); |
return ref; |
131 |
} |
} |
132 |
return null; |
return null; |
133 |
} |
} |
137 |
* generated automatically. |
* generated automatically. |
138 |
* |
* |
139 |
* @param object the object to add. |
* @param object the object to add. |
140 |
|
* @param port, on that the ORB will be listening to the remote |
141 |
|
* invocations. |
142 |
|
* |
143 |
|
* @return the newly created object record. |
144 |
*/ |
*/ |
145 |
public void add(org.omg.CORBA.Object object) |
public cObject add(org.omg.CORBA.Object object, int port) |
146 |
{ |
{ |
147 |
add(generateObjectKey(object), object); |
return add(generateObjectKey(object), object, port); |
148 |
} |
} |
149 |
|
|
150 |
/** |
/** |
152 |
* |
* |
153 |
* @param key the object key. |
* @param key the object key. |
154 |
* @param object the object to add. |
* @param object the object to add. |
155 |
|
* @param port the port, on that the ORB will be listening on the |
156 |
|
* remote invocations. |
157 |
*/ |
*/ |
158 |
public void add(byte[] key, org.omg.CORBA.Object object) |
public cObject add(byte[] key, org.omg.CORBA.Object object, int port) |
159 |
{ |
{ |
160 |
objects.put(key, object); |
cObject rec = new cObject(object, port, key); |
161 |
|
objects.put(key, rec); |
162 |
|
return rec; |
163 |
} |
} |
164 |
|
|
165 |
/** |
/** |
169 |
* |
* |
170 |
* @return the matching object, null if none is matching. |
* @return the matching object, null if none is matching. |
171 |
*/ |
*/ |
172 |
public org.omg.CORBA.Object get(byte[] key) |
public cObject get(byte[] key) |
173 |
{ |
{ |
174 |
return (org.omg.CORBA.Object) objects.get(key); |
return (cObject) objects.get(key); |
175 |
} |
} |
176 |
|
|
177 |
/** |
/** |
178 |
* Remover the given object. |
* Get the map entry set. |
179 |
|
* @return |
180 |
|
*/ |
181 |
|
public Set entrySet() |
182 |
|
{ |
183 |
|
return objects.entrySet(); |
184 |
|
} |
185 |
|
|
186 |
|
/** |
187 |
|
* Remove the given object. |
188 |
* |
* |
189 |
* @param object the object to remove. |
* @param object the object to remove. |
190 |
*/ |
*/ |
191 |
public void remove(org.omg.CORBA.Object object) |
public void remove(org.omg.CORBA.Object object) |
192 |
{ |
{ |
193 |
byte[] key = getKey(object); |
cObject ref = getKey(object); |
194 |
if (key != null) |
if (ref != null) |
195 |
objects.remove(key); |
objects.remove(ref.key); |
196 |
|
} |
197 |
|
|
198 |
|
/** |
199 |
|
* Remove the given object, indiciating it by the key. |
200 |
|
* |
201 |
|
* @param object the object to remove. |
202 |
|
*/ |
203 |
|
public void remove(byte[] key) |
204 |
|
{ |
205 |
|
objects.remove(key); |
206 |
} |
} |
207 |
|
|
208 |
/** |
/** |
228 |
free_object_number++; |
free_object_number++; |
229 |
return instance_number; |
return instance_number; |
230 |
} |
} |
231 |
} |
} |