public void run(){
  GangliaListener gangliaListener=null;
  try {
    final ThreadFactory threadFactory=new DaemonThreadFactory("GangliaService");
    if (!serviceStartTime.compareAndSet(0L,System.currentTimeMillis())) {
      throw new IllegalStateException("Already running.");
    }
    if (listen)     listenService=Executors.newSingleThreadExecutor(threadFactory);
    if (report)     sendService=Executors.newSingleThreadExecutor(threadFactory);
    scheduledService=Executors.newScheduledThreadPool(3,threadFactory);
    gangliaSender=new GangliaSender(metricsServers,IGangliaDefaults.BUFFER_SIZE);
    if (listen) {
      gangliaListener=new GangliaListener(listenGroup,listenPort,messageDecoder,new GangliaServiceHandler());
      listenerFuture=new FutureTask<Void>(gangliaListener);
      listenService.submit(listenerFuture);
    }
    if (report) {
      if (heartbeatInterval > 0) {
        scheduledService.scheduleWithFixedDelay(new HeartBeatTask(),initialDelay,heartbeatInterval,TimeUnit.SECONDS);
      }
      scheduledService.scheduleAtFixedRate(new GatherMetricsTask(),initialDelay,monitoringInterval,TimeUnit.SECONDS);
      scheduledService.scheduleAtFixedRate(new PurgeMetricsTask(),60,60,TimeUnit.SECONDS);
    }
    if (log.isInfoEnabled())     log.info("Running on " + hostName + " for "+ serviceName);
    if (listen) {
      listenerFuture.get();
    }
 else {
synchronized (keepAlive) {
        try {
          keepAlive.wait();
        }
 catch (        InterruptedException ex) {
        }
      }
    }
  }
 catch (  InterruptedException t) {
  }
catch (  Throwable t) {
    log.error(t,t);
  }
 finally {
    if (listenerFuture != null) {
      listenerFuture.cancel(true);
    }
    if (listenService != null) {
      listenService.shutdownNow();
    }
    if (gangliaSender != null) {
      sendMessage(new GangliaRequestMessage(hostName,"shutdown",false));
    }
    if (sendService != null) {
      sendService.shutdownNow();
    }
    if (gangliaSender != null)     gangliaSender.close();
    gangliaState.reset();
    serviceStartTime.set(0L);
  }
}

public void run ( ) { GangliaListener gangliaListener = null ; try { final ThreadFactory threadFactory = new DaemonThreadFactory ( "GangliaService" ) ; if ( ! serviceStartTime . compareAndSet ( 0L , System . currentTimeMillis ( ) ) ) { throw new IllegalStateException ( "Already running." ) ; } if ( listen ) listenService = Executors . newSingleThreadExecutor ( threadFactory ) ; if ( report ) sendService = Executors . newSingleThreadExecutor ( threadFactory ) ; scheduledService = Executors . newScheduledThreadPool ( 3 , threadFactory ) ; gangliaSender = new GangliaSender ( metricsServers , IGangliaDefaults . BUFFER_SIZE ) ; if ( listen ) { gangliaListener = new GangliaListener ( listenGroup , listenPort , messageDecoder , new GangliaServiceHandler ( ) ) ; listenerFuture = new FutureTask < Void > ( gangliaListener ) ; listenService . submit ( listenerFuture ) ; } if ( report ) { if ( heartbeatInterval > 0 ) { scheduledService . scheduleWithFixedDelay ( new HeartBeatTask ( ) , initialDelay , heartbeatInterval , TimeUnit . SECONDS ) ; } scheduledService . scheduleAtFixedRate ( new GatherMetricsTask ( ) , initialDelay , monitoringInterval , TimeUnit . SECONDS ) ; scheduledService . scheduleAtFixedRate ( new PurgeMetricsTask ( ) , 60 , 60 , TimeUnit . SECONDS ) ; } if ( log . isInfoEnabled ( ) ) log . info ( "Running on " + hostName + " for " + serviceName ) ; if ( listen ) { listenerFuture . get ( ) ; } else { synchronized ( keepAlive ) { try { keepAlive . wait ( ) ; } catch ( InterruptedException ex ) { } } } } catch ( InterruptedException t ) { } catch ( Throwable t ) { log . error ( t , t ) ; } finally { if ( listenerFuture != null ) { listenerFuture . cancel ( true ) ; } if ( listenService != null ) { listenService . shutdownNow ( ) ; } if ( gangliaSender != null ) { sendMessage ( new GangliaRequestMessage ( hostName , "shutdown" , false ) ) ; } if ( sendService != null ) { sendService . shutdownNow ( ) ; } if ( gangliaSender != null ) gangliaSender . close ( ) ; gangliaState . reset ( ) ; serviceStartTime . set ( 0L ) ; } }
run the ganglia service .
