Skip to content

Instantly share code, notes, and snippets.

@johndemic
Created November 30, 2011 21:51
Show Gist options
  • Save johndemic/1411118 to your computer and use it in GitHub Desktop.
Save johndemic/1411118 to your computer and use it in GitHub Desktop.
Integer getFailureCount() {
try {
objectStoreMutex.acquire();
} catch (InterruptedException e) {
logger.error("Could not acquire mutex", e);
}
ObjectStore objectStore = objectStoreManager.getObjectStore(MuleProperties.OBJECT_STORE_DEFAULT_PERSISTENT_NAME);
String key = String.format("%s.failureCount", breakerName);
Integer failureCount = 0;
try {
if (objectStore.contains(key)) {
failureCount = (Integer) objectStore.retrieve(key);
}
} catch (Exception e) {
logger.error("Could not retrieve key from object-store: " + key, e);
}
objectStoreMutex.release();
return failureCount;
}
void incrementFailureCount() {
try {
objectStoreMutex.acquire();
} catch (InterruptedException e) {
logger.error("Could not acquire mutex", e);
}
ObjectStore objectStore = objectStoreManager.getObjectStore(MuleProperties.OBJECT_STORE_DEFAULT_PERSISTENT_NAME);
String key = String.format("%s.failureCount", breakerName);
Integer failureCount = 0;
try {
if (objectStore.contains(key)) {
failureCount = (Integer) objectStore.retrieve(key);
objectStore.remove(key);
}
objectStore.store(key, failureCount + 1);
} catch (Exception e) {
logger.error("Could not retrieve key from object-store: " + key, e);
}
objectStoreMutex.release();
}
void resetFailureCount() {
try {
objectStoreMutex.acquire();
} catch (InterruptedException e) {
logger.error("Could not acquire mutex", e);
}
ObjectStore objectStore = objectStoreManager.getObjectStore(MuleProperties.OBJECT_STORE_DEFAULT_PERSISTENT_NAME);
String key = String.format("%s.failureCount", breakerName);
Integer failureCount = 0;
try {
if (objectStore.contains(key)) {
failureCount = (Integer) objectStore.retrieve(key);
objectStore.remove(key);
}
objectStore.store(key, 0);
} catch (Exception e) {
logger.error("Could not retrieve key from object-store: " + key, e);
}
objectStoreMutex.release();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment