use of org.mule.runtime.api.store.ObjectStoreException in project mule by mulesoft.
the class PollingSourceWrapper method acquireItem.
private boolean acquireItem(DefaultPollItem pollItem, SourceCallbackContext callbackContext) {
if (!pollItem.getItemId().isPresent()) {
return true;
}
String id = pollItem.getItemId().get();
Lock lock = lockFactory.createLock(flowName + "/" + id);
if (!lock.tryLock()) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Source at flow '{}' is skipping processing of item '{}' because another thread or node already has a mule " + "lock on it", flowName, id);
}
return false;
}
try {
if (inflightIdsObjectStore.contains(id)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Source at flow '{}' polled item '{}', but skipping it since it is already being processed in another " + "thread or node", flowName, id);
}
lock.unlock();
return false;
} else {
try {
inflightIdsObjectStore.store(id, id);
callbackContext.addVariable(ITEM_RELEASER_CTX_VAR, new ItemReleaser(id, lock));
return true;
} catch (ObjectStoreException e) {
lock.unlock();
LOGGER.error(format("Flow at source '%s' could not track item '%s' as being processed. %s", flowName, id, e.getMessage()), e);
return false;
}
}
} catch (Exception e) {
lock.unlock();
LOGGER.error(format("Could not guarantee idempotency for item '%s' for source at flow '%s'. '%s", id, flowName, e.getMessage()), e);
return false;
}
}
use of org.mule.runtime.api.store.ObjectStoreException in project mule by mulesoft.
the class ManagedStoresTestCase method testObjectStoreExpiry.
private void testObjectStoreExpiry(ObjectStoreManager manager, String storeName, ObjectStoreSettings settings) throws ObjectStoreException, InterruptedException {
ObjectStore<String> objectStore = manager.createObjectStore(storeName, settings);
try {
objectStore.store("key1", "value1");
assertEquals("value1", objectStore.retrieve("key1"));
new PollingProber(2000, 50).check(new JUnitLambdaProbe(() -> {
try {
assertFalse("Object with key1 still exists.", objectStore.contains("key1"));
} catch (Exception e) {
fail(e.getMessage());
}
return true;
}));
} finally {
manager.disposeStore(storeName);
}
}
use of org.mule.runtime.api.store.ObjectStoreException in project mule by mulesoft.
the class ManagedStoresTestCase method testObjectStore.
private void testObjectStore(ObjectStore<String> store) throws ObjectStoreException {
ObjectStoreException e = null;
store.store("key1", "value1");
assertEquals("value1", store.retrieve("key1"));
assertTrue(store.contains("key1"));
store.clear();
assertFalse(store.contains("key1"));
store.store("key1", "value1");
try {
store.store("key1", "value1");
} catch (ObjectAlreadyExistsException e1) {
e = e1;
}
assertNotNull(e);
e = null;
assertEquals(1, store.allKeys().size());
assertEquals("key1", store.allKeys().get(0));
assertEquals("value1", store.remove("key1"));
assertFalse(store.contains("key1"));
try {
store.retrieve("key1");
} catch (ObjectDoesNotExistException e1) {
e = e1;
}
assertNotNull(e);
e = null;
try {
store.remove("key1");
} catch (ObjectDoesNotExistException e1) {
e = e1;
}
assertNotNull(e);
}
use of org.mule.runtime.api.store.ObjectStoreException in project mule by mulesoft.
the class ManagedStoresTestCase method testObjectStoreMaxEntries.
private void testObjectStoreMaxEntries(ObjectStoreManager manager, String storeName, ObjectStoreSettings settings) throws ObjectStoreException, InterruptedException {
ObjectStore<String> objectStore = manager.createObjectStore(storeName, settings);
try {
storeObjects(objectStore, 0, 90);
ensureMillisecondChanged();
storeObjects(objectStore, 90, 100);
new PollingProber(2000, 50).check(new JUnitLambdaProbe(() -> {
try {
assertEquals(10, objectStore.allKeys().size());
for (int i = 90; i < 100; i++) {
assertTrue("Checking that key" + i + " exists", objectStore.contains("key" + i));
}
} catch (Exception e) {
fail(e.getMessage());
}
return true;
}));
} finally {
manager.disposeStore(storeName);
}
}
use of org.mule.runtime.api.store.ObjectStoreException in project mule by mulesoft.
the class EventCorrelator method process.
public CoreEvent process(CoreEvent event) throws RoutingException {
// the correlationId of the event's message
final String groupId = event.getCorrelationId();
if (logger.isTraceEnabled()) {
try {
logger.trace(format("Received async reply message for correlationID: %s%n%s%n%s", groupId, truncate(StringMessageUtils.toString(event.getMessage().getPayload().getValue()), 200, false), event.getMessage().toString()));
} catch (Exception e) {
// ignore
}
}
// spinloop for the EventGroup lookup
while (true) {
try {
if (isGroupAlreadyProcessed(groupId)) {
if (logger.isDebugEnabled()) {
logger.debug("An event was received for an event group that has already been processed, " + "this is probably because the async-reply timed out. GroupCorrelation Id is: " + groupId + ". Dropping event");
}
// Fire a notification to say we received this message
notificationFirer.dispatch(new RoutingNotification(event.getMessage(), event.getContext().getOriginatingLocation().getComponentIdentifier().getIdentifier().getNamespace(), MISSED_AGGREGATION_GROUP_EVENT));
return null;
}
} catch (ObjectStoreException e) {
throw new RoutingException(timeoutMessageProcessor, e);
}
// check for an existing group first
EventGroup group;
try {
group = this.getEventGroup(groupId);
} catch (ObjectStoreException e) {
throw new RoutingException(timeoutMessageProcessor, e);
}
// does the group exist?
if (group == null) {
// ..apparently not, so create a new one & add it
try {
EventGroup eventGroup = callback.createEventGroup(event, groupId);
eventGroup.initEventsStore(correlatorStore);
group = this.addEventGroup(eventGroup);
} catch (ObjectStoreException e) {
throw new RoutingException(timeoutMessageProcessor, e);
}
}
// ensure that only one thread at a time evaluates this EventGroup
synchronized (groupsLock) {
if (logger.isDebugEnabled()) {
logger.debug("Adding event to aggregator group: " + groupId);
}
// add the incoming event to the group
try {
group.addEvent(event);
} catch (ObjectStoreException e) {
throw new RoutingException(timeoutMessageProcessor, e);
}
// check to see if the event group is ready to be aggregated
if (callback.shouldAggregateEvents(group)) {
// create the response event
CoreEvent returnEvent = null;
try {
returnEvent = callback.aggregateEvents(group);
} catch (RoutingException routingException) {
try {
this.removeEventGroup(group);
group.clear();
} catch (ObjectStoreException objectStoreException) {
throw new RoutingException(timeoutMessageProcessor, objectStoreException);
}
throw routingException;
}
// for this group once we aggregate
try {
this.removeEventGroup(group);
group.clear();
} catch (ObjectStoreException e) {
throw new RoutingException(timeoutMessageProcessor, e);
}
return returnEvent;
} else {
return null;
}
}
}
}
Aggregations