|
Project Information
Members
Links
|
Version 0.806A distributed synchronization library for ZookeeperCages is a Java library of distributed synchronization primitives that uses the Apache ZooKeeper system. If you can run a ZooKeeper machine or cluster, then you can use Cages to synchronize and coordinate data access, data manipulation and data processing, configuration change and more esoteric things like cluster membership across multiple machines. Usage examples
Simple code example void executeTrade(long lotId, long sellerId, long buyerId) {
// In the following we need to hold write locks over both the seller and buyer's account balances
// so they can be checked and updated correctly. We also want a lock over the lot, since the value
// of lots owned might be used in conjunction with the bank balance by code considering the
// total worth of the owner. Acquiring the required locks simultaneously using ZkMultiLock avoids
// the possibility of accidental deadlock occurring between this client code and other client code
// contending access to the same data / lock paths.
ZkMultiLock mlock = new ZkMultiLock();
mlock.addWriteLock("/Bank/accounts/" + sellerId);
mlock.addWriteLock("/Bank/accounts/" + buyerId);
mlock.addWriteLock("/Warehouse/" + lotId);
mlock.acquire();
try {
// 1. check buyer has sufficient funds
// 2. debit buyer's account
// 3. credit seller's account
// 4. change ownership of goods
} finally {
mlock.release();
}
}Current issues Cages is quite rough and ready, and far from complete. I made the decision to offer it as open source because those parts that are present are already useful and there isn't much else that does a comparable job. There are some known limitions and issues related to certain aspects of ZooKeeper, and we plan on submitting ZooKeeper patches to address those shortly. More information on these will be placed in the Wiki soon. Things for the future Here is a brief list of new features planned:
|