KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xsocket > stream > AbstractConnectionPool


1 // $Id: BlockingConnection.java 1134 2007-04-05 17:44:43Z grro $
2
/*
3  * Copyright (c) xsocket.org, 2006 - 2007. All rights reserved.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Please refer to the LGPL license at: http://www.gnu.org/copyleft/lesser.txt
20  * The latest copy of this software may be found on http://www.xsocket.org/
21  */

22 package org.xsocket.stream;
23
24 import java.io.IOException JavaDoc;
25 import java.io.UnsupportedEncodingException JavaDoc;
26 import java.net.InetAddress JavaDoc;
27 import java.net.InetSocketAddress JavaDoc;
28 import java.net.SocketTimeoutException JavaDoc;
29 import java.nio.ByteBuffer JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.HashSet JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.Map JavaDoc;
35 import java.util.Set JavaDoc;
36 import java.util.Timer JavaDoc;
37 import java.util.TimerTask JavaDoc;
38 import java.util.concurrent.Executor JavaDoc;
39 import java.util.logging.Level JavaDoc;
40 import java.util.logging.Logger JavaDoc;
41
42 import org.xsocket.ClosedConnectionException;
43 import org.xsocket.DataConverter;
44 import org.xsocket.ILifeCycle;
45 import org.xsocket.MaxReadSizeExceededException;
46
47
48 /**
49  * implementation base of a connection pool
50  *
51  * @author grro@xsocket.org
52  */

