package at.gv.egovernment.moa.spss.server.invoke;
import at.gv.egovernment.moa.logging.LoggingContext;
import at.gv.egovernment.moa.logging.LoggingContextManager;
import at.gv.egovernment.moa.spss.server.config.ConfigurationException;
import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider;
import at.gv.egovernment.moa.spss.server.transaction.TransactionContext;
import at.gv.egovernment.moa.spss.server.transaction.TransactionContextManager;
/**
* A utility class for setting up and tearing down thread-local context
* information needed for calling the Invoker
classes.
*
* @author Patrick Peck
* @version $Id$
*/
public class ServiceContextUtils {
/**
* Set up the thread-local context information needed for calling the various
* Invoker
classes.
*
* @throws ConfigurationException An error occurred setting up the
* configuration in the TransactionContext
.
*/
public static void setUpContexts() throws ConfigurationException {
TransactionContextManager txMgr = TransactionContextManager.getInstance();
LoggingContextManager logMgr = LoggingContextManager.getInstance();
String transactionID = Thread.currentThread().getName();
if (txMgr.getTransactionContext() == null) {
TransactionContext ctx = new TransactionContext(transactionID, null, ConfigurationProvider.getInstance());
txMgr.setTransactionContext(ctx);
}
if (logMgr.getLoggingContext() == null) {
LoggingContext ctx = new LoggingContext(transactionID);
logMgr.setLoggingContext(ctx);
}
}
/**
* Tear down thread-local context information.
*/
public static void tearDownContexts() {
TransactionContextManager.getInstance().setTransactionContext(null);
LoggingContextManager.getInstance().setLoggingContext(null);
}
}