Inicio > Sin categoría > PingBlog: Agregandole soporte para JMX

PingBlog: Agregandole soporte para JMX

Domingo, 13 de abril de 2008

Realmente el software no requiere JMX. Sin embargo yo estoy aprendiendo a usar el API para otros proyectos en mi trabajo, asi que me decidí a escribir un “hola mundo”.

En el caso de PingBlog yo queria monitorear lo que hace cada instancia de la clase abstracta Pinger, así que declare una interfaz en JMX con la cual:

  • Puedo ver el estado interno de cada Pinger
  • Puedo provocar un ping para ver como se porta

La interfaz es trivial:

 1 package com.blogspot.elangelnegro.blog.pingblog.pinger; 2 3 /** 4  * JMX management interface for Ping implementations 5  * @author josevnz 6  * 7  */ 8 public interface PingMBean { 9  /**10   * Ping a given Blog, based on the given settings.11   * Note than the implementation could fail if you try to ping too fast!12   * @return If managed to ping or not the remote resource13   * @throws PingException14   */15  public boolean ping() throws PingException;1617  /**18   * Get the message received from the server19   * @return The message returned from the remote server20   */21  public String getMessage();2223  /**24   * Get the raw message received from the server25   * @return The message returned from the remote server26   */27  public abstract String getRawMessage();2829  /**30   * Get the name of the blog being advertised31   * @return Name of the directory32   */33  public String getName();3435  /**36   * Get the URL of the blog being advertised37   * @return Name of the directory38   */39  public String getUrl();4041  /**42   * Get the directory being ping43   * @return Name of the directory44   */45  public String getDirectory();4647  /**48   * Get the status of the last ping operation49   * @return50   */51  public boolean getStatus();525354 }

La clase Ping sólo tiene que implementar la interfaz. Luego de esto lo que queda es registrar cada uno de los MBeans para que puedan ser utilizados desde Jconsole en :

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();  try {   ObjectName mbeanName =    new ObjectName(      String.format("com.blogspot.elangelnegro.blog.pingblog.pinger:type=%s",        ping.getInstanceName()));   mbs.registerMBean(ping, mbeanName);  } catch (MBeanRegistrationException mre) {   throw new PingException(mre);  } catch (NotCompliantMBeanException nce) {   throw new PingException(nce);  } catch (InstanceAlreadyExistsException iaex) {   throw new PingException(iaex);  } catch (MalformedObjectNameException mne) {   throw new PingException(mne);  } } catch (PingException pExp) {  throw pExp; }

 return ping;

También le agregué lo siguiente al Shell Script que llama a la clase de Java (cuando es usado desde la linea de comandos y no la interfaz gráfica):

exec $JAVA_HOME/bin/java -cp $CLASSPATH-Dcom.sun.management.jmxremotecom.blogspot.elangelnegro.blog.pingblog.pinger.PingController $*

Buscar en otros sitios:

Blogalaxia:,
Technorati:,
To2blogs:,
Del.icio.us:,

Sin categoría ,

  1. Sin comentarios aún.
  1. Sin trackbacks aún.