/** * In our magic demo world users have unique combination of first and last names * * @param firstName * @param lastName */ @MetaLock( name = "User", param = {"firstName", "lastName"}) public void addMoneyForUser(String firstName, String lastName, int amountOfMoney) { auditor.logAction("Add " + amountOfMoney + " money for " + firstName + " " + lastName); worker.doSomeWork(200); auditor.logAction("Added " + amountOfMoney + " money for " + firstName + " " + lastName); }
/** * Save (insert or update) record in the Registry. * * @param recordKey * @param recordValue */ @MetaLock(name = "Record", param = "recordKey") public void saveRecord(String recordKey, String recordValue) { auditor.logAction("Save select " + recordKey); String value = recordsDummyStorage.get(recordKey); worker.doSomeWork(200); if (value == null) { auditor.logAction("Save insert " + recordKey + " " + recordValue); recordsDummyStorage.put(recordKey, recordValue); } else { auditor.logAction("Save update " + recordKey + " " + recordValue); recordsDummyStorage.put(recordKey, recordValue); } }
/** * Backup all domains. All write operations should be locked until the Backup is completed We have * to acquire both lock (Public and Personal) before write operations. */ @NameLock({PUBLIC_DOMAIN, PERSONAL_DOMAIN}) public void backupDomains() { auditor.logAction("Backup started"); worker.doSomeWork(200); auditor.logAction("Backup done"); }
/** * Create an Index for the Records in the Personal Domain. * * <p>We have to acquire a lock for this Domain before write operations. */ @NameLock(PERSONAL_DOMAIN) public void indexPersonalDomain() { auditor.logAction("Indexing Personal"); worker.doSomeWork(200); auditor.logAction("Indexed Personal"); }
/** * Create an Index for the Records in the Public Domain. * * <p>We have to acquire a lock for this Domain before write operations. */ @NameLock(PUBLIC_DOMAIN) public void indexPublicDomain() { auditor.logAction("Indexing Public"); worker.doSomeWork(200); auditor.logAction("Indexed Public"); }
/** * Create a new Directory in the Public Domain. * * <p>For a some reason we can't create new Directories in parallel. We have to acquire a lock * before write operations. */ @NameLock(PUBLIC_DOMAIN) public void createDirectoryInThePublicDomain(String directoryName) { auditor.logAction("Creating Public " + directoryName); worker.doSomeWork(200); auditor.logAction("Created Public " + directoryName); }