ApplicationTransaction.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.utils.logger.beans.context.application;

  21. import java.io.Serializable;
  22. import java.util.ArrayList;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;

  26. import org.openspcoop2.utils.logger.beans.context.core.AbstractTransactionWithClient;
  27. import org.openspcoop2.utils.logger.beans.context.core.BaseServer;

  28. /**
  29.  * ApplicationTransaction
  30.  *
  31.  * @author Poli Andrea (apoli@link.it)
  32.  * @author $Author$
  33.  * @version $Rev$, $Date$
  34.  */
  35. public class ApplicationTransaction extends AbstractTransactionWithClient implements Serializable {

  36.     /**
  37.      *
  38.      */
  39.     private static final long serialVersionUID = 1L;


  40.     private List<BaseServer> servers = new ArrayList<>();
  41.    
  42.     public List<BaseServer> getServers() {
  43.         return this.servers;
  44.     }
  45.    
  46.     public Map<String, BaseServer> getServersMap() {
  47.         Map<String, BaseServer> map = new HashMap<>();
  48.         int index = 1;
  49.         for (BaseServer baseServer : this.servers) {
  50.             if(baseServer.getName()!=null && !map.containsKey(baseServer.getName())) {
  51.                 map.put(baseServer.getName(), baseServer);
  52.             }
  53.             else {
  54.                 map.put("_server-"+index, baseServer);
  55.             }
  56.             index++;
  57.         }
  58.         return map;
  59.     }
  60.    
  61.     public void addServer(BaseServer server) {
  62.         this.servers.add(server);
  63.     }
  64.    
  65.     public int sizeServers() {
  66.         return this.servers.size();
  67.     }
  68.    
  69.     public BaseServer getServer(int index) {
  70.         return this.servers.get(index);
  71.     }
  72.    
  73.     public BaseServer getServer(String name) {
  74.         for (BaseServer baseServer : this.servers) {
  75.             if(name.equals(baseServer.getName())) {
  76.                 return baseServer;
  77.             }
  78.         }
  79.         return null;
  80.     }
  81.    
  82.     public BaseServer getLastServer() {
  83.         return this.servers.get(this.servers.size()-1);
  84.     }
  85.    
  86.     public BaseServer getFirstServer() {
  87.         return this.servers.get(0);
  88.     }
  89. }