UpdateDatiRequestProcessor.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.pdd.core.controllo_traffico.policy.driver.hazelcast;

  21. import java.util.Map.Entry;

  22. import org.openspcoop2.core.controllo_traffico.beans.ActivePolicy;
  23. import org.openspcoop2.core.controllo_traffico.beans.DatiCollezionati;
  24. import org.openspcoop2.core.controllo_traffico.beans.IDUnivocoGroupByPolicy;
  25. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  26. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  27. import org.openspcoop2.utils.Map;
  28. import org.slf4j.Logger;

  29. import com.hazelcast.core.Offloadable;
  30. import com.hazelcast.map.EntryProcessor;

  31. /**    
  32.  *  UpdateDatiRequestProcessor
  33.  *
  34.  * @author Francesco Scarlato (scarlato@link.it)
  35.  * @author $Author$
  36.  * @version $Rev$, $Date$
  37.  */
  38. public class UpdateDatiRequestProcessor implements EntryProcessor<IDUnivocoGroupByPolicy, DatiCollezionati, DatiCollezionati>, Offloadable {
  39.    
  40.     private static final long serialVersionUID = 1L;
  41.     private final ActivePolicy activePolicy;
  42.     private final Map<Object> ctx;

  43.     public UpdateDatiRequestProcessor(ActivePolicy policy, Map<Object> ctx) {
  44.         this.activePolicy = policy;    
  45.         this.ctx = ctx;
  46.     }
  47.    
  48.     @Override
  49.     public DatiCollezionati  process(Entry<IDUnivocoGroupByPolicy, DatiCollezionati> entry) {
  50.         //System.out.println("<"+idTransazione+"> registerStartRequest distribuita");
  51.         if(entry.getValue() == null) {
  52.             //System.out.println("<"/*+idTransazione*/+">updateDatiStartRequestApplicabile Non sono presenti alcun threads registrati per la richiesta con dati identificativi ["+entry.getKey().toString()+"]");
  53.             return null;
  54.         } else {
  55.             OpenSPCoop2Properties op2Properties = OpenSPCoop2Properties.getInstance();
  56.             Logger log = OpenSPCoop2Logger.getLoggerOpenSPCoopControlloTraffico(op2Properties.isControlloTrafficoDebug());

  57.             DatiCollezionati datiCollezionatiReaded = null;
  58.             boolean updated = entry.getValue().updateDatiStartRequestApplicabile(log, this.activePolicy, this.ctx);
  59.             if(updated) {
  60.                 datiCollezionatiReaded = (DatiCollezionati) entry.getValue().newInstance();
  61.                 entry.setValue(entry.getValue());
  62.             }
  63.            
  64.             // Tutti i restanti controlli sono effettuati usando il valore di datiCollezionatiReaded, che e' gia' stato modificato
  65.             // E' possibile procedere con l'analisi rispetto al valore che possiedono il counter dentro questo scope.
  66.             return datiCollezionatiReaded;
  67.         }
  68.     }

  69.     @Override
  70.     public String getExecutorName() {
  71.         return "hz:offloadable";
  72.     }
  73. }