Skip to content

Package: ZooKeeperSupportCache

ZooKeeperSupportCache

Coverage

1: /*
2: * Copyright (c) 2012, 2017 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package org.glassfish.grizzly.memcached.zookeeper;
18:
19: /**
20: * The interface using the ZooKeeper for synchronizing cache server list
21: * <p>
22: * Example of use:
23: * {@code
24: * final GrizzlyMemcachedCacheManager.Builder managerBuilder = new GrizzlyMemcachedCacheManager.Builder();
25: * // setup zookeeper server
26: * final ZooKeeperConfig zkConfig = ZooKeeperConfig.create("cache-manager", DEFAULT_ZOOKEEPER_ADDRESS);
27: * zkConfig.setRootPath(ROOT);
28: * zkConfig.setConnectTimeoutInMillis(3000);
29: * zkConfig.setSessionTimeoutInMillis(30000);
30: * zkConfig.setCommitDelayTimeInSecs(2);
31: * managerBuilder.zooKeeperConfig(zkConfig);
32: * // create a cache manager
33: * final GrizzlyMemcachedCacheManager manager = managerBuilder.build();
34: * final GrizzlyMemcachedCache.Builder<String, String> cacheBuilder = manager.createCacheBuilder("user");
35: * // setup memcached servers
36: * final Set<SocketAddress> memcachedServers = new HashSet<SocketAddress>();
37: * memcachedServers.add(MEMCACHED_ADDRESS1);
38: * memcachedServers.add(MEMCACHED_ADDRESS2);
39: * cacheBuilder.servers(memcachedServers);
40: * // create a user cache
41: * final GrizzlyMemcachedCache<String, String> cache = cacheBuilder.build();
42: * // ZooKeeperSupportCache's basic operations
43: * if (cache.isZooKeeperSupported()) {
44: * final String serverListPath = cache.getZooKeeperServerListPath();
45: * final String serverList = cache.getCurrentServerListFromZooKeeper();
46: * cache.setCurrentServerListOfZooKeeper("localhost:11211,localhost:11212");
47: * }
48: * // ...
49: * // clean
50: * manager.removeCache("user");
51: * manager.shutdown();
52: * }
53: *
54: * @author Bongjae Chang
55: */
56: public interface ZooKeeperSupportCache {
57:
58: /**
59: * Check if this cache supports the ZooKeeper for synchronizing the cache server list
60: *
61: * @return true if this cache supports it
62: */
63: public boolean isZooKeeperSupported();
64:
65: /**
66: * Return the path of the cache server list which has been registered in the ZooKeeper server
67: *
68: * @return the path of the cache server list in the ZooKeeper server.
69: * "null" means this cache doesn't support the ZooKeeper or this cache is not started yet
70: */
71: public String getZooKeeperServerListPath();
72:
73: /**
74: * Return the current cache server list string from the ZooKeeper server
75: *
76: * @return the current server list string
77: */
78: public String getCurrentServerListFromZooKeeper();
79:
80: /**
81: * Set the current cache server list string with the given {@code cacheServerList}
82: * <p>
83: * {@code cacheServerList} could be comma separated host:port pairs, each corresponding to a memcached server.
84: * e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"
85: * Be careful that this operation will propagate {@code cacheServerList} to caches which has joinned the same cache name(scope)
86: * because the cache list of ZooKeeper server will be changed.
87: *
88: * @param cacheServerList the cache server list string
89: * @return true if this cache server list is set successfully
90: */
91: public boolean setCurrentServerListOfZooKeeper(final String cacheServerList);
92:
93: /**
94: * Add the custom {@link BarrierListener}
95: *
96: * The given {@code listener} will be called after cache's default listener will be completed.
97: * {@link BarrierListener#onInit} will be called when this cache will be registered in the ZooKeeper.
98: * {@link BarrierListener#onCommit} will be called when this cache's server list will be changed in the ZooKeeper.
99: * {@link BarrierListener#onDestroy} will be called when this cache will be unregistered in the ZooKeeper.
100: *
101: * @param listener the custom listener
102: */
103: public void addZooKeeperListener( final BarrierListener listener );
104:
105: /**
106: * Remove the custom {@link BarrierListener}
107: *
108: * The given {@code listener} will be called after cache's default listener will be completed.
109: * {@link BarrierListener#onInit} will be called when this cache will be registered in the ZooKeeper.
110: * {@link BarrierListener#onCommit} will be called when this cache's server list will be changed in the ZooKeeper.
111: * {@link BarrierListener#onDestroy} will be called when this cache will be unregistered in the ZooKeeper.
112: *
113: * @param listener the custom listener which was given by {@link #addZooKeeperListener}
114: */
115: public void removeZooKeeperListener( final BarrierListener listener );
116: }