GestoreConsegnaApplicativi.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.jmx;

  21. import java.util.ArrayList;
  22. import java.util.Iterator;
  23. import java.util.List;

  24. import javax.management.Attribute;
  25. import javax.management.AttributeList;
  26. import javax.management.AttributeNotFoundException;
  27. import javax.management.DynamicMBean;
  28. import javax.management.InvalidAttributeValueException;
  29. import javax.management.JMException;
  30. import javax.management.MBeanAttributeInfo;
  31. import javax.management.MBeanConstructorInfo;
  32. import javax.management.MBeanException;
  33. import javax.management.MBeanInfo;
  34. import javax.management.MBeanOperationInfo;
  35. import javax.management.MBeanParameterInfo;
  36. import javax.management.NotificationBroadcasterSupport;
  37. import javax.management.ReflectionException;

  38. import org.openspcoop2.core.commons.CoreException;
  39. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  40. import org.openspcoop2.core.id.IDConnettore;
  41. import org.openspcoop2.pdd.config.ConfigurazionePdD;
  42. import org.openspcoop2.pdd.config.ConfigurazionePdDManager;
  43. import org.openspcoop2.pdd.config.ConfigurazionePdDReader;
  44. import org.openspcoop2.pdd.core.behaviour.built_in.load_balance.GestoreLoadBalancerCaching;
  45. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  46. import org.openspcoop2.pdd.services.OpenSPCoop2Startup;
  47. import org.slf4j.Logger;


  48. /**
  49.  * Implementazione JMX per la gestione della Configurazione di OpenSPCoop
  50.  *  
  51.  * @author Poli Andrea (apoli@link.it)
  52.  * @author $Author$
  53.  * @version $Rev$, $Date$
  54.  */
  55. public class GestoreConsegnaApplicativi extends NotificationBroadcasterSupport implements DynamicMBean {

  56.     /** Nomi proprieta' */
  57.     public static final String MAX_LIFE_PRESA_IN_CONSEGNA = "maxlifePresaInConsegna";

  58.     /** Nomi metodi' */
  59.     public static final String THREAD_POOL_STATUS = "getThreadPoolStatus";
  60.     public static final String QUEUE_CONFIG = "getQueueConfig";
  61.     public static final String GET_APPLICATIVI_PRIORITARI = "getApplicativiPrioritari";
  62.     public static final String GET_CONNETTORI_PRIORITARI = "getConnettoriPrioritari";
  63.     public static final String UPDATE_CONNETTORI_PRIORITARI = "updateConnettoriPrioritari";
  64.     public static final String RESET_CONNETTORI_PRIORITARI = "resetConnettoriPrioritari";
  65.        
  66.     /** Attributi */
  67.     private boolean cacheAbilitata = false;
  68.     private int maxLifePresaInConsegna = -1;
  69.    
  70.     /** getAttribute */
  71.     @Override
  72.     public Object getAttribute(String attributeName) throws AttributeNotFoundException,MBeanException,ReflectionException{
  73.        
  74.         if( (attributeName==null) || (attributeName.equals("")) )
  75.             throw new IllegalArgumentException("Il nome dell'attributo e' nullo o vuoto");
  76.        
  77.         if(attributeName.equals(JMXUtils.CACHE_ATTRIBUTE_ABILITATA))
  78.             return this.cacheAbilitata;
  79.        
  80.         if(attributeName.equals(GestoreConsegnaApplicativi.MAX_LIFE_PRESA_IN_CONSEGNA))
  81.             return this.maxLifePresaInConsegna;
  82.        
  83.         throw new AttributeNotFoundException("Attributo "+attributeName+" non trovato");
  84.     }
  85.    
  86.     /** getAttributes */
  87.     @Override
  88.     public AttributeList getAttributes(String [] attributesNames){
  89.        
  90.         if(attributesNames==null)
  91.             throw new IllegalArgumentException("Array nullo");
  92.        
  93.         AttributeList list = new AttributeList();
  94.         for (int i=0; i<attributesNames.length; i++){
  95.             try{
  96.                 list.add(new Attribute(attributesNames[i],getAttribute(attributesNames[i])));
  97.             }catch(JMException ex){}
  98.         }
  99.         return list;
  100.     }
  101.    
  102.     /** setAttribute */
  103.     @Override
  104.     public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException{
  105.        
  106.         if( attribute==null )
  107.             throw new IllegalArgumentException("Il nome dell'attributo e' nullo");
  108.        
  109.         try{
  110.            
  111.             if(attribute.getName().equals(JMXUtils.CACHE_ATTRIBUTE_ABILITATA)){
  112.                 boolean v = (Boolean) attribute.getValue();
  113.                 if(v){
  114.                     // la cache DEVE essere abilitata
  115.                     if(!this.cacheAbilitata){
  116.                         this.abilitaCache();
  117.                     }
  118.                 }
  119.                 else{
  120.                     // la cache DEVE essere disabilitata
  121.                     if(this.cacheAbilitata){
  122.                         this.disabilitaCache();
  123.                     }
  124.                 }
  125.             }
  126.            
  127.             throw new AttributeNotFoundException("Attributo "+attribute.getName()+" non trovato");
  128.            
  129.         }catch(ClassCastException ce){
  130.             throw new InvalidAttributeValueException("il tipo "+attribute.getValue().getClass()+" dell'attributo "+attribute.getName()+" non e' valido");
  131.         }catch(JMException j){
  132.             throw new MBeanException(j);
  133.         }
  134.        
  135.     }
  136.    
  137.     /** setAttributes */
  138.     @Override
  139.     public AttributeList setAttributes(AttributeList list){
  140.        
  141.         if(list==null)
  142.             throw new IllegalArgumentException("Lista degli attributi e' nulla");
  143.        
  144.         AttributeList ret = new AttributeList();
  145.         Iterator<?> it = ret.iterator();
  146.        
  147.         while(it.hasNext()){
  148.             try{
  149.                 Attribute attribute = (Attribute) it.next();
  150.                 setAttribute(attribute);
  151.                 ret.add(attribute);
  152.             }catch(JMException ex){}
  153.         }
  154.        
  155.         return ret;
  156.        
  157.     }
  158.    
  159.     /** invoke */
  160.     @Override
  161.     public Object invoke(String actionName, Object[]params, String[]signature) throws MBeanException,ReflectionException{
  162.        
  163.         if( (actionName==null) || (actionName.equals("")) )
  164.             throw new IllegalArgumentException("Nessuna operazione definita");
  165.        
  166.         if(actionName.equals(JMXUtils.CACHE_METHOD_NAME_RESET)){
  167.             return this.resetCache();
  168.         }
  169.        
  170.         if(actionName.equals(JMXUtils.CACHE_METHOD_NAME_PRINT_STATS)){
  171.             return this.printStatCache();
  172.         }
  173.                
  174.         if(actionName.equals(JMXUtils.CACHE_METHOD_NAME_DISABILITA)){
  175.             return this.disabilitaCacheConEsito();
  176.         }
  177.        
  178.         if(actionName.equals(JMXUtils.CACHE_METHOD_NAME_ABILITA)){
  179.             if(params.length != 4)
  180.                 throw new MBeanException(new Exception("["+JMXUtils.CACHE_METHOD_NAME_ABILITA+"] Lunghezza parametri non corretta: "+params.length));
  181.            
  182.             Long param1 = null;
  183.             if(params[0]!=null && !"".equals(params[0])){
  184.                 param1 = (Long)params[0];
  185.                 if(param1<0){
  186.                     param1 = null;
  187.                 }
  188.             }
  189.            
  190.             Boolean param2 = null;
  191.             if(params[1]!=null && !"".equals(params[1])){
  192.                 param2 = (Boolean)params[1];
  193.             }
  194.            
  195.             Long param3 = null;
  196.             if(params[2]!=null && !"".equals(params[2])){
  197.                 param3 = (Long)params[2];
  198.                 if(param3<0){
  199.                     param3 = null;
  200.                 }
  201.             }
  202.            
  203.             Long param4 = null;
  204.             if(params[3]!=null && !"".equals(params[3])){
  205.                 param4 = (Long)params[3];
  206.                 if(param4<0){
  207.                     param4 = null;
  208.                 }
  209.             }
  210.                    
  211.             return this.abilitaCache(param1, param2, param3, param4 );
  212.         }
  213.        
  214.         if(actionName.equals(JMXUtils.CACHE_METHOD_NAME_LIST_KEYS)){
  215.             return this.listKeysCache();
  216.         }
  217.        
  218.         if(actionName.equals(JMXUtils.CACHE_METHOD_NAME_GET_OBJECT)){
  219.            
  220.             if(params.length != 1)
  221.                 throw new MBeanException(new Exception("["+JMXUtils.CACHE_METHOD_NAME_GET_OBJECT+"] Lunghezza parametri non corretta: "+params.length));
  222.            
  223.             String param1 = null;
  224.             if(params[0]!=null && !"".equals(params[0])){
  225.                 param1 = (String)params[0];
  226.             }
  227.            
  228.             return this.getObjectCache(param1);
  229.         }
  230.        
  231.         if(actionName.equals(JMXUtils.CACHE_METHOD_NAME_REMOVE_OBJECT)){
  232.            
  233.             if(params.length != 1)
  234.                 throw new MBeanException(new Exception("["+JMXUtils.CACHE_METHOD_NAME_REMOVE_OBJECT+"] Lunghezza parametri non corretta: "+params.length));
  235.            
  236.             String param1 = null;
  237.             if(params[0]!=null && !"".equals(params[0])){
  238.                 param1 = (String)params[0];
  239.             }
  240.            
  241.             return this.removeObjectCache(param1);
  242.         }
  243.            
  244.         if(actionName.equals(THREAD_POOL_STATUS)){
  245.            
  246.             if(params.length > 1)
  247.                 throw new MBeanException(new Exception("["+THREAD_POOL_STATUS+"] Lunghezza parametri non corretta: "+params.length));
  248.            
  249.             if(params.length > 0) {
  250.                
  251.                 String param1 = null;
  252.                 if(params[0]!=null && !"".equals(params[0])){
  253.                     param1 = (String)params[0];
  254.                 }
  255.                
  256.                 return this.getThreadPoolStatus(param1);
  257.             }
  258.             else {
  259.                 return this.getThreadPoolStatus(CostantiConfigurazione.CODA_DEFAULT);
  260.             }
  261.         }
  262.        
  263.         if(actionName.equals(QUEUE_CONFIG)){
  264.            
  265.             if(params.length > 1)
  266.                 throw new MBeanException(new Exception("["+QUEUE_CONFIG+"] Lunghezza parametri non corretta: "+params.length));
  267.            
  268.             if(params.length > 0) {
  269.                
  270.                 String param1 = null;
  271.                 if(params[0]!=null && !"".equals(params[0])){
  272.                     param1 = (String)params[0];
  273.                 }
  274.                
  275.                 return this.getQueueConfig(param1);
  276.             }
  277.             else {
  278.                 return this.getQueueConfig(CostantiConfigurazione.CODA_DEFAULT);
  279.             }
  280.         }
  281.        
  282.         if(actionName.equals(GET_APPLICATIVI_PRIORITARI)){
  283.            
  284.             if(params.length > 1)
  285.                 throw new MBeanException(new Exception("["+QUEUE_CONFIG+"] Lunghezza parametri non corretta: "+params.length));
  286.            
  287.             if(params.length > 0) {
  288.                
  289.                 String param1 = null;
  290.                 if(params[0]!=null && !"".equals(params[0])){
  291.                     param1 = (String)params[0];
  292.                 }
  293.                
  294.                 return this.getApplicativiPrioritari(param1);
  295.             }
  296.             else {
  297.                 return this.getApplicativiPrioritari(CostantiConfigurazione.CODA_DEFAULT);
  298.             }
  299.         }
  300.        
  301.         if(actionName.equals(GET_CONNETTORI_PRIORITARI)){
  302.            
  303.             if(params.length > 1)
  304.                 throw new MBeanException(new Exception("["+QUEUE_CONFIG+"] Lunghezza parametri non corretta: "+params.length));
  305.            
  306.             if(params.length > 0) {
  307.                
  308.                 String param1 = null;
  309.                 if(params[0]!=null && !"".equals(params[0])){
  310.                     param1 = (String)params[0];
  311.                 }
  312.                
  313.                 return this.getConnettoriPrioritari(param1);
  314.             }
  315.             else {
  316.                 return this.getConnettoriPrioritari(CostantiConfigurazione.CODA_DEFAULT);
  317.             }
  318.         }
  319.        
  320.         if(actionName.equals(UPDATE_CONNETTORI_PRIORITARI)){
  321.            
  322.             if(params.length > 1)
  323.                 throw new MBeanException(new Exception("["+QUEUE_CONFIG+"] Lunghezza parametri non corretta: "+params.length));
  324.            
  325.             if(params.length > 0) {
  326.                
  327.                 String param1 = null;
  328.                 if(params[0]!=null && !"".equals(params[0])){
  329.                     param1 = (String)params[0];
  330.                 }
  331.                
  332.                 return this.updateConnettoriPrioritari(param1);
  333.             }
  334.             else {
  335.                 return this.updateConnettoriPrioritari(CostantiConfigurazione.CODA_DEFAULT);
  336.             }
  337.         }
  338.        
  339.         if(actionName.equals(RESET_CONNETTORI_PRIORITARI)){
  340.            
  341.             if(params.length > 1)
  342.                 throw new MBeanException(new Exception("["+QUEUE_CONFIG+"] Lunghezza parametri non corretta: "+params.length));
  343.            
  344.             if(params.length > 0) {
  345.                
  346.                 String param1 = null;
  347.                 if(params[0]!=null && !"".equals(params[0])){
  348.                     param1 = (String)params[0];
  349.                 }
  350.                
  351.                 return this.resetConnettoriPrioritari(param1);
  352.             }
  353.             else {
  354.                 return this.resetConnettoriPrioritari(CostantiConfigurazione.CODA_DEFAULT);
  355.             }
  356.         }
  357.                
  358.         throw new UnsupportedOperationException("Operazione "+actionName+" sconosciuta");
  359.     }
  360.    
  361.     /* MBean info */
  362.     @Override
  363.     public MBeanInfo getMBeanInfo(){
  364.                
  365.         // Descrizione della classe nel MBean
  366.         String className = this.getClass().getName();
  367.         String description = "Risorsa per la configurazione ("+this.openspcoopProperties.getVersione()+")";

  368.         // MetaData per l'attributo abilitaCache
  369.         MBeanAttributeInfo cacheAbilitataVAR = JMXUtils.MBEAN_ATTRIBUTE_INFO_CACHE_ABILITATA;

  370.         // MetaData per l'attributo maxLife
  371.         MBeanAttributeInfo maxLife
  372.             = new MBeanAttributeInfo(GestoreConsegnaApplicativi.MAX_LIFE_PRESA_IN_CONSEGNA,String.class.getName(),
  373.                         "Tempo massimo (in secondi) che un messaggio può essere tenuto in consegna da parte del gestore",
  374.                             JMXUtils.JMX_ATTRIBUTE_READABLE,!JMXUtils.JMX_ATTRIBUTE_WRITABLE,!JMXUtils.JMX_ATTRIBUTE_IS_GETTER);
  375.                
  376.         // MetaData per l'operazione resetCache
  377.         MBeanOperationInfo resetCacheOP = JMXUtils.MBEAN_OPERATION_RESET_CACHE;
  378.        
  379.         // MetaData per l'operazione printStatCache
  380.         MBeanOperationInfo printStatCacheOP = JMXUtils.MBEAN_OPERATION_PRINT_STATS_CACHE;
  381.        
  382.         // MetaData per l'operazione disabilitaCache
  383.         MBeanOperationInfo disabilitaCacheOP = JMXUtils.MBEAN_OPERATION_DISABILITA_CACHE;
  384.        
  385.         // MetaData per l'operazione abilitaCache con parametri
  386.         MBeanOperationInfo abilitaCacheParametriOP = JMXUtils.MBEAN_OPERATION_ABILITA_CACHE_CON_PARAMETRI;
  387.        
  388.         // MetaData per l'operazione listKeysCache
  389.         MBeanOperationInfo listKeysCacheOP = JMXUtils.MBEAN_OPERATION_LIST_KEYS_CACHE;

  390.         // MetaData per l'operazione getObjectCache
  391.         MBeanOperationInfo getObjectCacheOP = JMXUtils.MBEAN_OPERATION_GET_OBJECT_CACHE;
  392.        
  393.         // MetaData per l'operazione removeObjectCache
  394.         MBeanOperationInfo removeObjectCacheOP = JMXUtils.MBEAN_OPERATION_REMOVE_OBJECT_CACHE;
  395.                
  396.         // MetaData per l'operazione threadPoolStatus
  397.         MBeanOperationInfo threadPoolStatusDefault
  398.         = new MBeanOperationInfo(THREAD_POOL_STATUS,"Stato dei thread utilizzati per la consegna dei messaggi nella coda di default",
  399.             null,
  400.             String.class.getName(),
  401.             MBeanOperationInfo.ACTION);
  402.        
  403.         // MetaData per l'operazione threadPoolStatus
  404.         MBeanOperationInfo threadPoolStatus
  405.         = new MBeanOperationInfo(THREAD_POOL_STATUS,"Stato dei thread utilizzati per la consegna dei messaggi nella coda indicata",
  406.             new MBeanParameterInfo[]{
  407.                     new MBeanParameterInfo("coda",String.class.getName(),"Nome della coda"),
  408.             },
  409.             String.class.getName(),
  410.             MBeanOperationInfo.ACTION);
  411.        
  412.         // MetaData per l'operazione threadPoolStatus
  413.         MBeanOperationInfo queueConfigDefault
  414.         = new MBeanOperationInfo(QUEUE_CONFIG,"Configurazione della coda di default",
  415.             null,
  416.             String.class.getName(),
  417.             MBeanOperationInfo.ACTION);
  418.        
  419.         // MetaData per l'operazione threadPoolStatus
  420.         MBeanOperationInfo queueConfig
  421.         = new MBeanOperationInfo(QUEUE_CONFIG,"Configurazione della coda indicata",
  422.             new MBeanParameterInfo[]{
  423.                     new MBeanParameterInfo("coda",String.class.getName(),"Nome della coda"),
  424.             },
  425.             String.class.getName(),
  426.             MBeanOperationInfo.ACTION);
  427.        
  428.         // MetaData per l'operazione getApplicativiPrioritariDefault
  429.         MBeanOperationInfo getApplicativiPrioritariDefault
  430.         = new MBeanOperationInfo(GET_APPLICATIVI_PRIORITARI,"Applicativi configurati come prioritari nella coda di default",
  431.             null,
  432.             String.class.getName(),
  433.             MBeanOperationInfo.ACTION);
  434.        
  435.         // MetaData per l'operazione getApplicativiPrioritari
  436.         MBeanOperationInfo getApplicativiPrioritari
  437.         = new MBeanOperationInfo(GET_APPLICATIVI_PRIORITARI,"Applicativi configurati come prioritari nella coda indicata",
  438.             new MBeanParameterInfo[]{
  439.                     new MBeanParameterInfo("coda",String.class.getName(),"Nome della coda"),
  440.             },
  441.             String.class.getName(),
  442.             MBeanOperationInfo.ACTION);
  443.        
  444.         // MetaData per l'operazione getConnettoriPrioritariDefault
  445.         MBeanOperationInfo getConnettoriPrioritariDefault
  446.         = new MBeanOperationInfo(GET_CONNETTORI_PRIORITARI,"Connettori configurati come prioritari nella coda di default",
  447.             null,
  448.             String.class.getName(),
  449.             MBeanOperationInfo.ACTION);
  450.        
  451.         // MetaData per l'operazione getConnettoriPrioritari
  452.         MBeanOperationInfo getConnettoriPrioritari
  453.         = new MBeanOperationInfo(GET_CONNETTORI_PRIORITARI,"Connettori configurati come prioritari nella coda indicata",
  454.             new MBeanParameterInfo[]{
  455.                     new MBeanParameterInfo("coda",String.class.getName(),"Nome della coda"),
  456.             },
  457.             String.class.getName(),
  458.             MBeanOperationInfo.ACTION);
  459.        
  460.         // MetaData per l'operazione updateConnettoriPrioritariDefault
  461.         MBeanOperationInfo updateConnettoriPrioritariDefault
  462.         = new MBeanOperationInfo(UPDATE_CONNETTORI_PRIORITARI,"Aggiorna la configurazione dei connettori configurati come prioritari nella coda di default",
  463.             null,
  464.             String.class.getName(),
  465.             MBeanOperationInfo.ACTION);
  466.        
  467.         // MetaData per l'operazione updateConnettoriPrioritari
  468.         MBeanOperationInfo updateConnettoriPrioritari
  469.         = new MBeanOperationInfo(UPDATE_CONNETTORI_PRIORITARI,"Aggiorna la configurazione dei connettori configurati come prioritari nella coda indicata",
  470.             new MBeanParameterInfo[]{
  471.                     new MBeanParameterInfo("coda",String.class.getName(),"Nome della coda"),
  472.             },
  473.             String.class.getName(),
  474.             MBeanOperationInfo.ACTION);
  475.        
  476.         // MetaData per l'operazione resetConnettoriPrioritariDefault
  477.         MBeanOperationInfo resetConnettoriPrioritariDefault
  478.         = new MBeanOperationInfo(RESET_CONNETTORI_PRIORITARI,"Rimuove i connettori configurati come prioritari nella coda di default",
  479.             null,
  480.             String.class.getName(),
  481.             MBeanOperationInfo.ACTION);
  482.        
  483.         // MetaData per l'operazione resetConnettoriPrioritari
  484.         MBeanOperationInfo resetConnettoriPrioritari
  485.         = new MBeanOperationInfo(RESET_CONNETTORI_PRIORITARI,"Rimuove i connettori configurati come prioritari nella coda indicata",
  486.             new MBeanParameterInfo[]{
  487.                     new MBeanParameterInfo("coda",String.class.getName(),"Nome della coda"),
  488.             },
  489.             String.class.getName(),
  490.             MBeanOperationInfo.ACTION);
  491.        
  492.         // Mbean costruttore
  493.         MBeanConstructorInfo defaultConstructor = new MBeanConstructorInfo("Default Constructor","Crea e inizializza una nuova istanza del MBean",null);

  494.         // Lista attributi
  495.         MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[]{cacheAbilitataVAR,maxLife};
  496.        
  497.         // Lista Costruttori
  498.         MBeanConstructorInfo[] constructors = new MBeanConstructorInfo[]{defaultConstructor};
  499.        
  500.         // Lista operazioni
  501.         List<MBeanOperationInfo> listOperation = new ArrayList<>();
  502.         listOperation.add(resetCacheOP);
  503.         listOperation.add(printStatCacheOP);
  504.         listOperation.add(disabilitaCacheOP);
  505.         listOperation.add(abilitaCacheParametriOP);
  506.         listOperation.add(listKeysCacheOP);
  507.         listOperation.add(getObjectCacheOP);
  508.         listOperation.add(removeObjectCacheOP);
  509.         listOperation.add(threadPoolStatusDefault);
  510.         listOperation.add(threadPoolStatus);
  511.         listOperation.add(queueConfigDefault);
  512.         listOperation.add(queueConfig);
  513.         listOperation.add(getApplicativiPrioritariDefault);
  514.         listOperation.add(getApplicativiPrioritari);
  515.         listOperation.add(getConnettoriPrioritariDefault);
  516.         listOperation.add(getConnettoriPrioritari);
  517.         listOperation.add(updateConnettoriPrioritariDefault);
  518.         listOperation.add(updateConnettoriPrioritari);
  519.         listOperation.add(resetConnettoriPrioritariDefault);
  520.         listOperation.add(resetConnettoriPrioritari);
  521.         MBeanOperationInfo[] operations = listOperation.toArray(new MBeanOperationInfo[1]);
  522.        
  523.         return new MBeanInfo(className,description,attributes,constructors,operations,null);
  524.     }
  525.    
  526.     /* Variabili per la gestione JMX */
  527.     private Logger log;
  528.     org.openspcoop2.pdd.config.OpenSPCoop2Properties openspcoopProperties = null;
  529.    
  530.     /* Costruttore */
  531.     public GestoreConsegnaApplicativi(){
  532.         this.log = OpenSPCoop2Logger.getLoggerOpenSPCoopCore();
  533.         this.openspcoopProperties = org.openspcoop2.pdd.config.OpenSPCoop2Properties.getInstance();
  534.                
  535.         // Configurazione
  536.         try{
  537.             this.cacheAbilitata = GestoreLoadBalancerCaching.isCacheAbilitata();
  538.         }catch(Exception e){
  539.             this.log.error("Errore durante l'identificazione dello stato della cache");
  540.         }
  541.        
  542.         this.maxLifePresaInConsegna = this.openspcoopProperties.getTimerConsegnaContenutiApplicativiPresaInConsegnaMaxLife();

  543.     }
  544.    
  545.     public boolean isCacheAbilitata() {
  546.         return this.cacheAbilitata;
  547.     }
  548.    
  549.     /* Metodi di management JMX */
  550.     public String resetCache(){
  551.         try{
  552.             if(!this.cacheAbilitata)
  553.                 throw new CoreException("Cache non abilitata");
  554.             GestoreLoadBalancerCaching.resetCache();
  555.             return JMXUtils.MSG_RESET_CACHE_EFFETTUATO_SUCCESSO;
  556.         }catch(Exception e){
  557.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  558.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  559.         }
  560.     }
  561.    
  562.     public String printStatCache(){
  563.         try{
  564.             if(!this.cacheAbilitata)
  565.                 throw new CoreException("Cache non abilitata");
  566.             return GestoreLoadBalancerCaching.printStatsCache("\n");
  567.         }catch(Exception e){
  568.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  569.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  570.         }
  571.     }
  572.    
  573.     public void abilitaCache(){
  574.         try{
  575.             GestoreLoadBalancerCaching.abilitaCache();
  576.             this.cacheAbilitata = true;
  577.         }catch(Exception e){
  578.             this.log.error(e.getMessage(),e);
  579.         }
  580.     }

  581.     public String abilitaCache(Long dimensioneCache,Boolean algoritmoCacheLRU,Long itemIdleTime,Long itemLifeSecond){
  582.         try{
  583.             GestoreLoadBalancerCaching.abilitaCache(dimensioneCache,algoritmoCacheLRU,itemIdleTime,itemLifeSecond, OpenSPCoop2Logger.getLoggerOpenSPCoopCore());
  584.             this.cacheAbilitata = true;
  585.             return JMXUtils.MSG_ABILITAZIONE_CACHE_EFFETTUATA;
  586.         }catch(Exception e){
  587.             this.log.error(e.getMessage(),e);
  588.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  589.         }
  590.     }
  591.    
  592.     public void disabilitaCache() throws JMException{
  593.         try{
  594.             GestoreLoadBalancerCaching.disabilitaCache();
  595.             this.cacheAbilitata = false;
  596.         }catch(Exception e){
  597.             this.log.error(e.getMessage(),e);
  598.             throw new JMException(e.getMessage());
  599.         }
  600.     }
  601.     public String disabilitaCacheConEsito() {
  602.         try{
  603.             disabilitaCache();
  604.             return JMXUtils.MSG_DISABILITAZIONE_CACHE_EFFETTUATA;
  605.         }catch(Exception e){
  606.             this.log.error(e.getMessage(),e);
  607.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  608.         }
  609.     }
  610.    
  611.     public String listKeysCache(){
  612.         try{
  613.             if(this.cacheAbilitata==false)
  614.                 throw new CoreException("Cache non abilitata");
  615.             return GestoreLoadBalancerCaching.listKeysCache("\n");
  616.         }catch(Exception e){
  617.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  618.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  619.         }
  620.     }
  621.    
  622.     public String getObjectCache(String key){
  623.         try{
  624.             if(this.cacheAbilitata==false)
  625.                 throw new CoreException("Cache non abilitata");
  626.             return GestoreLoadBalancerCaching.getObjectCache(key);
  627.         }catch(Exception e){
  628.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  629.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  630.         }
  631.     }
  632.    
  633.     public String removeObjectCache(String key){
  634.         try{
  635.             if(this.cacheAbilitata==false)
  636.                 throw new CoreException("Cache non abilitata");
  637.             GestoreLoadBalancerCaching.removeObjectCache(key);
  638.             return JMXUtils.MSG_RIMOZIONE_CACHE_EFFETTUATA;
  639.         }catch(Exception e){
  640.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  641.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  642.         }
  643.     }
  644.    
  645.     public String getThreadPoolStatus(String queue) {
  646.         try{
  647.             if(OpenSPCoop2Startup.threadConsegnaContenutiApplicativiRefMap==null ||
  648.                     !OpenSPCoop2Startup.threadConsegnaContenutiApplicativiRefMap.containsKey(queue)) {
  649.                 throw new CoreException("Coda '"+queue+"' non esistente");
  650.             }
  651.             return OpenSPCoop2Startup.threadConsegnaContenutiApplicativiRefMap.get(queue).getThreadsImage();
  652.         }catch(Exception e){
  653.             this.log.error(e.getMessage(),e);
  654.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  655.         }
  656.     }
  657.    
  658.     public String getQueueConfig(String queue) {
  659.         try{
  660.             if(OpenSPCoop2Startup.threadConsegnaContenutiApplicativiRefMap==null ||
  661.                     !OpenSPCoop2Startup.threadConsegnaContenutiApplicativiRefMap.containsKey(queue)) {
  662.                 throw new CoreException("Coda '"+queue+"' non esistente");
  663.             }
  664.             return OpenSPCoop2Startup.threadConsegnaContenutiApplicativiRefMap.get(queue).getQueueConfig();
  665.         }catch(Exception e){
  666.             this.log.error(e.getMessage(),e);
  667.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  668.         }
  669.     }
  670.    
  671.     public String getApplicativiPrioritari(String queue) {
  672.         try{
  673.             if(OpenSPCoop2Startup.threadConsegnaContenutiApplicativiRefMap==null ||
  674.                     !OpenSPCoop2Startup.threadConsegnaContenutiApplicativiRefMap.containsKey(queue)) {
  675.                 throw new CoreException("Coda '"+queue+"' non esistente");
  676.             }
  677.             List<IDConnettore> list = ConfigurazionePdDManager.getInstance().getConnettoriConsegnaNotifichePrioritarie(queue);
  678.             if(list==null || list.isEmpty()) {
  679.                 return "";
  680.             }
  681.             else {
  682.                 StringBuilder sb = new StringBuilder();
  683.                 for (IDConnettore idConnettore : list) {
  684.                     if(sb.length()>0) {
  685.                         sb.append(", ");
  686.                     }
  687.                     sb.append(idConnettore.getNome()).append("@").append(idConnettore.getIdSoggettoProprietario().toString());
  688.                 }
  689.                 return sb.toString();
  690.             }
  691.         }catch(Exception e){
  692.             this.log.error(e.getMessage(),e);
  693.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  694.         }
  695.     }
  696.    
  697.     public String getConnettoriPrioritari(String queue) {
  698.         try{
  699.             if(OpenSPCoop2Startup.threadConsegnaContenutiApplicativiRefMap==null ||
  700.                     !OpenSPCoop2Startup.threadConsegnaContenutiApplicativiRefMap.containsKey(queue)) {
  701.                 throw new CoreException("Coda '"+queue+"' non esistente");
  702.             }
  703.             List<IDConnettore> list = ConfigurazionePdDManager.getInstance().getConnettoriConsegnaNotifichePrioritarie(queue);
  704.             if(list==null || list.isEmpty()) {
  705.                 return "";
  706.             }
  707.             else {
  708.                 StringBuilder sb = new StringBuilder();
  709.                 for (IDConnettore idConnettore : list) {
  710.                     if(sb.length()>0) {
  711.                         sb.append(", ");
  712.                     }
  713.                     sb.append(idConnettore.getNomeConnettore());
  714.                 }
  715.                 return sb.toString();
  716.             }
  717.         }catch(Exception e){
  718.             this.log.error(e.getMessage(),e);
  719.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  720.         }
  721.     }
  722.    
  723.     public String updateConnettoriPrioritari(String queue) {
  724.         try{
  725.             if(OpenSPCoop2Startup.threadConsegnaContenutiApplicativiRefMap==null ||
  726.                     !OpenSPCoop2Startup.threadConsegnaContenutiApplicativiRefMap.containsKey(queue)) {
  727.                 throw new CoreException("Coda '"+queue+"' non esistente");
  728.             }
  729.            
  730.             ConfigurazionePdDReader.removeObjectCache(ConfigurazionePdD.getKey_getConnettoriConsegnaNotifichePrioritarie(queue));
  731.            
  732.             return JMXUtils.MSG_OPERAZIONE_EFFETTUATA_SUCCESSO;
  733.         }catch(Exception e){
  734.             this.log.error(e.getMessage(),e);
  735.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  736.         }
  737.     }

  738.     public String resetConnettoriPrioritari(String queue) {
  739.         try{
  740.             if(OpenSPCoop2Startup.threadConsegnaContenutiApplicativiRefMap==null ||
  741.                     !OpenSPCoop2Startup.threadConsegnaContenutiApplicativiRefMap.containsKey(queue)) {
  742.                 throw new CoreException("Coda '"+queue+"' non esistente");
  743.             }
  744.            
  745.             ConfigurazionePdDManager.getInstance().resetConnettoriConsegnaNotifichePrioritarie(queue);
  746.            
  747.             ConfigurazionePdDReader.removeObjectCache(ConfigurazionePdD.getKey_getConnettoriConsegnaNotifichePrioritarie(queue));
  748.            
  749.             return JMXUtils.MSG_OPERAZIONE_EFFETTUATA_SUCCESSO;
  750.         }catch(Exception e){
  751.             this.log.error(e.getMessage(),e);
  752.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  753.         }
  754.     }
  755. }