Search in sources :

Example 6 with ObjectStoreException

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;
    }
}
Also used : ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) MuleException(org.mule.runtime.api.exception.MuleException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) Lock(java.util.concurrent.locks.Lock)

Example 7 with ObjectStoreException

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);
    }
}
Also used : JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) PollingProber(org.mule.tck.probe.PollingProber) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) ObjectDoesNotExistException(org.mule.runtime.api.store.ObjectDoesNotExistException) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) ObjectAlreadyExistsException(org.mule.runtime.api.store.ObjectAlreadyExistsException)

Example 8 with ObjectStoreException

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);
}
Also used : ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) ObjectDoesNotExistException(org.mule.runtime.api.store.ObjectDoesNotExistException) ObjectAlreadyExistsException(org.mule.runtime.api.store.ObjectAlreadyExistsException)

Example 9 with ObjectStoreException

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);
    }
}
Also used : JUnitLambdaProbe(org.mule.tck.probe.JUnitLambdaProbe) PollingProber(org.mule.tck.probe.PollingProber) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) ObjectDoesNotExistException(org.mule.runtime.api.store.ObjectDoesNotExistException) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) ObjectAlreadyExistsException(org.mule.runtime.api.store.ObjectAlreadyExistsException)

Example 10 with ObjectStoreException

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;
            }
        }
    }
}
Also used : ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) RoutingNotification(org.mule.runtime.api.notification.RoutingNotification) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) ObjectDoesNotExistException(org.mule.runtime.api.store.ObjectDoesNotExistException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) ObjectAlreadyExistsException(org.mule.runtime.api.store.ObjectAlreadyExistsException) EventGroup(org.mule.runtime.core.internal.routing.EventGroup)

Aggregations

ObjectStoreException (org.mule.runtime.api.store.ObjectStoreException)20 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)10 ObjectAlreadyExistsException (org.mule.runtime.api.store.ObjectAlreadyExistsException)9 ObjectDoesNotExistException (org.mule.runtime.api.store.ObjectDoesNotExistException)9 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)6 MuleException (org.mule.runtime.api.exception.MuleException)5 RegistrationException (org.mule.runtime.core.privileged.registry.RegistrationException)5 File (java.io.File)3 IOException (java.io.IOException)3 Serializable (java.io.Serializable)3 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)3 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)3 EventGroup (org.mule.runtime.core.internal.routing.EventGroup)3 RoutingException (org.mule.runtime.core.privileged.routing.RoutingException)3 PollingProber (org.mule.tck.probe.PollingProber)3 List (java.util.List)2 Message (org.mule.runtime.api.message.Message)2 RoutingNotification (org.mule.runtime.api.notification.RoutingNotification)2 ObjectStoreNotAvailableException (org.mule.runtime.api.store.ObjectStoreNotAvailableException)2 PartitionableObjectStore (org.mule.runtime.api.store.PartitionableObjectStore)2