xmlBlaster 2.2.0 API

org.xmlBlaster.client
Class SynchronousCache

java.lang.Object
  extended by org.xmlBlaster.client.SynchronousCache

public final class SynchronousCache
extends java.lang.Object

Caches the messages updated from xmlBlaster.

It is used to allow local (client side) cached messages which you can access with the synchronous getCached() method.

If XmlBlasterAccess has switched this cache on, a getCached() automatically makes a subscribe() behind the scenes as well and subsequent getCached() are high performing local calls.

Author:
konrad.krafft@doubleslash.de, xmlblaster@marcelruff.info
See Also:
XmlBlasterAccess.getCached(GetKey, GetQos), TestSynchronousCache, client.cache requirement

Field Summary
private  Global glob
           
private  int maxQueriesCached
           
private static java.lang.String ME
           
private  java.util.Hashtable query2SubId
          key==getQueryString(GetKey getKey), value=subscriptionId
private  java.util.Hashtable subscriptions
          key==subscriptionId, value=dataHashtable
And dataHashtable key=keyOid, value=MsgUnit
 
Constructor Summary
SynchronousCache(Global glob, int maxQueriesCached)
          Create a cache instance.
 
Method Summary
 void clear()
          Destroy all entries in the cash
 MsgUnit[] get(GetKey getKey, GetQos getQos)
          Access messages from cache
 int getNumQueriesCached()
          Return how full is this cache.
 java.lang.String getQueryString(GetKey getKey)
          Create a unique key for our Hashtable from a GetKey
private  java.lang.String getQueryString(java.lang.String subscriptionId)
          Access the query key for a given subscriptionId.
 java.util.Hashtable getSubscriptions()
          Return the registered subscriptions, for internal use only (to check cache).
 boolean newEntry(java.lang.String subId, GetKey getKey, MsgUnit[] units)
          Creates an new entry in the cache

 void removeEntry(java.lang.String subId)
          Remove a cache entry with the given subscriptionId.
 void removeEntryByQueryString(java.lang.String query)
          Remove a cache entry with the given query key string.
 void removeEntryByQueryString(java.lang.String query, java.lang.String keyOid)
          Remove a MsgUnit from cache with the given query key string and keyOid.
 java.lang.String toXml(java.lang.String extraOffset)
          Dump state of this object into a XML ASCII string.
 boolean update(java.lang.String subId, UpdateKey updateKey, byte[] content, UpdateQos updateQos)
          Updated the cache (add a new entry or replaces an existing or removes one).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ME

private static final java.lang.String ME
See Also:
Constant Field Values

glob

private final Global glob

query2SubId

private java.util.Hashtable query2SubId
key==getQueryString(GetKey getKey), value=subscriptionId


subscriptions

private java.util.Hashtable subscriptions
key==subscriptionId, value=dataHashtable
And dataHashtable key=keyOid, value=MsgUnit


maxQueriesCached

private int maxQueriesCached
Constructor Detail

SynchronousCache

public SynchronousCache(Global glob,
                        int maxQueriesCached)
Create a cache instance.

Method Detail

removeEntry

public void removeEntry(java.lang.String subId)
Remove a cache entry with the given subscriptionId.

This is usually called by the update() ERASE event


removeEntryByQueryString

public void removeEntryByQueryString(java.lang.String query,
                                     java.lang.String keyOid)
Remove a MsgUnit from cache with the given query key string and keyOid.

This is usually called by the update() ERASE event for XPATH queries, when the last oid disappears the cache entry is removed


removeEntryByQueryString

public void removeEntryByQueryString(java.lang.String query)
Remove a cache entry with the given query key string.

This is usually called by the update() ERASE event for EXACT queries.


getQueryString

private java.lang.String getQueryString(java.lang.String subscriptionId)
Access the query key for a given subscriptionId. Slow linear lookup ...

Returns:
null if not found

update

public boolean update(java.lang.String subId,
                      UpdateKey updateKey,
                      byte[] content,
                      UpdateQos updateQos)
               throws XmlBlasterException
Updated the cache (add a new entry or replaces an existing or removes one).

Returns:
true if message was for cache, false if we are not interested in such a message.
Throws:
XmlBlasterException

get

public MsgUnit[] get(GetKey getKey,
                     GetQos getQos)
              throws XmlBlasterException
Access messages from cache

Returns:
null if no messages are found in cache
Throws:
XmlBlasterException

getQueryString

public java.lang.String getQueryString(GetKey getKey)
Create a unique key for our Hashtable from a GetKey


newEntry

public boolean newEntry(java.lang.String subId,
                        GetKey getKey,
                        MsgUnit[] units)
                 throws XmlBlasterException
Creates an new entry in the cache

Returns:
true - entry has been created false- cache is full
Throws:
XmlBlasterException

clear

public void clear()
Destroy all entries in the cash


getNumQueriesCached

public int getNumQueriesCached()
Return how full is this cache.


getSubscriptions

public java.util.Hashtable getSubscriptions()
Return the registered subscriptions, for internal use only (to check cache).

Returns:
key==getQueryString(GetKey getKey), value=subscriptionId

toXml

public final java.lang.String toXml(java.lang.String extraOffset)
Dump state of this object into a XML ASCII string.

Parameters:
extraOffset - indenting of tags for nice output
Returns:
internal state of SynchronousCache as a XML ASCII string

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.