Package org.rhq.enterprise.communications

Examples of org.rhq.enterprise.communications.ServiceContainer


        if (stream == null) {
            return null;
        }

        try {
            ServiceContainer sc = m_agent.getServiceContainer();

            if (sc == null) {
                return stream;
            }
View Full Code Here


        if (stream == null) {
            return null;
        }

        try {
            ServiceContainer sc = m_agent.getServiceContainer();

            if (sc == null) {
                return stream;
            }
View Full Code Here

        prefs.put(ServiceContainerConfigurationConstants.CONFIG_SCHEMA_VERSION, ""
            + ServiceContainerConfigurationConstants.CURRENT_CONFIG_SCHEMA_VERSION);
        prefs.put(ServiceContainerConfigurationConstants.DATA_DIRECTORY, "target");
        prefs.remove(ServiceContainerConfigurationConstants.GLOBAL_CONCURRENCY_LIMIT); // make sure we do not have a global limit

        ServiceContainer sc = new ServiceContainer();
        sc.start(prefs, new ClientCommandSenderConfiguration());
        Map<String, Integer> map = sc.getConcurrencyManager().getAllConfiguredNumberOfPermitsAllowed();
        map.put("limited", 10);
        sc.setConcurrencyManager(new ConcurrencyManager(map));

        Thread.sleep(5000);

        AtomicInteger counter = new AtomicInteger(0);
        CountDownLatch latch = new CountDownLatch(1);
        LimitedConcurrencyPojo pojoImpl = new LimitedConcurrencyPojo(counter, latch);

        sc.addRemotePojo(pojoImpl, ILimitedConcurrencyPojo.class);
        try {
            // default for clientMaxPoolSize is 50, but we don't want remoting to be the limit for this test
            RemoteCommunicator comm = new JBossRemotingRemoteCommunicator(
                "socket://127.0.0.1:" + CommTestConstants.CONNECTOR_BIND_PORT + "/?clientMaxPoolSize=100");
            ClientCommandSenderConfiguration config = new ClientCommandSenderConfiguration();
            config.maxConcurrent = Integer.MAX_VALUE; // let the sender send as fast as it can
            config.defaultTimeoutMillis = 60000L;
            sender = new ClientCommandSender(comm, config);
            sender.startSending();

            final ILimitedConcurrencyPojo pojo = sender.getClientRemotePojoFactory().getRemotePojo(
                ILimitedConcurrencyPojo.class);

            // sanity check - make sure we can call it - this is needed to get the jboss/remoting client initialized with thread safety
            assert pojo.ping();

            for (int i = 0; i < 10; i++) {
                new Thread(new Runnable() {
                    public void run() {
                        pojo.limitedMethod("foo1");
                    }
                }).start();
            }

            int loopMax = 10; // should not take us over 10s for our threads to start
            while ((counter.get() < 10) && (loopMax-- > 0)) {
                Thread.sleep(1000);
            }

            assert counter.get() == 10 : "For some reason, we didn't invoke our pojo 10 times: " + counter;

            // so far so good - there should now be 10 concurrent threads in the limited method, no more are allowed
            new Thread(new Runnable() {
                public void run() {
                    pojo.limitedMethod("notallowed1");
                }
            }).start();

            Thread.sleep(5000);
            assert counter.get() == 10 : "Should not have been permitted, counter should still be 10: " + counter;

            latch.countDown(); // release the hounds! all threads should finish now
            loopMax = 10; // should not take us over 10s for our threads to finish
            while ((counter.get() > 0) && (loopMax-- > 0)) {
                Thread.sleep(1000);
            }

            assert counter.get() == 0 : "All the threads should have finished, counter should be 0: " + counter;

            // see that we can call it - we can call it synchronously, it shouldn't block and we can finish quick
            assert "allowed1".equals(pojo.limitedMethod("allowed1"));
        } finally {
            latch.countDown(); // in case we got exceptions, let's flush our threads that might be hung

            if (sender != null) {
                sender.stopSending(false);
            }

            sc.shutdown();
        }
    }
View Full Code Here

        prefs.put(ServiceContainerConfigurationConstants.CONFIG_SCHEMA_VERSION, ""
            + ServiceContainerConfigurationConstants.CURRENT_CONFIG_SCHEMA_VERSION);
        prefs.put(ServiceContainerConfigurationConstants.DATA_DIRECTORY, "target");
        prefs.remove(ServiceContainerConfigurationConstants.GLOBAL_CONCURRENCY_LIMIT); // make sure we do not have a global limit

        ServiceContainer sc = new ServiceContainer();
        sc.start(prefs, new ClientCommandSenderConfiguration());
        Map<String, Integer> map = sc.getConcurrencyManager().getAllConfiguredNumberOfPermitsAllowed();
        map.put("limitedTimeout", 10);
        sc.setConcurrencyManager(new ConcurrencyManager(map));
        Thread.sleep(5000);

        AtomicInteger counter = new AtomicInteger(0);
        CountDownLatch latch = new CountDownLatch(1);
        LimitedConcurrencyPojo pojoImpl = new LimitedConcurrencyPojo(counter, latch);

        sc.addRemotePojo(pojoImpl, ILimitedConcurrencyPojo.class);
        try {
            // default for clientMaxPoolSize is 50, but we don't want remoting to be the limit for this test
            RemoteCommunicator comm = new JBossRemotingRemoteCommunicator(
                "socket://127.0.0.1:" + CommTestConstants.CONNECTOR_BIND_PORT + "/?clientMaxPoolSize=100");
            ClientCommandSenderConfiguration config = new ClientCommandSenderConfiguration();
            config.maxConcurrent = Integer.MAX_VALUE; // let the sender send as fast as it can
            config.defaultTimeoutMillis = 60000L; // @Timeout will override this
            sender = new ClientCommandSender(comm, config);
            sender.startSending();

            final ILimitedConcurrencyPojo pojo = sender.getClientRemotePojoFactory().getRemotePojo(
                ILimitedConcurrencyPojo.class);

            // sanity check - make sure we can call it - this is needed to get the jboss/remoting client initialized with thread safety
            assert pojo.ping();

            final AtomicInteger timedOutThreads = new AtomicInteger(0);

            // 10 will timeout because of the latch, and 5 will timeout while waiting to get in due to concurrency limit
            for (int i = 0; i < 15; i++) {
                new Thread(new Runnable() {
                    public void run() {
                        try {
                            pojo.limitedWithTimeoutMethod("foo2");
                        } catch (Exception e) {
                            timedOutThreads.incrementAndGet();
                        }
                    }
                }).start();
            }

            int loopMax = 10; // should not take us over 10s for our threads to start

            // note that only 10 threads will be able to increment counter; the other 5 will block and timeout before they have a chance to
            while ((counter.get() < 10) && (loopMax-- > 0)) {
                Thread.sleep(1000);
            }

            assert counter.get() == 10 : "For some reason, we didn't invoke our pojo 10 times: " + counter;

            // do not open latch, show that the threads do die (which could only be due to timeout)
            loopMax = 10; // should not take us over 10s for our threads to finish
            while ((timedOutThreads.get() < 15) && (loopMax-- > 0)) {
                Thread.sleep(1000);
            }

            assert timedOutThreads.get() == 15 : "All the threads should have timed out, counter should be 15: "
                + counter;

            // see that we can call it - we can call it synchronously, it shouldn't block and we can finish quick
            latch.countDown();
            assert "allowed2".equals(pojo.limitedWithTimeoutMethod("allowed2"));
        } finally {
            latch.countDown(); // in case we got exceptions, let's flush our threads that might be hung

            if (sender != null) {
                sender.stopSending(false);
            }

            sc.shutdown();
        }
    }
