KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quickserver > net > server > impl > SyncClientIdentifier


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) 2003-2005 QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
10  * For questions, suggestions, bug-reports, enhancement-requests etc.
11  * visit http://www.quickserver.org
12  *
13  */

14
15 package org.quickserver.net.server.impl;
16
17 import java.io.*;
18 import java.util.*;
19 import java.util.logging.*;
20 import org.quickserver.util.pool.*;
21 import org.quickserver.net.server.*;
22 import java.util.regex.*;
23
24 /**
25  * Synchronized Client Identifier implementation.
26  * @author Akshathkumar Shetty
27  * @since 1.4.5
28  */

29 public class SyncClientIdentifier extends BasicClientIdentifier {
30     private static final Logger logger = Logger.getLogger(SyncClientIdentifier.class.getName());
31
32     public ClientHandler findFirstClientById(String JavaDoc id) {
33         ClientHandler foundClientHandler = null;
34
35         synchronized(getObjectToSynchronize()) {
36             Iterator iterator = findAllClient();
37             while(iterator.hasNext()) {
38                 foundClientHandler = checkClientId(
39                     (ClientHandler) iterator.next(), id);
40
41                 if(foundClientHandler!=null) break;
42             }//endof while
43
}
44         return foundClientHandler;
45     }
46
47     public Iterator findAllClientById(String JavaDoc pattern) {
48         ArrayList list = new ArrayList();
49         Pattern p = Pattern.compile(pattern);
50         ClientHandler foundClientHandler = null;
51         
52         synchronized(getObjectToSynchronize()) {
53             Iterator iterator = findAllClient();
54             
55             while(iterator.hasNext()) {
56                 foundClientHandler = checkClientId(
57                     (ClientHandler) iterator.next(), p);
58
59                 if(foundClientHandler!=null)
60                     list.add(foundClientHandler);
61             }//endof while
62
}
63         return list.iterator();
64     }
65
66     public ClientHandler findClientByKey(String JavaDoc key) {
67         ClientHandler foundClientHandler = null;
68
69         synchronized(getObjectToSynchronize()) {
70             Iterator iterator = findAllClient();
71             while(iterator.hasNext()) {
72                 foundClientHandler = checkClientKey(
73                     (ClientHandler) iterator.next(), key);
74
75                 if(foundClientHandler!=null) break;
76             }//endof while
77
}
78         return foundClientHandler;
79     }
80
81     public Iterator findAllClientByKey(String JavaDoc pattern) {
82         ArrayList list = new ArrayList();
83         Pattern p = Pattern.compile(pattern);
84         ClientHandler foundClientHandler = null;
85
86         synchronized(getObjectToSynchronize()) {
87             Iterator iterator = findAllClient();
88             while(iterator.hasNext()) {
89                 foundClientHandler = checkClientKey(
90                     (ClientHandler) iterator.next(), pattern);
91             
92                 if(foundClientHandler!=null)
93                     list.add(foundClientHandler);
94                 foundClientHandler = null;
95             }//endof while
96
}
97         return list.iterator();
98     }
99 }
100
Popular Tags