Protocolv30x.java :  » JVM » jmxetric » ganglia » gmetric » Java Open Source

Java Open Source » JVM » jmxetric 
jmxetric » ganglia » gmetric » Protocolv30x.java
 package ganglia.gmetric;

import ganglia.gmetric.GMetric.UDPAddressingMode;
import ganglia.xdr.v30x.Ganglia_gmetric_message;
import ganglia.xdr.v30x.Ganglia_message;
import ganglia.xdr.v30x.Ganglia_message_formats;

import org.acplt.oncrpc.XdrBufferEncodingStream;

public class Protocolv30x extends AbstractProtocol {

  private static final int MAX_BUFFER_SIZE = 1024 ;
    private XdrBufferEncodingStream xdr = new XdrBufferEncodingStream( MAX_BUFFER_SIZE );
    
    public Protocolv30x( String group, int port, UDPAddressingMode mode ) {
      super(group, port, mode);
    }
    
  @Override
  public void announce( String name, String value,
      GMetricType type, String units, GMetricSlope slope, int tmax,
      int dmax, String groupName) throws Exception {
        encodeGMetric( name, value, type, units, slope, tmax, dmax );
        send( xdr.getXdrData(), xdr.getXdrLength() );
  }
  
  /**
     * Encodes the metric using the classes generated by remotetea
     */
    private void encodeGMetric( String name, 
            String value, 
            GMetricType type,
            String units,
            GMetricSlope slope,
            int tmax,
            int dmax )
            throws Exception {
        Ganglia_message msg = new Ganglia_message() ;
        Ganglia_gmetric_message gmetric_msg = new Ganglia_gmetric_message() ;
        
        msg.id = Ganglia_message_formats.metric_user_defined ;
        msg.gmetric = gmetric_msg ;
        gmetric_msg.name = name ;
        gmetric_msg.value = value ;
        gmetric_msg.type = type.getGangliaType() ;
        gmetric_msg.units = units ;
        gmetric_msg.slope = slope.getGangliaSlope() ;
        gmetric_msg.tmax = tmax ;
        gmetric_msg.dmax = dmax ;
        
        xdr.beginEncoding(udpAddr, port) ;
        msg.xdrEncode(xdr);
        xdr.endEncoding();
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.