Skip to content

Commit 9dce32a

Browse files
committed
refactor(util): consolidate thread-local handling with unified stack pattern
- Introduced ThreadLocalStack utility class to replace individual ThreadLocal implementations - Removed CmsfThreadLocal, RoflThreadLocal, and YasfThreadLocal in favor of unified ThreadLocalStack approach - Introduced InfoWrangler base class for reading and writing various info types - Created specialized wranglers (CmsfWrangler, YasfWrangler) for managing protocol-specific operations - Deleted CmsfVersion and YasfHelper classes, consolidating functionality into wranglers - Updated all interceptors (CMSF, ROFL, YASF) to use new wrangler pattern with ThreadLocalStack - Modified RMI ObjectWriter and FieldDescriptor to integrate with new thread-local management - Updated ServerRequestInfo_impl and ClientRequestInfo_impl to use YASF_THREAD_LOCAL and CMSF_THREAD_LOCAL constants - Enhanced OrbSteward in testify-iiop to support new pattern - Updated all related tests to use new API - Substantive lines added: 722, lines removed: 774 Co-authored-by-AI: IBM Bob 1.0.4
1 parent f19962d commit 9dce32a

34 files changed

Lines changed: 743 additions & 795 deletions

testify-iiop/src/main/java/testify/iiop/annotation/OrbSteward.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
import org.omg.PortableServer.POAHelper;
2929
import org.omg.PortableServer.POAManagerPackage.AdapterInactive;
3030
import testify.iiop.annotation.ConfigureOrb.UseWithOrb;
31+
32+
import static org.apache.yoko.util.ThreadLocalStack.CMSF_THREAD_LOCAL;
33+
import static org.apache.yoko.util.ThreadLocalStack.ROFL_THREAD_LOCAL;
34+
import static org.apache.yoko.util.ThreadLocalStack.YASF_THREAD_LOCAL;
3135
import testify.iiop.annotation.ConfigureOrb.UseWithOrb.InitializerScope;
3236

3337
import java.util.Objects;
@@ -107,9 +111,9 @@ public synchronized void close() {
107111
// When ORB shuts down, in-flight requests may not complete their full interceptor lifecycle,
108112
// leaving ThreadLocal state on the stack. Reset to ensure clean state for next test.
109113
// TODO: Remove this workaround once issue #783 is properly fixed in Yoko core.
110-
org.apache.yoko.util.cmsf.CmsfThreadLocal.reset();
111-
org.apache.yoko.util.rofl.RoflThreadLocal.reset();
112-
org.apache.yoko.util.yasf.YasfThreadLocal.reset();
114+
CMSF_THREAD_LOCAL.reset();
115+
ROFL_THREAD_LOCAL.reset();
116+
YASF_THREAD_LOCAL.reset();
113117
}
114118

