Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,7 @@ private synchronized void checkRetry(int retry, SystemException ex) {
logged(RETRY_LOG, ex, "Allow retry");
}

@SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
// CollocatedServant must be explicitly destroyed in order to make it eligible for garbage collection
if (directServant != null) {
directServant.destroy();
}
super.finalize();
}


// ------------------------------------------------------------------
// Standard IDL to Java Mapping
Expand Down
32 changes: 0 additions & 32 deletions yoko-core/src/main/java/org/apache/yoko/orb/CORBA/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -736,38 +736,6 @@ public boolean poll_response() {
raiseDIIExceptions_ = orb._OB_raiseDIIExceptions();
}

protected void finalize() throws Throwable {
if (state_ == RequestStateSent) {
//
// TODO: This is a memory leak, as a request has been
// sent, but the response has never been picked
// up. The correct thing would be to tell the Downcall
// object to cancel the request. But we don't have
// this ability yet.
//
}

//
// Find out whether this was a deferred request for which
// get_response() hasn't been called yet.
//
ORBInstance orbInstance = delegate_
._OB_ORBInstance();
MultiRequestSender multi = orbInstance
.getMultiRequestSender();
if (multi != null) // It might be possible that the
// MultiRequestSender is already destroyed
{
//
// Remove this request from the list of the outstanding
// deferred requests
//
multi.removeDeferredRequest(this);
}

super.finalize();
}