53 abstract class AbstractConnectionPool implements IConnectionPool {
54
55     private static final Logger JavaDoc LOG = Logger.getLogger(AbstractConnectionPool.class.getName());
56
57     static final long MIN_CHECKPERIOD_MILLIS = 60L * 1000L;
58     static final long NULL = -1;
59     static final int MAX_SIZE = Integer.MAX_VALUE;
60     static final long MAX_TIMEOUT = Long.MAX_VALUE;
61
62     static final int CREATE_CONNECTION_TIMEOUT = 250;
63
64     private final Timer JavaDoc timer = new Timer JavaDoc("ConPoolWatchdog", true);
65
66     private int maxActive = Integer.MAX_VALUE;
67     private int maxIdle = 3;
68     private long maxWaitMillis = 0;
69     private long idleTimeoutMillis = MAX_TIMEOUT;
70     private long lifeTimeoutMillis = MAX_TIMEOUT;
71
72     private boolean isOpen = true;
73     private final Map JavaDoc<InetSocketAddress JavaDoc, List JavaDoc<PoolableConnection>> idlePool = new HashMap JavaDoc<InetSocketAddress JavaDoc, List JavaDoc<PoolableConnection>>();
74     private final Set JavaDoc<PoolableConnection> activePool = new HashSet JavaDoc<PoolableConnection>();
75
76     private long checkPeriod = 0;
77     private TimerTask JavaDoc watchDogTask = null;
78
79     // listeners
80
private final List JavaDoc<ILifeCycle> listeners = new ArrayList JavaDoc<ILifeCycle>();
81
82
83     /**
84      * constructor
85      *
86      * @param timeToIdleMillis the max idle time in the pool. After this time the free connection will be closed
87      * @param timeToLiveMillis the max living time of the connection. If a free connection exeeded this time, the connection will be closed (if it is in pool)
88      * @param maxWaitMillis the max wait time by acquiring a connection from the pool
89      * @param maxIdle the max number of free connection in the pool
90      */

91     AbstractConnectionPool(long idleTimeoutMillis, long lifeTimeoutMillis, int maxActive, long maxWaitMillis, int maxIdle) {
92         this.idleTimeoutMillis = idleTimeoutMillis;
93         this.lifeTimeoutMillis = lifeTimeoutMillis;
94         this.maxActive = maxActive;
95         this.maxWaitMillis = maxWaitMillis;
96         this.maxIdle = maxIdle;
97
98         resetCheckPeriod();
99     }
100
101
102     /**
103      * {@inheritDoc} <br> <br>
104      *
105      * This method is thread safe
106      */

107     public synchronized final void destroyConnection(IConnection connection) throws IOException JavaDoc {
108         if (connection == null) {
109             return;
110         }
111
112         if (connection instanceof PoolableConnection) {
113             if (LOG.isLoggable(Level.FINE)) {
114                 LOG.fine("destroying connection " + connection.getId());
115             }
116             activePool.remove(connection);
117             ((PoolableConnection) connection).reallyClose();
118         } else {
119             connection.close();
120         }
121     }
122
123
124     /**
125      * adds a listener
126      * @param listener gthe listener to add
127      */

128     public void addListener(ILifeCycle listener) {
129         listeners.add(listener);
130     }
131
132     /**
133      * removes a listener
134      * @param listener the listener to remove
135      * @return true, is the listener has been removed
136      */

137     public boolean removeListener(ILifeCycle listener) {
138         boolean result = listeners.remove(listener);
139
140         return result;
141     }
142
143
144     private void resetCheckPeriod() {
145
146         if (watchDogTask != null) {
147             watchDogTask.cancel();
148         }
149
150         watchDogTask = new TimerTask JavaDoc() {
151             @Override JavaDoc
152             public void run() {
153                 Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
154                 List JavaDoc<PoolableConnection> idleConnections = idleConnectionList();
155                 checkTimeout(idleConnections);
156                 checkSize(idleConnections);
157             }
158         };
159
160
161         long time = MIN_CHECKPERIOD_MILLIS;
162         if ((lifeTimeoutMillis / 5) < time) {
163             time = (lifeTimeoutMillis / 5);
164         }
165         if ((idleTimeoutMillis / 5) < time) {
166             time = (idleTimeoutMillis / 5);
167         }
168
169         checkPeriod = time;
170         timer.schedule(watchDogTask, checkPeriod, checkPeriod);
171     }
172
173
174     final long getCheckPeriodMillis() {
175         return checkPeriod;
176     }
177
178     /**
179      * {@inheritDoc}
180      */

181     public final synchronized int getMaxActive() {
182         return maxActive;
183     }
184
185     /**
186      * {@inheritDoc}
187      */

188     public final synchronized void setMaxActive(int maxActive) {
189         this.maxActive = maxActive;
190         notifyAll();
191     }
192
193     /**
194      * {@inheritDoc}
195      */

196     public final synchronized long getMaxWaitMillis() {
197         return maxWaitMillis;
198     }
199
200
201     /**
202      * {@inheritDoc}
203      */

204     public final synchronized void setMaxWaitMillis(long maxWaitMillis) {
205         this.maxWaitMillis = maxWaitMillis;
206         notifyAll();
207     }
208
209
210     /**
211      * {@inheritDoc}
212      */

213     public final synchronized int getMaxIdle() {
214         return maxIdle;
215     }
216
217
218     /**
219      * {@inheritDoc}
220      */

221     public final synchronized void setMaxIdle(int maxIdle) {
222         this.maxIdle = maxIdle;
223         notifyAll();
224     }
225
226
227     /**
228      * {@inheritDoc}
229      */

230     public final synchronized int getNumActive() {
231         return activePool.size();
232     }
233
234
235     /**
236      * {@inheritDoc}
237      */

238     public final synchronized int getNumIdle() {
239         int size = 0;
240         for (List JavaDoc<PoolableConnection> connectionList : idlePool.values()) {
241             size += connectionList.size();
242         }
243
244         return size;
245     }
246
247
248     /**
249      * {@inheritDoc}
250      */

251     public final long getIdleTimeoutMillis() {
252         return idleTimeoutMillis;
253     }
254
255
256     /**
257      * {@inheritDoc}
258      */

259     public final void setIdleTimeoutMillis(long idleTimeoutMillis) {
260         this.idleTimeoutMillis = idleTimeoutMillis;
261         resetCheckPeriod();
262     }
263
264
265     /**
266      * {@inheritDoc}
267      */

268     public final long getLifeTimeoutMillis() {
269         return lifeTimeoutMillis;
270     }
271
272
273     /**
274      * {@inheritDoc}
275      */

276     public final void setLifeTimeoutMillis(long lifeTimeoutMillis) {
277         this.lifeTimeoutMillis = lifeTimeoutMillis;
278         resetCheckPeriod();
279     }
280
281
282     synchronized List JavaDoc<String JavaDoc> getConnectionInfo() {
283         List JavaDoc<String JavaDoc> info = new ArrayList JavaDoc<String JavaDoc>();
284
285         for (PoolableConnection activeConnection : activePool) {
286             info.add(activeConnection.toString());
287         }
288
289         for (PoolableConnection idleConnection : idleConnectionList()) {
290             info.add(idleConnection.toString());
291         }
292
293         return info;
294     }
295
296     /**
297      * get a connection <br> <br>
298      *
299      * This method is thread safe
300      *
301      * @param host the server address
302      * @param port the server port
303      * @param workerPool the workerpool or <code>null</code>
304      * @return the connection
305      * @throws WaitTimeoutException if the wait timeout has been reached
306      * @throws IOException if an exception occurs
307      */

308     synchronized final PoolableConnection getConnection(InetSocketAddress JavaDoc address, Executor JavaDoc workerPool) throws IOException JavaDoc, WaitTimeoutException {
309
310         // pool is open
311
if (isOpen) {
312             PoolableConnection poolableConnection = getConnectionFromPool(address);
313
314             if (poolableConnection == null) {
315
316                 if (maxWaitMillis == NULL) {
317                     poolableConnection = newConnection(address, workerPool);
318                     if (LOG.isLoggable(Level.FINE)) {
319                         LOG.fine("new connection to " + poolableConnection.getId() + " has been established (idling=" + getNumIdle() + ", active=" + getNumActive() + ", maxActive=" + getMaxActive() + ", idleTimeoutMillis=" + getIdleTimeoutMillis() + ", lifeTimeout=" + getLifeTimeoutMillis() + ")");
320                     }
321                 } else {
322                     if (activePool.size() < maxActive) {
323                         poolableConnection = newConnection(address, workerPool);
324                         if (LOG.isLoggable(Level.FINE)) {
325                             LOG.fine("new connection to " + poolableConnection.getId() + " has been established (idling=" + getNumIdle() + ", active=" + getNumActive() + ", maxActive=" + getMaxActive() + ", idleTimeoutMillis=" + getIdleTimeoutMillis() + ", lifeTimeout=" + getLifeTimeoutMillis() + ")");
326                         }
327                     } else {
328                         if (LOG.isLoggable(Level.FINE)) {
329                             LOG.fine("no free connection available waiting for a free connection (idling=" + getNumIdle() + ", active=" + getNumActive() + ", maxActive=" + getMaxActive() + ", idleTimeoutMillis=" + getIdleTimeoutMillis() + ", lifeTimeout=" + getLifeTimeoutMillis() + ")");
330                         }
331
332                         long start = System.currentTimeMillis();
333                         while ((System.currentTimeMillis() - start) < maxWaitMillis) {
334                             try {
335                                 wait(maxWaitMillis - (System.currentTimeMillis() - start));
336                             } catch (InterruptedException JavaDoc ignore) { }
337
338                             poolableConnection = getConnectionFromPool(address);
339                             if (poolableConnection != null) {
340                                 break;
341                             }
342                         }
343                         if (poolableConnection == null) {
344                             if (LOG.isLoggable(Level.FINE)) {
345                                 LOG.fine("wait timeout reached (" + DataConverter.toFormatedDuration(maxWaitMillis) + ")");
346                             }
347                             throw new WaitTimeoutException("wait timeout reached (" + DataConverter.toFormatedDuration(maxWaitMillis) + ")");
348                         }
349                     }
350                 }
351             }
352
353             if (poolableConnection != null) {
354                 activePool.add(poolableConnection);
355                 poolableConnection.setStateActive();
356             }
357             return poolableConnection;
358
359
360         // pool is already closed
361
} else {
362             throw new RuntimeException JavaDoc("pool is already closed");
363         }
364     }
365
366
367     private PoolableConnection getConnectionFromPool(InetSocketAddress JavaDoc address) throws IOException JavaDoc {
368
369         try {
370             List JavaDoc<PoolableConnection> connectionList = idlePool.get(address);
371
372             // connection list found
373
if (connectionList != null) {
374
375                 // .. and it contains connections
376
if (!connectionList.isEmpty()) {
377                     PoolableConnection poolableConnection = connectionList.remove(0);
378
379                     // check if the connection is valid
380
if (isConnectionValid(System.currentTimeMillis(), poolableConnection)) {
381                         poolableConnection.reset();
382
383                         // remove connection list if is empty
384
if (connectionList.isEmpty()) {
385                             idlePool.remove(address);
386                         }
387
388                         if (LOG.isLoggable(Level.FINE)) {
389                             LOG.fine("got connection to " + poolableConnection.getId() + " from pool (idling=" + getNumIdle() + ", active=" + getNumActive() + ", maxActive=" + getMaxActive() + ", idleTimeoutMillis=" + getIdleTimeoutMillis() + ", lifeTimeout=" + getLifeTimeoutMillis() + ")");
390                         }
391
392                         return poolableConnection;
393
394                     // .. else call recursive
395
} else {
396                         return getConnectionFromPool(address);
397                     }
398                 }
399             }
400         } catch (Exception JavaDoc e) {
401             return null;
402         }
403
404         return null;
405     }
406
407     /**
408      * get adress as string
409      * @param host the server address
410      * @param port the server port
411      * @return the address as string
412      */

413     final String JavaDoc getAddressString(String JavaDoc host, int port) {
414         return host + ":" + port;
415     }
416
417
418     /**
419      * recycle a connection
420      *
421      * @param connection the connection to recycle
422      * @throws IOException if an exception occurs
423      */

424     final synchronized void returnConnection(PoolableConnection poolableConnection) throws IOException JavaDoc {
425
426         activePool.remove(poolableConnection);
427         poolableConnection.setStateIdle();
428
429         // pool is open
430
if (isOpen) {
431
432             // if connection is invalid close really and return
433
if (!isConnectionValid(System.currentTimeMillis(), poolableConnection)) {
434                 if (LOG.isLoggable(Level.FINE)) {
435                     LOG.fine("do not return given connection to pool, because it is not valid/reuseable");
436                 }
437                 poolableConnection.reallyClose();
438                 return;
439
440             } else {
441                 try {
442                     poolableConnection.reset();
443                 } catch (Exception JavaDoc e) {
444                     poolableConnection.reallyClose();
445                     return;
446                 }
447
448                 addConnectionToPool(poolableConnection);
449             }
450
451         // pool is already closed
452
} else {
453             if (LOG.isLoggable(Level.FINE)) {
454                 LOG.fine("pool is already closed destroy returned connection to " + poolableConnection.getId());
455             }
456             poolableConnection.reallyClose();
457             return;
458         }
459
460         notifyAll();
461     }
462
463
464     private void addConnectionToPool(PoolableConnection connection) throws IOException JavaDoc {
465         if (idlePool.size() < maxIdle) {
466             List JavaDoc<PoolableConnection> connectionList = idlePool.get(connection.getAddress());
467             if (connectionList == null) {
468                 connectionList = new ArrayList JavaDoc<PoolableConnection>();
469                 idlePool.put(connection.getAddress(), connectionList);
470             }
471
472             connectionList.add(connection);
473
474             if (LOG.isLoggable(Level.FINER)) {
475                 LOG.finer("connection to " + connection.getId() + " has been inserted into the pool (idling=" + getNumIdle() + ", active=" + getNumActive() + ", maxActive=" + getMaxActive() + ", idleTimeoutMillis=" + getIdleTimeoutMillis() + ", lifeTimeout=" + getLifeTimeoutMillis() + ")");
476             }
477         } else {
478             connection.reallyClose();
479         }
480     }
481
482
483     /**
484      * {@inheritDoc}<br> <br>
485      *
486      * This method is thread safe
487      */

488     public final synchronized void close() {
489         if (LOG.isLoggable(Level.FINE)) {
490             LOG.fine("closing (idling=" + getNumIdle() + ", active=" + getNumActive() + ")");
491         }
492
493         timer.cancel();
494
495         for (List JavaDoc<PoolableConnection> connectionList : idlePool.values()) {
496             for (PoolableConnection connection : connectionList) {
497                 try {
498                     connection.reallyClose();
499                 } catch (Exception JavaDoc e) {
500                     if (LOG.isLoggable(Level.FINE)) {
501                         LOG.fine("error occured by (really) closing of conection " + connection.getId() + ". Reason: " + e.toString());
502                     }
503                 }
504             }
505         }
506
507         idlePool.clear();
508
509         for (ILifeCycle lifeCycle : listeners) {
510             lifeCycle.onDestroy();
511         }
512     }
513
514
515     /**
516      * {@inheritDoc}
517      */

518     @Override JavaDoc
519     public String JavaDoc toString() {
520         return this.getClass().getSimpleName() + " idling=" + getNumIdle() + ", active=" + getNumActive() + ", maxActive=" + getMaxActive() + ", idleTimeoutMillis=" + getIdleTimeoutMillis() + ", lifeTimeout=" + getLifeTimeoutMillis() + ")";
521     }
522
523
524
525     private boolean isConnectionValid(long currentTime, PoolableConnection poolableConnection) {
526
527         if (!poolableConnection.isOpen()) {
528             return false;
529         }
530
531         if (!poolableConnection.isReuseable()) {
532             return false;
533         }
534
535         if (idleTimeoutMillis != MAX_TIMEOUT) {
536             if (currentTime > (poolableConnection.getLastUsageTime() + idleTimeoutMillis)) {
537                 return false;
538             }
539         }
540
541         if (lifeTimeoutMillis != MAX_TIMEOUT) {
542             if (currentTime > (poolableConnection.getCreationTime() + lifeTimeoutMillis)) {
543                 return false;
544             }
545         }
546
547         return true;
548     }
549
550
551
552     private void checkTimeout(List JavaDoc<PoolableConnection> idleConnections) {
553         long currentTime = System.currentTimeMillis();
554
555         for (PoolableConnection poolableConnection : idleConnections) {
556
557             if (!isConnectionValid(currentTime, poolableConnection)) {
558                 closeConnection(poolableConnection, "auto");
559             }
560         }
561     }
562
563
564     private void checkSize(List JavaDoc<PoolableConnection> idleConnections) {
565         if (idleConnections.size() > maxIdle) {
566             for (int i =0; i < (idleConnections.size() - maxIdle); i++ ) {
567                 PoolableConnection poolableConnection = idleConnections.get(i);
568                 closeConnection(poolableConnection, "auto");
569             }
570         }
571     }
572
573
574     private synchronized List JavaDoc<PoolableConnection> idleConnectionList() {
575         List JavaDoc<PoolableConnection> idleConnections = new ArrayList JavaDoc<PoolableConnection>();
576
577         for (List JavaDoc<PoolableConnection> connectionList : idlePool.values()) {
578             idleConnections.addAll(connectionList);
579         }
580
581         return idleConnections;
582     }
583
584
585     private synchronized boolean closeConnection(PoolableConnection poolableConnection, String JavaDoc reason) {
586         assert (poolableConnection != null);
587
588         List JavaDoc<PoolableConnection> connectionList = idlePool.get(poolableConnection.getAddress());
589         if (connectionList.contains(poolableConnection)) {
590             connectionList.remove(poolableConnection);
591             try {
592                 poolableConnection.reallyClose();
593             } catch (Exception JavaDoc e) {
594                 if (LOG.isLoggable(Level.FINE)) {
595                     LOG.fine("error occured by (really) closing of connection " + poolableConnection.getId() + ". Reason: " + e.toString());
596                 }
597             }
598
599
600             if (LOG.isLoggable(Level.FINE)) {
601                 LOG.fine(reason + " close of connection " + poolableConnection.getId() + " (idling=" + getNumIdle() + ", active=" + getNumActive() + ", maxActive=" + getMaxActive() + ", idleTimeoutMillis=" + getIdleTimeoutMillis() + ", lifeTimeout=" + getLifeTimeoutMillis() + ")");
602             }
603
604             return true;
605         } else {
606             return false;
607         }
608     }
609
610
611     private PoolableConnection newConnection(InetSocketAddress JavaDoc address, Executor JavaDoc workerPool) throws IOException JavaDoc {
612         int trials = 0;
613         int sleepTime = 3;
614
615         IOException JavaDoc ex = null;
616
617         long start = System.currentTimeMillis();
618         PoolableConnection connection = null;
619         do {
620             trials++;
621             try {
622
623                 connection = createConnection(address, workerPool);
624                 return connection;
625             } catch (IOException JavaDoc ioe) {
626                 ex = ioe;
627                 sleepTime = sleepTime * 3;
628             }
629
630             try {
631                 Thread.sleep(sleepTime);
632             } catch (InterruptedException JavaDoc ignore) { }
633         } while (System.currentTimeMillis() < (start + CREATE_CONNECTION_TIMEOUT));
634
635         if (LOG.isLoggable(Level.FINE)) {
636             LOG.fine("error occured by creating connection to " + address
637                    + ". creation timeout " + CREATE_CONNECTION_TIMEOUT + " reached. (" + trials + " trials done)");
638         }
639
640         if (ex != null) {
641             throw ex;
642         } else {
643             throw new IOException JavaDoc("couldn't create a new connetion to " + address);
644         }
645     }
646
647
648     /**
649      * create a new poolable connection
650      *
651      * @param host the server address
652      * @param port the server port
653      * @param workerPool the worker pool or <code>null</code>
654      * @return the new connection
655      * @throws IOException if an exception occrs
656      */

657     abstract PoolableConnection createConnection(InetSocketAddress JavaDoc address, Executor JavaDoc workerPool) throws IOException JavaDoc;
658
659
660     /**
661      * implemenation base for a poolable connection
662      *
663      * @author grro
664      */

665     abstract class PoolableConnection implements IConnection {
666
667
668         private AbstractConnectionPool pool = null;
669         private InetSocketAddress JavaDoc address = null;
670         private Connection delegee;
671
672         private long creationTime = System.currentTimeMillis();
673         private long lastUsageTime = System.currentTimeMillis();
674         private boolean isActive = false;
675         private long enteredState = System.currentTimeMillis();
676
677         private boolean isDeleted = false;
678         private boolean isReuseable = true;
679
680         public PoolableConnection(AbstractConnectionPool pool, Connection delegee, InetSocketAddress JavaDoc address) throws IOException JavaDoc {
681             this.pool = pool;
682             this.delegee = delegee;
683             this.address = address;
684         }
685
686         final boolean isReuseable() {
687             return isReuseable;
688         }
689
690         final void setReuseable(boolean isReusable) {
691             this.isReuseable = isReusable;
692         }
693
694         final void setStateActive() {
695             isActive = true;
696             enteredState = System.currentTimeMillis();
697         }
698
699         final void setStateIdle() {
700             isActive = false;
701             enteredState = System.currentTimeMillis();
702         }
703
704         final boolean isActive() {
705             return isActive;
706         }
707
708         final long getStateEntered() {
709             return enteredState;
710         }
711
712         final Connection getDelegee() {
713             return delegee;
714         }
715
716         final InetSocketAddress JavaDoc getAddress() {
717             return address;
718         }
719
720         final long getLastUsageTime() {
721             return lastUsageTime;
722         }
723
724         final long getCreationTime() {
725             return creationTime;
726         }
727
728
729         public void close() throws IOException JavaDoc {
730             if (delegee.isOpen()) {
731                 lastUsageTime = System.currentTimeMillis();
732                 pool.returnConnection(this);
733             } else {
734                 if (LOG.isLoggable(Level.FINE)) {
735                     LOG.fine("connection " + delegee.getId() + " will not return to pool because it is closed");
736                 }
737             }
738         }
739
740         void reset() throws IOException JavaDoc {
741             delegee.reset();
742         }
743
744         public void setIdleTimeoutSec(int timeoutInSec) {
745             getDelegee().setIdleTimeoutSec(timeoutInSec);
746         }
747
748         public int getIdleTimeoutSec() {
749             return getDelegee().getIdleTimeoutSec();
750         }
751
752         public Object JavaDoc getOption(String JavaDoc name) throws IOException JavaDoc {
753             return getDelegee().getOption(name);
754         }
755
756         public Map JavaDoc<String JavaDoc, Class JavaDoc> getOptions() {
757             return getDelegee().getOptions();
758         }
759
760
761         public void setConnectionTimeoutSec(int timeoutSec) {
762             getDelegee().setConnectionTimeoutSec(timeoutSec);
763         }
764
765
766         public int getConnectionTimeoutSec() {
767             return getDelegee().getConnectionTimeoutSec();
768         }
769
770         public void resumeRead() throws IOException JavaDoc{
771             getDelegee().resumeRead();
772         }
773
774         public void suspendRead() throws IOException JavaDoc {
775             getDelegee().suspendRead();
776         }
777
778         void reallyClose() throws IOException JavaDoc {
779             isDeleted = true;
780             delegee.close();
781         }
782
783         public void flush() throws ClosedConnectionException, IOException JavaDoc, SocketTimeoutException JavaDoc {
784             delegee.flush();
785         }
786
787         public boolean isOpen() {
788             return !isDeleted && delegee.isOpen();
789         }
790
791         public void activateSecuredMode() throws IOException JavaDoc {
792             throw new UnsupportedOperationException JavaDoc("activateSecuredMode is not supported for a pooled connection");
793         }
794
795         public final int getPendingWriteDataSize() {
796             return delegee.getPendingWriteDataSize();
797         }
798
799
800         public boolean getAutoflush() {
801             return delegee.getAutoflush();
802         }
803
804         public void setAutoflush(boolean autoflush) {
805             delegee.setAutoflush(autoflush);
806         }
807
808         public void setDefaultEncoding(String JavaDoc encoding) {
809             delegee.setDefaultEncoding(encoding);
810         }
811
812
813         public String JavaDoc getDefaultEncoding() {
814             return delegee.getDefaultEncoding();
815         }
816
817         public int getIndexOf(String JavaDoc str) throws IOException JavaDoc, ClosedConnectionException {
818             return delegee.getIndexOf(str);
819         }
820
821         public int getIndexOf(String JavaDoc str, int maxLength) throws IOException JavaDoc, ClosedConnectionException, MaxReadSizeExceededException {
822             return delegee.getIndexOf(str, maxLength);
823         }
824
825         public int getIndexOf(String JavaDoc str, String JavaDoc encoding, int maxLength) throws IOException JavaDoc, ClosedConnectionException, MaxReadSizeExceededException {
826             return delegee.getIndexOf(str, encoding, maxLength);
827         }
828
829         public int read(ByteBuffer JavaDoc buffer) throws IOException JavaDoc {
830             return delegee.read(buffer);
831         }
832
833         public byte readByte() throws IOException JavaDoc, ClosedConnectionException, SocketTimeoutException JavaDoc {
834             return delegee.readByte();
835         }
836
837         public ByteBuffer JavaDoc[] readByteBufferByDelimiter(String JavaDoc delimiter) throws IOException JavaDoc, ClosedConnectionException, SocketTimeoutException JavaDoc {
838             return delegee.readByteBufferByDelimiter(delimiter);
839         }
840
841         public ByteBuffer JavaDoc[] readByteBufferByDelimiter(String JavaDoc delimiter, int maxLength) throws IOException JavaDoc, ClosedConnectionException, SocketTimeoutException JavaDoc, MaxReadSizeExceededException {
842             return delegee.readByteBufferByDelimiter(delimiter, maxLength);
843         }
844
845         public ByteBuffer JavaDoc[] readByteBufferByDelimiter(String JavaDoc delimiter, String JavaDoc encoding, int maxLength) throws IOException JavaDoc, ClosedConnectionException, MaxReadSizeExceededException {
846             return delegee.readByteBufferByDelimiter(delimiter, encoding, maxLength);
847         }
848
849         public ByteBuffer JavaDoc[] readByteBufferByLength(int length) throws IOException JavaDoc, ClosedConnectionException, SocketTimeoutException JavaDoc {
850             return delegee.readByteBufferByLength(length);
851         }
852
853         public byte[] readBytesByDelimiter(String JavaDoc delimiter) throws IOException JavaDoc, ClosedConnectionException, SocketTimeoutException JavaDoc {
854             return delegee.readBytesByDelimiter(delimiter);
855         }
856
857         public byte[] readBytesByDelimiter(String JavaDoc delimiter, int maxLength) throws IOException JavaDoc, ClosedConnectionException, SocketTimeoutException JavaDoc, MaxReadSizeExceededException {
858             return delegee.readBytesByDelimiter(delimiter, maxLength);
859         }
860
861         public byte[] readBytesByDelimiter(String JavaDoc delimiter, String JavaDoc encoding, int maxLength) throws IOException JavaDoc, ClosedConnectionException, MaxReadSizeExceededException {
862             return delegee.readBytesByDelimiter(delimiter, encoding, maxLength);
863         }
864
865         public byte[] readBytesByLength(int length) throws IOException JavaDoc, ClosedConnectionException, SocketTimeoutException JavaDoc {
866             return delegee.readBytesByLength(length);
867         }
868
869         public double readDouble() throws IOException JavaDoc, ClosedConnectionException, SocketTimeoutException JavaDoc {
870             return delegee.readDouble();
871         }
872
873         public int readInt() throws IOException JavaDoc, ClosedConnectionException, SocketTimeoutException JavaDoc {
874             return delegee.readInt();
875         }
876
877         public short readShort() throws IOException JavaDoc, ClosedConnectionException, SocketTimeoutException JavaDoc {
878             return delegee.readShort();
879         }
880
881         public long readLong() throws IOException JavaDoc, ClosedConnectionException, SocketTimeoutException JavaDoc {
882             return delegee.readLong();
883         }
884
885         public String JavaDoc readStringByDelimiter(String JavaDoc delimiter) throws IOException JavaDoc, ClosedConnectionException, UnsupportedEncodingException JavaDoc, SocketTimeoutException JavaDoc {
886             return delegee.readStringByDelimiter(delimiter);
887         }
888
889         public String JavaDoc readStringByDelimiter(String JavaDoc delimiter, int maxLength) throws IOException JavaDoc, ClosedConnectionException, UnsupportedEncodingException JavaDoc, SocketTimeoutException JavaDoc, MaxReadSizeExceededException {
890             return delegee.readStringByDelimiter(delimiter, maxLength);
891         }
892
893         public String JavaDoc readStringByDelimiter(String JavaDoc delimiter, String JavaDoc encoding) throws IOException JavaDoc, ClosedConnectionException, UnsupportedEncodingException JavaDoc, SocketTimeoutException JavaDoc {
894             return delegee.readStringByDelimiter(delimiter, encoding);
895         }
896
897         public String JavaDoc readStringByDelimiter(String JavaDoc delimiter, String JavaDoc encoding, int maxLength) throws IOException JavaDoc, ClosedConnectionException, UnsupportedEncodingException JavaDoc, SocketTimeoutException JavaDoc, MaxReadSizeExceededException {
898             return delegee.readStringByDelimiter(delimiter, encoding, maxLength);
899         }
900
901         public int indexOf(String JavaDoc str) throws IOException JavaDoc, ClosedConnectionException {
902             return delegee.indexOf(str);
903         }
904
905         public String JavaDoc readStringByLength(int length) throws IOException JavaDoc, ClosedConnectionException, SocketTimeoutException JavaDoc {
906             return delegee.readStringByLength(length);
907         }
908
909         public String JavaDoc readStringByLength(int length, String JavaDoc encoding) throws IOException JavaDoc, ClosedConnectionException, SocketTimeoutException JavaDoc {
910             return delegee.readStringByLength(length, encoding);
911         }
912
913         public void removeReadMark() {
914             delegee.removeReadMark();
915         }
916
917         public void removeWriteMark() {
918             delegee.removeWriteMark();
919         }
920
921         public void markReadPosition() {
922             delegee.markReadPosition();
923         }
924
925         public void markWritePosition() {
926             delegee.markWritePosition();
927         }
928
929         public boolean resetToReadMark() {
930             return delegee.resetToReadMark();
931         }
932
933         public boolean resetToWriteMark() {
934             return delegee.resetToWriteMark();
935         }
936
937         public String JavaDoc getId() {
938             return delegee.getId();
939         }
940
941         public InetAddress JavaDoc getLocalAddress() {
942             return delegee.getLocalAddress();
943         }
944
945         public int getLocalPort() {
946             return delegee.getLocalPort();
947         }
948
949         public InetAddress JavaDoc getRemoteAddress() {
950             return delegee.getRemoteAddress();
951         }
952
953         public int getRemotePort() {
954             return delegee.getRemotePort();
955         }
956
957         public int write(byte b) throws ClosedConnectionException, IOException JavaDoc, SocketTimeoutException JavaDoc {
958             return delegee.write(b);
959         }
960
961         public int write(byte... bytes) throws ClosedConnectionException, IOException JavaDoc, SocketTimeoutException JavaDoc {
962             return delegee.write(bytes);
963         }
964
965         public int write(short s) throws ClosedConnectionException, IOException JavaDoc, SocketTimeoutException JavaDoc {
966             return delegee.write(s);
967         }
968
969         public int write(byte[] bytes, int offset, int length) throws ClosedConnectionException, IOException JavaDoc, SocketTimeoutException JavaDoc {
970             return delegee.write(bytes, offset, length);
971         }
972
973         public int write(ByteBuffer JavaDoc buffer) throws ClosedConnectionException, IOException JavaDoc, SocketTimeoutException JavaDoc {
974             return delegee.write(buffer);
975         }
976
977         public long write(ByteBuffer JavaDoc[] arg0, int arg1, int arg2) throws IOException JavaDoc {
978             return delegee.write(arg0, arg1, arg2);
979         }
980
981         public long write(ByteBuffer JavaDoc[] buffers) throws ClosedConnectionException, IOException JavaDoc, SocketTimeoutException JavaDoc {
982             return delegee.write(buffers);
983         }
984
985         public int write(double d) throws ClosedConnectionException, IOException JavaDoc, SocketTimeoutException JavaDoc {
986             return delegee.write(d);
987         }
988
989         public int write(int i) throws ClosedConnectionException, IOException JavaDoc, SocketTimeoutException JavaDoc {
990             return delegee.write(i);
991         }
992
993         public int write(long l) throws ClosedConnectionException, IOException JavaDoc, SocketTimeoutException JavaDoc {
994             return delegee.write(l);
995         }
996
997         public int write(String JavaDoc message) throws ClosedConnectionException, IOException JavaDoc, SocketTimeoutException JavaDoc {
998             return delegee.write(message);
999         }
1000
1001        public int write(String JavaDoc message, String JavaDoc encoding) throws ClosedConnectionException, IOException JavaDoc, SocketTimeoutException JavaDoc {
1002            return delegee.write(message, encoding);
1003        }
1004
1005        public Object JavaDoc attach(Object JavaDoc obj) {
1006            return delegee.attach(obj);
1007        }
1008
1009        public Object JavaDoc attachment() {
1010            return delegee.attachment();
1011        }
1012
1013
1014        @Override JavaDoc
1015        public String JavaDoc toString() {
1016            String JavaDoc state = "idle";
1017            if (isActive()) {
1018                state = "active";
1019            }
1020            return "[" + state + ", since " + DataConverter.toFormatedDuration(System.currentTimeMillis() - getStateEntered()) + "] " + delegee.toString();
1021        }
1022    }
1023}
1024
Popular Tags