115119
private boolean isOrbModifier(Class<?> c) {

yoko-core/src/main/java/org/apache/yoko/orb/OB/Upcall.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424
import org.apache.yoko.orb.OCI.GiopVersion;
2525
import org.apache.yoko.orb.OCI.ProfileInfo;
2626
import org.apache.yoko.orb.OCI.TransportInfo;
27+
import org.apache.yoko.io.SimplyCloseable;
2728
import org.apache.yoko.util.Assert;
2829
import org.apache.yoko.util.Timeout;
29-
import org.apache.yoko.util.cmsf.CmsfThreadLocal;
30-
import org.apache.yoko.util.cmsf.CmsfThreadLocal.CmsfOverride;
3130
import org.omg.CORBA.Any;
3231
import org.omg.CORBA.Policy;
3332
import org.omg.CORBA.PolicyManager;
@@ -48,6 +47,7 @@
4847
import static org.apache.yoko.io.Buffer.createWriteBuffer;
4948
import static org.apache.yoko.util.Arrays.EMPTY_INTS;
5049
import static org.apache.yoko.orb.OB.SendingContextRuntimes.SENDING_CONTEXT_RUNTIME;
50+
import static org.apache.yoko.util.ThreadLocalStack.CMSF_THREAD_LOCAL;
5151
import static org.apache.yoko.orb.OCI.GiopVersion.GIOP1_2;
5252

5353
public class Upcall {
@@ -292,7 +292,7 @@ public void setSystemException(SystemException ex) {
292292

293293
private static void createUnknownExceptionServiceContexts(UnknownException ex, ServiceContexts replyContexts) {
294294
final Throwable t = ex.originalEx;
295-
try (CmsfOverride o = CmsfThreadLocal.override()) {
295+
try (SimplyCloseable o = CMSF_THREAD_LOCAL.overrideForInterceptors()) {
296296
CodecPair codecs = CodecPair.getDefaultCodecs(GIOP1_2);
297297
try (YokoOutputStream os = new YokoOutputStream(codecs, GIOP1_2)) {
298298
os._OB_writeEndian();

yoko-core/src/main/java/org/apache/yoko/orb/PortableInterceptor/ClientRequestInfo_impl.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@
2424
import org.apache.yoko.orb.OB.PIDowncall;
2525
import org.apache.yoko.orb.OB.Util;
2626
import org.apache.yoko.orb.OCI.ProfileInfo;
27+
import org.apache.yoko.io.SimplyCloseable;
2728
import org.apache.yoko.util.Assert;
2829
import org.apache.yoko.util.CollectionExtras;
2930
import org.apache.yoko.util.Exceptions;
30-
import org.apache.yoko.util.cmsf.CmsfThreadLocal;
31-
import org.apache.yoko.util.cmsf.CmsfThreadLocal.CmsfOverride;
32-
import org.apache.yoko.util.yasf.YasfThreadLocal;
33-
import org.apache.yoko.util.yasf.YasfThreadLocal.YasfOverride;
3431
import org.omg.CORBA.Any;
3532
import org.omg.CORBA.BAD_INV_ORDER;
3633
import org.omg.CORBA.BAD_PARAM;
@@ -49,6 +46,9 @@
4946
import org.omg.PortableInterceptor.ClientRequestInfo;
5047
import org.omg.PortableInterceptor.ClientRequestInterceptor;
5148
import org.omg.PortableInterceptor.ForwardRequest;
49+
50+
import static org.apache.yoko.util.ThreadLocalStack.CMSF_THREAD_LOCAL;
51+
import static org.apache.yoko.util.ThreadLocalStack.YASF_THREAD_LOCAL;
5252
import org.omg.PortableInterceptor.LOCATION_FORWARD;
5353
import org.omg.PortableInterceptor.SUCCESSFUL;
5454
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
@@ -269,8 +269,8 @@ public void _OB_request(List<ClientRequestInterceptor> interceptors) throws Loca
269269
argStrategy.setArgsAvail(true);
270270
argStrategy.setExceptAvail(true);
271271

272-
try (CmsfOverride ignored = CmsfThreadLocal.override();
273-
YasfOverride ignored1 = YasfThreadLocal.override()) {
272+
try (SimplyCloseable ignored = CMSF_THREAD_LOCAL.overrideForInterceptors();
273+
SimplyCloseable ignored1 = YASF_THREAD_LOCAL.overrideForInterceptors()) {
274274
for(ClientRequestInterceptor interceptor: interceptors) {
275275
try {
276276
interceptor.send_request(this);
@@ -303,8 +303,8 @@ public void _OB_reply() throws LocationForward {
303303
piCurrent._OB_pushSlotData(newThreadScopePICurrentSlotData);
304304
}
305305

306-
try (CmsfOverride ignored = CmsfThreadLocal.override();
307-
YasfOverride ignored1 = YasfThreadLocal.override()) {
306+
try (SimplyCloseable ignored = CMSF_THREAD_LOCAL.overrideForInterceptors();
307+
SimplyCloseable ignored1 = YASF_THREAD_LOCAL.overrideForInterceptors()) {
308308
for (ClientRequestInterceptor i: CollectionExtras.removeInReverse(interceptors)) {
309309
try {
310310
switch (replyStatus) {

yoko-core/src/main/java/org/apache/yoko/orb/PortableInterceptor/ServerRequestInfo_impl.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@
2525
import org.apache.yoko.orb.OB.ParameterDesc;
2626
import org.apache.yoko.orb.OB.Util;
2727
import org.apache.yoko.orb.OCI.TransportInfo;
28+
import org.apache.yoko.io.SimplyCloseable;
2829
import org.apache.yoko.util.Assert;
29-
import org.apache.yoko.util.cmsf.CmsfThreadLocal;
30-
import org.apache.yoko.util.cmsf.CmsfThreadLocal.CmsfOverride;
31-
import org.apache.yoko.util.yasf.YasfThreadLocal;
32-
import org.apache.yoko.util.yasf.YasfThreadLocal.YasfOverride;
3330
import org.omg.CORBA.Any;
3431
import org.omg.CORBA.BAD_INV_ORDER;
3532
import org.omg.CORBA.CompletionStatus;
@@ -49,6 +46,9 @@
4946
import org.omg.PortableInterceptor.ObjectReferenceTemplate;
5047
import org.omg.PortableInterceptor.SUCCESSFUL;
5148
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
49+
50+
import static org.apache.yoko.util.ThreadLocalStack.CMSF_THREAD_LOCAL;
51+
import static org.apache.yoko.util.ThreadLocalStack.YASF_THREAD_LOCAL;
5252
import org.omg.PortableInterceptor.ServerRequestInterceptor;
5353
import org.omg.PortableInterceptor.TRANSPORT_RETRY;
5454
import org.omg.PortableInterceptor.USER_EXCEPTION;
@@ -279,8 +279,8 @@ public void _OB_requestServiceContext(List<ServerRequestInterceptor> interceptor
279279
argStrategy.setArgsAvail(false);
280280
argStrategy.setExceptAvail(false);
281281

282-
try (CmsfOverride ignored = CmsfThreadLocal.override();
283-
YasfOverride ignored1 = YasfThreadLocal.override()) {
282+
try (SimplyCloseable ignored = CMSF_THREAD_LOCAL.overrideForInterceptors();
283+
SimplyCloseable ignored1 = YASF_THREAD_LOCAL.overrideForInterceptors()) {
284284
for (ServerRequestInterceptor i: interceptors) {
285285
i.receive_request_service_contexts(this);
286286
this.interceptors.add(i);
@@ -301,8 +301,8 @@ public void _OB_request() throws LocationForward {
301301
argStrategy.setExceptAvail(true);
302302
replyStatus = NO_REPLY;
303303

304-
try (CmsfOverride ignored = CmsfThreadLocal.override();
305-
YasfOverride ignored1 = YasfThreadLocal.override()) {
304+
try (SimplyCloseable ignored = CMSF_THREAD_LOCAL.overrideForInterceptors();
305+
SimplyCloseable ignored1 = YASF_THREAD_LOCAL.overrideForInterceptors()) {
306306
for (ServerRequestInterceptor sri: interceptors)
307307
sri.receive_request(this);
308308
} catch (ForwardRequest ex) {
@@ -318,8 +318,8 @@ public void _OB_sendReply() {
318318
// The servant is no longer available
319319
servant = null;
320320

321-
try (CmsfOverride ignored = CmsfThreadLocal.override();
322-
YasfOverride ignored1 = YasfThreadLocal.override()) {
321+
try (SimplyCloseable ignored = CMSF_THREAD_LOCAL.overrideForInterceptors();
322+
SimplyCloseable ignored1 = YASF_THREAD_LOCAL.overrideForInterceptors()) {
323323
for (ServerRequestInterceptor i: removeInReverse(interceptors)) {
324324
i.send_reply(this);
325325
}
@@ -334,8 +334,8 @@ public void _OB_sendException() throws LocationForward {
334334
// The servant is no longer available
335335
servant = null;
336336

337-
try (CmsfOverride ignored = CmsfThreadLocal.override();
338-
YasfOverride ignored1 = YasfThreadLocal.override()) {
337+
try (SimplyCloseable ignored = CMSF_THREAD_LOCAL.overrideForInterceptors();
338+
SimplyCloseable ignored1 = YASF_THREAD_LOCAL.overrideForInterceptors()) {
339339
Assert.ensure(replyStatus == SYSTEM_EXCEPTION.value || replyStatus == USER_EXCEPTION.value);
340340

341341
for (ServerRequestInterceptor i : removeInReverse(interceptors)) {
@@ -371,8 +371,8 @@ public void _OB_sendOther() throws LocationForward {
371371
// The servant is no longer available
372372
servant = null;
373373

374-
try (CmsfOverride ignored = CmsfThreadLocal.override();
375-
YasfOverride ignored1 = YasfThreadLocal.override()) {
374+
try (SimplyCloseable ignored = CMSF_THREAD_LOCAL.overrideForInterceptors();
375+
SimplyCloseable ignored1 = YASF_THREAD_LOCAL.overrideForInterceptors()) {
376376
Assert.ensure(replyStatus == LOCATION_FORWARD.value || replyStatus == TRANSPORT_RETRY.value);
377377

378378
for (ServerRequestInterceptor i: removeInReverse(interceptors)) {
@@ -415,8 +415,8 @@ public void _OB_contextSwitch() {
415415
piCurrent._OB_pushSlotData(requestSlotData);
416416
// Call pre_unmarshal on extended interceptors after context switch
417417
// Use override to maintain consistency with other interceptor calls
418-
try (CmsfOverride ignored = CmsfThreadLocal.override();
419-
YasfOverride ignored1 = YasfThreadLocal.override()) {
418+
try (SimplyCloseable ignored = CMSF_THREAD_LOCAL.overrideForInterceptors();
419+
SimplyCloseable ignored1 = YASF_THREAD_LOCAL.overrideForInterceptors()) {
420420
interceptors.stream()
421421
.filter(ExtendedServerRequestInterceptor.class::isInstance)
422422
.map(ExtendedServerRequestInterceptor.class::cast)
@@ -429,8 +429,8 @@ public void _OB_contextSwitch() {
429429
public void _OB_postMarshal() {
430430
logger.fine(() -> "Calling post_marshal on extended interceptors");
431431
// Use override to maintain consistency with other interceptor calls
432-
try (CmsfOverride ignored = CmsfThreadLocal.override();
433-
YasfOverride ignored1 = YasfThreadLocal.override()) {
432+
try (SimplyCloseable ignored = CMSF_THREAD_LOCAL.overrideForInterceptors();
433+
SimplyCloseable ignored1 = YASF_THREAD_LOCAL.overrideForInterceptors()) {
434434
interceptors.stream()
435435
.filter(ExtendedServerRequestInterceptor.class::isInstance)
436436
.map(ExtendedServerRequestInterceptor.class::cast)
Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 IBM Corporation and others.
2+
* Copyright 2026 IBM Corporation and others.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -8,7 +8,7 @@
88
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an \"AS IS\" BASIS,
11+
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
@@ -17,41 +17,30 @@
1717
*/
1818
package org.apache.yoko.orb.cmsf;
1919

20-
import static org.apache.yoko.util.MinorCodes.MinorInvalidComponentId;
21-
import static org.apache.yoko.orb.cmsf.CmsfVersion.CMSFv1;
22-
import static org.apache.yoko.orb.cmsf.CmsfVersion.CMSFv2;
20+
import org.apache.yoko.io.SimplyCloseable;
21+
import org.apache.yoko.util.cmsf.Cmsf;
22+
import org.omg.CORBA.LocalObject;
23+
import org.omg.PortableInterceptor.ClientRequestInfo;
24+
import org.omg.PortableInterceptor.ClientRequestInterceptor;
25+
import org.omg.PortableInterceptor.ForwardRequest;
2326

2427
import java.io.IOException;
2528
import java.io.NotSerializableException;
2629
import java.io.ObjectInputStream;
2730
import java.io.ObjectOutputStream;
2831

29-
import org.apache.yoko.util.cmsf.CmsfThreadLocal;
30-
import org.omg.CORBA.BAD_PARAM;
31-
import org.omg.CORBA.LocalObject;
32-
import org.omg.IOP.TAG_RMI_CUSTOM_MAX_STREAM_FORMAT;
33-
import org.omg.IOP.TaggedComponent;
34-
import org.omg.PortableInterceptor.ClientRequestInfo;
35-
import org.omg.PortableInterceptor.ClientRequestInterceptor;
36-
import org.omg.PortableInterceptor.ForwardRequest;
32+
import static org.apache.yoko.util.ThreadLocalStack.CMSF_THREAD_LOCAL;
33+
import static org.apache.yoko.util.cmsf.CmsfWrangler.CMSF_WRANGLER;
3734

3835
public final class CmsfClientInterceptor extends LocalObject implements ClientRequestInterceptor {
3936
private static final String NAME = CmsfClientInterceptor.class.getName();
4037

4138
@Override
4239
public void send_request(ClientRequestInfo ri) throws ForwardRequest {
43-
CmsfVersion cmsf = CMSFv1;
44-
try {
45-
TaggedComponent tc = ri.get_effective_component(TAG_RMI_CUSTOM_MAX_STREAM_FORMAT.value);
46-
cmsf = CmsfVersion.readData(tc.component_data);
47-
} catch (BAD_PARAM e) {
48-
if (e.minor != MinorInvalidComponentId) {
49-
throw e;
50-
}
51-
}
52-
CmsfThreadLocal.push(cmsf.getValue());
53-
54-
if (CmsfVersion.ENABLED) ri.add_request_service_context(CMSFv2.getSc(), false);
40+
Cmsf cmsf = CMSF_WRANGLER.readData(ri);
41+
CMSF_WRANGLER.addSc(ri);
42+
@SuppressWarnings("resource") // popped in receive_*
43+
SimplyCloseable ignored = CMSF_THREAD_LOCAL.push(cmsf);
5544
}
5645

5746
@Override
@@ -60,17 +49,17 @@ public void send_poll(ClientRequestInfo ri) {
6049

6150
@Override
6251
public void receive_reply(ClientRequestInfo ri) {
63-
CmsfThreadLocal.pop();
52+
CMSF_THREAD_LOCAL.pop();
6453
}
6554

6655
@Override
67-
public void receive_exception(ClientRequestInfo ri) throws ForwardRequest {
68-
CmsfThreadLocal.pop();
56+
public void receive_exception(ClientRequestInfo ri) {
57+
CMSF_THREAD_LOCAL.pop();
6958
}
7059

7160
@Override
72-
public void receive_other(ClientRequestInfo ri) throws ForwardRequest {
73-
CmsfThreadLocal.pop();
61+
public void receive_other(ClientRequestInfo ri) {
62+
CMSF_THREAD_LOCAL.pop();
7463
}
7564

7665
@Override
@@ -81,13 +70,12 @@ public String name() {
8170
@Override
8271
public void destroy() {
8372
}
84-
73+
8574
private void readObject(ObjectInputStream ios) throws IOException {
8675
throw new NotSerializableException(NAME);
8776
}
88-
77+
8978
private void writeObject(ObjectOutputStream oos) throws IOException {
9079
throw new NotSerializableException(NAME);
9180
}
92-
9381
}

yoko-core/src/main/java/org/apache/yoko/orb/cmsf/CmsfIORInterceptor.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 IBM Corporation and others.
2+
* Copyright 2026 IBM Corporation and others.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -8,7 +8,7 @@
88
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an \"AS IS\" BASIS,
11+
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
@@ -17,23 +17,23 @@
1717
*/
1818
package org.apache.yoko.orb.cmsf;
1919

20-
import static org.apache.yoko.orb.cmsf.CmsfVersion.CMSFv2;
20+
import org.omg.CORBA.LocalObject;
21+
import org.omg.PortableInterceptor.IORInfo;
22+
import org.omg.PortableInterceptor.IORInterceptor;
2123

2224
import java.io.IOException;
2325
import java.io.NotSerializableException;
2426
import java.io.ObjectInputStream;
2527
import java.io.ObjectOutputStream;
2628

27-
import org.omg.CORBA.LocalObject;
28-
import org.omg.PortableInterceptor.IORInfo;
29-
import org.omg.PortableInterceptor.IORInterceptor;
29+
import static org.apache.yoko.util.cmsf.CmsfWrangler.CMSF_WRANGLER;
3030

3131
public final class CmsfIORInterceptor extends LocalObject implements IORInterceptor {
3232
private static final String NAME = CmsfIORInterceptor.class.getName();
3333

3434
@Override
3535
public void establish_components(IORInfo info) {
36-
if (CmsfVersion.ENABLED) info.add_ior_component(CMSFv2.getTc());
36+
CMSF_WRANGLER.addTc(info);
3737
}
3838

3939
@Override
@@ -44,11 +44,11 @@ public String name() {
4444
@Override
4545
public void destroy() {
4646
}
47-
47+
4848
private void readObject(ObjectInputStream ios) throws IOException {
4949
throw new NotSerializableException(NAME);
5050
}
51-
51+
5252
private void writeObject(ObjectOutputStream oos) throws IOException {
5353
throw new NotSerializableException(NAME);
5454
}

0 commit comments

Comments
 (0)