BatchTransaction.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.batch;

  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.AbstractTransaction;
  27. import org.openspcoop2.utils.logger.beans.context.core.BaseServer;

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

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

  40.     private List<BaseServer> servers = new ArrayList<>();

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