Skip to content

Commit ae5e0d2

Browse files
committed
ORB Refactoring to simplify its initialization and avoid race conditions
- Fixed bug I made in 2024-02 in 6f6b961 which destroyed ORB restarts. - Signed-off-by: David Matějček <[email protected]>
1 parent 8e196fe commit ae5e0d2

File tree

45 files changed

+1514
-2032
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1514
-2032
lines changed

appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/AppClientContainerBuilder.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import org.glassfish.appclient.client.acc.config.TargetServer;
4141
import org.glassfish.appclient.client.acc.config.util.XML;
4242
import org.glassfish.embeddable.client.UserError;
43-
import org.glassfish.enterprise.iiop.api.GlassFishORBHelper;
43+
import org.glassfish.enterprise.iiop.api.GlassFishORBLocator;
4444
import org.xml.sax.SAXException;
4545

4646
import static java.util.logging.Level.CONFIG;
@@ -87,7 +87,7 @@ public class AppClientContainerBuilder implements AppClientContainer.Builder {
8787

8888
private boolean sendPassword = true;
8989

90-
private GlassFishORBHelper orbHelper;
90+
private GlassFishORBLocator orbLocator;
9191

9292
/** caller-provided message security configurations */
9393
private final List<MessageSecurityConfig> messageSecurityConfigs = new ArrayList<>();
@@ -183,7 +183,7 @@ private CallbackHandler getCallbackHandlerFromDescriptor(final String callbackHa
183183

184184
private void prepareHabitat() throws URISyntaxException {
185185
ACCModulesManager.initialize(Thread.currentThread().getContextClassLoader());
186-
orbHelper = ACCModulesManager.getService(GlassFishORBHelper.class);
186+
orbLocator = ACCModulesManager.getService(GlassFishORBLocator.class);
187187
}
188188

189189
/**
@@ -220,11 +220,10 @@ private void prepareIIOP(final TargetServer[] targetServers, Properties containe
220220
}
221221

222222
if (isSSLRequired(targetServers, containerProperties)) {
223-
orbHelper.setCSIv2Prop(ORB_SSL_CLIENT_REQUIRED, "true");
223+
orbLocator.setCSIv2Prop(ORB_SSL_CLIENT_REQUIRED, "true");
224224
}
225225

226226
logger.log(CONFIG, "Using endpoint address(es): {0}", sb.toString());
227-
228227
}
229228

230229
/**

appserver/appclient/client/acc/src/main/java/org/glassfish/appclient/client/acc/TargetServerHelper.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
23
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
34
*
45
* This program and the accompanying materials are made available under the
@@ -24,7 +25,8 @@
2425
import org.glassfish.appclient.client.acc.config.Security;
2526
import org.glassfish.appclient.client.acc.config.TargetServer;
2627
import org.glassfish.embeddable.client.UserError;
27-
import org.glassfish.enterprise.iiop.api.GlassFishORBHelper;
28+
29+
import static org.glassfish.internal.api.ORBLocator.DEFAULT_ORB_INIT_PORT;
2830

2931
/**
3032
* Encapsulates the logic for deciding what TargetServer objects to use for
@@ -34,7 +36,7 @@
3436
*/
3537
public class TargetServerHelper {
3638

37-
private static int DEFAULT_ENDPOINT_PORT = Integer.parseInt(GlassFishORBHelper.DEFAULT_ORB_INIT_PORT);
39+
private static int DEFAULT_ENDPOINT_PORT = Integer.parseInt(DEFAULT_ORB_INIT_PORT);
3840
private static final String SSL_PROPERTY_NAME = "ssl";
3941

4042

appserver/ejb/ejb-container/src/main/java/com/sun/ejb/EjbNamingReferenceManagerImpl.java

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2022, 2025 Contributors to the Eclipse Foundation.
33
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
44
*
55
* This program and the accompanying materials are made available under the
@@ -33,7 +33,7 @@
3333
import org.glassfish.api.invocation.ComponentInvocation;
3434
import org.glassfish.api.invocation.InvocationManager;
3535
import org.glassfish.api.naming.SimpleJndiName;
36-
import org.glassfish.enterprise.iiop.api.GlassFishORBHelper;
36+
import org.glassfish.internal.api.ORBLocator;
3737
import org.jvnet.hk2.annotations.Service;
3838
import org.omg.CORBA.ORB;
3939

@@ -48,10 +48,10 @@
4848
public class EjbNamingReferenceManagerImpl implements EjbNamingReferenceManager {
4949

5050
@Inject
51-
InvocationManager invMgr;
51+
private InvocationManager invMgr;
5252

5353
@Inject
54-
Provider<GlassFishORBHelper> glassFishORBHelperProvider;
54+
private Provider<ORBLocator> orbLocatorProvider;
5555

5656
@Override
5757
public Object resolveEjbReference(EjbReferenceDescriptor ejbRefDesc, Context context)
@@ -119,22 +119,17 @@ public Object resolveEjbReference(EjbReferenceDescriptor ejbRefDesc, Context con
119119

120120
ClassLoader origClassLoader = Utility.getClassLoader();
121121
boolean setCL = false;
122-
123122
try {
124-
125123
try {
126-
127-
String refInterface = ejbRefDesc.isEJB30ClientView() ?
128-
ejbRefDesc.getEjbInterface() : ejbRefDesc.getHomeClassName();
124+
String refInterface = ejbRefDesc.isEJB30ClientView()
125+
? ejbRefDesc.getEjbInterface()
126+
: ejbRefDesc.getHomeClassName();
129127
origClassLoader.loadClass(refInterface);
130128

131-
} catch(ClassNotFoundException e) {
132-
133-
ClassLoader referringBundleClassLoader =
134-
ejbRefDesc.getReferringBundleDescriptor().getClassLoader();
135-
Utility.setContextClassLoader(referringBundleClassLoader);
136-
setCL = true;
137-
129+
} catch (ClassNotFoundException e) {
130+
ClassLoader referringBundleClassLoader = ejbRefDesc.getReferringBundleDescriptor().getClassLoader();
131+
Utility.setContextClassLoader(referringBundleClassLoader);
132+
setCL = true;
138133
}
139134

140135
/* For remote ejb refs, first lookup the target remote object
@@ -147,8 +142,7 @@ public Object resolveEjbReference(EjbReferenceDescriptor ejbRefDesc, Context con
147142
* MEJB resolution for cluster support post V3 FCS.
148143
*/
149144
if (remoteJndiName.hasCorbaPrefix()) {
150-
GlassFishORBHelper orbHelper = glassFishORBHelperProvider.get();
151-
ORB orb = orbHelper.getORB();
145+
ORB orb = orbLocatorProvider.get().getORB();
152146
jndiObj = orb.string_to_object(remoteJndiName.toString());
153147
} else {
154148
jndiObj = context.lookup(remoteJndiName.toString());
@@ -190,17 +184,13 @@ public Object getEJBContextObject(String contextType) {
190184

191185
if(currentInv == null) {
192186
throw new IllegalStateException("no current invocation");
193-
} else if (currentInv.getInvocationType() !=
194-
ComponentInvocation.ComponentInvocationType.EJB_INVOCATION) {
195-
throw new IllegalStateException
196-
("Illegal invocation type for EJB Context : "
197-
+ currentInv.getInvocationType());
187+
} else if (currentInv.getInvocationType() != ComponentInvocation.ComponentInvocationType.EJB_INVOCATION) {
188+
throw new IllegalStateException(
189+
"Illegal invocation type for EJB Context : " + currentInv.getInvocationType());
198190
}
199191

200192
EjbInvocation ejbInv = (EjbInvocation) currentInv;
201-
202193
Object returnObject = ejbInv.context;
203-
204194
if (contextType.equals("jakarta.ejb.TimerService")) {
205195
if (EJBTimerService.getEJBTimerService() == null) {
206196
throw new IllegalStateException("EJB Timer Service not available");

appserver/ejb/ejb-container/src/main/java/com/sun/ejb/base/io/EJBObjectInputStreamHandler.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (c) 2025 Contributors to the Eclipse Foundation
23
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
34
*
45
* This program and the accompanying materials are made available under the
@@ -25,7 +26,7 @@
2526
import java.util.logging.Level;
2627
import java.util.logging.Logger;
2728

28-
import org.glassfish.enterprise.iiop.api.GlassFishORBHelper;
29+
import org.glassfish.enterprise.iiop.api.GlassFishORBLocator;
2930
import org.glassfish.enterprise.iiop.api.ProtocolManager;
3031
import org.glassfish.internal.api.Globals;
3132

@@ -69,14 +70,8 @@ public Object resolveObject(Object obj)
6970
}
7071
}
7172

72-
/**
73-
* Do all ProtocolManager access lazily and only request orb if it has already been
74-
* initialized so that code doesn't make the assumption that an orb is available in
75-
* this runtime.
76-
*/
7773
private ProtocolManager getProtocolManager() {
78-
GlassFishORBHelper orbHelper = Globals.getDefaultHabitat().getService(GlassFishORBHelper.class);
79-
return orbHelper.isORBInitialized() ? orbHelper.getProtocolManager() : null;
74+
GlassFishORBLocator orbLocator = Globals.getDefaultHabitat().getService(GlassFishORBLocator.class);
75+
return orbLocator.getProtocolManager();
8076
}
81-
8277
}

appserver/ejb/ejb-container/src/main/java/com/sun/ejb/base/io/EJBObjectOutputStreamHandler.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2021, 2025 Contributors to the Eclipse Foundation.
33
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
44
*
55
* This program and the accompanying materials are made available under the
@@ -40,7 +40,7 @@
4040

4141
import org.glassfish.api.naming.GlassfishNamingManager;
4242
import org.glassfish.api.naming.SimpleJndiName;
43-
import org.glassfish.enterprise.iiop.api.GlassFishORBHelper;
43+
import org.glassfish.enterprise.iiop.api.GlassFishORBLocator;
4444
import org.glassfish.enterprise.iiop.api.ProtocolManager;
4545
import org.glassfish.internal.api.Globals;
4646

@@ -92,14 +92,9 @@ public Object replaceObject(Object obj) throws IOException {
9292
}
9393

9494

95-
/**
96-
* Do all ProtocolManager access lazily and only request orb if it has already been
97-
* initialized so that code doesn't make the assumption that an orb is available in
98-
* this runtime.
99-
*/
10095
private ProtocolManager getProtocolManager() {
101-
GlassFishORBHelper orbHelper = Globals.getDefaultHabitat().getService(GlassFishORBHelper.class);
102-
return orbHelper.isORBInitialized() ? orbHelper.getProtocolManager() : null;
96+
GlassFishORBLocator orbLocator = Globals.getDefaultHabitat().getService(GlassFishORBLocator.class);
97+
return orbLocator.getProtocolManager();
10398
}
10499

105100

@@ -199,7 +194,7 @@ protected static java.rmi.Remote doRemoteRefClassLoaderConversion(final java.rmi
199194
byte[] serializedRef = EJBObjectOutputStreamHandler._javaEEIOUtils.serializeObject(reference, false);
200195
Remote returnReference = (java.rmi.Remote) EJBObjectOutputStreamHandler._javaEEIOUtils
201196
.deserializeObject(serializedRef, false, contextClassLoader);
202-
GlassFishORBHelper orbHelper = EjbContainerUtilImpl.getInstance().getORBHelper();
197+
GlassFishORBLocator orbHelper = EjbContainerUtilImpl.getInstance().getOrbLocator();
203198
ProtocolManager protocolMgr = orbHelper.getProtocolManager();
204199
protocolMgr.connectObject(returnReference);
205200
return returnReference;

appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/BaseContainer.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2025 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2022, 2025 Contributors to the Eclipse Foundation.
33
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
44
*
55
* This program and the accompanying materials are made available under the
@@ -142,7 +142,6 @@
142142
import org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor;
143143
import org.glassfish.ejb.spi.EjbContainerInterceptor;
144144
import org.glassfish.ejb.spi.WSEjbEndpointRegistry;
145-
import org.glassfish.enterprise.iiop.api.GlassFishORBHelper;
146145
import org.glassfish.enterprise.iiop.api.ProtocolManager;
147146
import org.glassfish.enterprise.iiop.api.RemoteReferenceFactory;
148147
import org.glassfish.enterprise.iiop.spi.EjbContainerFacade;
@@ -765,9 +764,7 @@ private void addToGeneratedMonitoredMethodInfo(Class generatedClass) {
765764

766765
protected void initializeProtocolManager() {
767766
try {
768-
GlassFishORBHelper orbHelper = ejbContainerUtilImpl.getORBHelper();
769-
protocolMgr = orbHelper.getProtocolManager();
770-
767+
protocolMgr = ejbContainerUtilImpl.getOrbLocator().getProtocolManager();
771768
} catch (Throwable t) {
772769
throw new RuntimeException(
773770
"IIOP Protocol Manager initialization failed. " + "Possible cause is that ORB is not available in this "

appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EjbContainerUtil.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2022, 2025 Contributors to the Eclipse Foundation.
33
* Copyright (c) 2008, 2020 Oracle and/or its affiliates. All rights reserved.
44
*
55
* This program and the accompanying materials are made available under the
@@ -38,7 +38,7 @@
3838
import org.glassfish.api.naming.GlassfishNamingManager;
3939
import org.glassfish.ejb.config.EjbContainer;
4040
import org.glassfish.ejb.config.EjbTimerService;
41-
import org.glassfish.enterprise.iiop.api.GlassFishORBHelper;
41+
import org.glassfish.enterprise.iiop.api.GlassFishORBLocator;
4242
import org.glassfish.flashlight.provider.ProbeProviderFactory;
4343
import org.glassfish.hk2.api.ServiceLocator;
4444
import org.glassfish.internal.api.ServerContext;
@@ -64,7 +64,7 @@ public interface EjbContainerUtil {
6464
// Used by the TimerService upgrade
6565
String TIMER_SERVICE_UPGRADED = "ejb-timer-service-upgraded";
6666

67-
GlassFishORBHelper getORBHelper();
67+
GlassFishORBLocator getOrbLocator();
6868

6969
ServiceLocator getServices();
7070

appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EjbContainerUtilImpl.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2021, 2025 Contributors to the Eclipse Foundation.
33
* Copyright (c) 2008, 2020 Oracle and/or its affiliates. All rights reserved.
44
*
55
* This program and the accompanying materials are made available under the
@@ -63,7 +63,7 @@
6363
import org.glassfish.ejb.config.EjbContainer;
6464
import org.glassfish.ejb.config.EjbTimerService;
6565
import org.glassfish.ejb.spi.CMPDeployer;
66-
import org.glassfish.enterprise.iiop.api.GlassFishORBHelper;
66+
import org.glassfish.enterprise.iiop.api.GlassFishORBLocator;
6767
import org.glassfish.flashlight.provider.ProbeProviderFactory;
6868
import org.glassfish.hk2.api.PostConstruct;
6969
import org.glassfish.hk2.api.PreDestroy;
@@ -93,7 +93,7 @@ public class EjbContainerUtilImpl implements PostConstruct, PreDestroy, EjbConta
9393
private ServerContext serverContext;
9494

9595
@Inject
96-
JavaEEIOUtils javaEEIOUtils;
96+
private JavaEEIOUtils javaEEIOUtils;
9797

9898
private final Map<Long, BaseContainer> id2Container = new ConcurrentHashMap<>();
9999

@@ -123,7 +123,7 @@ public class EjbContainerUtilImpl implements PostConstruct, PreDestroy, EjbConta
123123
private EjbContainer ejbContainer;
124124

125125
@Inject
126-
private GlassFishORBHelper orbHelper;
126+
private GlassFishORBLocator orbLocator;
127127

128128
@Inject
129129
private ServerEnvironmentImpl env;
@@ -138,13 +138,13 @@ public class EjbContainerUtilImpl implements PostConstruct, PreDestroy, EjbConta
138138
private EjbAsyncInvocationManager ejbAsyncInvocationManager;
139139

140140
@Inject
141-
ProbeProviderFactory probeProviderFactory;
141+
private ProbeProviderFactory probeProviderFactory;
142142

143143
@Inject
144-
Domain domain;
144+
private Domain domain;
145145

146146
@Inject
147-
Provider<Deployment> deploymentProvider;
147+
private Provider<Deployment> deploymentProvider;
148148

149149
@Inject
150150
private Provider<CMPDeployer> cmpDeployerProvider;
@@ -199,8 +199,8 @@ public void preDestroy() {
199199
}
200200

201201
@Override
202-
public GlassFishORBHelper getORBHelper() {
203-
return orbHelper;
202+
public GlassFishORBLocator getOrbLocator() {
203+
return orbLocator;
204204
}
205205

206206
@Override

appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/GlassFishORBFactory.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (c) 2025 Contributors to the Eclipse Foundation
23
* Copyright (c) 2009, 2021 Oracle and/or its affiliates. All rights reserved.
34
*
45
* This program and the accompanying materials are made available under the
@@ -16,10 +17,13 @@
1617

1718
package org.glassfish.enterprise.iiop.api;
1819

20+
import com.sun.enterprise.deployment.EjbDescriptor;
21+
1922
import java.util.Properties;
2023

2124
import org.jvnet.hk2.annotations.Contract;
2225
import org.omg.CORBA.ORB;
26+
import org.omg.PortableInterceptor.IORInfo;
2327
import org.omg.PortableInterceptor.ServerRequestInfo;
2428

2529
/**
@@ -33,6 +37,7 @@ public interface GlassFishORBFactory {
3337
String ENV_IS_SERVER_PROPERTY = "com.sun.corba.ee.ORBEnvironmentIsGlassFishServer";
3438

3539
ORB createORB(Properties props);
40+
3641
int getOTSPolicyType();
3742

3843
int getCSIv2PolicyType();
@@ -50,4 +55,6 @@ public interface GlassFishORBFactory {
5055
boolean isEjbCall(ServerRequestInfo sri);
5156

5257
String getIIOPEndpoints();
58+
59+
EjbDescriptor getEjbDescriptor(IORInfo iorInfo);
5360
}

0 commit comments

Comments
 (0)