X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Ftestingservices%2Fscheduledthreadpool%2FTestingScheduledThreadPoolModule.java;h=a16c7c5092ba6506834e121726e1be40512aa882;hp=77d1f8bbdfedfca2402b9c310d54cf1413f94340;hb=f43b01b81319959b1907e3e04537f5169e7f33d8;hpb=0641db636be750bf98e85c702c4948c7c835b9b6 diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/scheduledthreadpool/TestingScheduledThreadPoolModule.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/scheduledthreadpool/TestingScheduledThreadPoolModule.java index 77d1f8bbdf..a16c7c5092 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/scheduledthreadpool/TestingScheduledThreadPoolModule.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/scheduledthreadpool/TestingScheduledThreadPoolModule.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2013, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -12,9 +12,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import java.io.Closeable; - import javax.annotation.Nullable; - import org.opendaylight.controller.config.api.ModuleIdentifier; import org.opendaylight.controller.config.api.RuntimeBeanRegistratorAwareModule; import org.opendaylight.controller.config.api.runtime.RootRuntimeBeanRegistrator; @@ -25,10 +23,8 @@ import org.opendaylight.controller.config.spi.Module; * This class has two exported interfaces and two runtime beans. Recreation is * triggered by setting Recreate attribute to true. */ -public class TestingScheduledThreadPoolModule implements Module, - TestingScheduledThreadPoolConfigBeanMXBean, - RuntimeBeanRegistratorAwareModule, - TestingScheduledThreadPoolServiceInterface { +public class TestingScheduledThreadPoolModule implements Module, TestingScheduledThreadPoolConfigBeanMXBean, + RuntimeBeanRegistratorAwareModule, TestingScheduledThreadPoolServiceInterface { private final ModuleIdentifier identifier; @Nullable @@ -36,22 +32,20 @@ public class TestingScheduledThreadPoolModule implements Module, @Nullable private final TestingScheduledThreadPoolImpl oldInstance; - private final int threadCount = 10; + private int threadCount = 10; private TestingScheduledThreadPoolImpl instance; private RootRuntimeBeanRegistrator runtimeBeanRegistrator; private boolean recreate; - public TestingScheduledThreadPoolModule(ModuleIdentifier identifier, - @Nullable AutoCloseable oldCloseable, - @Nullable TestingScheduledThreadPoolImpl oldInstance) { + public TestingScheduledThreadPoolModule(final ModuleIdentifier identifier, + @Nullable final AutoCloseable oldCloseable, @Nullable final TestingScheduledThreadPoolImpl oldInstance) { this.identifier = identifier; this.oldCloseable = oldCloseable; this.oldInstance = oldInstance; } @Override - public void setRuntimeBeanRegistrator( - RootRuntimeBeanRegistrator runtimeBeanRegistrator) { + public void setRuntimeBeanRegistrator(final RootRuntimeBeanRegistrator runtimeBeanRegistrator) { this.runtimeBeanRegistrator = runtimeBeanRegistrator; } @@ -59,8 +53,13 @@ public class TestingScheduledThreadPoolModule implements Module, public void validate() { assertNull(runtimeBeanRegistrator); // check thread count - checkState(threadCount > 0, - "Parameter 'ThreadCount' must be greater than 0"); + checkState(threadCount > 0, "Parameter 'ThreadCount' must be greater than 0"); + } + + @Override + public boolean canReuse(final Module oldModule) { + return getClass().isInstance(oldModule) + && getThreadCount() == ((TestingScheduledThreadPoolModule) oldModule).getThreadCount(); } @Override @@ -69,6 +68,12 @@ public class TestingScheduledThreadPoolModule implements Module, } @Override + public void setThreadCount(final int threadCount) { + this.threadCount = threadCount; + } + + @Override + @SuppressWarnings("IllegalCatch") public Closeable getInstance() { assertNotNull(runtimeBeanRegistrator); if (instance == null) { @@ -80,13 +85,12 @@ public class TestingScheduledThreadPoolModule implements Module, if (oldCloseable != null) { try { oldCloseable.close(); - } catch (Exception e) { + } catch (final Exception e) { throw new RuntimeException(e); } } // close old threadpool and esp. unregister runtime beans - instance = new TestingScheduledThreadPoolImpl( - runtimeBeanRegistrator, threadCount); + instance = new TestingScheduledThreadPoolImpl(runtimeBeanRegistrator, threadCount); } } return instance; @@ -99,7 +103,7 @@ public class TestingScheduledThreadPoolModule implements Module, } @Override - public void setRecreate(boolean recreate) { + public void setRecreate(final boolean recreate) { this.recreate = recreate; } @@ -107,6 +111,4 @@ public class TestingScheduledThreadPoolModule implements Module, public ModuleIdentifier getIdentifier() { return identifier; } - - }