org.jboss.weld.context.AbstractManagedContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of weld-osgi-bundle Show documentation
Show all versions of weld-osgi-bundle Show documentation
Weld runtime packaged as an OSGi bundle
package org.jboss.weld.context;
import static java.lang.Boolean.FALSE;
public abstract class AbstractManagedContext extends AbstractContext implements ManagedContext {
private final ThreadLocal active;
private final ThreadLocal valid;
public AbstractManagedContext(boolean multithreaded) {
super(multithreaded);
this.active = new ThreadLocal();
this.valid = new ThreadLocal();
}
public boolean isActive() {
Boolean active = this.active.get();
return active == null ? false : active.booleanValue();
}
protected void setActive(boolean active) {
this.active.set(active);
}
public void invalidate() {
this.valid.set(FALSE);
}
public void activate() {
setActive(true);
}
private boolean isValid() {
Boolean valid = this.valid.get();
return valid == null ? true : valid.booleanValue();
}
public void deactivate() {
if (!isValid()) {
destroy();
}
active.remove();
}
@Override
public void cleanup() {
super.cleanup();
active.remove();
valid.remove();
}
}