RequestThreadContext.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.protocol.sdk.state;

  21. import org.slf4j.Logger;

  22. /**
  23.  * RequestThreadContext
  24.  *
  25.  * @author Poli Andrea (apoli@link.it)
  26.  * @author $Author$
  27.  * @version $Rev$, $Date$
  28.  */
  29. public class RequestThreadContext {

  30.     private static Logger log = null;
  31.     public static synchronized void setLog(Logger log) {
  32.         if(RequestThreadContext.log==null) {
  33.             RequestThreadContext.log = log;
  34.         }
  35.     }

  36.     private static final ThreadLocal<RequestThreadContext> transactionContext_threadLocal =  new ThreadLocal<RequestThreadContext>() {
  37.          @Override
  38.          protected RequestThreadContext initialValue() {
  39.              String tName = Thread.currentThread().getName();
  40.              return new RequestThreadContext(tName, log);
  41.          }
  42.     };
  43.    
  44.     public static RequestThreadContext getRequestThreadContext() {
  45.         return transactionContext_threadLocal.get();
  46.     }
  47.    
  48.     public static void removeRequestThreadContext() {
  49.         transactionContext_threadLocal.remove();
  50.     }
  51.    
  52.    
  53.     public RequestThreadContext(String tName, Logger log) {
  54.         this.tName = tName;
  55.         if(log!=null) {
  56.             log.debug("ThreadLocal request context created for thread '"+tName+"'");
  57.         }
  58.     }
  59.    
  60.     private String tName;
  61.    
  62.     private RequestFruitore requestFruitoreTrasportoInfo;
  63.     private RequestFruitore requestFruitoreTokenInfo;

  64.     public RequestFruitore getRequestFruitoreTrasportoInfo() {
  65.         return this.requestFruitoreTrasportoInfo;
  66.     }
  67.     public void setRequestFruitoreTrasportoInfo(RequestFruitore requestFruitoreTrasportoInfo) {
  68.         this.requestFruitoreTrasportoInfo = requestFruitoreTrasportoInfo;
  69.     }

  70.     public RequestFruitore getRequestFruitoreTokenInfo() {
  71.         return this.requestFruitoreTokenInfo;
  72.     }
  73.     public void setRequestFruitoreTokenInfo(RequestFruitore requestFruitoreTokenInfo) {
  74.         this.requestFruitoreTokenInfo = requestFruitoreTokenInfo;
  75.     }


  76.     public String gettName() {
  77.         return this.tName;
  78.     }

  79.     public void clear() {
  80.         this.requestFruitoreTrasportoInfo = null;
  81.         this.requestFruitoreTokenInfo = null;
  82.     }

  83. }