ServiceProcessManager.java
01 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
02  *
03  * Copyright 2000-2011,  Michael Meyling <mime@qedeq.org>.
04  *
05  * "Hilbert II" is free software; you can redistribute
06  * it and/or modify it under the terms of the GNU General Public
07  * License as published by the Free Software Foundation; either
08  * version 2 of the License, or (at your option) any later version.
09  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  */
15 
16 package org.qedeq.kernel.bo.service;
17 
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.Map;
21 
22 import org.qedeq.kernel.bo.common.ServiceProcess;
23 import org.qedeq.kernel.bo.module.KernelQedeqBo;
24 import org.qedeq.kernel.se.common.Plugin;
25 
26 /**
27  * Manage all known processes.
28  */
29 public class ServiceProcessManager {
30 
31     /** Stores all processes. */
32     private final List processes = new ArrayList();
33 
34 
35     /**
36      * Get all service processes.
37      *
38      @return  All service processes.
39      */
40     public synchronized ServiceProcess[] getServiceProcesses() {
41         return (ServiceProcess[]) processes.toArray(new ServiceProcess[] {});
42     }
43 
44     /**
45      * Create service process.
46      *
47      @param   service     The service that runs in current thread.
48      @param   qedeq       QEDEQ module for service.
49      @param   parameters  Parameter for the service.
50      @return  Created process.
51      */
52     public synchronized ServiceProcess createProcess(final Plugin service,
53             final KernelQedeqBo qedeq, final Map parameters) {
54         final ServiceProcess process = new ServiceProcessImpl(service, qedeq, parameters);
55         processes.add(process);
56         return process;
57     }
58 
59     /**
60      * Remove all service processes. All processes are also terminated via interruption.
61      */
62     public synchronized void terminateAndRemoveAllServiceProcesses() {
63         for (int i = 0; i < processes.size(); i++) {
64             final ServiceProcess proc = (ServiceProcessprocesses.get(i);
65             proc.interrupt();
66         }
67         processes.clear();
68     }
69 
70 
71 }