Skip to content

Commit

Permalink
ARIES-696: Make sure scheduled futures are appropriately purge, so Bl…
Browse files Browse the repository at this point in the history
…ueprint does not loose memory for timeout periods ...

git-svn-id: https://svn.apache.org/repos/asf/aries/trunk/blueprint/blueprint-core@1141853 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Valentin Mahrwald committed Jul 1, 2011
1 parent 4f6afed commit c437e07
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -122,7 +122,7 @@ private enum State {
private final List<Object> pathList;
private final ComponentDefinitionRegistryImpl componentDefinitionRegistry;
private final AggregateConverter converter;
private final ScheduledExecutorService executors;
private final ScheduledThreadPoolExecutor executors;
private Set<URI> namespaces;
private State state = State.Unknown;
private NamespaceHandlerSet handlerSet;
Expand All @@ -143,7 +143,7 @@ private enum State {
private AccessControlContext accessControlContext;
private final IdSpace tempRecipeIdSpace = new IdSpace();

public BlueprintContainerImpl(BundleContext bundleContext, Bundle extenderBundle, BlueprintListener eventDispatcher, NamespaceHandlerRegistry handlers, ScheduledExecutorService executors, List<Object> pathList) {
public BlueprintContainerImpl(BundleContext bundleContext, Bundle extenderBundle, BlueprintListener eventDispatcher, NamespaceHandlerRegistry handlers, ScheduledThreadPoolExecutor executors, List<Object> pathList) {
this.bundleContext = bundleContext;
this.extenderBundle = extenderBundle;
this.eventDispatcher = eventDispatcher;
Expand Down Expand Up @@ -330,6 +330,7 @@ public void run() {
break;
case Create:
timeoutFuture.cancel(false);
executors.purge();
registerServices();
instantiateEagerComponents();
// Register the BlueprintContainer in the OSGi registry
Expand Down Expand Up @@ -814,15 +815,18 @@ public void destroy() {

if (timeoutFuture != null) {
timeoutFuture.cancel(false);
executors.purge();
}
AriesFrameworkUtil.safeUnregisterService(registration);
if (handlerSet != null) {
handlerSet.removeListener(this);
handlerSet.destroy();
}

unregisterServices();

synchronized (running) {
if (handlerSet != null) {
handlerSet.removeListener(this);
handlerSet.destroy();
}

while (running.get()) {
try {
running.wait();
Expand All @@ -846,6 +850,7 @@ protected void quiesce() {

if (timeoutFuture != null) {
timeoutFuture.cancel(false);
executors.purge();
}
AriesFrameworkUtil.safeUnregisterService(registration);
if (handlerSet != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

import java.util.concurrent.ScheduledThreadPoolExecutor;
import org.apache.aries.blueprint.BlueprintConstants;
import org.apache.aries.blueprint.annotation.service.BlueprintAnnotationScanner;
import org.apache.aries.blueprint.namespace.NamespaceHandlerRegistryImpl;
Expand Down Expand Up @@ -64,12 +63,12 @@
*/
public class BlueprintExtender implements BundleActivator, SynchronousBundleListener {

/** The QuiesceParticipant implementation class name */
private static final String QUIESCE_PARTICIPANT_CLASS = "org.apache.aries.quiesce.participant.QuiesceParticipant";
/** The QuiesceParticipant implementation class name */
private static final String QUIESCE_PARTICIPANT_CLASS = "org.apache.aries.quiesce.participant.QuiesceParticipant";
private static final Logger LOGGER = LoggerFactory.getLogger(BlueprintExtender.class);

private BundleContext context;
private ScheduledExecutorService executors;
private ScheduledThreadPoolExecutor executors;
private Map<Bundle, BlueprintContainerImpl> containers;
private BlueprintEventDispatcher eventDispatcher;
private NamespaceHandlerRegistry handlers;
Expand All @@ -83,7 +82,7 @@ public void start(BundleContext ctx) {

this.context = ctx;
handlers = new NamespaceHandlerRegistryImpl(ctx);
executors = Executors.newScheduledThreadPool(3, new BlueprintThreadFactory("Blueprint Extender"));
executors = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(3, new BlueprintThreadFactory("Blueprint Extender"));
eventDispatcher = new BlueprintEventDispatcher(ctx, executors);
containers = new HashMap<Bundle, BlueprintContainerImpl>();

Expand Down Expand Up @@ -152,7 +151,7 @@ private void checkInitialBundle(Bundle b) {
public void stop(BundleContext context) {
LOGGER.debug("Stopping blueprint extender...");
if (bt != null) {
bt.close();
bt.close();
}

AriesFrameworkUtil.safeUnregisterService(parserServiceReg);
Expand Down Expand Up @@ -444,7 +443,7 @@ public void removedBundle(Bundle b, BundleEvent event, Object arg2) {

protected BlueprintContainerImpl getBlueprintContainerImpl(Bundle bundle)
{
return containers.get(bundle);
return containers.get(bundle);
}

}

0 comments on commit c437e07

Please sign in to comment.