[jboss-user] [JBoss Cache: Core Edition] - Re: State Transfer
lovelyliatroim
do-not-reply at jboss.com
Mon Sep 22 08:04:18 EDT 2008
Ok i have got it to work through getState and setState, however I would nearly call it a hack version but it works. I have tried to re-use what is already in JBoss Cache to do the state transfer, now whether it is a good idea or not to reuse im not sure. How often does this area change?? Would I be looking at re-test for every minor version upgrade??
Anyways here it is
| public void setState(String path, InputStream istream) {
| log.info("About to set state in real time cache for path ="+path);
| CacheSPI cache = (CacheSPI)CacheManager.getCacheById("realTimeCache");
| if(cache == null){
| log.error("Cant set state for real time cache because it has not been configured for this node!! Looking to import Path="+path);
| return;
| }
| MarshalledValueInputStream in = null;
| try
| {
| in = new MarshalledValueInputStream(istream);
| Fqn subroot = Fqn.fromString(path);
| Configuration configuration = new Configuration();
| configuration.setFetchInMemoryState(true);
| StateTransferManager stateTransferManager = new StateTransferManager(cache);
| stateTransferManager.injectDependencies(cache, cache.getMarshaller(), cache.getRegionManager(), configuration,new NodeBasedLockManager());
| stateTransferManager.setState(in, subroot);
| }
| catch (Exception e)
| {
| log.error("Failed to upload state into real time cache for path="+path,e);
| }
| finally
| {
| Util.close(in);
| }
| }
|
| public void getState(String path, OutputStream ostream) {
| log.info("Server has been asked for its real time state for path "+path);
|
| CacheSPI cache = (CacheSPI)CacheManager.getCacheById("realTimeCache");
| if(cache == null){
| log.error("Cant ask for state when realTimeCache is not configured for this node. Path looking for "+path);
| return;
| }
|
| String sourceRoot = path;
| MarshalledValueOutputStream out = null;
| try
| {
| out = new MarshalledValueOutputStream(ostream);
|
| Configuration configuration = new Configuration();
| configuration.setFetchInMemoryState(true);
| StateTransferManager stateTransferManager = new StateTransferManager(cache);
| stateTransferManager.injectDependencies(cache, cache.getMarshaller(), cache.getRegionManager(), configuration,new NodeBasedLockManager());
| stateTransferManager.getState(out, Fqn.fromString(sourceRoot), configuration.getStateRetrievalTimeout(), true, true);
| //cache.getMarshaller().objectToObjectStream(stateTransferManager, out,Fqn.fromString(sourceRoot) );
|
|
| }catch (Throwable e)
| {
| log.error("Failed to replicate state transfer for path "+path,e);
| }
| finally
| {
| Util.close(out);
| }
| }
|
|
Now what im most interested in is this
| stateTransferManager.injectDependencies(cache, cache.getMarshaller(), cache.getRegionManager(), configuration,new NodeBasedLockManager());
|
How does these parameters inputted look to you guys? In particular the NodeBasedLockManager, is there any way to find out or get the LockManager of a cache without having to do what i did above? Any implications of using the NodebasedLockManager that i should look out for?
Not the happiest about doing it this way but it works, thoughts on this approach are welcome. Will look into the region based activation and see what it offers.
Thanks,
LL
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4178026#4178026
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4178026
More information about the jboss-user
mailing list