public class CacheClient extends Object implements ChannelEventListener, ConnectionRequestInfo, AutoCloseable
| Constructor and Description |
|---|
CacheClient(String clientId,
String sharedSecret,
ServerLocator brokerLocator) |
| Modifier and Type | Method and Description |
|---|---|
void |
channelClosed() |
void |
close()
Closes the client.
|
void |
disconnect()
Disconnects the client.
|
CacheEntry |
fetch(String key)
Returns an entry from the local cache, if not found asks to the
CacheServer to find the entry on other clients
|
CacheEntry |
fetch(String key,
KeyLock lock)
Returns an entry from the local cache, if not found asks to the
CacheServer to find the entry on other clients.
|
CacheEntry |
get(String key)
Returns an entry from the local cache.
|
long |
getActualMemory() |
ServerLocator |
getBrokerLocator() |
int |
getCacheSize()
Actual number of entries in the local cache
|
String |
getClientId() |
long |
getConnectionTimestamp() |
Set<String> |
getLocalKeySetByPrefix(String prefix)
Return the local key set
|
long |
getMaxMemory()
Maximum amount of memory used for storing entry values. 0 or negative to
disable
|
String |
getSharedSecret() |
String |
getStatus() |
void |
invalidate(String key)
Invalidates an entry from the local cache and blocks until any other
client which holds the same entry has invalidated the entry locally
|
void |
invalidate(String key,
KeyLock lock) |
void |
invalidateByPrefix(String prefix)
Same as
invalidate(java.lang.String) but it applies to every
entry whose key 'startsWith' the given prefix |
boolean |
isConnected() |
KeyLock |
lock(String key) |
void |
messageReceived(Message message)
Called for each message which is not a direct reply to another message.
|
boolean |
put(String key,
byte[] data,
long expireTime)
Put an entry on the local cache.
|
boolean |
put(String key,
byte[] data,
long expireTime,
KeyLock lock) |
void |
setMaxMemory(long maxMemory)
Maximum amount of memory used for storing entry values. 0 or negative to
disable
|
void |
start()
Start the client.
|
void |
stop() |
void |
touchEntry(String key,
long expiretime)
Modifies the expireTime for a given entry.
|
void |
touchEntry(String key,
long expiretime,
KeyLock lock)
Modifies the expireTime for a given entry.
|
void |
unlock(KeyLock keyLock) |
boolean |
waitForConnection(int timeout)
Waits for the client to establish the first connection to the server
|
boolean |
waitForDisconnection(int timeout)
Waits for the client to be disconnected
|
public CacheClient(String clientId, String sharedSecret, ServerLocator brokerLocator)
public long getMaxMemory()
public void setMaxMemory(long maxMemory)
public long getActualMemory()
public String getStatus()
public ServerLocator getBrokerLocator()
public void start()
isConnected(),
waitForConnection(int)public boolean waitForConnection(int timeout)
throws InterruptedException
timeout - InterruptedExceptionpublic boolean waitForDisconnection(int timeout)
throws InterruptedException
timeout - InterruptedExceptionpublic String getClientId()
getClientId in interface ConnectionRequestInfopublic boolean isConnected()
public long getConnectionTimestamp()
public int getCacheSize()
public void disconnect()
public void messageReceived(Message message)
ChannelEventListenermessageReceived in interface ChannelEventListenerpublic void channelClosed()
channelClosed in interface ChannelEventListenerpublic String getSharedSecret()
getSharedSecret in interface ConnectionRequestInfopublic void close()
throws Exception
close in interface AutoCloseableExceptionpublic void stop()
public CacheEntry fetch(String key) throws InterruptedException
key - InterruptedExceptionget(java.lang.String)public CacheEntry fetch(String key, KeyLock lock) throws InterruptedException
key - lock - previouly acquired lockInterruptedExceptionget(java.lang.String),
lock(java.lang.String)public void touchEntry(String key, long expiretime)
key - expiretime - public void touchEntry(String key, long expiretime, KeyLock lock)
key - expiretime - lock(java.lang.String)public CacheEntry get(String key)
key - fetch(java.lang.String)public void invalidate(String key) throws InterruptedException
key - InterruptedExceptionpublic void invalidate(String key, KeyLock lock) throws InterruptedException
InterruptedExceptionpublic void invalidateByPrefix(String prefix) throws InterruptedException
invalidate(java.lang.String) but it applies to every
entry whose key 'startsWith' the given prefixprefix - InterruptedExceptionpublic boolean put(String key, byte[] data, long expireTime) throws InterruptedException, CacheException
key - data - expireTime - This is the UNIX timestamp at which the entry should be
invalidated automatically. Use 0 in order to create an immortal entryInterruptedExceptionCacheExceptiontouchEntry(java.lang.String, long)public boolean put(String key, byte[] data, long expireTime, KeyLock lock) throws InterruptedException, CacheException
InterruptedExceptionCacheExceptionpublic KeyLock lock(String key) throws InterruptedException, CacheException
InterruptedExceptionCacheExceptionpublic void unlock(KeyLock keyLock) throws InterruptedException, CacheException
InterruptedExceptionCacheExceptionCopyright © 2016. All rights reserved.