1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.aggregator;
18
19 import java.util.Enumeration;
20 import java.util.Hashtable;
21
22 /***
23 * Maintains a context attributes for the current Thread
24 *
25 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
26 * @version $Id: $
27 */
28 public final class CurrentWorkerContext
29 {
30 private static ThreadLocal currentWorkerContext =
31 new ThreadLocal() {
32 protected synchronized Object initialValue() {
33 return new Hashtable();
34 }
35 };
36
37 private static ThreadLocal parallelRenderingMode =
38 new ThreadLocal() {
39 protected synchronized Object initialValue() {
40 return new boolean [] { false };
41 }
42 };
43
44 private CurrentWorkerContext()
45 {
46 }
47
48 /***
49 * Returns an Enumeration containing the names of the attributes available to this Thread.
50 * This method returns an empty Enumeration if the thread has no attributes available to it.
51 */
52 public static Enumeration getAttributeNames()
53 {
54 return ((Hashtable) currentWorkerContext.get()).keys();
55 }
56
57 /***
58 * @return an attribute in the current Thread
59 * @param attrName Locale for this Thread
60 */
61 public static Object getAttribute(String name)
62 {
63 return ((Hashtable) currentWorkerContext.get()).get(name);
64 }
65
66 /***
67 * Stores an attribute in this Thread.
68 * <br>
69 * @param name - a String specifying the name of the attribute
70 * @param o - the Object to be stored
71 */
72 public static void setAttribute(String name, Object o)
73 {
74 if (o != null) {
75 ((Hashtable) currentWorkerContext.get()).put(name, o);
76 } else {
77 removeAttribute(name);
78 }
79 }
80
81 /***
82 * Removes an attribute from this Thread.
83 * <br>
84 * @param name - a String specifying the name of the attribute
85 */
86 public static void removeAttribute(String name)
87 {
88 ((Hashtable) currentWorkerContext.get()).remove(name);
89 }
90
91 /***
92 * Removes all attributes from this Thread.
93 */
94 public static void removeAllAttributes()
95 {
96 ((Hashtable) currentWorkerContext.get()).clear();
97 }
98
99 public static void setParallelRenderingMode(boolean parallelMode)
100 {
101 ((boolean []) parallelRenderingMode.get())[0] = parallelMode;
102 }
103
104 public static boolean getParallelRenderingMode()
105 {
106 return ((boolean []) parallelRenderingMode.get())[0];
107 }
108 }