InitProcessor.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.DatiCollezionati;
  23. import org.openspcoop2.core.controllo_traffico.beans.IDUnivocoGroupByPolicy;

  24. import com.hazelcast.core.Offloadable;
  25. import com.hazelcast.map.EntryProcessor;

  26. /**
  27.  *

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

  29. 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.

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

  31. 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.

  32. 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.

  33.  * @author Francesco Scarlato (scarlato@link.it)
  34.  * @author $Author$
  35.  * @version $Rev$, $Date$
  36.  */
  37. public class InitProcessor implements EntryProcessor<IDUnivocoGroupByPolicy, DatiCollezionati, DatiCollezionati>, Offloadable {
  38.    
  39.     private static final long serialVersionUID = 1L;
  40.    
  41.     private DatiCollezionati dati = null;
  42.    
  43.     public InitProcessor(DatiCollezionati dati) {
  44.         this.dati = dati;
  45.     }
  46.    
  47.     @Override
  48.     public DatiCollezionati process(Entry<IDUnivocoGroupByPolicy, DatiCollezionati> entry) {
  49.         if(entry.getValue()==null) {
  50.             // devo inizializarla solo allo startup del primo nodo. Gli altri troveranno il valore gia' presente
  51.             entry.setValue(this.dati);
  52.         }
  53.         return entry.getValue();
  54.     }

  55.     @Override
  56.     public String getExecutorName() {
  57.         return "hz:offloadable";
  58.     }
  59. }