JBoss Cache as a POJO Cache
Pages: 1, 2, 3, 4, 5, 6
Result Output
Finally, when the example is run, the resulting output will printed as follows:
Initial state
---------------------------------------------
Japan (Summary : 2000 [ok])
+ Tokyo (Summary : 2000 [ok])
+ + WindSensor1 (Summary : 2000 [ok])
+ + | ( name = power supply, id = 1000, state =1040)
+ + | ( name = sensor unit, id = 1001, state =1040)
+ + RainSensor1 (Summary : 2000 [ok])
+ + | ( name = power supply, id = 1002, state =1040)
+ + | ( name = sensor unit, id = 1003, state =1040)
+ Yokohama (Summary : 2000 [ok])
+ + WindSensor2 (Summary : 2000 [ok])
+ + | ( name = power supply, id = 1000, state =1040)
+ + | ( name = sensor unit, id = 1001, state =1040)
+ + RainSensor2 (Summary : 2000 [ok])
+ + | ( name = power supply, id = 1002, state =1040)
+ + | ( name = sensor unit, id = 1003, state =1040)
---------------------------------------------
Modified on Manager #1
StateItem.setState(): id: 1003 state changed \
from 1040 to 1041
---------------------------------------------
Japan.Tokyo.RainSensor1: id: 1003 state: 1040->1041 \
(retrieved from Manager #2!)
---------------------------------------------
Japan (Summary : 2004)
+ Tokyo (Summary : 2004)
+ + WindSensor1 (Summary : 2000 [ok])
+ + | ( name = power supply, id = 1000, state =1040)
+ + | ( name = sensor unit, id = 1001, state =1040)
+ + RainSensor1 (Summary : 2004)
+ + | ( name = power supply, id = 1002, state =1040)
+ + | ( name = sensor unit, id = 1003, state =1041)
+ Yokohama (Summary : 2000 [ok])
+ + WindSensor2 (Summary : 2000 [ok])
+ + | ( name = power supply, id = 1000, state =1040)
+ + | ( name = sensor unit, id = 1001, state =1040)
+ + RainSensor2 (Summary : 2000 [ok])
+ + | ( name = power supply, id = 1002, state =1040)
+ + | ( name = sensor unit, id = 1003, state =1040)
---------------------------------------------
Modified on Manager #2
StateItem.setState(): id: 1001 state changed \
from 1040 to 1041
---------------------------------------------
Japan.Yokohama.WindSensor2: id: 1001 state: 1040->1041 \
(retrieved from Manager #1!)
---------------------------------------------
Japan (Summary : 2004)
+ Tokyo (Summary : 2004)
+ + WindSensor1 (Summary : 2000 [ok])
+ + | ( name = power supply, id = 1000, state =1040)
+ + | ( name = sensor unit, id = 1001, state =1040)
+ + RainSensor1 (Summary : 2004)
+ + | ( name = power supply, id = 1002, state =1040)
+ + | ( name = sensor unit, id = 1003, state =1041)
+ Yokohama (Summary : 2004)
+ + WindSensor2 (Summary : 2004)
+ + | ( name = power supply, id = 1000, state =1040)
+ + | ( name = sensor unit, id = 1001, state =1041)
+ + RainSensor2 (Summary : 2000 [ok])
+ + | ( name = power supply, id = 1002, state =1040)
+ + | ( name = sensor unit, id = 1003, state =1040)
---------------------------------------------
Add a new VibrationSensor on Tokyo station
StateItem.setState(): id: 1004 state changed from \
2000 to 1040
StateItem.setState(): id: 1005 state changed from \
2000 to 1040
---------------------------------------------
Japan.Tokyo.VibrationSensor1: (retrieved from cache #2)
---------------------------------------------
Japan (Summary : 2004)
+ Tokyo (Summary : 2004)
+ + WindSensor1 (Summary : 2000 [ok])
+ + | ( name = power supply, id = 1000, state =1040)
+ + | ( name = sensor unit, id = 1001, state =1040)
+ + RainSensor1 (Summary : 2004)
+ + | ( name = power supply, id = 1002, state =1040)
+ + | ( name = sensor unit, id = 1003, state =1041)
+ + VibrationSensor1 (Summary : 2000 [ok])
+ + | ( name = power supply, id = 1004, state =1040)
+ + | ( name = sensor unit, id = 1005, state =1040)
+ Yokohama (Summary : 2004)
+ + WindSensor2 (Summary : 2004)
+ + | ( name = power supply, id = 1000, state =1040)
+ + | ( name = sensor unit, id = 1001, state =1041)
+ + RainSensor2 (Summary : 2000 [ok])
+ + | ( name = power supply, id = 1002, state =1040)
+ + | ( name = sensor unit, id = 1003, state =1040)
Please note the bold text lines. Basically, we do a POJO operation setState first on manager #1 and then print out the propagation tree from the second manager to verify that the state has been updated, and vice versa. It is worthwhile to repeat that, although not shown in the output for the replication layer traffic, each setState() operation will only trigger a fine-grained field-level replication. In addition, if the call is under a transaction context, then the update will be batched; i.e., replicated only when it is ready to commit. Finally, notice that we have the capability to add a new sensor into the network on the fly. A traditional system would have required some sort of restart mechanism.
If you are interested in running this example yourself, you can download JBoss Cache release 1.2.4. Check under the directory examples/aop/sensor that contains the full source and instructions to run.
Conclusion
In this article we have demonstrated the capability of JBoss Cache acting as a POJO cache by leveraging the TreeCacheAop component. By using the POJO cache functionality, it provides seamless failover capability for POJOs by performing fine-grained replication while preserving object-graph relationship.
Acknowledgment
The author would like to acknowledge Mr. Yusuke Komori of SMG Co. from Japan for kindly contributing the use case in this article.
References
Ben Wang is currently the lead for JBoss Clustering and POJO Cache.
Return to ONJava.com.
-
Search
2008-01-31 16:08:29 vilokanah [View]
-
Caching preconfigured data
2006-06-13 00:53:51 Bhawu [View]
-
Caching preconfigured data
2007-04-03 06:27:37 MQSeries [View]
-
Will caching help
2006-03-24 03:20:37 skcn [View]
-
Will caching help
2006-03-28 18:07:51 bwang00 [View]
-
CachedIntereceptor
2006-02-10 15:15:36 anupa [View]
-
CachedIntereceptor
2006-02-12 07:57:56 bwang00 [View]
-
Need source code
2006-01-26 12:49:10 anupa [View]
-
Need source code
2006-02-01 18:03:44 bwang00 [View]
-
enterprise alternative
2006-01-11 09:06:35 cpurdy [View]
-
enterprise alternative??
2006-01-12 00:15:23 bwang00 [View]
-
cache2_.getObject("monitor") returns null
2005-11-18 17:16:21 korosh [View]
-
cache2_.getObject("monitor") returns null
2005-11-21 18:34:32 bwang00 [View]
-
cache2_.getObject("monitor") returns null
2005-11-23 12:57:40 korosh [View]
-
cache2_.getObject("monitor") returns null
2005-11-20 16:01:05 bwang00 [View]
-
cache2_.getObject("monitor") returns null
2005-11-21 10:38:52 korosh [View]
-
Looks very interesting
2005-11-13 13:00:20 shmert [View]
-
Looks very interesting
2005-11-13 20:02:15 bwang00 [View]