org.restexpress.plugin.statechange.StateContext Maven / Gradle / Ivy
/*
Copyright 2014, Strategic Gains, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.restexpress.plugin.statechange;
import java.util.Collections;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
/**
* The StateContext class maintains a Map of name/value pairs much like the
* Log4j mapped diagnostic context (MDC). A StateContext,
* is an instrument for passing augmentation data from different sources to
* lower levels in the framework for each message received.
*
* The StateContext is managed on a per thread basis. A child
* thread automatically inherits a copy of the state context of its parent.
*
* The class requires JDK 1.6 or above.
*
* The StateContext is cleaned up after each request by removing the values set by that request,
* since all threads are pooled and re-used. This is accomplished via a call to
* StateContext.clear()
in a finally processor within the StateChangePlugin.
*
* @author toddf
* @since Feb 17, 2014
*/
public class StateContext
{
final static StateContext SC = new StateContext();
private ThreadLocal