/** * Looks up thread local context and {@link InternalContext#enter() enters} it or creates a new * context if necessary. * * <p>All callers of this are responsible for calling {@link InternalContext#close()}. Typical * usage should look like: * * <pre>{@code * InternalContext ctx = injector.enterContext(); * try { * ... use ctx ... * } finally { * ctx.close(); * } * }</pre> */ InternalContext enterContext() { Object[] reference = localContext.get(); if (reference == null) { reference = new Object[1]; localContext.set(reference); } InternalContext ctx = (InternalContext) reference[0]; if (ctx == null) { reference[0] = ctx = new InternalContext(options, reference); } else { ctx.enter(); } return ctx; }
/** * Looks up thread local context and {@link InternalContext#enter() enters} it or creates a new * context if necessary. * * <p>All callers of this are responsible for calling {@link InternalContext#close()}. Typical * usage should look like: * * <pre>{@code * InternalContext ctx = injector.enterContext(); * try { * ... use ctx ... * } finally { * ctx.close(); * } * }</pre> */ InternalContext enterContext() { Object[] reference = localContext.get(); if (reference == null) { reference = new Object[1]; localContext.set(reference); } InternalContext ctx = (InternalContext) reference[0]; if (ctx == null) { reference[0] = ctx = new InternalContext(options, reference); } else { ctx.enter(); } return ctx; }
/** * Looks up thread local context and {@link InternalContext#enter() enters} it or creates a new * context if necessary. * * <p>All callers of this are responsible for calling {@link InternalContext#close()}. Typical * usage should look like: * * <pre>{@code * InternalContext ctx = injector.enterContext(); * try { * ... use ctx ... * } finally { * ctx.close(); * } * }</pre> */ InternalContext enterContext() { Object[] reference = localContext.get(); if (reference == null) { reference = new Object[1]; localContext.set(reference); } InternalContext ctx = (InternalContext) reference[0]; if (ctx == null) { reference[0] = ctx = new InternalContext(options, reference); } else { ctx.enter(); } return ctx; }
/** 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[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]); } }
/** 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[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]); } }
/** 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[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]); } }
reference[0] = new InternalContext(options); globalInternalContext.put(currentThread, (InternalContext) reference[0]); try {