Search in sources :

Example 6 with LifecycleException

use of com.googlecode.jmxtrans.exceptions.LifecycleException in project jmxtrans by jmxtrans.

the class JmxTransformer method start.

public synchronized void start() throws LifecycleException {
    if (isRunning) {
        throw new LifecycleException("Process already started");
    } else {
        log.info("Starting Jmxtrans on : {}", configuration.getJsonDirOrFile());
        try {
            this.serverScheduler.start();
            this.startupWatchdir();
            this.startupSystem();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            throw new LifecycleException(e);
        }
        // Ensure resources are free
        Runtime.getRuntime().addShutdownHook(shutdownHook);
        isRunning = true;
    }
}
Also used : LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException) ValidationException(com.googlecode.jmxtrans.model.ValidationException) SchedulerException(org.quartz.SchedulerException) ParseException(java.text.ParseException) LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException)

Example 7 with LifecycleException

use of com.googlecode.jmxtrans.exceptions.LifecycleException in project jmxtrans by jmxtrans.

the class JmxTransformer method processServersIntoJobs.

/**
	 * Processes all the Servers into Job's
	 * <p/>
	 * Needs to be called after processFiles()
	 */
private void processServersIntoJobs() throws LifecycleException {
    for (Server server : this.masterServersList) {
        try {
            // need to inject the poolMap
            for (Query query : server.getQueries()) {
                for (OutputWriter writer : query.getOutputWriterInstances()) {
                    writer.start();
                }
            }
            // Now validate the setup of each of the OutputWriter's per
            // query.
            this.validateSetup(server, server.getQueries());
            // Now schedule the jobs for execution.
            this.scheduleJob(server);
        } catch (ParseException ex) {
            throw new LifecycleException("Error parsing cron expression: " + server.getCronExpression(), ex);
        } catch (SchedulerException ex) {
            throw new LifecycleException("Error scheduling job for server: " + server, ex);
        } catch (ValidationException ex) {
            throw new LifecycleException("Error validating json setup for query", ex);
        }
    }
}
Also used : LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException) SchedulerException(org.quartz.SchedulerException) ValidationException(com.googlecode.jmxtrans.model.ValidationException) MBeanServer(javax.management.MBeanServer) Server(com.googlecode.jmxtrans.model.Server) Query(com.googlecode.jmxtrans.model.Query) ParseException(java.text.ParseException) OutputWriter(com.googlecode.jmxtrans.model.OutputWriter)

Example 8 with LifecycleException

use of com.googlecode.jmxtrans.exceptions.LifecycleException in project jmxtrans by jmxtrans.

the class JmxTransformer method stopServices.

// There is a sleep to work around a Quartz issue. The issue is marked to be
// fixed, but will require further analysis. This should not be reported by
// Findbugs, but as a more complex issue.
@SuppressFBWarnings(value = "SWL_SLEEP_WITH_LOCK_HELD", justification = "Workaround for Quartz issue")
private synchronized void stopServices() throws LifecycleException {
    try {
        // Shutdown the scheduler
        if (serverScheduler.isStarted()) {
            serverScheduler.shutdown(true);
            log.debug("Shutdown server scheduler");
            try {
                // FIXME: Quartz issue, need to sleep
                Thread.sleep(1500);
            } catch (InterruptedException e) {
                log.error(e.getMessage(), e);
                currentThread().interrupt();
            }
        }
        shutdownAndAwaitTermination(queryProcessorExecutor, 10, SECONDS);
        shutdownAndAwaitTermination(resultProcessorExecutor, 10, SECONDS);
        // Shutdown the file watch service
        if (watcher != null) {
            watcher.stopService();
            watcher = null;
            log.debug("Shutdown watch service");
        }
        // Shutdown the outputwriters
        stopWriterAndClearMasterServerList();
    } catch (Exception e) {
        throw new LifecycleException(e);
    }
}
Also used : LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException) ValidationException(com.googlecode.jmxtrans.model.ValidationException) SchedulerException(org.quartz.SchedulerException) ParseException(java.text.ParseException) LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 9 with LifecycleException

use of com.googlecode.jmxtrans.exceptions.LifecycleException in project jmxtrans by jmxtrans.

the class JmxTransformer method stopWriterAndClearMasterServerList.

/**
	 * Shut down the output writers and clear the master server list
	 * Used both during shutdown and when re-reading config files
	 */
private void stopWriterAndClearMasterServerList() {
    for (Server server : this.masterServersList) {
        for (OutputWriter writer : server.getOutputWriters()) {
            try {
                writer.close();
            } catch (LifecycleException ex) {
                log.error("Eror stopping writer: {}", writer);
            }
        }
        for (Query query : server.getQueries()) {
            for (OutputWriter writer : query.getOutputWriterInstances()) {
                try {
                    writer.close();
                    log.debug("Stopped writer: {} for query: {}", writer, query);
                } catch (LifecycleException ex) {
                    log.error("Error stopping writer: {} for query: {}", writer, query, ex);
                }
            }
        }
    }
    this.masterServersList = ImmutableList.of();
}
Also used : LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException) MBeanServer(javax.management.MBeanServer) Server(com.googlecode.jmxtrans.model.Server) Query(com.googlecode.jmxtrans.model.Query) OutputWriter(com.googlecode.jmxtrans.model.OutputWriter)

Example 10 with LifecycleException

use of com.googlecode.jmxtrans.exceptions.LifecycleException in project jmxtrans by jmxtrans.

the class JmxTransformer method stop.

public synchronized void stop() throws LifecycleException {
    if (!isRunning) {
        throw new LifecycleException("Process already stopped");
    } else {
        try {
            log.info("Stopping Jmxtrans");
            // Remove hook to not call twice
            if (shutdownHook != null) {
                Runtime.getRuntime().removeShutdownHook(shutdownHook);
            }
            this.stopServices();
            isRunning = false;
        } catch (LifecycleException e) {
            log.error(e.getMessage(), e);
            throw new LifecycleException(e);
        }
    }
}
Also used : LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException)

Aggregations

LifecycleException (com.googlecode.jmxtrans.exceptions.LifecycleException)10 ValidationException (com.googlecode.jmxtrans.model.ValidationException)5 ParseException (java.text.ParseException)3 MBeanServer (javax.management.MBeanServer)3 SchedulerException (org.quartz.SchedulerException)3 OutputWriter (com.googlecode.jmxtrans.model.OutputWriter)2 Query (com.googlecode.jmxtrans.model.Query)2 Server (com.googlecode.jmxtrans.model.Server)2 IOException (java.io.IOException)2 SocketException (java.net.SocketException)2 DatagramSocketFactory (com.googlecode.jmxtrans.connections.DatagramSocketFactory)1 JmxProcess (com.googlecode.jmxtrans.model.JmxProcess)1 ManagedGenericKeyedObjectPool (com.googlecode.jmxtrans.monitoring.ManagedGenericKeyedObjectPool)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 File (java.io.File)1 DatagramSocket (java.net.DatagramSocket)1 InetSocketAddress (java.net.InetSocketAddress)1 GenericKeyedObjectPool (org.apache.commons.pool.impl.GenericKeyedObjectPool)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1