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;
}
}
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);
}
}
}
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);
}
}
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();
}
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);
}
}
}
Aggregations