void configure(Object beanInstance) { // check the ApplicationContext states first , and call the refresh if necessary if (((SpringCamelContext) getCamelContext()).getApplicationContext() instanceof ConfigurableApplicationContext) { ConfigurableApplicationContext context = (ConfigurableApplicationContext) ((SpringCamelContext) getCamelContext()).getApplicationContext(); if (!context.isActive()) { context.refresh(); } } configurer.configureBean(beanId, beanInstance); }
/** * Test start kaa node server application. * * @throws Exception the exception */ @Test public void testStartKaaNodeServerApplication() throws Exception { TestingCluster zkCluster = null; TTransport transport = null; Thread kaaNodeServerLauncherThread = null; KaaNodeThriftService.Client client = null; CuratorFramework zkClient = null; CountDownLatch latch = new CountDownLatch(1); boolean kaaNodeStarted = false; TestKaaNodeLauncher launcher = new TestKaaNodeLauncher(); try { zkCluster = new TestingCluster(new InstanceSpec(null, 2185, -1, -1, true, -1, -1, -1)); zkCluster.start(); zkClient = CuratorFrameworkFactory.newClient(zkCluster.getConnectString(), new RetryOneTime(100)); zkClient.start(); kaaNodeServerLauncherThread = new Thread(launcher); kaaNodeServerLauncherThread.start(); OperationsNodeStartupListener operationsNodeStartupListener = new OperationsNodeStartupListener(); zkClient.getCuratorListenable().addListener(operationsNodeStartupListener); zkClient.getChildren().inBackground(latch).forPath(OPERATIONS_SERVER_NODE_PATH); // Wait for operations service to start kaaNodeStarted = latch.await(KAA_NODE_START_TIMEOUT_SEC, TimeUnit.SECONDS); zkClient.getCuratorListenable().removeListener(operationsNodeStartupListener); transport = new TSocket(HOST, PORT); TProtocol protocol = new TBinaryProtocol(transport); TMultiplexedProtocol mp = new TMultiplexedProtocol(protocol, KaaThriftService.KAA_NODE_SERVICE.getServiceName()); client = new KaaNodeThriftService.Client(mp); transport.open(); client.shutdown(); } finally { boolean shutdownFailed = false; Closeables.close(zkClient, true); if (transport != null && transport.isOpen()) { Closeables.close(transport, true); } if (kaaNodeServerLauncherThread != null) { kaaNodeServerLauncherThread.join(30000); shutdownFailed = kaaNodeServerLauncherThread.isAlive(); } Closeables.close(zkCluster, true); if (launcher != null) { ConfigurableApplicationContext appContext = launcher.getApplicationContext(); if (appContext.isActive()) { Closeables.close(appContext, true); } } if (!kaaNodeStarted) { throw new TimeoutException( "Timeout (" + KAA_NODE_START_TIMEOUT_SEC + " sec) occured while waiting kaa node server to start!"); } else if (shutdownFailed) { throw new TimeoutException( "Timeout (" + KAA_NODE_STOP_TIMEOUT_SEC + " sec) occured while waiting kaa node server shutdown thread!"); } } }