View Full Code Here

        prefs.put(ServiceContainerConfigurationConstants.CONFIG_SCHEMA_VERSION, ""
            + ServiceContainerConfigurationConstants.CURRENT_CONFIG_SCHEMA_VERSION);
        prefs.put(ServiceContainerConfigurationConstants.DATA_DIRECTORY, "target");
        prefs.remove(ServiceContainerConfigurationConstants.GLOBAL_CONCURRENCY_LIMIT); // make sure we do not have a global limit

        ServiceContainer sc = new ServiceContainer();
        sc.start(prefs, new ClientCommandSenderConfiguration());
        Thread.sleep(5000);

        AtomicInteger counter = new AtomicInteger(0);
        CountDownLatch latch = new CountDownLatch(1);
        LimitedConcurrencyPojo pojoImpl = new LimitedConcurrencyPojo(counter, latch);

        sc.addRemotePojo(pojoImpl, ILimitedConcurrencyPojo.class);
        try {
            // default for clientMaxPoolSize is 50, but we don't want remoting to be the limit for this test
            RemoteCommunicator comm = new JBossRemotingRemoteCommunicator(
                "socket://127.0.0.1:" + CommTestConstants.CONNECTOR_BIND_PORT + "/?clientMaxPoolSize=100");
            ClientCommandSenderConfiguration config = new ClientCommandSenderConfiguration();
            config.maxConcurrent = Integer.MAX_VALUE; // let the sender send as fast as it can
            config.defaultTimeoutMillis = 60000L;
            sender = new ClientCommandSender(comm, config);
            sender.startSending();

            final ILimitedConcurrencyPojo pojo = sender.getClientRemotePojoFactory().getRemotePojo(
                ILimitedConcurrencyPojo.class);

            // sanity check - make sure we can call it - this is needed to get the jboss/remoting client initialized with thread safety
            assert pojo.ping();

            for (int i = 0; i < 60; i++) // 60 is larger than the default concurrent limit (when @LimitedConcurrency is used)
            {
                new Thread(new Runnable() {
                    public void run() {
                        pojo.unlimitedMethod("unlimited3"); // unlimited number of concurrent calls are allowed here
                    }
                }).start();
            }

            int loopMax = 30; // should not take us over 30s for our threads to start
            while ((counter.get() < 60) && (loopMax-- > 0)) {
                Thread.sleep(1000);
            }

            assert counter.get() == 60 : "For some reason, we didn't invoke our pojo 60 times: " + counter;

            latch.countDown(); // release the hounds! all threads should finish now

            loopMax = 30; // should not take us over 30s for our threads to finish
            while ((counter.get() > 0) && (loopMax-- > 0)) {
                Thread.sleep(1000);
            }

            assert counter.get() == 0 : "All the threads should have finished, counter should be 0: " + counter;
        } finally {
            latch.countDown(); // in case we got exceptions, let's flush our threads that might be hung

            if (sender != null) {
                sender.stopSending(false);
            }

            sc.shutdown();
        }
    }
