Search in sources :

Example 6 with InternalContext

use of org.elasticsearch.common.inject.internal.InternalContext in project elasticsearch by elastic.

the class InjectorImpl method callInContext.

/**
     * Looks up thread local context. Creates (and removes) a new context if necessary.
     */
<T> T callInContext(ContextualCallable<T> callable) throws ErrorsException {
    Object[] reference = localContext.get();
    if (reference == null) {
        reference = new Object[1];
        localContext.set(reference);
    }
    if (reference[0] == null) {
        reference[0] = new InternalContext();
        try {
            return callable.call((InternalContext) reference[0]);
        } finally {
            // Only clear the context if this call created it.
            reference[0] = null;
        }
    } else {
        // Someone else will clean up this context.
        return callable.call((InternalContext) reference[0]);
    }
}
Also used : InternalContext(org.elasticsearch.common.inject.internal.InternalContext)

Aggregations

InternalContext (org.elasticsearch.common.inject.internal.InternalContext)6 Errors (org.elasticsearch.common.inject.internal.Errors)4 ErrorsException (org.elasticsearch.common.inject.internal.ErrorsException)4 InternalFactory (org.elasticsearch.common.inject.internal.InternalFactory)2 SourceProvider (org.elasticsearch.common.inject.internal.SourceProvider)2 Dependency (org.elasticsearch.common.inject.spi.Dependency)2