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

pl.morgwai.base.guice.scopes.InducedContextScope Maven / Gradle / Ivy

Go to download

Classes for building Guice scopes, that get automatically transferred when dispatching work to other threads

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy