Search in sources :

Example 1 with ShutdownTracker

use of io.fabric8.common.util.ShutdownTracker in project fabric8 by jboss-fuse.

the class ExtendedBurnIn method lotsOfClientLoad.

@Test
public void lotsOfClientLoad() throws Exception {
    startRestEndpoint();
    startHttpGateway();
    DetectingGateway gateway = startDetectingGateway();
    final ShutdownTracker tracker = new ShutdownTracker();
    // Run some concurrent load against the broker via the gateway...
    final StompJmsConnectionFactory factory = new StompJmsConnectionFactory();
    factory.setBrokerURI("tcp://localhost:" + gateway.getBoundPort());
    for (int client = 0; client < 10; client++) {
        new Thread("JMS Client: " + client) {

            @Override
            public void run() {
                while (tracker.attemptRetain()) {
                    try {
                        Connection connection = factory.createConnection();
                        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                        MessageConsumer consumer = session.createConsumer(session.createTopic("FOO"));
                        MessageProducer producer = session.createProducer(session.createTopic("FOO"));
                        producer.send(session.createTextMessage("Hello"));
                        consumer.receive(1000);
                        connection.close();
                    } catch (JMSException e) {
                        e.printStackTrace();
                    } finally {
                        tracker.release();
                    }
                }
            }
        }.start();
    }
    int httpPort = gateway.getBoundPort();
    final URL httpUrl = new URL("http://localhost:" + httpPort + "/hello/world");
    for (int client = 0; client < 10; client++) {
        new Thread("HTTP Client: " + client) {

            @Override
            public void run() {
                while (tracker.attemptRetain()) {
                    try {
                        InputStream is = httpUrl.openConnection().getInputStream();
                        try {
                            ByteArrayOutputStream baos = new ByteArrayOutputStream();
                            int c = 0;
                            while ((c = is.read()) >= 0) {
                                baos.write(c);
                            }
                            assertEquals("Hello World!", new String(baos.toByteArray()));
                        } finally {
                            is.close();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        tracker.release();
                    }
                }
            }
        }.start();
    }
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // Lets monitor memory usage for 5 min..
    for (int i = 0; i < 60 * 5; i++) {
        Thread.sleep(900);
        Runtime.getRuntime().gc();
        Thread.sleep(100);
        long usedMB = ((Long) ((CompositeData) mBeanServer.getAttribute(new ObjectName("java.lang:type=Memory"), "HeapMemoryUsage")).get("used")).longValue() / (1024 * 1024);
        System.out.println("Using " + usedMB + " MB of heap.");
    }
    tracker.stop();
}
Also used : DetectingGateway(io.fabric8.gateway.handlers.detecting.DetectingGateway) InputStream(java.io.InputStream) CompositeData(javax.management.openmbean.CompositeData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URL(java.net.URL) ObjectName(javax.management.ObjectName) ShutdownTracker(io.fabric8.common.util.ShutdownTracker) StompJmsConnectionFactory(org.fusesource.stomp.jms.StompJmsConnectionFactory) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 2 with ShutdownTracker

use of io.fabric8.common.util.ShutdownTracker in project fabric8 by jboss-fuse.

the class FabricDetectingGateway method activate.

@Activate
void activate(Map<String, ?> configuration) throws Exception {
    shutdownTacker = new ShutdownTracker();
    initialize(configuration);
}
Also used : ShutdownTracker(io.fabric8.common.util.ShutdownTracker)

Example 3 with ShutdownTracker

use of io.fabric8.common.util.ShutdownTracker in project fabric8 by jboss-fuse.

the class FabricMBeanRegistrationListener method registerFabricMBeans.

private void registerFabricMBeans() {
    this.healthCheck = new HealthCheck(fabricService.get());
    this.managerMBean = new FabricManager((FabricServiceImpl) fabricService.get());
    this.zooKeeperMBean = new ZooKeeperFacade((FabricServiceImpl) fabricService.get());
    this.fileSystemMBean = new FileSystem(runtimeProperties.get());
    healthCheck.registerMBeanServer(shutdownTracker, mbeanServer.get());
    managerMBean.registerMBeanServer(shutdownTracker, mbeanServer.get());
    fileSystemMBean.registerMBeanServer(shutdownTracker, mbeanServer.get());
    zooKeeperMBean.registerMBeanServer(shutdownTracker, mbeanServer.get());
}
Also used : FabricManager(io.fabric8.core.jmx.FabricManager) ZooKeeperFacade(io.fabric8.core.jmx.ZooKeeperFacade) FileSystem(io.fabric8.core.jmx.FileSystem) HealthCheck(io.fabric8.core.jmx.HealthCheck)

Example 4 with ShutdownTracker

use of io.fabric8.common.util.ShutdownTracker in project fabric8 by jboss-fuse.

the class FabricManager method registerMBeanServer.

public void registerMBeanServer(ShutdownTracker shutdownTracker, MBeanServer mbeanServer) {
    try {
        ObjectName name = getObjectName();
        if (!mbeanServer.isRegistered(name)) {
            StandardMBean mbean = new StandardMBean(this, FabricManagerMBean.class);
            mbeanServer.registerMBean(mbean, name);
        }
    } catch (Exception e) {
        LOG.warn("An error occurred during mbean server registration: " + e, e);
    }
}
Also used : StandardMBean(javax.management.StandardMBean) MalformedObjectNameException(javax.management.MalformedObjectNameException) FabricException(io.fabric8.api.FabricException) MalformedURLException(java.net.MalformedURLException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) ObjectName(javax.management.ObjectName)

Aggregations

ShutdownTracker (io.fabric8.common.util.ShutdownTracker)2 ObjectName (javax.management.ObjectName)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 FabricException (io.fabric8.api.FabricException)1 FabricManager (io.fabric8.core.jmx.FabricManager)1 FileSystem (io.fabric8.core.jmx.FileSystem)1 HealthCheck (io.fabric8.core.jmx.HealthCheck)1 ZooKeeperFacade (io.fabric8.core.jmx.ZooKeeperFacade)1 DetectingGateway (io.fabric8.gateway.handlers.detecting.DetectingGateway)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 MBeanServer (javax.management.MBeanServer)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 StandardMBean (javax.management.StandardMBean)1 CompositeData (javax.management.openmbean.CompositeData)1 StompJmsConnectionFactory (org.fusesource.stomp.jms.StompJmsConnectionFactory)1 Test (org.junit.Test)1