View Full Code Here

        prefs.put(ServiceContainerConfigurationConstants.CONFIG_SCHEMA_VERSION, ""
            + ServiceContainerConfigurationConstants.CURRENT_CONFIG_SCHEMA_VERSION);
        prefs.put(ServiceContainerConfigurationConstants.DATA_DIRECTORY, "target");
        prefs.put(ServiceContainerConfigurationConstants.GLOBAL_CONCURRENCY_LIMIT, "5");

        ServiceContainer sc = new ServiceContainer();
        sc.start(prefs, new ClientCommandSenderConfiguration());
        Thread.sleep(5000);

        AtomicInteger counter = new AtomicInteger(0);
        CountDownLatch latch = new CountDownLatch(1);
        LimitedConcurrencyPojo pojoImpl = new LimitedConcurrencyPojo(counter, latch);

        sc.addRemotePojo(pojoImpl, ILimitedConcurrencyPojo.class);
        try {
            // default for clientMaxPoolSize is 50, but we don't want remoting to be the limit for this test
            RemoteCommunicator comm = new JBossRemotingRemoteCommunicator(
                "socket://127.0.0.1:" + CommTestConstants.CONNECTOR_BIND_PORT + "/?clientMaxPoolSize=100");
            ClientCommandSenderConfiguration config = new ClientCommandSenderConfiguration();
            config.maxConcurrent = Integer.MAX_VALUE; // let the sender send as fast as it can
            config.defaultTimeoutMillis = 6000000L;
            sender = new ClientCommandSender(comm, config);
            sender.startSending();

            final ILimitedConcurrencyPojo pojo = sender.getClientRemotePojoFactory().getRemotePojo(
                ILimitedConcurrencyPojo.class);

            // sanity check - make sure we can call it - this is needed to get the jboss/remoting client initialized with thread safety
            assert pojo.ping();

            // 5 will timeout because of the latch, and 10 will timeout while waiting to get in due to concurrency limit
            for (int i = 0; i < 15; i++) {
                new Thread(new Runnable() {
                    public void run() {
                        pojo.unlimitedMethod("unlimited3"); // unlimited number of concurrent calls are allowed here
                    }
                }).start();
            }

            int loopMax = 10; // should not take us over 10s for our threads to start

            // note that only 5 threads will be able to increment counter; the other 10 will block due to concurrency limit
            while ((counter.get() < 5) && (loopMax-- > 0)) {
                Thread.sleep(1000);
            }

            assert counter.get() == 5 : "For some reason, we didn't invoke our pojo 5 times: " + counter;

            // release the hounds! see that we can call it now - we can call it synchronously, it shouldn't block and we can finish quick
            latch.countDown();
            assert "unlimited3".equals(pojo.unlimitedMethod("unlimited3"));
        } finally {
            latch.countDown(); // in case we got exceptions, let's flush our threads that might be hung

            if (sender != null) {
                sender.stopSending(false);
            }

            sc.shutdown();
        }
    }
