1
14
15 package com.liferay.portal.cache.memcached;
16
17 import com.liferay.portal.kernel.util.GetterUtil;
18 import com.liferay.portal.kernel.util.StringPool;
19 import com.liferay.portal.kernel.util.StringUtil;
20
21 import java.net.InetSocketAddress;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import net.spy.memcached.ConnectionFactory;
27 import net.spy.memcached.MemcachedClient;
28 import net.spy.memcached.MemcachedClientIF;
29
30
36 public class DefaultMemcachedClientFactory implements MemcachedClientFactory {
37
38 public void clear() {
39 }
40
41 public void close() {
42 }
43
44 public MemcachedClientIF getMemcachedClient() throws Exception {
45 return new MemcachedClient(_connectionFactory, _inetSocketAddresses);
46 }
47
48 public int getNumActive() {
49 throw new UnsupportedOperationException();
50 }
51
52 public int getNumIdle() {
53 throw new UnsupportedOperationException();
54 }
55
56 public void invalidateMemcachedClient(MemcachedClientIF memcachedClient) {
57 throw new UnsupportedOperationException();
58 }
59
60 public void returnMemcachedObject(MemcachedClientIF memcachedClient) {
61 throw new UnsupportedOperationException();
62 }
63
64 public void setAddresses(List<String> addresses) {
65 for (String address : addresses) {
66 String[] hostAndPort = StringUtil.split(address, StringPool.COLON);
67
68 String hostName = hostAndPort[0];
69
70 int port = _DEFAULT_MEMCACHED_PORT;
71
72 if (hostAndPort.length == 2) {
73 port = GetterUtil.getInteger(hostAndPort[1]);
74 }
75
76 InetSocketAddress inetSocketAddress = new InetSocketAddress(
77 hostName, port);
78
79 _inetSocketAddresses.add(inetSocketAddress);
80 }
81 }
82
83 public void setConnectionFactory(ConnectionFactory connectionFactory) {
84 _connectionFactory = connectionFactory;
85 }
86
87 private static final int _DEFAULT_MEMCACHED_PORT = 11211;
88
89 private ConnectionFactory _connectionFactory;
90 private List<InetSocketAddress> _inetSocketAddresses =
91 new ArrayList<InetSocketAddress>();
92
93 }