gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / process / RasterTaskQueue.java @ 1419
History | View | Annotate | Download (3.12 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.impl.process; |
23 |
|
24 |
import java.util.ArrayList; |
25 |
import java.util.EventObject; |
26 |
import java.util.TreeMap; |
27 |
|
28 |
/**
|
29 |
* Clase donde se registran todos los procesos raster para poder ser accedidos por distintos
|
30 |
* objetos y puedan mandarles se?ales.
|
31 |
*
|
32 |
* @version 30/08/2007
|
33 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
34 |
*
|
35 |
*/
|
36 |
public class RasterTaskQueue { |
37 |
|
38 |
private static TreeMap<String, RasterTask> processPool = new TreeMap<String, RasterTask>(); |
39 |
private static ArrayList<String> processID = new ArrayList<String>(); |
40 |
|
41 |
/**
|
42 |
* Registra procesos para que puedan ser accedidos
|
43 |
* @param id Identificador del proceso
|
44 |
* @param process Proceso
|
45 |
*/
|
46 |
public static void register(RasterTask process) { |
47 |
processPool.put(process.getID(), process); |
48 |
processID.add(process.getID()); |
49 |
} |
50 |
|
51 |
/**
|
52 |
* Saca un proceso del repositorio
|
53 |
* @param id Identificador del proceso.
|
54 |
*/
|
55 |
public static void remove(RasterTask process) { |
56 |
processPool.remove(process.getID()); |
57 |
for (int i = 0; i < processID.size(); i++) { |
58 |
if(((String)processID.get(i)).compareTo(process.getID()) == 0) { |
59 |
processID.remove(i); |
60 |
break;
|
61 |
} |
62 |
} |
63 |
} |
64 |
|
65 |
/**
|
66 |
* Gets a process from its identifier. If the object is null, this method will create a new RasterTask
|
67 |
* @param id Process identifier
|
68 |
* @return Process
|
69 |
*/
|
70 |
public static RasterTask get(String id) { |
71 |
return ((RasterTask)processPool.get(id) == null) ? new RasterTask(null) : (RasterTask)processPool.get(id); |
72 |
} |
73 |
|
74 |
/**
|
75 |
* Gets a process from its identifier
|
76 |
* @param id Process identifier
|
77 |
* @return Process
|
78 |
*/
|
79 |
public static RasterTask getRasterTask(String id) { |
80 |
return (RasterTask)processPool.get(id);
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* Envia un evento al proceso cuyo id coincide con el par?metro
|
85 |
* @param id Identificador del proceso
|
86 |
* @param ev Evento
|
87 |
*/
|
88 |
public static void sendSignal(String id, EventObject ev) { |
89 |
Object obj = processPool.get(id);
|
90 |
if(obj != null && obj instanceof RasterTask) |
91 |
((RasterTask)obj).setEvent(ev); |
92 |
} |
93 |
|
94 |
/**
|
95 |
* Envia un evento a todos los procesos
|
96 |
* @param id Identificador del proceso
|
97 |
* @param ev Evento
|
98 |
*/
|
99 |
public static void sendSignal(EventObject ev) { |
100 |
for (int i = 0; i < processID.size(); i++) { |
101 |
String id = (String)processID.get(i); |
102 |
sendSignal(id, ev); |
103 |
} |
104 |
} |
105 |
|
106 |
} |