Search in sources :

Example 21 with Server

use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.

the class ServerListBuilderTest method outputWritersAreReusedOnServersAndQueries.

@Test
public void outputWritersAreReusedOnServersAndQueries() {
    Server server = Server.builder(serverWithNoQuery()).addOutputWriterFactory(new DummyOutputWriterFactory("output1")).addQuery(Query.builder(dummyQuery()).addOutputWriterFactory(new DummyOutputWriterFactory("output1")).build()).build();
    ImmutableList<Server> servers = new ServerListBuilder().add(singletonList(server)).build();
    Server createdServer = servers.iterator().next();
    Query createdQuery = createdServer.getQueries().iterator().next();
    assertThat(createdQuery.getOutputWriterInstances()).hasSize(1);
    assertThat(createdServer.getOutputWriters().iterator().next()).isSameAs(createdQuery.getOutputWriterInstances().iterator().next());
}
Also used : ServerFixtures.dummyServer(com.googlecode.jmxtrans.model.ServerFixtures.dummyServer) Server(com.googlecode.jmxtrans.model.Server) QueryFixtures.dummyQuery(com.googlecode.jmxtrans.model.QueryFixtures.dummyQuery) Query(com.googlecode.jmxtrans.model.Query) ServerFixtures.serverWithNoQuery(com.googlecode.jmxtrans.model.ServerFixtures.serverWithNoQuery) Test(org.junit.Test)

Example 22 with Server

use of com.googlecode.jmxtrans.model.Server 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)

Aggregations

Server (com.googlecode.jmxtrans.model.Server)22 Test (org.junit.Test)12 Query (com.googlecode.jmxtrans.model.Query)11 ServerFixtures.dummyServer (com.googlecode.jmxtrans.model.ServerFixtures.dummyServer)8 Result (com.googlecode.jmxtrans.model.Result)5 ArrayList (java.util.ArrayList)5 OutputWriter (com.googlecode.jmxtrans.model.OutputWriter)4 MBeanServer (javax.management.MBeanServer)4 ImmutableList (com.google.common.collect.ImmutableList)3 QueryFixtures.dummyQuery (com.googlecode.jmxtrans.model.QueryFixtures.dummyQuery)3 ServerFixtures.serverWithNoQuery (com.googlecode.jmxtrans.model.ServerFixtures.serverWithNoQuery)3 IOException (java.io.IOException)3 MBeanServerConnection (javax.management.MBeanServerConnection)3 JMXConnector (javax.management.remote.JMXConnector)3 LifecycleException (com.googlecode.jmxtrans.exceptions.LifecycleException)2 JmxProcess (com.googlecode.jmxtrans.model.JmxProcess)2 JobDataMap (org.quartz.JobDataMap)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Gson (com.google.gson.Gson)1 Injector (com.google.inject.Injector)1