001: /*
002: * This file is part of the QuickServer library
003: * Copyright (C) 2003-2005 QuickServer.org
004: *
005: * Use, modification, copying and distribution of this software is subject to
006: * the terms and conditions of the GNU Lesser General Public License.
007: * You should have received a copy of the GNU LGP License along with this
008: * library; if not, you can download a copy from <http://www.quickserver.org/>.
009: *
010: * For questions, suggestions, bug-reports, enhancement-requests etc.
011: * visit http://www.quickserver.org
012: *
013: */
014:
015: package org.quickserver.net.server.impl;
016:
017: import java.io.*;
018: import java.util.*;
019: import java.util.logging.*;
020: import org.quickserver.util.pool.*;
021: import org.quickserver.net.server.*;
022: import java.util.regex.*;
023:
024: /**
025: * Synchronized Client Identifier implementation.
026: * @author Akshathkumar Shetty
027: * @since 1.4.5
028: */
029: public class SyncClientIdentifier extends BasicClientIdentifier {
030: private static final Logger logger = Logger
031: .getLogger(SyncClientIdentifier.class.getName());
032:
033: public ClientHandler findFirstClientById(String id) {
034: ClientHandler foundClientHandler = null;
035:
036: synchronized (getObjectToSynchronize()) {
037: Iterator iterator = findAllClient();
038: while (iterator.hasNext()) {
039: foundClientHandler = checkClientId(
040: (ClientHandler) iterator.next(), id);
041:
042: if (foundClientHandler != null)
043: break;
044: }//endof while
045: }
046: return foundClientHandler;
047: }
048:
049: public Iterator findAllClientById(String pattern) {
050: ArrayList list = new ArrayList();
051: Pattern p = Pattern.compile(pattern);
052: ClientHandler foundClientHandler = null;
053:
054: synchronized (getObjectToSynchronize()) {
055: Iterator iterator = findAllClient();
056:
057: while (iterator.hasNext()) {
058: foundClientHandler = checkClientId(
059: (ClientHandler) iterator.next(), p);
060:
061: if (foundClientHandler != null)
062: list.add(foundClientHandler);
063: }//endof while
064: }
065: return list.iterator();
066: }
067:
068: public ClientHandler findClientByKey(String key) {
069: ClientHandler foundClientHandler = null;
070:
071: synchronized (getObjectToSynchronize()) {
072: Iterator iterator = findAllClient();
073: while (iterator.hasNext()) {
074: foundClientHandler = checkClientKey(
075: (ClientHandler) iterator.next(), key);
076:
077: if (foundClientHandler != null)
078: break;
079: }//endof while
080: }
081: return foundClientHandler;
082: }
083:
084: public Iterator findAllClientByKey(String pattern) {
085: ArrayList list = new ArrayList();
086: Pattern p = Pattern.compile(pattern);
087: ClientHandler foundClientHandler = null;
088:
089: synchronized (getObjectToSynchronize()) {
090: Iterator iterator = findAllClient();
091: while (iterator.hasNext()) {
092: foundClientHandler = checkClientKey(
093: (ClientHandler) iterator.next(), pattern);
094:
095: if (foundClientHandler != null)
096: list.add(foundClientHandler);
097: foundClientHandler = null;
098: }//endof while
099: }
100: return list.iterator();
101: }
102: }
|