| Method from org.jboss.ha.framework.server.DistributedStateImpl Detail: |
protected Fqn buildFqn(String category) {
return new Fqn(ROOTFQN, category);
}
ExtendedTreeCacheListener methods |
protected Fqn buildFqn(String category,
Serializable key) {
return new Fqn(new Object[] { ROOT, category, key });
}
|
protected Fqn buildFqn(String category,
Serializable key,
Serializable value) {
return new Fqn(new Object[] { ROOT, category, key, value });
}
|
protected void cleanupKeyListeners() {
// NOT IMPLEMENTED YET
}
|
protected void createService() throws Exception {
}
|
public void destroyService() throws Exception {
}
|
public Serializable get(String category,
Serializable key) {
try
{
return (Serializable) cache.get(buildFqn(category), key);
} catch (CacheException ce)
{
return null;
}
}
|
public Collection getAllCategories() {
try
{
Node base = cache.getRoot().getChild(ROOTFQN);
Collection keys = (base == null ? null : base.getChildrenNames());
if(keys != null && keys.size() > 0)
{
keys = Collections.unmodifiableCollection(keys);
}
return keys;
}
catch(CacheException ce)
{
return null;
}
}
|
public Collection getAllKeys(String category) {
try
{
Node node = getNode(category);
if (node==null)
return null;
return node.getKeys();
} catch (CacheException ce)
{
return null;
}
}
|
public Collection getAllValues(String category) {
try
{
Node categoryNode = getNode(category);
if (categoryNode == null) {
return null;
}
Set childNodes = categoryNode.getKeys();
if (childNodes == null)
{
return null;
}
Map entries = categoryNode.getData();
if (entries == null)
return null;
Collection retVal = new HashSet(entries.values());
return Collections.unmodifiableCollection(retVal);
} catch (CacheException ce)
{
return null;
}
}
|
public Cache getClusteredCache() {
return cache;
}
|
protected Node getNode(String category) throws CacheException {
return cache.getRoot().getChild(buildFqn(category));
}
|
public String listContent() throws Exception {
StringBuffer result = new StringBuffer ();
Collection cats = this.getAllCategories ();
if (cats == null)
return result.toString();
Iterator catsIter = cats.iterator ();
while (catsIter.hasNext ())
{
String category = (String)catsIter.next ();
Iterator keysIter = this.getAllKeys(category).iterator ();
result.append ("-----------------------------------------------\n");
result.append ("Logger : ").append (category).append ("\n\n");
result.append ("KEY\t:\tVALUE\n");
while (keysIter.hasNext ())
{
Serializable key = (Serializable) keysIter.next ();
String value = this.get (category, key).toString ();
result.append ("'").append(key);
result.append ("'\t:\t'");
result.append (value);
result.append("'\n");
}
result.append ("\n");
}
return result.toString ();
}
|
public String listXmlContent() throws Exception {
StringBuffer result = new StringBuffer ();
result.append ("< DistributedState >\n");
Collection cats = this.getAllCategories ();
if (cats != null)
{
Iterator catsIter = cats.iterator ();
while (catsIter.hasNext ())
{
String category = (String)catsIter.next ();
Iterator keysIter = this.getAllKeys(category).iterator ();
result.append ("\t< Logger >\n");
result.append ("\t\t< LoggerName >").append (category).append ("< /LoggerName >\n");
while (keysIter.hasNext ())
{
Serializable key = (Serializable) keysIter.next ();
String value = this.get (category, key).toString ();
result.append ("\t\t< Entry >\n");
result.append ("\t\t\t< Key >").append (key).append ("< /Key >\n");
result.append ("\t\t\t< Value >").append (value).append ("< /Value >\n");
result.append ("\t\t< /Entry >\n");
}
result.append ("\t< /Logger >\n");
}
}
result.append ("< /DistributedState >\n");
return result.toString ();
}
|
public void nodeModified(NodeModifiedEvent event) {
if (event.isPre())
return;
// we're only interested in put and remove data operations
ModificationType modType = event.getModificationType();
if (!modType.equals(ModificationType.PUT_DATA) && !modType.equals(ModificationType.REMOVE_DATA))
return;
// ignore changes for other roots in a shared cache
Fqn fqn = event.getFqn();
if (!fqn.isChildOf(ROOTFQN))
return;
Serializable key = null;
Serializable value = null;
// there should be exactly one key/value pair in the map
Map data = event.getData();
if (data != null && !data.isEmpty())
{
key = (Serializable)data.keySet().iterator().next();
value = (Serializable)data.get(key);
}
if (modType.equals(ModificationType.PUT_DATA))
DistributedStateImpl.this.notifyKeyListeners((String)fqn.get(ROOTFQNSIZE), key, value, event.isOriginLocal());
else
DistributedStateImpl.this.notifyKeyListenersOfRemove((String)fqn.get(ROOTFQNSIZE), key, value, event.isOriginLocal());
}
|
protected void notifyKeyListeners(String category,
Serializable key,
Serializable value,
boolean locallyModified) {
synchronized(this.keyListeners)
{
ArrayList listeners = (ArrayList)keyListeners.get (category);
if (listeners == null)
return;
String strKey = key.toString();
for (int i = 0; i < listeners.size (); i++)
{
Object listener = listeners.get (i);
if( listener instanceof DSListener )
{
DSListener dslistener = (DSListener) listener;
dslistener.valueHasChanged (category, strKey, value, locallyModified);
}
else
{
DSListenerEx dslistener = (DSListenerEx) listener;
dslistener.valueHasChanged (category, key, value, locallyModified);
}
}
}
}
|
protected void notifyKeyListenersOfRemove(String category,
Serializable key,
Serializable oldContent,
boolean locallyModified) {
synchronized(this.keyListeners)
{
ArrayList listeners = (ArrayList)keyListeners.get (category);
if (listeners == null)
return;
String strKey = key.toString();
for (int i = 0; i < listeners.size (); i++)
{
Object listener = listeners.get (i);
if( listener instanceof DSListener )
{
DSListener dslistener = (DSListener) listener;
dslistener.keyHasBeenRemoved (category, strKey, oldContent, locallyModified);
}
else
{
DSListenerEx dslistener = (DSListenerEx) listener;
dslistener.keyHasBeenRemoved (category, key, oldContent, locallyModified);
}
}
}
}
|
public void registerDSListener(String category,
DSListener subscriber) {
registerListener(category, subscriber);
}
|
public void registerDSListenerEx(String category,
DSListenerEx subscriber) {
registerListener(category, subscriber);
}
|
protected void registerListener(String category,
Object subscriber) {
synchronized(this.keyListeners)
{
ArrayList listeners = (ArrayList)keyListeners.get (category);
if (listeners == null)
{
listeners = new ArrayList ();
keyListeners.put (category, listeners);
}
listeners.add (subscriber);
}
}
|
public Serializable remove(String category,
Serializable key) throws Exception {
return remove(category, key, true);
}
|
public Serializable remove(String category,
Serializable key,
boolean asynchronousCall) throws Exception {
Serializable retVal = get(category, key);
if(retVal != null)
{
if (replAsync != asynchronousCall)
{
if (asynchronousCall)
cache.getInvocationContext().getOptionOverrides().setForceAsynchronous(true);
else
cache.getInvocationContext().getOptionOverrides().setForceSynchronous(true);
}
cache.remove(buildFqn(category), key);
}
return retVal;
}
|
public void set(String category,
Serializable key,
Serializable value) throws Exception {
set(category, key, value, true);
}
|
public void set(String category,
Serializable key,
Serializable value,
boolean asynchronousCall) throws Exception {
if (replAsync != asynchronousCall)
{
if (asynchronousCall)
cache.getInvocationContext().getOptionOverrides().setForceAsynchronous(true);
else
cache.getInvocationContext().getOptionOverrides().setForceSynchronous(true);
}
cache.put(buildFqn(category), key, value);
}
|
public void setClusteredCache(Cache cache) {
this.cache = cache;
if (this.cache != null)
{
CacheMode cm = cache.getConfiguration().getCacheMode();
if (CacheMode.REPL_ASYNC == cm)
this.replAsync = true;
else if (CacheMode.REPL_SYNC == cm)
this.replAsync = true;
else
throw new IllegalStateException("Cache must be configured for replication, not " + cm);
}
}
|
public void startService() throws Exception {
if (cache == null)
throw new IllegalStateException("No clustered cache available");
this.cache.addCacheListener(this);
}
|
public void stopService() throws Exception {
cache.removeCacheListener(this);
}
|
public void unregisterDSListener(String category,
DSListener subscriber) {
unregisterListener(category, subscriber);
}
|
public void unregisterDSListenerEx(String category,
DSListenerEx subscriber) {
unregisterListener(category, subscriber);
}
|
protected void unregisterListener(String category,
Object subscriber) {
synchronized(this.keyListeners)
{
ArrayList listeners = (ArrayList)keyListeners.get (category);
if (listeners == null) return;
listeners.remove (subscriber);
if (listeners.size () == 0)
{
keyListeners.remove (category);
}
}
}
|