Skip to content

Commit

Permalink
Merge branch 'apache-3.1' into apache-3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbumenJ committed Mar 12, 2023
2 parents 100a442 + 234f1c6 commit 179e1e7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;

/**
* {@link ExtensionLoader}, {@code DubboBootstrap} and this class are at present designed to be
Expand Down Expand Up @@ -344,6 +345,11 @@ public void setDeployer(ApplicationDeployer deployer) {
this.deployer = deployer;
}

@Override
protected Lock acquireDestroyLock() {
return frameworkModel.acquireDestroyLock();
}

// =============================== Deprecated Methods Start =======================================

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;

/**
Expand All @@ -48,7 +50,7 @@ public class FrameworkModel extends ScopeModel {
private static final AtomicLong index = new AtomicLong(1);

private static final Object globalLock = new Object();

private volatile static FrameworkModel defaultInstance;

private static final List<FrameworkModel> allInstances = new CopyOnWriteArrayList<>();
Expand All @@ -68,6 +70,8 @@ public class FrameworkModel extends ScopeModel {

private final ApplicationModel internalApplicationModel;

private final ReentrantLock destroyLock = new ReentrantLock();

/**
* Use {@link FrameworkModel#newModel()} to create a new model
*/
Expand Down Expand Up @@ -356,6 +360,12 @@ public FrameworkServiceRepository getServiceRepository() {
return serviceRepository;
}


@Override
protected Lock acquireDestroyLock() {
return destroyLock;
}

@Override
public Environment getModelEnvironment() {
throw new UnsupportedOperationException("Environment is inaccessible for FrameworkModel");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.util.HashMap;
import java.util.Set;
import java.util.concurrent.locks.Lock;

/**
* Model of a service module
Expand Down Expand Up @@ -173,6 +174,11 @@ public void setDeployer(ModuleDeployer deployer) {
this.deployer = deployer;
}

@Override
protected Lock acquireDestroyLock() {
return getApplicationModel().getFrameworkModel().acquireDestroyLock();
}

/**
* for ut only
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;

import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_UNABLE_DESTROY_MODEL;

Expand Down Expand Up @@ -109,8 +110,12 @@ protected void initialize() {
}
}

protected abstract Lock acquireDestroyLock();

public void destroy() {
synchronized (instLock) {
Lock lock = acquireDestroyLock();
try {
lock.lock();
if (destroyed.compareAndSet(false, true)) {
try {
onDestroy();
Expand All @@ -128,6 +133,8 @@ public void destroy() {
LOGGER.error(CONFIG_UNABLE_DESTROY_MODEL, "", "", "Error happened when destroying ScopeModel.", t);
}
}
} finally {
lock.unlock();
}
}

Expand Down

0 comments on commit 179e1e7

Please sign in to comment.