01: // $Id: DataConverter.java 1546 2007-07-23 06:07:56Z grro $
02:
03: /*
04: * Copyright (c) xcache.org, 2007. All rights reserved.
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: *
20: * Please refer to the LGPL license at: http://www.gnu.org/copyleft/lesser.txt
21: * The latest copy of this software may be found on http://www.xcache.org/
22: */
23: package org.xcache;
24:
25: import java.io.IOException;
26:
27: import org.xsocket.stream.BlockingConnectionPool;
28: import org.xsocket.stream.IBlockingConnection;
29: import org.xsocket.stream.IConnection;
30:
31: /**
32: *
33: *
34: * @author grro@xcache.org
35: */
36: final class ConnectionPool {
37:
38: private static final ConnectionPool INSTANCE = new ConnectionPool();
39:
40: private final BlockingConnectionPool pool = new BlockingConnectionPool(
41: 60L * 1000L);
42:
43: private ConnectionPool() {
44: }
45:
46: static ConnectionPool getInstance() {
47: return INSTANCE;
48: }
49:
50: public IBlockingConnection getConnection(Address address)
51: throws IOException {
52: IBlockingConnection connection = pool.getBlockingConnection(
53: address.getAddress(), address.getPort());
54: connection.setAutoflush(false);
55: connection.setOption(IConnection.TCP_NODELAY, true);
56: connection.setIdleTimeoutSec(CacheServer.IDLE_TIMEOUT_SEC * 5);
57: connection
58: .setConnectionTimeoutSec(CacheServer.CONNECTION_TIMEOUT_SEC);
59:
60: return connection;
61: }
62:
63: public void destroyConnection(IBlockingConnection connection)
64: throws IOException {
65: pool.destroyConnection(connection);
66: }
67: }
|