@Override public List<String> allKeys() throws ObjectStoreException { return partitionedObjectStore.allKeys(partitionName); }
@Override public List<String> allKeys(String partitionName) throws ObjectStoreException { return wrapped.allKeys(partitionName); }
@Override public List<String> allKeys() throws ObjectStoreException { return wrapped.allKeys(); }
/** * Returns the number of events collected so far. * * @return number of events in this group or 0 if the group is empty. */ public int size() { synchronized (this) { try { return eventsObjectStore.allKeys(eventsPartitionKey).size(); } catch (ObjectStoreException e) { // TODO Check if this is ok. return -1; } } }
/** * Returns a snapshot of collected events in this group, optionally sorted by their arrival time. * * @return an array of collected {@link CoreEvent}s. * @throws ObjectStoreException */ public PrivilegedEvent[] toArray(boolean sortByArrival) throws ObjectStoreException { synchronized (this) { if (eventsObjectStore.allKeys(eventsPartitionKey).isEmpty()) { return EMPTY_EVENTS_ARRAY; } List<String> keys = eventsObjectStore.allKeys(eventsPartitionKey); PrivilegedEvent[] eventArray = new PrivilegedEvent[keys.size()]; for (int i = 0; i < keys.size(); i++) { eventArray[i] = (PrivilegedEvent) eventsObjectStore.retrieve(keys.get(i), eventsPartitionKey); } if (sortByArrival) { Arrays.sort(eventArray, new ArrivalOrderEventComparator()); } return eventArray; } }
/** * Removes the elements in expiredAndDispatchedGroups when groupLife is reached */ @Override public void expired() { try { for (String o : (List<String>) correlatorStore.allKeys(getExpiredAndDispatchedPartitionKey())) { Long time = (Long) correlatorStore.retrieve(o, getExpiredAndDispatchedPartitionKey()); if (time + DAYS.toMillis(1) < currentTimeMillis()) { correlatorStore.remove(o, getExpiredAndDispatchedPartitionKey()); logger.warn(MessageFormat.format("Discarding group {0}", o)); } } } catch (ObjectStoreException e) { logger.warn("Expiration of objects failed due to ObjectStoreException " + e + "."); } }
/** * Returns an iterator over a snapshot copy of this group's collected events., optionally sorted by arrival order. If you need * to iterate over the group and e.g. remove select events, do so via {@link #removeEvent(CoreEvent)}. If you need to do so * atomically in order to prevent e.g. concurrent reception/aggregation of the group during iteration, wrap the iteration in a * synchronized block on the group instance. * * @return an iterator over collected {@link CoreEvent}s. * @throws ObjectStoreException */ @SuppressWarnings("unchecked") public Iterator<CoreEvent> iterator(boolean sortByArrival) throws ObjectStoreException { synchronized (this) { if (eventsObjectStore.allKeys(eventsPartitionKey).isEmpty()) { return IteratorUtils.emptyIterator(); } else { return IteratorUtils.arrayIterator(this.toArray(sortByArrival)); } } }
@Override public void run() { //// TODO(pablo.kraan): is not good to have threads doing nothing in all the nodes but the primary. Need to //// start the thread on the primary node only, and then use a notification schema to start a new thread //// in a different node when the primary goes down. if (!muleContext.isPrimaryPollingInstance()) { return; } List<EventGroup> expired = new ArrayList<>(1); try { for (String o : (List<String>) correlatorStore.allKeys(getEventGroupsPartitionKey())) { EventGroup group = getEventGroup(o); // group may have been removed by another thread right after eventGroups.allKeys() if (group != null && group.getCreated() + getTimeout() < currentTimeMillis()) { expired.add(group); } } } catch (ObjectStoreException e) { logger.warn("expiry failed dues to ObjectStoreException " + e); } for (final EventGroup group : expired) { try { handleGroupExpiry(group); } catch (MessagingException e) { flowConstruct.getExceptionListener().handleException(e, e.getEvent()); } catch (Exception e) { muleContext.getExceptionListener().handleException(e); } } }