Skip to content

Commit

Permalink
Some more explicit cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Dec 2, 2009
1 parent bdb420a commit 1ab1fef
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 4 deletions.
6 changes: 5 additions & 1 deletion impl/src/main/java/org/jboss/weld/Container.java
Expand Up @@ -25,6 +25,8 @@
import org.jboss.weld.bootstrap.api.Singleton;
import org.jboss.weld.bootstrap.api.SingletonProvider;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.weld.logging.LoggerFactory;
import org.jboss.weld.logging.MessageConveyorFactory;

/**
* A Weld application container
Expand Down Expand Up @@ -102,7 +104,6 @@ public static boolean available()
{
return instance.isSet() && instance() != null && instance().getStatus().isAvailable();
}


/**
* Initialize the container for the current application deployment
Expand Down Expand Up @@ -155,6 +156,9 @@ public void cleanup()

deploymentServices.cleanup();
deploymentManager.cleanup();
LoggerFactory.cleanup();
MessageConveyorFactory.cleanup();
instance.clear();
}

/**
Expand Down
Expand Up @@ -8,25 +8,57 @@
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashSet;
import java.util.concurrent.Callable;

import javassist.util.proxy.MethodHandler;

import org.jboss.weld.Container;
import org.jboss.weld.NullInstanceException;
import org.jboss.weld.bootstrap.api.Service;
import org.slf4j.cal10n.LocLogger;

public class CallableMethodHandler implements MethodHandler, Serializable
{

public static class CallableMethodHandlerCleaner implements Service
{

private final Collection<CallableMethodHandler> callableMethodHandlers;

public CallableMethodHandlerCleaner()
{
this.callableMethodHandlers = new HashSet<CallableMethodHandler>();
}

private void add(CallableMethodHandler callableMethodHandler)
{
this.callableMethodHandlers.add(callableMethodHandler);
}

public void cleanup()
{
for (CallableMethodHandler callableMethodHandler : callableMethodHandlers)
{
callableMethodHandler.cleanup();
}
callableMethodHandlers.clear();
}

}

private static final long serialVersionUID = -1348302663981663427L;
private static final LocLogger log = loggerFactory().getLogger(BEAN);

private final Callable<?> callable;
// Can't make this final, need to deallocate on shutdown
private Callable<?> callable;

public CallableMethodHandler(Callable<?> callable)
{
super();
this.callable = callable;
Container.instance().deploymentServices().get(CallableMethodHandlerCleaner.class).add(this);
}

public Object invoke(Object self, Method proxiedMethod, Method proceed, Object[] args) throws Throwable
Expand Down Expand Up @@ -60,5 +92,10 @@ public Object invoke(Object self, Method proxiedMethod, Method proceed, Object[]
}
}
}

private void cleanup()
{
this.callable = null;
}

}
@@ -0,0 +1 @@

Expand Up @@ -46,6 +46,7 @@
import org.jboss.weld.Validator;
import org.jboss.weld.Container.Status;
import org.jboss.weld.bean.builtin.BeanManagerBean;
import org.jboss.weld.bean.builtin.CallableMethodHandler.CallableMethodHandlerCleaner;
import org.jboss.weld.bootstrap.api.Bootstrap;
import org.jboss.weld.bootstrap.api.Environment;
import org.jboss.weld.bootstrap.api.Lifecycle;
Expand Down Expand Up @@ -320,6 +321,7 @@ private ServiceRegistry getImplementationServices(ResourceLoader resourceLoader)
services.add(MetaAnnotationStore.class, new MetaAnnotationStore(services.get(ClassTransformer.class)));
services.add(ContextualStore.class, new ContextualStoreImpl());
services.add(ServiceLoaderFactory.class, new DefaultServiceLoaderFactory());
services.add(CallableMethodHandlerCleaner.class, new CallableMethodHandlerCleaner());
return services;
}

Expand Down
11 changes: 10 additions & 1 deletion impl/src/main/java/org/jboss/weld/logging/LoggerFactory.java
Expand Up @@ -10,7 +10,12 @@
public class LoggerFactory
{

private static LoggerFactory INSTANCE = new LoggerFactory("WELD");
private static LoggerFactory INSTANCE;

public static void cleanup()
{
INSTANCE = null;
}

private final LocLoggerFactory locLoggerFactory;
private final IMessageConveyor messageConveyor;
Expand All @@ -33,6 +38,10 @@ public XLogger getXLogger(Category category)

public static LoggerFactory loggerFactory()
{
if (INSTANCE == null)
{
INSTANCE = new LoggerFactory("WELD");
}
return INSTANCE;
}

Expand Down
Expand Up @@ -9,7 +9,7 @@
public abstract class MessageConveyorFactory
{

private static MessageConveyorFactory INSTANCE = load();
private static MessageConveyorFactory INSTANCE;

private static MessageConveyorFactory load()
{
Expand All @@ -29,9 +29,18 @@ private static MessageConveyorFactory load()

public static MessageConveyorFactory messageConveyerFactory()
{
if (INSTANCE == null)
{
INSTANCE = load();
}
return INSTANCE;
}

public static void cleanup()
{
INSTANCE = null;
}

public static IMessageConveyor defaultMessageConveyer(String subsystem)
{
return messageConveyerFactory().getDefaultMessageConveyer(subsystem);
Expand Down

0 comments on commit 1ab1fef

Please sign in to comment.