Search in sources :

Example 1 with LifecycleException

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();
}
Also used : LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException) JmxProcess(com.googlecode.jmxtrans.model.JmxProcess) File(java.io.File) LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException)

Example 2 with LifecycleException

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));
    }
}
Also used : SocketException(java.net.SocketException) LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with LifecycleException

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);
    }
}
Also used : LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException) ManagedGenericKeyedObjectPool(com.googlecode.jmxtrans.monitoring.ManagedGenericKeyedObjectPool) GenericKeyedObjectPool(org.apache.commons.pool.impl.GenericKeyedObjectPool) DatagramSocketFactory(com.googlecode.jmxtrans.connections.DatagramSocketFactory) ManagedGenericKeyedObjectPool(com.googlecode.jmxtrans.monitoring.ManagedGenericKeyedObjectPool) ValidationException(com.googlecode.jmxtrans.model.ValidationException) IOException(java.io.IOException) LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException)

Example 4 with LifecycleException

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);
    }
}
Also used : LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException) ValidationException(com.googlecode.jmxtrans.model.ValidationException) IOException(java.io.IOException) LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException) MBeanServer(javax.management.MBeanServer)

Example 5 with LifecycleException

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);
    }
}
Also used : SocketException(java.net.SocketException) LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException) DatagramSocket(java.net.DatagramSocket) InetSocketAddress(java.net.InetSocketAddress)

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