View Full Code Here

            + ServiceContainerConfigurationConstants.CURRENT_CONFIG_SCHEMA_VERSION);
        prefs1.put(ServiceContainerConfigurationConstants.DATA_DIRECTORY, "target/data1");
        prefs1.put(ServiceContainerConfigurationConstants.MBEANSERVER_NAME, "commstreamtest1");
        prefs1.put(ServiceContainerConfigurationConstants.CMDSERVICE_DIRECTORY_DYNAMIC_DISCOVERY, "false");

        serviceContainer1 = new ServiceContainer();
        try {
            serviceContainer1.start(prefs1, new ClientCommandSenderConfiguration());
        } catch (Exception e) {
            throw new Exception("Failed to bind server socket to 127.0.0.1:" + CommTestConstants.CONNECTOR_BIND_PORT, e);
        }

        // setup the server #2
        Preferences prefs2 = getPrefs1();
        prefs2.put(ServiceContainerConfigurationConstants.CONNECTOR_TRANSPORT, "socket");
        prefs2.put(ServiceContainerConfigurationConstants.CONNECTOR_BIND_ADDRESS, "127.0.0.1");
        prefs2.put(ServiceContainerConfigurationConstants.CONNECTOR_BIND_PORT, CommTestConstants.CONNECTOR2_BIND_PORT);
        prefs2.put(ServiceContainerConfigurationConstants.CONFIG_SCHEMA_VERSION, ""
            + ServiceContainerConfigurationConstants.CURRENT_CONFIG_SCHEMA_VERSION);
        prefs2.put(ServiceContainerConfigurationConstants.DATA_DIRECTORY, "target/data2");
        prefs2.put(ServiceContainerConfigurationConstants.MBEANSERVER_NAME, "commstreamtest2");
        prefs2.put(ServiceContainerConfigurationConstants.CMDSERVICE_DIRECTORY_DYNAMIC_DISCOVERY, "false");

        serviceContainer2 = new ServiceContainer();
        try {
            serviceContainer2.start(prefs2, new ClientCommandSenderConfiguration());
        } catch (BindException e) {
            throw new Exception("Failed to bind server socket to 127.0.0.1:" + CommTestConstants.CONNECTOR2_BIND_PORT, e);
        }
