pl.morgwai.base.guice.scopes.InducedContextScope Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of guice-context-scopes Show documentation
Show all versions of guice-context-scopes Show documentation
Classes for building Guice scopes, that get automatically transferred when dispatching work to other threads
// Copyright (c) Piotr Morgwai Kotarbinski, Licensed under the Apache License, Version 2.0
package pl.morgwai.base.guice.scopes;
import java.util.function.Function;
/**
* Scopes object to a context induced by another context obtained from the associated
* {@link ContextTracker}. For example HTTP session context may be induced by HTTP servlet request
* context.
*/
public class InducedContextScope<
InducingCtxT extends TrackableContext,
InducedCtxT extends ServerSideContext
> extends ContextScope {
final Function inducer;
public InducedContextScope(
String name,
ContextTracker tracker,
Function inducer) {
super(name, tracker);
this.inducer = inducer;
}
protected ServerSideContext getContext() {
return inducer.apply(tracker.getCurrentContext());
}
}