StartRequestProcessor.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.Date;
  22. import java.util.Map.Entry;

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

  31. import com.hazelcast.core.Offloadable;
  32. import com.hazelcast.map.EntryProcessor;

  33. /**
  34.  *

  35. You can use the following system properties to configure the Near Cache invalidation:

  36. hazelcast.map.invalidation.batch.enabled: Enable or disable batching. Its default value is true. When it is set to false, all invalidations are sent immediately.

  37. hazelcast.map.invalidation.batch.size: Maximum number of invalidations in a batch. Its default value is 100.

  38. hazelcast.map.invalidation.batchfrequency.seconds: If the collected invalidations do not reach the configured batch size, a background process sends them periodically. Its default value is 10 seconds.

  39. If there are a lot of clients or many mutating operations, batching should remain enabled and the batch size should be configured with the hazelcast.map.invalidation.batch.size system property to a suitable value.

  40.  *
  41.  * @author Francesco Scarlato (scarlato@link.it)
  42.  * @author $Author$
  43.  * @version $Rev$, $Date$
  44.  */
  45. public class StartRequestProcessor implements EntryProcessor<IDUnivocoGroupByPolicy, DatiCollezionati, DatiCollezionati>, Offloadable {
  46.    
  47.     private static final long serialVersionUID = 1L;
  48.     private final ActivePolicy activePolicy;
  49.     private final Map<Object> ctx;

  50.     public StartRequestProcessor(ActivePolicy policy, Map<Object> ctx) {
  51.         this.activePolicy = policy;
  52.         this.ctx = ctx;
  53.     }
  54.    
  55.     @Override
  56.     public DatiCollezionati  process(Entry<IDUnivocoGroupByPolicy, DatiCollezionati> entry) {
  57.         //System.out.println("<"+idTransazione+"> registerStartRequest distribuita");
  58.         OpenSPCoop2Properties op2Properties = OpenSPCoop2Properties.getInstance();
  59.         Logger log = OpenSPCoop2Logger.getLoggerOpenSPCoopControlloTraffico(op2Properties.isControlloTrafficoDebug());

  60.         if (entry.getValue() == null) {
  61.             Date gestorePolicyConfigDate = PolicyDateUtils.readGestorePolicyConfigDateIntoContext(this.ctx);
  62.             entry.setValue(new DatiCollezionati(this.activePolicy.getInstanceConfiguration().getUpdateTime(), gestorePolicyConfigDate));
  63.         }
  64.         else {
  65.             if(entry.getValue().getUpdatePolicyDate()!=null) {
  66.                 if(!entry.getValue().getUpdatePolicyDate().equals(this.activePolicy.getInstanceConfiguration().getUpdateTime())) {
  67.                     // data aggiornata
  68.                     entry.getValue().resetCounters(this.activePolicy.getInstanceConfiguration().getUpdateTime());
  69.                 }
  70.             }
  71.         }

  72.         entry.getValue().registerStartRequest(log, this.activePolicy, this.ctx);
  73.        
  74.         // mi salvo l'attuale stato
  75.         DatiCollezionati datiCollezionatiReaded = (DatiCollezionati) entry.getValue().newInstance();
  76.         // Tutti i restanti controlli sono effettuati usando il valore di datiCollezionatiReaded, che e' gia' stato modificato
  77.         // E' possibile procedere con l'analisi rispetto al valore che possiedono il counter dentro questo scope.
  78.        
  79.         entry.setValue(entry.getValue());
  80.        
  81.         return datiCollezionatiReaded;
  82.     }

  83.     @Override
  84.     public String getExecutorName() {
  85.         return "hz:offloadable";
  86.     }
  87. }