We have some followup questions. We are writing unit tests that operate out of container
and with the TreeCache not clustered.
When we create the TreeCache locally for out-of-container testing, we call
setCacheMode(TreeCache.LOCAL):
TreeCache theTreeCache = new TreeCache();
theTreeCache.setCacheMode(TreeCache.LOCAL);
theTreeCache.createService();
theTreeCache.startService();
When we're in a call, we need to be able to determine whether we should be sending
replication notifications or not. So our code looks like this:
public final void cache(Object somethingToCache, ReplicationMode replicationMode)
throws ServiceException
{
TreeCache treeCache = mTreeCache;
Fqn typePath = MetadataCachePaths.typePathFor(somethingToCache);
if ((replicationMode == ReplicationMode.Replicate) &&
(treeCache.getCacheModeInternal() != 1))
{
treeCache.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
}
else
{
treeCache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
}
treeCache.put(typePath, BaseTypeKey, customizedBaseType);
}
We're not sure about several things about our approach:
1) Does setCacheModeLocal(TreeCache.LOCAL) when we create the TreeCache set the default
mode? If so, does that mean that the getOptionOverrides().setCacheModeLocal leaves the
overall default mode alone, so we don't have to first save the mode, then set it in
the invocation context, then set it back to the original mode?
2) When we create TreeCache locally, the call to getOptionOverrides().setCacheModeLocal
blows up with an NPE because there are no option overrides. Are we supposed to set them
ourselves when we create the local TreeCache?
3) Is calling getCacheModeInternal the right way to determine whether an instance of
TreeCache is clustered or not? If that's not the right way to make that determination,
what is?
4) Is there an example somewhere that shows how to use TreeCache out of container, and an
example that shows how to determine if a TreeCache is clustered and how to enable/disable
replication notifications based on whether it's clustered?
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4179638#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...