idok-commit AT lists.psi.ch
Subject: Commit emails of the iDok project
List archive
[idok-commit] idok commit r370 - in trunk: java/ch/idok/dmsd/impl/config/svnlucene java/ch/idok/dmsd/impl/controller java/ch/idok/dmsd/impl/queue sites/psi/scripts/admin/dmsd
Chronological Thread
- From: "AFS account Stadler Hans Christian" <stadler_h AT savannah.psi.ch>
- To: idok-commit AT lists.psi.ch
- Subject: [idok-commit] idok commit r370 - in trunk: java/ch/idok/dmsd/impl/config/svnlucene java/ch/idok/dmsd/impl/controller java/ch/idok/dmsd/impl/queue sites/psi/scripts/admin/dmsd
- Date: Wed, 24 Jun 2009 10:45:30 +0200
- List-archive: <https://lists.web.psi.ch/pipermail/idok-commit/>
- List-id: Commit emails of the iDok project <idok-commit.lists.psi.ch>
Author: stadler_h
Date: Wed Jun 24 10:45:30 2009
New Revision: 370
Log:
Possibility to change number of threads at runtime
Modified:
trunk/java/ch/idok/dmsd/impl/config/svnlucene/Config.java
trunk/java/ch/idok/dmsd/impl/controller/SimpleController.java
trunk/java/ch/idok/dmsd/impl/controller/SimpleControllerManager.java
trunk/java/ch/idok/dmsd/impl/controller/SimpleControllerManagerMBean.java
trunk/java/ch/idok/dmsd/impl/queue/Event.java
trunk/java/ch/idok/dmsd/impl/queue/EventPriority.java
trunk/java/ch/idok/dmsd/impl/queue/EventQueue.java
trunk/sites/psi/scripts/admin/dmsd/build.xml
Modified: trunk/java/ch/idok/dmsd/impl/config/svnlucene/Config.java
==============================================================================
--- trunk/java/ch/idok/dmsd/impl/config/svnlucene/Config.java (original)
+++ trunk/java/ch/idok/dmsd/impl/config/svnlucene/Config.java Wed Jun 24
10:45:30 2009
@@ -875,8 +875,10 @@
* @see dmsd.config.Configurator.destroy()
*/
public void destroy() {
- for (String key : extractors.keySet()) {
- extractors.get(key).destroy();
+ if (extractors != null) {
+ for (String key : extractors.keySet()) {
+ extractors.get(key).destroy();
+ }
}
extractors = null;
}
Modified: trunk/java/ch/idok/dmsd/impl/controller/SimpleController.java
==============================================================================
--- trunk/java/ch/idok/dmsd/impl/controller/SimpleController.java
(original)
+++ trunk/java/ch/idok/dmsd/impl/controller/SimpleController.java Wed
Jun 24 10:45:30 2009
@@ -30,8 +30,10 @@
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -117,9 +119,15 @@
AtomicInteger activeEvents;
/**
+ * @brief Number of threads in the thread pool
+ */
+ private int numThreads = 32;
+
+ /**
* @brief Event Loop Executor Service
+ * This will be a FixedThreadPool
*/
- ExecutorService executor;
+ private AtomicReference<ExecutorService> executor;
/**
* @brief Mime key for the original mime type.
@@ -134,7 +142,7 @@
/**
* @brief Map for accumulated values.
*/
- HashMap<String, Double> accum = new HashMap<String, Double>();
+ private HashMap<String, Double> accum = new HashMap<String, Double>();
/**
* @brief Event Handler
@@ -182,7 +190,8 @@
monitor.addCounter("operation.exceptions", 0);
new SimpleControllerManager(this);
activeEvents = new AtomicInteger(0);
- executor = Executors.newFixedThreadPool(32);
+ numThreads =
Integer.getInteger("ch.idok.dmsd.controller.nthreads",8);
+ executor = new
AtomicReference<ExecutorService>(Executors.newFixedThreadPool(numThreads));
}
// -------------- Error Handling ------------------------
@@ -445,16 +454,14 @@
aev = activeEvents.get();
Event event = EventQueue.dequeue();
while (event != null) {
+ ExecutorService exe = executor.get();
if (reactToStop && stopnow) {
EventQueue.flush();
- try {
- executor.awaitTermination(60, TimeUnit.SECONDS);
- } catch (InterruptedException ex) { /*ignore*/ }
break;
}
try {
activeEvents.incrementAndGet();
- executor.execute(new EventHandler(event));
+ exe.execute(new EventHandler(event));
aev = activeEvents.get();
event = EventQueue.dequeue();
} catch (Throwable th) {
@@ -534,6 +541,8 @@
} while (true);
config.reconfig(false);
} while (true);
+ // Tell the thread pool to shut down - it should be already
+ executor.get().shutdown();
return scheduledStop == 0 ? 1 : 0;
} catch (InterruptedException ex) {
logger.warning("Received interrupt. Stopping operation..");
@@ -659,5 +668,26 @@
*/
public void startCycle() {
}
-
+
+ /**
+ * @brief Change the number of threads in the thread pool
+ */
+ public void setNumberOfThreads(int nThreads) {
+ if (nThreads <= 0)
+ return;
+ if (nThreads == numThreads)
+ return;
+ ExecutorService newExe = Executors.newFixedThreadPool(nThreads);
+ numThreads = nThreads;
+ ExecutorService oldExe = executor.getAndSet(newExe);
+ oldExe.shutdown();
+ }
+
+ /**
+ * @brief Number of threads
+ * @return Return the number of threads in the thread pool
+ */
+ public int getNumberOfThreads() {
+ return numThreads;
+ }
}
Modified: trunk/java/ch/idok/dmsd/impl/controller/SimpleControllerManager.java
==============================================================================
--- trunk/java/ch/idok/dmsd/impl/controller/SimpleControllerManager.java
(original)
+++ trunk/java/ch/idok/dmsd/impl/controller/SimpleControllerManager.java
Wed Jun 24 10:45:30 2009
@@ -141,6 +141,20 @@
}
/**
+ * @brief Set number of threads
+ */
+ public void setNumberOfThreads(int nThreads) {
+ controller.setNumberOfThreads(nThreads);
+ }
+
+ /**
+ * @brief Get number of threads
+ */
+ public int getNumberOfThreads() {
+ return controller.getNumberOfThreads();
+ }
+
+ /**
* @brief Set the root log level.
*
* @param logLevel
Modified:
trunk/java/ch/idok/dmsd/impl/controller/SimpleControllerManagerMBean.java
==============================================================================
--- trunk/java/ch/idok/dmsd/impl/controller/SimpleControllerManagerMBean.java
(original)
+++ trunk/java/ch/idok/dmsd/impl/controller/SimpleControllerManagerMBean.java
Wed Jun 24 10:45:30 2009
@@ -38,6 +38,14 @@
public void pingDaemon();
/**
+ * @brief Set number of threads
+ */
+ public void setNumberOfThreads(int nThreads);
+
+ /** @brief Number of threads */
+ public int getNumberOfThreads();
+
+ /**
* @brief Set the log level of the root logger.
*
* @param logLevel
Modified: trunk/java/ch/idok/dmsd/impl/queue/Event.java
==============================================================================
--- trunk/java/ch/idok/dmsd/impl/queue/Event.java (original)
+++ trunk/java/ch/idok/dmsd/impl/queue/Event.java Wed Jun 24 10:45:30
2009
@@ -64,7 +64,7 @@
* - more than 0 if this has lower priority than o
*/
public int compareTo(Event o) {
- return priority - o.priority;
+ return EventPriority.compare(priority, o.priority);
}
/**
Modified: trunk/java/ch/idok/dmsd/impl/queue/EventPriority.java
==============================================================================
--- trunk/java/ch/idok/dmsd/impl/queue/EventPriority.java (original)
+++ trunk/java/ch/idok/dmsd/impl/queue/EventPriority.java Wed Jun 24
10:45:30 2009
@@ -19,11 +19,34 @@
package ch.idok.dmsd.impl.queue;
+/**
+ * @brief Defines event priorities
+ */
public final class EventPriority {
- public static final int urgent = -2;
+ /** @brief Highest priority event */
+ public static final int urgent = -2;
+ /** @brief Event should be handled before data event */
public static final int handleBeforeData = -1;
+ /** @brief Normal data event */
public static final int data = 0;
+ /** @brief Event should be handled first after data events */
public static final int handleAfterData1 = 1;
+ /** @brief Event should be handled after data events */
public static final int handleAfterData2 = 2;
+ /** @brief Event should be handled last after data events */
public static final int handleAfterData3 = 3;
+
+ /**
+ * @brief Comparator method
+ *
+ * @param prio1 First event
+ * @param prio2 Second event
+ * @return
+ * - less than 0 if the first event has higher priority than the second
event
+ * - 0 if the first event has the same priority as the second event
+ * - more than 0 if the first event has lower priority than the second
event
+ */
+ static final int compare(int prio1, int prio2) {
+ return prio1 - prio2;
+ }
}
Modified: trunk/java/ch/idok/dmsd/impl/queue/EventQueue.java
==============================================================================
--- trunk/java/ch/idok/dmsd/impl/queue/EventQueue.java (original)
+++ trunk/java/ch/idok/dmsd/impl/queue/EventQueue.java Wed Jun 24 10:45:30
2009
@@ -98,6 +98,7 @@
return rval;
}
+ /** @brief Get the event queue singleton */
public static EventQueue instance() {
if (singleton == null) {
logger = Setup.getConfig().getLogger("dmsd.eventqueue");
@@ -106,9 +107,11 @@
return singleton;
}
+ /** @brief Get the event queue of the singleton */
private static AbstractQueue<Event> eventQueue() {
return instance().eventQueue;
}
+ /** @brief The event queue singleton instance */
private static EventQueue singleton;
}
Modified: trunk/sites/psi/scripts/admin/dmsd/build.xml
==============================================================================
--- trunk/sites/psi/scripts/admin/dmsd/build.xml (original)
+++ trunk/sites/psi/scripts/admin/dmsd/build.xml Wed Jun 24 10:45:30
2009
@@ -131,7 +131,7 @@
<mkdir dir="${build}/${svncommon}"/>
<javac srcdir="${src}/${svnjava}"
destdir="${build}/${svnjava}" classpath="${jsvn}:${lucene}"
includeAntRuntime="no" includeJavaRuntime="yes"
listfiles="yes" debug="${debug}"
- includes="${common}/**/*.java"
excludes="**/*Test.java,**/*TestBase.java"/>
+ includes="${common}/**/*.java"
excludes="**/client/**,**/kerberized/**,**/*Test.java,**/*TestBase.java"/>
</target>
<!-- Compile dmsd -->
- [idok-commit] idok commit r370 - in trunk: java/ch/idok/dmsd/impl/config/svnlucene java/ch/idok/dmsd/impl/controller java/ch/idok/dmsd/impl/queue sites/psi/scripts/admin/dmsd, AFS account Stadler Hans Christian, 06/24/2009
Archive powered by MHonArc 2.6.19.