AdapterManager extends ComponentManagerImpl<Adapter> implements AdapterManagerMBean, AdapterRuntimeManager { @Override public void forceClose() throws CoreException { sendNotification(createLifecycleNotification(NOTIF_MSG_FORCE_CLOSE, myObjectName)); log.trace("Force Close on {}", myObjectName); ManagedThreadFactory.interruptManagedThreads(); super.requestClose(); } private  AdapterManager();  AdapterManager(Adapter owner); @Override ObjectName createObjectName(); @Override long requestStartTime(); @Override long requestStopTime(); @Override Collection<ObjectName> getChildren(); @Override boolean addChild(ChannelRuntimeManager cmb); @Override boolean removeChild(ChannelRuntimeManager cmb); @Override boolean addChildren(Collection<ChannelRuntimeManager> coll); @Override boolean removeChildren(Collection<ChannelRuntimeManager> coll); @Override Adapter getWrappedComponent(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Override Collection<BaseComponentMBean> getAllDescendants(); @Override Collection<ObjectName> getChildRuntimeInfoComponents(); @Override boolean addChildJmxComponent(ChildRuntimeInfoComponent comp); @Override boolean removeChildJmxComponent(ChildRuntimeInfoComponent comp); @Override String createObjectHierarchyString(); @Override boolean addSharedConnection(String xmlString); @Override boolean addAndBindSharedConnection(String xmlString); @Override boolean removeSharedConnection(String connectionId); @Override boolean containsSharedConnection(String connectionId); @Override Collection<String> getSharedConnectionIds(); @Override boolean addSharedService(String xmlString); @Override boolean addAndBindSharedService(String xmlString); @Override boolean removeSharedService(String serviceId); @Override boolean containsSharedService(String serviceId); @Override Collection<String> getSharedServiceIds(); @Override boolean removeSharedComponent(String id); @Override ObjectName addChannel(String xml); @Override boolean removeChannel(String id); @Override void setMessageErrorHandler(String xml); @Override void setFailedMessageRetrier(String xml); @Override void registerMBean(); @Override void unregisterMBean(); @Override void childUpdated(); @Override String getAdapterBuildVersion(); @Override List<String> getModuleVersions(); @Override List<String> getArtifactIdentifiers(); @Override void sendLifecycleEvent(AdapterLifecycleEvent event); @Override MBeanNotificationInfo[] getNotificationInfo(); @Override void forceClose();  }
@Test public void testForceClose_ErrorOnInit_RequestInit() throws Exception { final TimeInterval waitTime = new TimeInterval(5L, TimeUnit.SECONDS); String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName); MockFailingConnection conn = new MockFailingConnection(getName(), "Init"); conn.setConnectionAttempts(-1); conn.setConnectionRetryInterval(new TimeInterval(100L, TimeUnit.MILLISECONDS)); adapter.getSharedComponents().addConnection(conn); List<BaseComponentMBean> mBeans = createJmxManagers(adapter); try { register(mBeans); ObjectName adapterObj = createAdapterObjectName(adapterName); final AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class); final CyclicBarrier gate = new CyclicBarrier(2); MyExceptionHandler exceptionHandler = new MyExceptionHandler(); Thread initThread = new ManagedThreadFactory().newThread(new Runnable() { @Override public void run() { try { manager.requestInit(); } catch (CoreException e) { throw new RuntimeException(e); } try { gate.await(waitTime.toMilliseconds(), TimeUnit.MILLISECONDS); } catch (Exception gateException) { } } }); initThread.setUncaughtExceptionHandler(exceptionHandler); initThread.start(); try { gate.await(waitTime.toMilliseconds(), TimeUnit.MILLISECONDS); fail("Adapter init success, when not expected"); } catch (Exception gateException) { manager.forceClose(); } assertEquals(ClosedState.getInstance(), manager.getComponentState()); assertEquals(0, conn.getInitCount()); assertEquals(0, conn.getCloseCount()); } finally { adapter.requestClose(); } }
@Test public void testForceClose_ErrorOnInit_RequestStart() throws Exception { final TimeInterval waitTime = new TimeInterval(5L, TimeUnit.SECONDS); String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName); MockFailingConnection conn = new MockFailingConnection(getName(), "Init"); conn.setConnectionAttempts(-1); conn.setConnectionRetryInterval(new TimeInterval(100L, TimeUnit.MILLISECONDS)); adapter.getSharedComponents().addConnection(conn); List<BaseComponentMBean> mBeans = createJmxManagers(adapter); try { register(mBeans); ObjectName adapterObj = createAdapterObjectName(adapterName); final AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class); final CyclicBarrier gate = new CyclicBarrier(3); MyExceptionHandler exceptionHandler = new MyExceptionHandler(); ManagedThreadFactory threadFactory = new ManagedThreadFactory(); Thread initThread = threadFactory.newThread(new Runnable() { @Override public void run() { try { manager.requestInit(); } catch (CoreException e) { throw new RuntimeException(e); } try { gate.await(waitTime.toMilliseconds(), TimeUnit.MILLISECONDS); } catch (Exception gateException) { } } }); initThread.setUncaughtExceptionHandler(exceptionHandler); initThread.start(); Thread startThread = threadFactory.newThread(new Runnable() { @Override public void run() { try { manager.requestStart(); } catch (CoreException e) { throw new RuntimeException(e); } try { gate.await(waitTime.toMilliseconds(), TimeUnit.MILLISECONDS); } catch (Exception gateException) { } } }); startThread.setUncaughtExceptionHandler(exceptionHandler); startThread.start(); try { gate.await(waitTime.toMilliseconds(), TimeUnit.MILLISECONDS); fail("Adapter init success, when not expected"); } catch (Exception gateException) { manager.forceClose(); } assertEquals(ClosedState.getInstance(), manager.getComponentState()); assertEquals(0, conn.getInitCount()); assertEquals(0, conn.getCloseCount()); } finally { adapter.requestClose(); } }
@Test public void testForceClose_ErrorOnStart_RequestStart() throws Exception { final TimeInterval waitTime = new TimeInterval(5L, TimeUnit.SECONDS); String adapterName = this.getClass().getSimpleName() + "." + getName(); Adapter adapter = createAdapter(adapterName); MockFailingConnection conn = new MockFailingConnection(getName(), "Start"); conn.setConnectionAttempts(-1); conn.setConnectionRetryInterval(new TimeInterval(100L, TimeUnit.MILLISECONDS)); adapter.getSharedComponents().addConnection(conn); List<BaseComponentMBean> mBeans = createJmxManagers(adapter); try { register(mBeans); ObjectName adapterObj = createAdapterObjectName(adapterName); final AdapterManagerMBean manager = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class); final CyclicBarrier gate = new CyclicBarrier(2); MyExceptionHandler exceptionHandler = new MyExceptionHandler(); Thread startThread = new ManagedThreadFactory().newThread(new Runnable() { @Override public void run() { try { manager.requestStart(); } catch (CoreException e) { throw new RuntimeException(e); } try { gate.await(waitTime.toMilliseconds(), TimeUnit.MILLISECONDS); } catch (Exception gateException) { } } }); startThread.setUncaughtExceptionHandler(exceptionHandler); startThread.start(); try { gate.await(waitTime.toMilliseconds(), TimeUnit.MILLISECONDS); fail("Adapter Start success, when not expected"); } catch (Exception gateException) { manager.forceClose(); } assertEquals(ClosedState.getInstance(), manager.getComponentState()); assertEquals(1, conn.getInitCount()); assertEquals(0, conn.getStartCount()); assertEquals(1, conn.getCloseCount()); } finally { adapter.requestClose(); } }