KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > server > notify > NotifyRequestList


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.smb.server.notify;
18
19 import java.util.Vector JavaDoc;
20
21 import org.alfresco.filesys.server.filesys.NetworkFile;
22 import org.alfresco.filesys.smb.server.SMBSrvSession;
23
24 /**
25  * Notify Change Request List Class
26  */

27 public class NotifyRequestList
28 {
29
30     // List of notify change requests
31

32     private Vector JavaDoc<NotifyRequest> m_requests;
33
34     /**
35      * Default constructor
36      */

37     public NotifyRequestList()
38     {
39         m_requests = new Vector JavaDoc<NotifyRequest>();
40     }
41
42     /**
43      * Return the specified request
44      *
45      * @param idx int
46      * @return NotifyRequest
47      */

48     public final synchronized NotifyRequest getRequest(int idx)
49     {
50
51         // Range check the index
52

53         if (idx >= m_requests.size())
54             return null;
55
56         // Return the notify request
57

58         return (NotifyRequest) m_requests.elementAt(idx);
59     }
60
61     /**
62      * Return the global filter mask, generated by combining all of the pending notify request
63      * filters
64      *
65      * @return int
66      */

67     public final synchronized int getGlobalFilter()
68     {
69
70         // Loop through all the requests
71

72         int filter = 0;
73
74         if (m_requests.size() > 0)
75         {
76
77             // Build the global filter mask from all pending requests
78

79             for (int i = 0; i < m_requests.size(); i++)
80             {
81                 NotifyRequest req = m_requests.get(i);
82                 filter |= req.getFilter();
83             }
84         }
85
86         // Return the filter mask
87

88         return filter;
89     }
90
91     /**
92      * Add a request to the list
93      *
94      * @param req NotifyRequest
95      */

96     public final synchronized void addRequest(NotifyRequest req)
97     {
98         m_requests.addElement(req);
99     }
100
101     /**
102      * Find the notify request for the matching ids
103      *
104      * @param mid int
105      * @param tid int
106      * @param uid int
107      * @param pid int
108      * @return NotifyRequest
109      */

110     public final synchronized NotifyRequest findRequest(int mid, int tid, int uid, int pid)
111     {
112
113         // Search for the required request, and remove it from the list
114

115         for (int i = 0; i < m_requests.size(); i++)
116         {
117
118             // Get the current request
119

120             NotifyRequest curReq = (NotifyRequest) m_requests.elementAt(i);
121             if (curReq.getMultiplexId() == mid && curReq.getTreeId() == tid && curReq.getUserId() == uid
122                     && curReq.getProcessId() == pid)
123             {
124
125                 // Return the request
126

127                 return curReq;
128             }
129         }
130
131         // Request not found in the list
132

133         return null;
134     }
135
136     /**
137      * Find the notify request for the specified directory and filter
138      *
139      * @param dir NetworkFile
140      * @param filter int
141      * @param watchTree boolean
142      */

143     public final synchronized NotifyRequest findRequest(NetworkFile dir, int filter, boolean watchTree)
144     {
145
146         // Search for the required request
147

148         for (int i = 0; i < m_requests.size(); i++)
149         {
150
151             // Get the current request
152

153             NotifyRequest curReq = (NotifyRequest) m_requests.elementAt(i);
154             if (curReq.getDirectory() == dir && curReq.getFilter() == filter && curReq.hasWatchTree() == watchTree)
155             {
156
157                 // Return the request
158

159                 return curReq;
160             }
161         }
162
163         // Request not found in the list
164

165         return null;
166     }
167
168     /**
169      * Remove a request from the list
170      *
171      * @param req NotifyRequest
172      */

173     public final synchronized NotifyRequest removeRequest(NotifyRequest req)
174     {
175
176         // Search for the required request, and remove it from the list
177

178         for (int i = 0; i < m_requests.size(); i++)
179         {
180
181             // Get the current request
182

183             NotifyRequest curReq = (NotifyRequest) m_requests.elementAt(i);
184             if (curReq == req)
185             {
186
187                 // Remove the request from the list
188

189                 m_requests.removeElementAt(i);
190                 return curReq;
191             }
192         }
193
194         // Request not found in the list
195

196         return null;
197     }
198
199     /**
200      * Remove a request from the list
201      *
202      * @param idx int
203      */

204     public final synchronized NotifyRequest removeRequestAt(int idx)
205     {
206
207         // Check if the request index is valid
208

209         if (idx < 0 || idx >= m_requests.size())
210             return null;
211
212         // Remove the specified request
213

214         NotifyRequest req = (NotifyRequest) m_requests.elementAt(idx);
215         m_requests.removeElementAt(idx);
216         return req;
217     }
218
219     /**
220      * Remove all requests for the specified session
221      *
222      * @param sess SMBSrvSession
223      */

224     public final synchronized void removeAllRequestsForSession(SMBSrvSession sess)
225     {
226
227         // Search for the required requests, and remove from the list
228

229         int idx = 0;
230
231         while (idx < m_requests.size())
232         {
233
234             // Get the current request
235

236             NotifyRequest curReq = (NotifyRequest) m_requests.elementAt(idx);
237             if (curReq.getSession() == sess)
238             {
239
240                 // Remove the request from the list
241

242                 m_requests.removeElementAt(idx);
243             }
244             else
245                 idx++;
246         }
247     }
248
249     /**
250      * Remove all requests for the specified session and tree connection
251      *
252      * @param sess SMBSrvSession
253      * @param tid int
254      */

255     public final synchronized void removeAllRequestsForSession(SMBSrvSession sess, int tid)
256     {
257
258         // Search for the required requests, and remove from the list
259

260         int idx = 0;
261
262         while (idx < m_requests.size())
263         {
264
265             // Get the current request
266

267             NotifyRequest curReq = (NotifyRequest) m_requests.elementAt(idx);
268             if (curReq.getSession() == sess && curReq.getTreeId() == tid)
269             {
270
271                 // Remove the request from the list
272

273                 m_requests.removeElementAt(idx);
274             }
275             else
276                 idx++;
277         }
278     }
279
280     /**
281      * Remove all requests from the list
282      */

283     public final synchronized void clearRequestList()
284     {
285         m_requests.removeAllElements();
286     }
287
288     /**
289      * Return the request list size
290      *
291      * @return int
292      */

293     public final synchronized int numberOfRequests()
294     {
295         return m_requests.size();
296     }
297 }
298
Popular Tags