public boolean _OB_completed() {
synchronized (stateMutex_) {
return state_ == RequestStateReceived;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ public final class ClientManager {
// ClientManager private and protected member implementations
// ----------------------------------------------------------------------

protected void finalize() throws Throwable {
Assert.ensure(destroyed);
Assert.ensure(allClients.isEmpty());
Assert.ensure(reusableClients.isEmpty());

super.finalize();
}

// ----------------------------------------------------------------------
// ClientManager package member implementations
Expand Down
134 changes: 71 additions & 63 deletions yoko-core/src/main/java/org/apache/yoko/orb/OB/DowncallStub.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,20 @@
*/
package org.apache.yoko.orb.OB;

import static java.util.logging.Level.FINE;
import static org.apache.yoko.io.AlignmentBoundary.EIGHT_BYTE_BOUNDARY;
import static org.apache.yoko.util.Arrays.emptyArray;
import static org.apache.yoko.io.Buffer.createWriteBuffer;
import static org.apache.yoko.logging.VerboseLogging.RETRY_LOG;
import static org.apache.yoko.orb.OCI.GiopVersion.GIOP1_2;
import static org.apache.yoko.orb.exceptions.Transients.NO_USABLE_PROFILE_IN_IOR;
import static org.apache.yoko.util.Assert.ensure;
import static org.apache.yoko.util.MinorCodes.MinorShutdownCalled;
import static org.apache.yoko.util.MinorCodes.describeBadInvOrder;
import static org.omg.CORBA.CompletionStatus.COMPLETED_NO;

import java.util.Vector;
import java.util.logging.Logger;

import org.apache.yoko.io.ReadBuffer;
import org.apache.yoko.io.SimplyCloseable;
import org.apache.yoko.io.WriteBuffer;
import org.apache.yoko.orb.CORBA.YokoInputStream;
import org.apache.yoko.orb.CORBA.OutputStreamHolder;
import org.apache.yoko.orb.CORBA.YokoInputStream;
import org.apache.yoko.orb.CORBA.YokoOutputStream;
import org.apache.yoko.orb.IOP.ServiceContexts;
import org.apache.yoko.orb.OCI.ConnectorInfo;
import org.apache.yoko.orb.OCI.ProfileInfo;
import org.apache.yoko.orb.OCI.ProfileInfoHolder;
import org.apache.yoko.orb.OCI.TransportInfo;
import org.apache.yoko.util.Assert;
import org.apache.yoko.util.concurrent.LazyReference;
import org.apache.yoko.util.concurrent.YokoCleaner;
import org.omg.CORBA.BAD_INV_ORDER;
import org.omg.CORBA.BooleanHolder;
import org.omg.CORBA.COMM_FAILURE;
Expand Down Expand Up @@ -84,11 +72,55 @@
import org.omg.Messaging.PolicyValueSeqHolder;
import org.omg.Messaging.ReplyHandler;

import java.util.Vector;
import java.util.logging.Logger;

import static java.util.logging.Level.FINE;
import static org.apache.yoko.io.AlignmentBoundary.EIGHT_BYTE_BOUNDARY;
import static org.apache.yoko.io.Buffer.createWriteBuffer;
import static org.apache.yoko.logging.VerboseLogging.RETRY_LOG;
import static org.apache.yoko.orb.OCI.GiopVersion.GIOP1_2;
import static org.apache.yoko.orb.exceptions.Transients.NO_USABLE_PROFILE_IN_IOR;
import static org.apache.yoko.util.Arrays.emptyArray;
import static org.apache.yoko.util.Assert.ensure;
import static org.apache.yoko.util.MinorCodes.MinorShutdownCalled;
import static org.apache.yoko.util.MinorCodes.describeBadInvOrder;
import static org.omg.CORBA.CompletionStatus.COMPLETED_NO;

//
// DowncallStub is equivalent to the C++ class OB::MarshalStubImpl
//
public final class DowncallStub {
static final Logger logger = Logger.getLogger(DowncallStub.class.getName());
private static final YokoCleaner cleaner = YokoCleaner.create();

//
// Shared state for cleanup - must not reference DowncallStub instance
// Uses LazyReference to handle lazy initialization of clientProfilePairs_
//
private static final class CleanupState {
final ORBInstance orbInstance;
final LazyReference<Vector<ClientProfilePair>> clientProfilePairsRef;

CleanupState(ORBInstance orbInstance, LazyReference<Vector<ClientProfilePair>> clientProfilePairsRef) {
this.orbInstance = orbInstance;
this.clientProfilePairsRef = clientProfilePairsRef;
}

void cleanup() {
ClientManager clientManager = orbInstance.getClientManager();
if (clientManager != null && clientProfilePairsRef != null) {
Vector<ClientProfilePair> pairs = clientProfilePairsRef.get();
if (pairs != null) {
for (ClientProfilePair pair : pairs) {
clientManager.releaseClient(pair.client);
}
pairs.removeAllElements();
}
}
}
}

//
// The ORBInstance object
//
Expand All @@ -107,84 +139,59 @@ public final class DowncallStub {
private RefCountPolicyList policies_;

//
// All client/profile pairs
// All client/profile pairs - uses LazyReference for thread-safe lazy initialization
//
private Vector<ClientProfilePair> clientProfilePairs_;
private final LazyReference<Vector<ClientProfilePair>> clientProfilePairsRef;

//
// We need a class to carry the DowncallStub and Downcall across
// a portable stub invocation
//
private class InvocationContext {
private static class InvocationContext {
DowncallStub downcallStub;

Downcall downcall;
}

// ------------------------------------------------------------------
// Private and protected member implementations
// ------------------------------------------------------------------
private synchronized ClientProfilePair getClientProfilePair() throws FailureException {
// Lazy initialization of the client/profile pairs
if (null == clientProfilePairs_) {
// Get all clients that can be used
ClientManager clientManager = orbInstance_.getClientManager();
clientProfilePairs_ = clientManager.getClientProfilePairs(IOR_, policies_.value);
}
// Get the lazily-initialized client/profile pairs
Vector<ClientProfilePair> pairs = clientProfilePairsRef.get();

// If we can't get any client/profile pairs, set and raise the
// failure exception, and let the stub handle this.
if (clientProfilePairs_.isEmpty()) {
if (pairs.isEmpty()) {
RETRY_LOG.fine(() -> "No profiles available");
throw new FailureException(NO_USABLE_PROFILE_IN_IOR.create());
}
// NB: see handleFailureException() for how clientProfilePairs_ is modified (pruned) in exception
// NB: see handleFailureException() for how clientProfilePairsRef is modified (pruned) in exception
// processing (so the first element may change)
return clientProfilePairs_.elementAt(0);
return pairs.elementAt(0);
}

private void destroy() {
//
// If the ORB has been destroyed then the clientManager can be nil
//
ClientManager clientManager = orbInstance_.getClientManager();

if (clientManager != null && clientProfilePairs_ != null) {
for (ClientProfilePair pair: clientProfilePairs_) {
clientManager.releaseClient(pair.client);
}
}

clientProfilePairs_.removeAllElements();
}

protected void finalize() throws Throwable {
destroy();

super.finalize();
}

// ------------------------------------------------------------------
// Public member implementations
// ------------------------------------------------------------------

public DowncallStub(ORBInstance orbInstance, IOR ior, IOR origIOR, RefCountPolicyList policies) {
clientProfilePairs_ = null;

//
// Save the ORBInstance object
//
// Initialize fields
orbInstance_ = orbInstance;
//
// Save the IOR
//
IOR_ = ior;
origIOR_ = origIOR;

//
// Save the policies
//
policies_ = policies;

// Lazy initialization of client/profile pairs
clientProfilePairsRef = new LazyReference<>(() -> {
ClientManager clientManager = orbInstance_.getClientManager();
return clientManager.getClientProfilePairs(IOR_, policies_.value);
});

// Register cleanup action - uses shared state to avoid referencing 'this'
CleanupState state = new CleanupState(orbInstance_, clientProfilePairsRef);
@SuppressWarnings("resource") SimplyCloseable ignored = cleaner.register(this, state::cleanup);
}

//
Expand Down Expand Up @@ -339,10 +346,11 @@ public synchronized void handleFailureException(ClientProfilePair cp, FailureExc
MinorShutdownCalled,
COMPLETED_NO);

clientProfilePairs_.stream()
Vector<ClientProfilePair> pairs = clientProfilePairsRef.get();
pairs.stream()
.filter(cp::equals)
.findFirst()
.ifPresent(clientProfilePairs_::remove);
.ifPresent(pairs::remove);

// We only retry upon COMM_FAILURE, TRANSIENT, and NO_RESPONSE
try {
Expand All @@ -362,7 +370,7 @@ public synchronized void handleFailureException(ClientProfilePair cp, FailureExc
}

// If no client/profile pairs are left, we cannot retry either
if (clientProfilePairs_.isEmpty()) {
if (pairs.isEmpty()) {
logger.log(FINE, ex.exception, () -> "no profiles left to try");
throw ex;
}
Expand Down
11 changes: 0 additions & 11 deletions yoko-core/src/main/java/org/apache/yoko/orb/OB/GIOPServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,6 @@ final class GIOPServer extends Server {

protected GIOPServerStarter starter_; // The server starter

// ----------------------------------------------------------------------
// GIOPServer private and protected member implementations
// ----------------------------------------------------------------------

protected void finalize() throws Throwable {
ensure(destroy_);
ensure(starter_ == null);

super.finalize();
}

// ----------------------------------------------------------------------
// GIOPServer package member implementations
// ----------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

abstract class GIOPServerStarter {
static final Logger logger = Logger.getLogger(GIOPServerStarter.class.getName());

protected final ORBInstance orbInstance_; // The ORBInstance

protected final Acceptor acceptor_; // The acceptor
Expand All @@ -58,12 +58,6 @@ public boolean cannotTransitionTo(ServerState next) {
// GIOPServer private and protected member implementation
// ----------------------------------------------------------------------

protected void finalize() throws Throwable {
Assert.ensure(serverState == CLOSED);

super.finalize();
}

//
// Emit a trace message when closing the acceptor
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ private static class Service {
// InitialServiceManager private and protected member implementations
// ----------------------------------------------------------------------

protected void finalize() throws Throwable {
Assert.ensure(destroy_);
super.finalize();
}

// ----------------------------------------------------------------------
// InitialServiceManager package member implementations
Expand Down
10 changes: 3 additions & 7 deletions yoko-core/src/main/java/org/apache/yoko/orb/OB/ORBInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ public final class ORBInstance {
private OrbAsyncHandler asyncHandler;
private final AtomicBoolean destroyCalled = new AtomicBoolean(); // True if destroy() was called

protected void finalize() throws Throwable {
Assert.ensure(destroyCalled.get());
super.finalize();
}

public ORBInstance(ORB orb, String orbId, String serverID,
String serverInstance, ObjectFactory objectFactory,
Expand Down Expand Up @@ -201,7 +197,7 @@ public void destroy() {
// CoreTraceLevels is not destroyed -- it is indestructible

// Client and server executors shut down in the ORBControl

conFactoryRegistry = null;
accFactoryRegistry = null;
unknownExceptionStrategy = null;
Expand Down Expand Up @@ -292,11 +288,11 @@ public ExecutorService getServerExecutor() {
public Phaser getServerPhaser() {
return serverPhaser;
}

public ExecutorService getClientExecutor() {
return clientExecutor;
}

public Phaser getClientPhaser() {
return clientPhaser;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

public final class ServerManager {
static final Logger logger = getLogger(ServerManager.class.getName());

private boolean destroy_; // if destroy() was called

private CollocatedServer collocatedServer_; // The collocated server
Expand All @@ -40,13 +40,6 @@ public final class ServerManager {
// ServerManager private and protected member implementations
// ----------------------------------------------------------------------

protected void finalize() throws Throwable {
Assert.ensure(destroy_);
Assert.ensure(allServers_.isEmpty());
Assert.ensure(collocatedServer_ == null);

super.finalize();
}

// ----------------------------------------------------------------------
// ServerManager public member implementations
Expand Down
Loading
Loading