/** * Sets the notification in processed state. * * @param notification the notification */ protected void unlock(final ImportNotification notification) { notification.setState(ImportNotificationState.PROCESSED); importNotificationDao.update(notification); if (LOG.isDebugEnabled()) { LOG.debug( "Import notification has been processed. Process ID: " + notification.getProcessId()); } }
/** * Tries to lock the notification by setting it into in_process state. * * @param notification the notification to lock * @return true if the lock has been gained successfully */ protected boolean lock(final ImportNotification notification) { if (ObjectUtils.equals(ImportNotificationState.IN_PROCESS, notification.getState())) { return false; } // set in process on notification so that no other parties should take it over notification.setState(ImportNotificationState.IN_PROCESS); try { // update the notification which makes sure that no other participants will take it for // processing // could throw OptimisticLockException wrapped in EpPersistenceException when some other party // has updated the same object which means that it was already locked importNotificationDao.update(notification); } catch (EpPersistenceException exc) { LOG.debug("Cannot gain lock over notification: " + notification, exc); return false; } return true; }