Projets

Comparaison des versions

Légende

  • Ces lignes ont été ajoutées. Ce mot a été ajouté.
  • Ces lignes ont été supprimées. Ce mot a été supprimé.
  • La mise en forme a été modifiée.
<?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">          <bean id="cmisFileStorageService"         lazy
Bloc de code

Exemple simple de mise en place d'une surveillance d'un serveur CMIS

Les beans Spring :

     <bean id="cmisFileStorageService" class="org.esupportail.application.service.fileStorage.CmisFileStorageServiceImpl" lazy-init="true">

...


  

...

   

...

 <description>A

...

bean

...

to

...

manage

...

files

...

upload

...

and

...

download

...

to

...

the

...

CMIS server.</description>

...


        

...

...

...


  

...

   

...

 <property

...

name="jmxTestCmis"

...

ref="jmxTestCmis"/>

...


  

...

 </bean>

...


       
    <!

...

- 

...

JMX

...

to

...

control

...

CMIS

...

-

...

>

...


  

...

 <bean

...

id="exporter"

...

class="org.springframework.jmx.export.MBeanExporter" >
        <property name="beans">

...


  

...

   

...

   

...

 <map>

...


  

...

   

...

   

...

   

...

 <entry

...

key="bean:name=testCmis"

...

value-ref="jmxTestCmis"/>

...


  

...

   

...

   

...

 </map>

...


  

...

   

...

 </property>

...


  

...

 </bean>

...


  

...

 

...


  

...

 <bean

...

id="jmxTestCmis"

...


  

...

   

...

 class="org.esupportail.application.service.fileStorage.JmxTestCmisImpl">

...


  

...

   

...

 ...

...


  

...

 </bean>

...

La classe métier cliente JMX

Bloc de code
public class CmisFileStorageServiceImpl  {
     ....

    /**
     * Bean to test if cmis is ready.
     */
    private JmxTestCmis jmxTestCmis;

    public void afterPropertiesSet() throws Exception {
        ....
        Assert.notNull(this.jmxTestCmis,
                "property jmxTestCmis of class " + this.getClass().getName() + " can not be null");
    }    
    ...
    /**
     * @param jmxTestCmis the jmxTestCmis to set
     */
    public void setJmxTestCmis(final JmxTestCmis jmxTestCmis) {
        this.jmxTestCmis = jmxTestCmis;
    }

    public FileStorage getFile(...) throws IOException {
        FileStorage file = null;
        if (jmxTestCmis.getCmisIsReady()) {
                         file= ...;
            
        }  else {
            System.err.println("--------le service CMIS est indisponible");
        }
        return file;
    }
}

Le bean JMX

Bloc de code
package org.esupportail.application.services.fileStorage;
public interface JmxTestCmis {
    /**
     * Enable the use of CMIS.
     */
    void enabledCmis();
    
    /**
     * Disable the use of CMIS.
     */
    void disabledCmis();
    
    /**
     * @return the cmisIsReady
     */
    Boolean getCmisIsReady();
}

package org.esupportail.application.services.fileStorage;
import java.io.Serializable;
public class JmxTestCmisImpl implements JmxTestCmis, Serializable {
    /**
     * True if cmis is ready.
     * Default value = true.
     */
    private Boolean cmisIsReady;
    public JmxTestCmisImpl() {
        super();
        cmisIsReady = true;
    }

    @Override
    public void disabledCmis() {
        cmisIsReady = false;
    }

    @Override
    public void enabledCmis() {
        cmisIsReady = true;
    }
    
    public Boolean getCmisIsReady() {
        return cmisIsReady;
    }
}

L'activation de l'écoute JMX

L'application écoute le port jmx 9656 (par exemple)
Au lancement de l'application, on aura les options suivantes:

Bloc de code
\-Dcom.sun.management.jmxremote
\-Dcom.sun.management.jmxremote.port=9656
\-Dcom.sun.management.jmxremote.authenticate=false
\-Dcom.sun.management.jmxremote.ssl=false

L'activation de la survaillence JMX

Application "surveillée" : activation/désactivation de la surveillance

activationJMX.sh

Bloc de code
 #!/bin/csh
set cmdLineJMXJar=/opt/admin-java/jmx/cmdline-jmxclient.jar
set jmxHost=host.etablissement.fr
set jmXPort=9656
#No User and password so pass '-'
echo "active l'utilisation de CMIS pour les applications en ecoute sur le port 9656"
/opt/jdk1.6.0/bin/java -jar ${cmdLineJMXJar} - ${jmxHost}:${port} bean:name=testCmis enabled

desactivationJMX.sh

Bloc de code
 #!/bin/csh
set cmdLineJMXJar=/opt/admin-java/jmx/cmdline-jmxclient.jar
set port=9656
set jmxHost=host.etablissement.fr
#No User and password so pass '-'
echo "désactive l'utilisation de CMIS pour les applications en ecoute sur le port 9656"
/opt/jdk1.6.0/bin/java -jar ${cmdLineJMXJar} - ${jmxHost}:${port} bean:name=testCmis disabled