All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.weld.context.AbstractManagedContext Maven / Gradle / Ivy

There is a newer version: 6.0.0.Beta4
Show newest version
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();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy