use of com.googlecode.jmxtrans.exceptions.LifecycleException in project jmxtrans by jmxtrans.
the class ConfigurationParser method parseServers.
public ImmutableList parseServers(Iterable<File> jsonFiles, boolean continueOnJsonError) throws LifecycleException {
ServerListBuilder serverListBuilder = new ServerListBuilder();
for (File jsonFile : jsonFiles) {
try {
JmxProcess process = jsonUtils.parseProcess(jsonFile);
log.debug("Loaded file: {}", jsonFile.getAbsolutePath());
serverListBuilder.add(process.getServers());
} catch (Exception ex) {
String message = "Error parsing json: " + jsonFile;
// error parsing one file should not prevent the startup of JMXTrans
if (continueOnJsonError)
log.error(message, ex);
else
throw new LifecycleException(message, ex);
}
}
return serverListBuilder.build();
}
use of com.googlecode.jmxtrans.exceptions.LifecycleException in project jmxtrans by jmxtrans.
the class TCollectorUDPWriterTests method testSocketException.
/**
* Test a socket exception when creating the DatagramSocket.
*/
@Test
public void testSocketException() throws Exception {
// Prepare
SocketException sockExc = new SocketException("X-SOCK-EXC-X");
PowerMockito.whenNew(DatagramSocket.class).withNoArguments().thenThrow(sockExc);
try {
// Execute
this.writer.start();
Assert.fail("LifecycleException missing");
} catch (LifecycleException lcExc) {
// Verify
Assert.assertSame(sockExc, lcExc.getCause());
Mockito.verify(this.mockLog).error(contains("create a datagram socket"), eq(sockExc));
}
}
use of com.googlecode.jmxtrans.exceptions.LifecycleException in project jmxtrans by jmxtrans.
the class StatsDWriter method start.
@Override
public void start() throws LifecycleException {
try {
pool = new GenericKeyedObjectPool<>(new DatagramSocketFactory());
pool.setTestOnBorrow(true);
pool.setMaxActive(-1);
pool.setMaxIdle(-1);
pool.setTimeBetweenEvictionRunsMillis(MILLISECONDS.convert(5, MINUTES));
pool.setMinEvictableIdleTimeMillis(MILLISECONDS.convert(5, MINUTES));
this.mbean = new ManagedGenericKeyedObjectPool((GenericKeyedObjectPool) pool, "StatsdConnectionPool");
ManagementFactory.getPlatformMBeanServer().registerMBean(this.mbean, this.mbean.getObjectName());
} catch (Exception e) {
throw new LifecycleException(e);
}
}
use of com.googlecode.jmxtrans.exceptions.LifecycleException in project jmxtrans by jmxtrans.
the class StatsDWriter method close.
@Override
public void close() throws LifecycleException {
try {
if (this.mbean != null) {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
mbs.unregisterMBean(this.mbean.getObjectName());
this.mbean = null;
}
if (this.pool != null) {
pool.close();
this.pool = null;
}
} catch (Exception e) {
throw new LifecycleException(e);
}
}
use of com.googlecode.jmxtrans.exceptions.LifecycleException in project jmxtrans by jmxtrans.
the class TCollectorUDPWriter method prepareSender.
/**
* Setup at start of the writer.
*/
@Override
public void prepareSender() throws LifecycleException {
if (host == null || port == null) {
throw new LifecycleException("Host and port for " + this.getClass().getSimpleName() + " output can't be null");
}
try {
this.dgSocket = new DatagramSocket();
this.address = new InetSocketAddress(host, port);
} catch (SocketException sockExc) {
log.error("Failed to create a datagram socket", sockExc);
throw new LifecycleException(sockExc);
}
}
Aggregations