View Full Code Here

        prefs.put(ServiceContainerConfigurationConstants.CONFIG_SCHEMA_VERSION, ""
            + ServiceContainerConfigurationConstants.CURRENT_CONFIG_SCHEMA_VERSION);
        prefs.put(ServiceContainerConfigurationConstants.DATA_DIRECTORY, "target");
        prefs.put(ServiceContainerConfigurationConstants.CMDSERVICES, EchoCommandService.class.getName());

        ServiceContainer sc = new ServiceContainer();
        sc.start(prefs, new ClientCommandSenderConfiguration());
        Thread.sleep(5000);

        try {
            // numberOfRetries tells jboss remoting effectively the number of seconds before declaring "cannot connect"
            RemoteCommunicator comm = new JBossRemotingRemoteCommunicator(
                "socket://127.0.0.1:" + CommTestConstants.CONNECTOR_BIND_PORT + "/?force_remote=true&numberOfRetries=2");
            ClientCommandSenderConfiguration config = new ClientCommandSenderConfiguration();
            config.maxRetries = 5;
            config.retryInterval = 500L;
            config.defaultTimeoutMillis = 4000L;
            sender = new ClientCommandSender(comm, config);
            sender.startSending();

            // sanity check - make sure we can call it
            Command cmd = createNewCommand("hello");
            assert sender.sendSynch(cmd).getResults().toString().equals("hello");

            // try to send a command that can never make it - we should never retry this one
            cmd = createNewCommand(new NotSerializable());
            TestCommandResponseCallback callback = new TestCommandResponseCallback();

            synchronized (callback) {
                sender.sendAsynchGuaranteed(cmd, callback);
                callback.wait(3000L); // should not retry so should go fast
            }

            assert callback.response != null;
            assert callback.response.getCommand() != null;
            assert !callback.response.isSuccessful() : "Command wasn't serializable, should have failed: "
                + callback.response;
            assert !callback.response.getCommand().getConfiguration().containsKey("rhq.retry") : "Should not have retried at all: "
                + callback.response;

            sc.shutdown();
            Thread.sleep(2000L); // give the server container time to shutdown

            // shutdown listener and try to send - should retry forever due to cannot-connect exception (max-retries will be ignored)
            cmd = createNewCommand("forever");
            callback = new TestCommandResponseCallback();

            synchronized (callback) {
                sender.sendAsynchGuaranteed(cmd, callback);
                callback.wait((config.maxRetries * (config.retryInterval + config.defaultTimeoutMillis)) + 1000); // we will not get a callback - this proves max-retries doesn't take effect
            }

            assert callback.response == null : "Server was shut down, and we should have retried forever; should not have received a response yet: "
                + callback.response;

            // now restart the server and the command should immediately get triggered
            synchronized (callback) {
                sc.start(prefs, new ClientCommandSenderConfiguration());
                callback.wait(5000); // should get notified very fast, probably within a second
            }

            assert callback.response != null : "Command should have been finished by now";
            assert callback.response.isSuccessful() : "Command should have been successful: " + callback.response;
            assert callback.response.getResults().toString().equals("forever");
            assert Integer.parseInt(callback.response.getCommand().getConfiguration().getProperty("rhq.retry")) >= config.maxRetries : "Should have retried: "
                + callback.response;
        } finally {
            if (sender != null) {
                sender.stopSending(false);
            }

            sc.shutdown();
        }
    }
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.communications.ServiceContainer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.