X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Ftestingservices%2Fthreadpool%2FTestingFixedThreadPoolModule.java;fp=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Ftestingservices%2Fthreadpool%2FTestingFixedThreadPoolModule.java;h=ff33b164c509958743bd0bde313fe71966e159d2;hb=9fb64948564e252018f9b1e13e7cea2c92f991aa;hp=0000000000000000000000000000000000000000;hpb=1742b3894614be478c333a1043ced8ef1bc5dc84;p=controller.git diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/threadpool/TestingFixedThreadPoolModule.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/threadpool/TestingFixedThreadPoolModule.java new file mode 100644 index 0000000000..ff33b164c5 --- /dev/null +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/threadpool/TestingFixedThreadPoolModule.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2013 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, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.manager.testingservices.threadpool; + +import static com.google.common.base.Preconditions.checkState; + +import java.io.Closeable; + +import javax.annotation.Nullable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.opendaylight.controller.config.api.ModuleIdentifier; +import org.opendaylight.controller.config.manager.testingservices.seviceinterface.ModifiableThreadPoolServiceInterface; +import org.opendaylight.controller.config.spi.Module; + +@NotThreadSafe +public class TestingFixedThreadPoolModule implements + TestingFixedThreadPoolConfigMXBean, Module, + TestingThreadPoolConfigMXBean, ModifiableThreadPoolServiceInterface { + private final AutoCloseable oldCloseable; + private final TestingFixedThreadPool oldInstance; + private final ModuleIdentifier name; + private TestingFixedThreadPool instance; + private int threadCount = 0; + private boolean triggerNewInstanceCreation; + + TestingFixedThreadPoolModule(ModuleIdentifier name, + @Nullable AutoCloseable oldCloseable, + @Nullable TestingFixedThreadPool oldInstance) { + this.name = name; + this.oldCloseable = oldCloseable; + this.oldInstance = oldInstance; + } + + @Override + public ModuleIdentifier getName() { + return name; + } + + // attributes + @Override + public void setThreadCount(int threadCount) { + this.threadCount = threadCount; + } + + @Override + public int getThreadCount() { + return threadCount; + } + + @Override + public boolean isTriggerNewInstanceCreation() { + return triggerNewInstanceCreation; + } + + @Override + public void setTriggerNewInstanceCreation(boolean triggerNewInstanceCreation) { + this.triggerNewInstanceCreation = triggerNewInstanceCreation; + } + + // operations + + private boolean isReusable() { + return oldInstance != null; + } + + @Override + public void validate() { + checkState(threadCount > 0, + "Parameter 'threadCount' must be greater than 0"); + } + + @Override + public Closeable getInstance() { + if (instance == null) { + if (isReusable() && triggerNewInstanceCreation == false) { // simulate + // big + // change + // using + // triggerNewInstanceCreation + oldInstance.setMaximumNumberOfThreads(threadCount); + instance = oldInstance; + } else { + if (oldCloseable != null) { + try { + oldCloseable.close(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + instance = new TestingFixedThreadPool(threadCount, + name.toString()); + } + } + return instance; + } + +}