ServantBasePeerImpl.java
11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.CORBA.impl;
import com.adobe.CORBA.ServantBase;
import com.adobe.CORBA.impl.ServantBasePeer;
import com.adobe.CORBA.impl.ServantLocator;
import com.adobe.service.ResourcePeer;
import com.adobe.service.impl.Platform;
import java.lang.reflect.Constructor;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;
import javax.naming.NameNotFoundException;
import org.omg.CORBA.ORB;
import org.omg.CORBA.Object;
import org.omg.CORBA.Policy;
import org.omg.PortableServer.IdAssignmentPolicy;
import org.omg.PortableServer.IdAssignmentPolicyValue;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAManager;
import org.omg.PortableServer.POAManagerPackage.AdapterInactive;
import org.omg.PortableServer.RequestProcessingPolicy;
import org.omg.PortableServer.RequestProcessingPolicyValue;
import org.omg.PortableServer.Servant;
import org.omg.PortableServer.ServantManager;
import org.omg.PortableServer.ServantRetentionPolicy;
import org.omg.PortableServer.ServantRetentionPolicyValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ServantBasePeerImpl
extends ServantBasePeer {
private static final Logger log = LoggerFactory.getLogger(ServantBasePeerImpl.class);
private java.lang.Object _owner;
private final java.lang.Object operations;
private byte[] objectId = null;
private POA myPOA;
private static final Map<java.lang.Object, POA> ownerToPOA = new HashMap<java.lang.Object, POA>();
private static POA rootPOA;
private static final Map<Class, Constructor<Servant>> constructors;
private ServantBasePeerImpl(java.lang.Object operations) {
this.operations = operations;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
* Enabled aggressive block sorting
* Enabled unnecessary exception pruning
* Enabled aggressive exception aggregation
*/
public synchronized Object activate(java.lang.Object owner) {
this._owner = owner;
ClassLoader old = Thread.currentThread().getContextClassLoader();
try {
try {
Object object;
if (this.objectId != null) {
Object corbaObj = this.myPOA.id_to_reference(this.objectId);
log.debug("Servant {} already activated, returning CORBA object {}", new java.lang.Object[]{this, corbaObj});
Object object2 = corbaObj;
java.lang.Object var12_10 = null;
Thread.currentThread().setContextClassLoader(old);
return object2;
}
if (owner == null) {
POA poa;
this.myPOA = poa = ServantBasePeerImpl.getRootPOA();
Servant tie = this.getTie(poa);
POA pOA = poa;
synchronized (pOA) {
this.objectId = poa.activate_object(tie);
}
Object corbaObj = poa.servant_to_reference(tie);
log.debug("Servant {} activated without owner, returning CORBA object {}", new java.lang.Object[]{this, corbaObj});
Object object2 = corbaObj;
java.lang.Object var12_11 = null;
Thread.currentThread().setContextClassLoader(old);
return object2;
}
Map<java.lang.Object, POA> corbaObj = ownerToPOA;
synchronized (corbaObj) {
POA poa = ownerToPOA.get(owner);
if (poa == null) {
poa = this.createPOA();
ownerToPOA.put(owner, poa);
}
this.myPOA = poa;
Servant tie = this.getTie(poa);
ServantLocator locator = (ServantLocator)((java.lang.Object)poa.get_servant_manager());
this.objectId = locator.activate_object(tie);
String[] intfs = tie._all_interfaces(poa, this.objectId);
Thread.currentThread().setContextClassLoader(poa.getClass().getClassLoader());
Object corbaObj2 = poa.create_reference_with_id(this.objectId, intfs[0]);
log.debug("Servant {} activated with owner {}, returning CORBA object {}", new java.lang.Object[]{this, owner, corbaObj2});
object = corbaObj2;
}
java.lang.Object var12_12 = null;
Thread.currentThread().setContextClassLoader(old);
return object;
}
catch (Exception e) {
log.warn("Error in object activation", (Throwable)e);
if (e instanceof RuntimeException) {
throw (RuntimeException)e;
}
throw new UndeclaredThrowableException(e);
}
}
catch (Throwable var11_21) {
java.lang.Object var12_13 = null;
Thread.currentThread().setContextClassLoader(old);
throw var11_21;
}
}
public synchronized void deactivate() {
if (this.objectId == null) {
return;
}
try {
if (this.myPOA.the_parent() == null) {
this.myPOA.deactivate_object(this.objectId);
} else {
ServantLocator locator = (ServantLocator)((java.lang.Object)this.myPOA.get_servant_manager());
locator.deactivate_object(this.objectId);
}
this.objectId = null;
this.myPOA = null;
}
catch (Exception e) {
log.warn("Error encountered in servant deactivation", (Throwable)e);
}
}
Servant getTie(POA poa) {
Constructor constructor = constructors.get(this.operations.getClass());
if (constructor == null) {
block4 : for (Class cls = this.operations.getClass(); cls != ServantBase.class; cls = cls.getSuperclass()) {
Class<?>[] interfaces = cls.getInterfaces();
String operationsString = "Operations";
for (Class intf : interfaces) {
if (!intf.getName().endsWith(operationsString)) continue;
String nm = intf.getName();
nm = nm.substring(0, nm.length() - operationsString.length());
try {
Class tieClass = this.operations.getClass().getClassLoader().loadClass(nm + "POATie");
constructor = tieClass.getConstructor(intf, POA.class);
break block4;
}
catch (Exception e) {
log.debug("Error loading POATie class/constructor for operations interface " + intf.getName() + ", moving on...", (Throwable)e);
}
}
}
if (constructor == null) {
throw new IllegalStateException("Failed to find generated POATie class. Make sure that right idlj options are used.");
}
constructors.put(this.operations.getClass(), constructor);
}
try {
return constructor.newInstance(this.operations, poa);
}
catch (Exception e) {
throw new UndeclaredThrowableException(e);
}
}
private static synchronized POA getRootPOA() {
ClassLoader old = Thread.currentThread().getContextClassLoader();
boolean switched = false;
try {
block6 : {
try {
if (rootPOA != null) break block6;
Thread.currentThread().setContextClassLoader(ORB.class.getClassLoader());
switched = true;
rootPOA = (POA)Platform.UTIL.getOrb().resolve_initial_references("RootPOA");
rootPOA.the_POAManager().activate();
}
catch (Exception e) {
throw new UndeclaredThrowableException(e);
}
}
java.lang.Object var4_2 = null;
if (switched) {
Thread.currentThread().setContextClassLoader(old);
}
}
catch (Throwable var3_5) {
java.lang.Object var4_3 = null;
if (switched) {
Thread.currentThread().setContextClassLoader(old);
}
throw var3_5;
}
return rootPOA;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private POA createPOA() {
long poaSeqNum;
POA parent = ServantBasePeerImpl.getRootPOA();
Policy[] policies = new Policy[]{rootPOA.create_servant_retention_policy(ServantRetentionPolicyValue.NON_RETAIN), rootPOA.create_request_processing_policy(RequestProcessingPolicyValue.USE_SERVANT_MANAGER), rootPOA.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID)};
POA pOA = parent;
synchronized (pOA) {
String key = "com.adobe.nextPOA";
poaSeqNum = Long.getLong(key, 0);
System.setProperty(key, Long.toString(++poaSeqNum));
}
try {
String poaName = "BR-" + poaSeqNum;
POA poa = rootPOA.create_POA(poaName, null, policies);
poa.set_servant_manager((ServantManager)((java.lang.Object)new ServantLocator()));
poa.the_POAManager().activate();
return poa;
}
catch (Exception e) {
throw new UndeclaredThrowableException(e);
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public Object newServiceConnection(String serviceName) throws NameNotFoundException {
Object object;
try {
if (this._owner != null && this._owner instanceof ResourcePeer) {
((ResourcePeer)this._owner).resumeTx();
}
object = super.newServiceConnection(serviceName);
java.lang.Object var4_3 = null;
}
catch (Throwable var3_5) {
java.lang.Object var4_4 = null;
if (this._owner != null && this._owner instanceof ResourcePeer) {
((ResourcePeer)this._owner).suspendTx();
}
throw var3_5;
}
if (this._owner != null && this._owner instanceof ResourcePeer) {
((ResourcePeer)this._owner).suspendTx();
}
return object;
}
static {
constructors = Collections.synchronizedMap(new WeakHashMap());
}
public static class Factory
implements ServantBasePeer.Factory {
public ServantBasePeer create(java.lang.Object operations) {
return new ServantBasePeerImpl(operations);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void deactivateForOwner(java.lang.Object owner) {
POA poa;
Map map = ownerToPOA;
synchronized (map) {
poa = (POA)ownerToPOA.remove(owner);
if (poa == null) {
return;
}
}
try {
poa.the_POAManager().deactivate(false, false);
}
catch (AdapterInactive e) {
log.warn("Error occurred while deactivating the CORBA instance", (Throwable)e);
throw new UndeclaredThrowableException(e);
}
poa.destroy(false, false);
}
}
}