Skip to content

Commit

Permalink
Quick code cleanup
Browse files Browse the repository at this point in the history
- I would like to do more, but it has too many open ends connected even to
  different libraries like glassfish-corba-orb

Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Feb 13, 2024
1 parent 6f6b961 commit 9fbe46d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,18 @@ public class GlassFishORBHelper implements ORBLocator {
private ProcessEnvironment processEnv;

@Inject
Provider<ProtocolManager> protocolManagerProvider;
private Provider<ProtocolManager> protocolManagerProvider;

@Inject
Provider<GlassfishNamingManager> glassfishNamingManagerProvider;
private Provider<GlassfishNamingManager> glassfishNamingManagerProvider;

private volatile ORB orb;
private ProtocolManager protocolManager;
private SelectableChannelDelegate selectableChannelDelegate;
private GlassFishORBFactory orbFactory;
private boolean destroyed;

// volatile is enough for sync, just one thread can write
private volatile ORB orb;
private volatile boolean destroyed;

@PostConstruct
public void postConstruct() {
Expand All @@ -87,6 +89,7 @@ public void onShutdown() {
}
}

// Called by PEORBConfigurator executed from glassfish-corba-orb.jar
public synchronized void setORB(ORB orb) {
this.orb = orb;
}
Expand All @@ -100,55 +103,54 @@ public ORB getORB() {
// Use a volatile double-checked locking idiom here so that we can publish
// a partly-initialized ORB early, so that lazy init can come into getORB()
// and allow an invocation to the transport to complete.
if (orb == null && !destroyed) {

synchronized (this) {
if (orb == null) {
try {
boolean isServer = processEnv.getProcessType().isServer();

Properties props = new Properties();
props.setProperty(GlassFishORBFactory.ENV_IS_SERVER_PROPERTY, Boolean.toString(isServer));
if (orb != null || destroyed) {
return orb;
}

// Create orb and make it visible.
//
// This will allow loopback calls to getORB() from portable interceptors activated as a
// side-effect of the remaining initialization.
//
// If it's a server, there's a small time window during which the ProtocolManager won't be available.
// Any callbacks that result from the protocol manager initialization itself cannot depend on having
// access to the protocol manager.
orb = orbFactory.createORB(props);
synchronized (this) {
if (orb != null) {
return orb;
}
try {
final boolean isServer = processEnv.getProcessType().isServer();

if (isServer) {
if (protocolManager == null) {
ProtocolManager tempProtocolManager = protocolManagerProvider.get();
final Properties props = new Properties();
props.setProperty(GlassFishORBFactory.ENV_IS_SERVER_PROPERTY, Boolean.toString(isServer));

tempProtocolManager.initialize(orb);
// Create orb and make it visible.
//
// This will allow loopback calls to getORB() from portable interceptors activated as a
// side-effect of the remaining initialization.
//
// If it's a server, there's a small time window during which the ProtocolManager won't be available.
// Any callbacks that result from the protocol manager initialization itself cannot depend on having
// access to the protocol manager.
orb = orbFactory.createORB(props);

// Move startup of naming to PEORBConfigurator so it runs before interceptors.
tempProtocolManager.initializePOAs();
if (isServer) {
if (protocolManager == null) {
final ProtocolManager tempProtocolManager = protocolManagerProvider.get();

// Now make protocol manager visible.
protocolManager = tempProtocolManager;
tempProtocolManager.initialize(orb);

GlassfishNamingManager namingManager = glassfishNamingManagerProvider.get();
// Move startup of naming to PEORBConfigurator so it runs before interceptors.
tempProtocolManager.initializePOAs();

Remote remoteSerialProvider = namingManager.initializeRemoteNamingSupport(orb);
// Now make protocol manager visible.
protocolManager = tempProtocolManager;

protocolManager.initializeRemoteNaming(remoteSerialProvider);
}
}
} catch (Exception e) {
orb = null;
protocolManager = null;
throw new RuntimeException("Orb initialization erorr", e);
final GlassfishNamingManager namingManager = glassfishNamingManagerProvider.get();
final Remote remoteSerialProvider = namingManager.initializeRemoteNamingSupport(orb);
protocolManager.initializeRemoteNaming(remoteSerialProvider);
}
}
return orb;
} catch (Exception e) {
orb = null;
protocolManager = null;
throw new RuntimeException("Orb initialization erorr", e);
}
}

return orb;
}

public void setSelectableChannelDelegate(SelectableChannelDelegate d) {
Expand All @@ -159,27 +161,22 @@ public SelectableChannelDelegate getSelectableChannelDelegate() {
return this.selectableChannelDelegate;
}

public interface SelectableChannelDelegate {
void handleRequest(SelectableChannel channel);
}

/**
* Get a protocol manager for creating remote references. ProtocolManager is only available in the server. Otherwise,
* this method returns null.
*
* If it's the server and the orb hasn't been already created, calling this method has the side effect of creating the
* orb.
* Get a protocol manager for creating remote references.
* ProtocolManager is only available in the server.
* Otherwise, this method returns null.
* If it's the server and the orb hasn't been already created, calling this method has the side
* effect of creating the orb.
*/
public ProtocolManager getProtocolManager() {
if (!processEnv.getProcessType().isServer() || destroyed) {
return null;
}

synchronized (this) {
if (protocolManager == null) {
getORB();
}

return protocolManager;
}
}
Expand Down Expand Up @@ -222,4 +219,7 @@ public boolean isEjbCall(ServerRequestInfo sri) {
return orbFactory.isEjbCall(sri);
}

public interface SelectableChannelDelegate {
void handleRequest(SelectableChannel channel);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -140,7 +140,7 @@ public void handle(ObjectKey objectkey) {
} catch (NoSuchWorkQueueException ex) {
Logger.getLogger(PEORBConfigurator.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

private static void configureCopiers(ORB orb) {
CopierManager cpm = orb.getCopierManager();
Expand Down

0 comments on commit 9fbe46d

Please sign in to comment.