JCS3CacheImpl.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.cache;

  21. import java.io.ByteArrayOutputStream;
  22. import java.io.FileInputStream;
  23. import java.io.IOException;
  24. import java.io.ObjectOutputStream;
  25. import java.io.OutputStream;
  26. import java.io.Serializable;
  27. import java.util.ArrayList;
  28. import java.util.Arrays;
  29. import java.util.Enumeration;
  30. import java.util.List;
  31. import java.util.Properties;
  32. import java.util.Set;

  33. import org.apache.commons.jcs3.JCS;
  34. import org.apache.commons.jcs3.access.CacheAccess;
  35. import org.apache.commons.jcs3.admin.CountingOnlyOutputStream;
  36. import org.apache.commons.jcs3.admin.JCSAdminBean;
  37. import org.apache.commons.jcs3.engine.CacheElementSerialized;
  38. import org.apache.commons.jcs3.engine.behavior.ICacheElement;
  39. import org.apache.commons.jcs3.engine.behavior.ICompositeCacheAttributes;
  40. import org.apache.commons.jcs3.engine.behavior.IElementAttributes;
  41. import org.apache.commons.jcs3.engine.control.CompositeCache;
  42. import org.apache.commons.jcs3.engine.memory.behavior.IMemoryCache;
  43. import org.apache.commons.jcs3.log.LogManager;
  44. import org.openspcoop2.utils.Utilities;
  45. import org.openspcoop2.utils.UtilsException;
  46. import org.openspcoop2.utils.properties.CollectionProperties;
  47. import org.openspcoop2.utils.properties.PropertiesUtilities;
  48. import org.slf4j.Logger;

  49. /**
  50.  * JCS3CacheImpl
  51.  *
  52.  * @author Poli Andrea (apoli@link.it)
  53.  * @author $Author$
  54.  * @version $Rev$, $Date$
  55.  */
  56. public class JCS3CacheImpl extends AbstractCacheImpl {

  57.     public static void setLog4jSystem() {
  58.         System.setProperty("jcs.logSystem", LogManager.LOGSYSTEM_LOG4J2);
  59.     }
  60.     public static boolean initialize(Logger logConsole,Logger logCore,
  61.             String cachePropertiesName,
  62.             String rootDirectory,Properties objectProperties,
  63.             String OPENSPCOOP2_LOCAL_HOME,String OPENSPCOOP2_CACHE_PROPERTIES,String OPENSPCOOP2_CACHE_LOCAL_PATH){
  64.         try{
  65.            
  66.             // Originale
  67.             java.util.Properties cacheProperties = new java.util.Properties();
  68.             java.io.File loggerFile = new java.io.File(rootDirectory+cachePropertiesName);
  69.             if(loggerFile .exists() == false ){
  70.                 cacheProperties.load(Cache.class.getResourceAsStream("/"+cachePropertiesName));
  71.             }else{
  72.                 FileInputStream fin = null;
  73.                 try{
  74.                     fin = new java.io.FileInputStream(loggerFile);
  75.                     cacheProperties.load(fin);
  76.                 }finally{
  77.                     try{
  78.                         if(fin!=null){
  79.                             fin.close();
  80.                         }
  81.                     }catch(Exception eClose){
  82.                         // close
  83.                     }
  84.                 }
  85.             }
  86.            
  87.             // File Local Implementation
  88.             CollectionProperties cachePropertiesRidefinito =  
  89.                 PropertiesUtilities.searchLocalImplementation(OPENSPCOOP2_LOCAL_HOME,logConsole, OPENSPCOOP2_CACHE_PROPERTIES ,OPENSPCOOP2_CACHE_LOCAL_PATH, rootDirectory);
  90.             if(cachePropertiesRidefinito!=null && cachePropertiesRidefinito.size()>0){
  91.                 Enumeration<?> ridefinito = cachePropertiesRidefinito.keys();
  92.                 while (ridefinito.hasMoreElements()) {
  93.                     String key = (String) ridefinito.nextElement();
  94.                     String value = (String) cachePropertiesRidefinito.get(key);
  95.                     if(cacheProperties.containsKey(key)){
  96.                         //Object o =
  97.                         cacheProperties.remove(key);
  98.                     }
  99.                     cacheProperties.put(key, value);
  100.                     //System.out.println("CHECK NUOVO VALORE: "+loggerProperties.get(key));
  101.                 }
  102.             }
  103.            
  104.             // File Object Implementation
  105.             if(objectProperties!=null && objectProperties.size()>0){
  106.                 Enumeration<?> ridefinito = objectProperties.keys();
  107.                 while (ridefinito.hasMoreElements()) {
  108.                     String key = (String) ridefinito.nextElement();
  109.                     String value = (String) objectProperties.get(key);
  110.                     if(cacheProperties.containsKey(key)){
  111.                         //Object o =
  112.                         cacheProperties.remove(key);
  113.                     }
  114.                     cacheProperties.put(key, value);
  115.                     //System.out.println("CHECK NUOVO VALORE: "+loggerProperties.get(key));
  116.                 }
  117.             }
  118.            
  119.             JCS.setConfigProperties(cacheProperties);
  120.            
  121.             return true;
  122.            
  123.         }catch(Exception e){
  124.             logCore.error("Riscontrato errore durante l'inizializzazione del sistema di cache: "
  125.                     +e.getMessage(),e);
  126.             return false;
  127.         }
  128.     }
  129.    
  130.    
  131.     private CacheAccess<Object, Serializable> cache = null;
  132.     @SuppressWarnings("unused")
  133.     private JCSAdminBean cacheAdmin = null;
  134.    
  135.     private JCS3CacheImpl() {
  136.         // Metodo usato per le utilities
  137.         setLog4jSystem();
  138.         this.cacheAdmin = new JCSAdminBean();
  139.     }
  140.     public JCS3CacheImpl(String name) throws UtilsException{
  141.         this(name, org.openspcoop2.utils.cache.Cache.DEFAULT_DISABLE_SYNCRONIZED_GET);
  142.     }
  143.     @Deprecated
  144.     private JCS3CacheImpl(String name, boolean disableSyncronizedGet) throws UtilsException{
  145.         super(CacheType.JCS, name);
  146.         setLog4jSystem();
  147.         try{
  148.             this.cacheAdmin = new JCSAdminBean();
  149.             this.cache = JCS.getInstance(this.cacheName);
  150.             if(disableSyncronizedGet) {
  151.                 // Dalla versione 3.0 non è più presente la gestione del synchronized
  152.                 //this.cache.getCacheControl().setSyncDisabled(disableSyncronizedGet);
  153.             }
  154.         }catch(Exception e){
  155.             throw new UtilsException(e.getMessage(),e);
  156.         }
  157.     }
  158.    
  159.    
  160.     //  *** Inizializzazione ***
  161.    
  162.     @Override
  163.     public int getCacheSize() {
  164.         return this.cache.getCacheAttributes().getMaxObjects();
  165.     }
  166.     @Override
  167.     public void setCacheSize(int cacheSize) {
  168.         // E' necessario prendere l'oggetto e poi risettarlo a causa di un bug.
  169.         ICompositeCacheAttributes attr = this.cache.getCacheAttributes();
  170.         attr.setMaxObjects(cacheSize);
  171.         this.cache.setCacheAttributes(attr);
  172.     }

  173.     @Override
  174.     public CacheAlgorithm getCacheAlgoritm() {
  175.         return CacheAlgorithm.toEnum(this.cache.getCacheAttributes().getCacheName());
  176.     }
  177.     @Override
  178.     public void setCacheAlgoritm(CacheAlgorithm cacheAlgoritm) {
  179.         // E' necessario prendere l'oggetto e poi risettarlo a causa di un bug.
  180.         ICompositeCacheAttributes attr = this.cache.getCacheAttributes();
  181.         attr.setCacheName(cacheAlgoritm.getAlgorithm());
  182.         this.cache.setCacheAttributes(attr);
  183.     }

  184.     @Override
  185.     public long getItemIdleTime() throws UtilsException {
  186.         try{
  187.             return this.cache.getDefaultElementAttributes().getIdleTime();
  188.         }catch(Exception e){
  189.             throw new UtilsException(e.getMessage(),e);
  190.         }
  191.     }
  192.     @Override
  193.     public void setItemIdleTime(long itemIdleTimeCache) throws UtilsException {
  194.         try{
  195.             // E' necessario prendere l'oggetto e poi risettarlo a causa di un bug.
  196.             IElementAttributes el = this.cache.getDefaultElementAttributes();
  197.             el.setIdleTime(itemIdleTimeCache);
  198.             this.cache.setDefaultElementAttributes(el);
  199.         }catch(Exception e){
  200.             throw new UtilsException(e.getMessage(),e);
  201.         }
  202.     }

  203.     @Override
  204.     public long getItemLifeTime() throws UtilsException {
  205.         try{
  206.             return this.cache.getDefaultElementAttributes().getMaxLife();
  207.         }catch(Exception e){
  208.             throw new UtilsException(e.getMessage(),e);
  209.         }
  210.     }
  211.     @Override
  212.     public boolean isEternal() throws UtilsException {
  213.         try{
  214.             return this.cache.getDefaultElementAttributes().getIsEternal();
  215.         }catch(Exception e){
  216.             throw new UtilsException(e.getMessage(),e);
  217.         }
  218.     }
  219.     @Override
  220.     public void setItemLifeTime(long itemLifeTimeCache) throws UtilsException {
  221.         try{
  222.             // E' necessario prendere l'oggetto e poi risettarlo a causa di un bug.
  223.             IElementAttributes el = this.cache.getDefaultElementAttributes();
  224.             if(itemLifeTimeCache>0) {
  225.                 el.setIsEternal(false);
  226.                 el.setMaxLife(itemLifeTimeCache);
  227.             }
  228.             else {
  229.                 el.setIsEternal(true);
  230.                 el.setMaxLife(-1);
  231.             }
  232.             this.cache.setDefaultElementAttributes(el);
  233.         }catch(Exception e){
  234.             throw new UtilsException(e.getMessage(),e);
  235.         }
  236.     }
  237.    
  238.     @Override
  239.     public void build() throws UtilsException{
  240.         // nop; le operazioni di aggiustamento delle dimensioni, si fanno direttamente sugli oggetti
  241.     }
  242.    
  243.    
  244.     //  *** Gestione ***
  245.    
  246.     @Override
  247.     public void clear() throws UtilsException{
  248.         if(this.cache!=null){
  249.             try{
  250.                 this.cache.clear();
  251.             }catch(Exception e){
  252.                 throw new UtilsException(e.getMessage(),e);
  253.             }
  254.         }
  255.     }
  256.    
  257.     @Override
  258.     public Object get(String key){
  259.         return this.cache.get(this.formatKeyCache(key));
  260.     }
  261.    
  262.     @Override
  263.     public void remove(String key) throws UtilsException{
  264.         try{
  265.             this.cache.remove(this.formatKeyCache(key));
  266.         }catch(Exception e){
  267.             throw new UtilsException(e.getMessage(),e);
  268.         }  
  269.     }
  270.    
  271.     @Override
  272.     public void put(String key,org.openspcoop2.utils.cache.CacheResponse value) throws UtilsException{
  273.         try{
  274.             this.cache.put(this.formatKeyCache(key), value);
  275.         }catch(Exception e){
  276.             throw new UtilsException(e.getMessage(),e);
  277.         }
  278.     }
  279.     @Override
  280.     public void put(String key,Serializable value) throws UtilsException{
  281.         try{
  282.             this.cache.put(this.formatKeyCache(key), value);
  283.         }catch(Exception e){
  284.             throw new UtilsException(e.getMessage(),e);
  285.         }
  286.     }
  287.    
  288.     private String formatKeyCache(String key) {
  289.         // org/apache/commons/jcs/engine/control/CompositeCache.java
  290.         //      if ( cacheElement.getKey() instanceof String
  291.         //              && cacheElement.getKey().toString().endsWith( NAME_COMPONENT_DELIMITER ) )
  292.         //          {
  293.         //              throw new IllegalArgumentException( "key must not end with " + NAME_COMPONENT_DELIMITER
  294.         //                  + " for a put operation" );
  295.         //          }
  296.         //
  297.         // Dove in org.apache.commons.jcs3.engine.behavior.ICache
  298.         //      public static final String NAME_COMPONENT_DELIMITER = ":";

  299.         /*StringBuilder bf = new StringBuilder(key);
  300.         if(bf.toString().endsWith(org.apache.commons.jcs3.engine.behavior.ICache.NAME_COMPONENT_DELIMITER)){
  301.             bf.append("_");
  302.         }
  303.         return bf.toString();*/
  304.         if(key.endsWith(org.apache.commons.jcs3.engine.behavior.ICache.NAME_COMPONENT_DELIMITER)) {
  305.             return key+"_";
  306.         }
  307.         else {
  308.             return key;
  309.         }
  310.     }
  311.    
  312.     @Override
  313.     public int getItemCount()  throws UtilsException {
  314.         CompositeCache<Object, Serializable> cache = JCSAdminBean.getCompositeCacheManager().getCache(this.cacheName);
  315.         return cache.getSize();
  316.     }
  317.    
  318.     @Override
  319.     public List<String> keys() throws UtilsException {
  320.         try{
  321.            
  322.             List<String> keys = new ArrayList<>();
  323.             Serializable[] keysObject = this.cache.getCacheControl().getKeySet().toArray(new Serializable[0]);
  324.             if(keysObject!=null){
  325.                 for (int i = 0; i < keysObject.length; i++) {
  326.                     keys.add((String)keysObject[i]);
  327.                 }
  328.             }
  329.             return keys;
  330.        
  331.         }catch(Exception e){
  332.             throw new UtilsException(e.getMessage(),e);
  333.         }
  334.     }
  335.    
  336.    
  337.    
  338.     //  *** Info ***
  339.    
  340.     @Override
  341.     public void printStats(OutputStream out, String separator) throws UtilsException{
  342.         this.printStats(this.cacheName,out,separator,true);
  343.     }
  344.    
  345.     private void printStats(String cacheName, OutputStream out, String separator, boolean thisCache) throws UtilsException {
  346.        
  347.         try{
  348.        
  349.             StringBuilder bf = new StringBuilder();
  350.            
  351.             CompositeCache<Object, Serializable> cache = JCSAdminBean.getCompositeCacheManager().getCache(cacheName);
  352.                        
  353.             //bf.append(Utilities.convertBytesToFormatString(region.getByteCount()));
  354.             // NOTA: e' stato re-implementato il metodo poiche' casualmente avveniva un errore del tipo:
  355.             //       Problem getting byte count.  Likley cause is a non serilizable object.null
  356.             //       Il problema derivava dall'implementazione del metodo all'interno della classe org/apache/commons/jcs/admin/JCSAdminBean
  357.             //       Viene utilizzato l'iterator dentro una struttura dinamica che cambia.
  358.             //       A volte, quando poi veniva registrato l'errore soprastante, avveniva questo errore (scoperto aggiungendo stampe nelle classi di JCS)
  359.             //       java.util.ConcurrentModificationException
  360.             //          at java.util.Hash table$Enumerator.next(Hash table.java:1031)
  361.             //          at org.apache.commons.jcs3.engine.memory.lru.LRUMemoryCache$IteratorWrapper.next(LRUMemoryCache.java:428)
  362.             //          at org.apache.commons.jcs3.admin.JCSAdminBean.getByteCount(JCSAdminBean.java:95)
  363.             int tentativi = 0;
  364.             long sizeAttuale = -1;
  365.             while (tentativi<10) {
  366.                 sizeAttuale = this.getByteCount(cache);
  367.                 if(this.errorOccursCountingBytes==false){
  368.                     break;
  369.                 }
  370.                 if(thisCache){
  371.                     //System.err.println("PROVO ALTRO TENTATIVO");
  372.                     tentativi++;
  373.                     cache = JCSAdminBean.getCompositeCacheManager().getCache(cacheName);
  374.                 }
  375.                 else{
  376.                     break;
  377.                 }
  378.             }
  379.                
  380.            
  381.             bf.append("Nome:");
  382.             bf.append(cacheName);
  383.             bf.append(" ");
  384.            
  385.             bf.append(separator);
  386.            
  387.             bf.append("Tipo:");
  388.             bf.append(CacheType.JCS);
  389.             bf.append(" ");
  390.            
  391.             bf.append(separator);
  392.            
  393.             bf.append("Stato:");
  394.             bf.append(cache.getStatus());
  395.             bf.append(" ");
  396.            
  397.             bf.append(separator);
  398.            
  399.             // Dalla versione 3.0 non è più presente la gestione del synchronized
  400. //          bf.append("GetSyncDisabled:");
  401. //          bf.append(cache.isSyncDisabled());
  402. //          bf.append(" ");
  403. //          
  404. //          bf.append(separator);
  405.            
  406.             if(cache.getCacheAttributes()!=null){
  407.            
  408.                 bf.append("Algoritmo:");
  409.                 String cacheAlgoName = cache.getCacheAttributes().getCacheName();
  410.                 CacheAlgorithm cacheEnum = CacheAlgorithm.toEnum(cacheAlgoName);
  411.                 if(cacheEnum!=null){
  412.                     bf.append(cacheEnum.name());
  413.                 }else{
  414.                     bf.append(cacheAlgoName);
  415.                 }
  416.                 bf.append(" ");
  417.                
  418.                 bf.append(separator);
  419.                
  420.                 bf.append("Dimensione:");
  421.                 bf.append(cache.getCacheAttributes().getMaxObjects());
  422.                 bf.append(" ");
  423.                
  424.                 bf.append(separator);
  425.                
  426.             }
  427.            
  428.             bf.append("ElementiInCache:");
  429.             bf.append(cache.getSize());
  430.             bf.append(" ");
  431.            
  432.             bf.append(separator);
  433.            
  434.             bf.append("MemoriaOccupata:");
  435.             if(this.errorOccursCountingBytes){
  436.                 bf.append("[WARN !Error occurs counting bytes, re-try!]");
  437.             }
  438.             bf.append(Utilities.convertBytesToFormatString(sizeAttuale));
  439.             bf.append(" ");
  440.            
  441.             bf.append(separator);
  442.            
  443.             if(cache.getElementAttributes()!=null){
  444.            
  445.                 bf.append("IdleTime:");
  446.                 long idleTime = cache.getElementAttributes().getIdleTime();
  447.                 if(idleTime>0){
  448.                     bf.append(Utilities.convertSystemTimeIntoStringMillisecondi(idleTime*1000,false));
  449.                 }
  450.                 else if(idleTime==0){
  451.                     bf.append("0");
  452.                 }
  453.                 else if(idleTime<0){
  454.                     bf.append("Infinito");
  455.                 }
  456.                 bf.append(" ");
  457.                
  458.                 bf.append(separator);
  459.                
  460.                 bf.append("LifeTime:");
  461.                 long lifeTime = cache.getElementAttributes().getMaxLife();
  462.                 if(lifeTime>0){
  463.                     bf.append(Utilities.convertSystemTimeIntoStringMillisecondi(lifeTime*1000,false));
  464.                 }
  465.                 else if(lifeTime==0){
  466.                     bf.append("0");
  467.                 }
  468.                 else if(lifeTime<0){
  469.                     if(cache.getElementAttributes().getIsEternal()) {
  470.                         bf.append("Infinito");
  471.                     }
  472.                     else {
  473.                         bf.append("Infinito (NoEternal?)");
  474.                     }
  475.                 }
  476.                 bf.append(" ");
  477.                
  478.                 bf.append(separator);
  479.            
  480.             }
  481.            
  482.             bf.append("PutCount:");
  483.             bf.append(cache.getUpdateCount());
  484.             bf.append(" ");
  485.            
  486.             bf.append(separator);
  487.            
  488.             bf.append("HitCount(Aux):");
  489.             bf.append(cache.getHitCountAux());
  490.             bf.append(" ");
  491.            
  492.             bf.append(separator);
  493.            
  494.             bf.append("HitCount(Ram):");
  495.             bf.append(cache.getHitCountRam());
  496.             bf.append(" ");
  497.            
  498.             bf.append(separator);
  499.            
  500.             bf.append("MissCount(Expired):");
  501.             bf.append(cache.getMissCountExpired());
  502.             bf.append(" ");
  503.            
  504.             bf.append(separator);
  505.            
  506.             bf.append("MissCount(NotFound):");
  507.             bf.append(cache.getMissCountNotFound());
  508.             bf.append(" ");
  509.            
  510.             out.write(bf.toString().getBytes());
  511.            
  512.         }catch(Exception e){
  513.             throw new UtilsException(e.getMessage(),e);
  514.         }
  515.     }
  516.    
  517.     private boolean errorOccursCountingBytes_debug = false;
  518.     private boolean errorOccursCountingBytes = false;
  519.     public <K, V> long getByteCount(CompositeCache<K, V> cache)
  520.     {
  521.         this.errorOccursCountingBytes = false;
  522.        
  523.         if (cache == null)
  524.         {
  525.             throw new IllegalArgumentException("The cache object specified was null.");
  526.         }

  527.         long size = 0;
  528.         IMemoryCache<K, V> memCache = cache.getMemoryCache();

  529.         try {
  530.             for (K key : memCache.getKeySet())
  531.             {
  532.                 ICacheElement<K, V> ice = null;
  533.                 try
  534.                 {
  535.                     ice = memCache.get(key);
  536.                 }
  537.                 catch (IOException e)
  538.                 {
  539.                     //Modificato per openspcoop
  540.                     if(this.errorOccursCountingBytes_debug) {
  541.                         System.err.println("["+this.cacheName+"] Element cache get");
  542.                         e.printStackTrace(System.err);
  543.                     }
  544.                     this.errorOccursCountingBytes = true;
  545.                     continue;
  546.                     //throw new RuntimeException("IOException while trying to get a cached element", e);
  547.                 }

  548.                 if (ice == null)
  549.                 {
  550.                     continue;
  551.                 }

  552.                 if (ice instanceof CacheElementSerialized)
  553.                 {
  554.                     size += ((CacheElementSerialized<K, V>) ice).getSerializedValue().length;
  555.                 }
  556.                 else
  557.                 {
  558.                     Object element = ice.getVal();
  559.                     if(element == null) {
  560.                         //Modificato per openspcoop
  561.                         if(this.errorOccursCountingBytes_debug) {
  562.                             System.err.println("["+this.cacheName+"] Element cache is null");
  563.                         }
  564.                         this.errorOccursCountingBytes = true;
  565.                         continue;
  566.                     }

  567.                     //CountingOnlyOutputStream: Keeps track of the number of bytes written to it, but doesn't write them anywhere.
  568.                     CountingOnlyOutputStream counter = new CountingOnlyOutputStream();
  569.                     try (ObjectOutputStream out = new ObjectOutputStream(counter);)
  570.                     {
  571.                         out.writeObject(element);
  572.                     }
  573.                     catch (IOException e)
  574.                     {
  575.                         // Modificato per openspcoop
  576.                         if(this.errorOccursCountingBytes_debug) {
  577.                             System.err.println("["+this.cacheName+"] Element cache writeObject ("+element.getClass().getName()+")");
  578.                             e.printStackTrace(System.err);
  579.                         }
  580.                         this.errorOccursCountingBytes = true;
  581.                         continue;
  582.                         //throw new RuntimeException("IOException while trying to measure the size of the cached element", e);
  583.                     }
  584.                     finally
  585.                     {
  586.                         try
  587.                         {
  588.                             counter.close();
  589.                         }
  590.                         catch (IOException e)
  591.                         {
  592.                             // ignore
  593.                         }
  594.                     }

  595.                     // 4 bytes lost for the serialization header
  596.                    size += counter.getCount() - 4;
  597.                 }
  598.             }
  599.         }
  600.         catch ( Exception e )
  601.         {
  602.             System.err.println( "Problem getting byte count (Modified by GovWay).  Likley cause is a non serilizable object." + e.getMessage() );
  603.             e.printStackTrace(System.err);  
  604.         }

  605.         return size;
  606.     }
  607.    
  608.     public static String printAllStats(String separatorStat, String separatorCache) throws UtilsException {
  609.         try{
  610.             ByteArrayOutputStream bout = new ByteArrayOutputStream();
  611.             printAllStats(bout,separatorStat,separatorCache);
  612.             bout.flush();
  613.             bout.close();
  614.             return bout.toString();
  615.         }catch(Exception e){
  616.             throw new UtilsException(e.getMessage(),e);
  617.         }
  618.     }
  619.     public static void printAllStats(OutputStream out, String separatorStat, String separatorCache) throws UtilsException {
  620.         try{
  621.             JCS3CacheImpl cacheUtility = new JCS3CacheImpl();
  622.            
  623.             Set<String> cacheNames_tmp = JCSAdminBean.getCompositeCacheManager().getCacheNames();
  624.             if(cacheNames_tmp.size()>0) {
  625.                 String[] cacheNames = new String[cacheNames_tmp.size()];
  626.                 int index = 0;
  627.                 for (String name : cacheNames_tmp) {
  628.                     cacheNames[index] = name;
  629.                     index++;
  630.                 }
  631.                 Arrays.sort( cacheNames );
  632.                 for ( int i = 0; i < cacheNames.length; i++ ) {
  633.                     cacheUtility.printStats(cacheNames[i],out,separatorStat,false);
  634.                     out.write(separatorCache.getBytes());
  635.                 }
  636.             }
  637.         }catch(Exception e){
  638.             throw new UtilsException(e.getMessage(),e);
  639.         }
  640.     }
  641.    
  642.    
  643.    
  644.    
  645.     //  *** Sincronizzazione ***
  646.    
  647.     @SuppressWarnings("deprecation")
  648.     @Override
  649.     @Deprecated
  650.     public void disableSyncronizedGet() throws UtilsException {
  651.         if(this.cache==null) {
  652.             throw new UtilsException("Cache disabled");
  653.         }
  654.         try{
  655.             // Dalla versione 3.0 non è più presente la gestione del synchronized
  656.             //this.cache.getCacheControl().setSyncDisabled(true);
  657.         }catch(Exception e){
  658.             throw new UtilsException(e.getMessage(),e);
  659.         }
  660.     }
  661.     @SuppressWarnings("deprecation")
  662.     @Override
  663.     @Deprecated
  664.     public boolean isDisableSyncronizedGet() throws UtilsException {
  665.         if(this.cache==null) {
  666.             throw new UtilsException("Cache disabled");
  667.         }
  668.         try{
  669.             // Dalla versione 3.0 non è più presente la gestione del synchronized
  670.             //return this.cache.getCacheControl().isSyncDisabled();
  671.             return true;
  672.         }catch(Exception e){
  673.             throw new UtilsException(e.getMessage(),e);
  674.         }
  675.     }
  676.    
  677.     @SuppressWarnings("deprecation")
  678.     @Override
  679.     @Deprecated
  680.     public void enableDebugSystemOut() throws UtilsException {
  681.         if(this.cache==null) {
  682.             throw new UtilsException("Cache disabled");
  683.         }
  684.         try{
  685.             // Dalla versione 3.0 non è più presente la gestione del synchronized
  686.             //this.cache.getCacheControl().setDebugSystemOut(true);
  687.         }catch(Exception e){
  688.             throw new UtilsException(e.getMessage(),e);
  689.         }
  690.     }
  691.     @SuppressWarnings("deprecation")
  692.     @Override
  693.     @Deprecated
  694.     public boolean isEnableDebugSystemOut() throws UtilsException {
  695.         if(this.cache==null) {
  696.             throw new UtilsException("Cache disabled");
  697.         }
  698.         try{
  699.             // Dalla versione 3.0 non è più presente la gestione del synchronized
  700.             //return this.cache.getCacheControl().isDebugSystemOut();
  701.             return false;
  702.         }catch(Exception e){
  703.             throw new UtilsException(e.getMessage(),e);
  704.         }
  705.     }
  706. }