1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.orchestra.conversation;
20
21 import java.util.HashSet;
22 import java.util.Set;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27
28
29
30
31
32
33
34 public class ConversationWiperThread extends Thread
35 {
36 private final Log log = LogFactory.getLog(ConversationWiperThread.class);
37
38 private final long checkTime;
39
40 private Set conversationManagers = new HashSet();
41
42
43
44
45
46
47
48 public ConversationWiperThread(long checkTime)
49 {
50 this.checkTime = checkTime;
51
52 setDaemon(true);
53 setName(ConversationWiperThread.class.getName());
54 }
55
56
57
58
59
60
61 public void addConversationManager(ConversationManager cm)
62 {
63 synchronized (conversationManagers)
64 {
65 conversationManagers.add(cm);
66 }
67 }
68
69
70
71
72
73
74 public void removeConversationManager(ConversationManager cm)
75 {
76 synchronized (conversationManagers)
77 {
78 boolean found = conversationManagers.remove(cm);
79 if (!found)
80 {
81
82 log.error("Conversation Manager not found in remove");
83 }
84 }
85 }
86
87 public void run()
88 {
89 log.debug("ConversationWiperThread startup");
90 _run();
91 log.debug("ConversationWiperThread shtudown");
92 }
93
94 private void _run()
95 {
96 while (!isInterrupted())
97 {
98 ConversationManager[] managersArray;
99 synchronized (conversationManagers)
100 {
101 managersArray = new ConversationManager[conversationManagers.size()];
102 conversationManagers.toArray(managersArray);
103 }
104
105 if (log.isDebugEnabled())
106 {
107 log.debug("ConversationWiperThread running against " + managersArray.length + " instances.");
108 }
109
110 for (int i = 0; i<managersArray.length; i++)
111 {
112 ConversationManager conversationManager = managersArray[i];
113 conversationManager.checkTimeouts();
114 }
115
116 try
117 {
118 Thread.sleep(checkTime);
119 }
120 catch (InterruptedException e)
121 {
122 return;
123 }
124 }
125 }
126 }