use of org.wso2.carbon.registry.core.Collection in project siddhi by wso2.
the class AndMultiPrimaryKeyCollectionExecutor method find.
public StreamEvent find(StateEvent matchingEvent, IndexedEventHolder indexedEventHolder, StreamEventCloner storeEventCloner) {
ComplexEventChunk<StreamEvent> returnEventChunk = new ComplexEventChunk<StreamEvent>(false);
Collection<StreamEvent> storeEventSet = findEvents(matchingEvent, indexedEventHolder);
if (storeEventSet == null) {
return returnEventChunk.getFirst();
} else {
for (StreamEvent storeEvent : storeEventSet) {
if (storeEventCloner != null) {
returnEventChunk.add(storeEventCloner.copyStreamEvent(storeEvent));
} else {
returnEventChunk.add(storeEvent);
}
}
return returnEventChunk.getFirst();
}
}
use of org.wso2.carbon.registry.core.Collection in project siddhi by wso2.
the class CompareCollectionExecutor method find.
public StreamEvent find(StateEvent matchingEvent, IndexedEventHolder indexedEventHolder, StreamEventCloner storeEventCloner) {
ComplexEventChunk<StreamEvent> returnEventChunk = new ComplexEventChunk<StreamEvent>(false);
Collection<StreamEvent> storeEventSet = findEvents(matchingEvent, indexedEventHolder);
if (storeEventSet == null) {
// triggering sequential scan
Collection<StreamEvent> storeEvents = indexedEventHolder.getAllEvents();
for (StreamEvent storeEvent : storeEvents) {
matchingEvent.setEvent(storeEventIndex, storeEvent);
if ((Boolean) expressionExecutor.execute(matchingEvent)) {
if (storeEventCloner != null) {
returnEventChunk.add(storeEventCloner.copyStreamEvent(storeEvent));
} else {
returnEventChunk.add(storeEvent);
}
}
matchingEvent.setEvent(storeEventIndex, null);
}
return returnEventChunk.getFirst();
} else {
for (StreamEvent storeEvent : storeEventSet) {
if (storeEventCloner != null) {
returnEventChunk.add(storeEventCloner.copyStreamEvent(storeEvent));
} else {
returnEventChunk.add(storeEvent);
}
}
return returnEventChunk.getFirst();
}
}
use of org.wso2.carbon.registry.core.Collection in project siddhi by wso2.
the class NonCollectionExecutor method find.
public StreamEvent find(StateEvent matchingEvent, IndexedEventHolder indexedEventHolder, StreamEventCloner storeEventCloner) {
if ((Boolean) expressionExecutor.execute(matchingEvent)) {
ComplexEventChunk<StreamEvent> returnEventChunk = new ComplexEventChunk<StreamEvent>(false);
Collection<StreamEvent> storeEvents = indexedEventHolder.getAllEvents();
for (StreamEvent storeEvent : storeEvents) {
if (storeEventCloner != null) {
returnEventChunk.add(storeEventCloner.copyStreamEvent(storeEvent));
} else {
returnEventChunk.add(storeEvent);
}
}
return returnEventChunk.getFirst();
} else {
return null;
}
}
use of org.wso2.carbon.registry.core.Collection in project siddhi by wso2.
the class NotCollectionExecutor method delete.
@Override
public void delete(StateEvent deletingEvent, IndexedEventHolder indexedEventHolder) {
Collection<StreamEvent> notStreamEvents = notCollectionExecutor.findEvents(deletingEvent, indexedEventHolder);
if (notStreamEvents == null) {
exhaustiveCollectionExecutor.delete(deletingEvent, indexedEventHolder);
} else if (notStreamEvents.size() == 0) {
indexedEventHolder.deleteAll();
} else if (notStreamEvents.size() != indexedEventHolder.getAllEvents().size()) {
Collection<StreamEvent> allEvents = indexedEventHolder.getAllEvents();
Set<StreamEvent> returnSet = new HashSet<StreamEvent>();
for (StreamEvent aEvent : allEvents) {
if (!notStreamEvents.contains(aEvent)) {
returnSet.add(aEvent);
}
}
indexedEventHolder.deleteAll(returnSet);
}
}
use of org.wso2.carbon.registry.core.Collection in project carbon-business-process by wso2.
the class ProcessManagementServiceSkeleton method processQuery.
/**
* Query processes based on a {@link org.apache.ode.bpel.common.ProcessFilter} criteria. This is
* implemented in memory rather than via database calls since the processes
* are managed by the {@link org.apache.ode.bpel.iapi.ProcessStore} object and we don't want to make
* this needlessly complicated.
*
* @param filter process filter
* @param tenantsProcessStore Current Tenant's process store
* @return ProcessConf collection
* @throws ProcessManagementException if an error occurred while processing query
*/
private Collection<ProcessConf> processQuery(ProcessFilter filter, TenantProcessStoreImpl tenantsProcessStore) throws ProcessManagementException {
Map<QName, ProcessConfigurationImpl> processes = tenantsProcessStore.getProcessConfigMap();
if (log.isDebugEnabled()) {
for (Map.Entry<QName, ProcessConfigurationImpl> process : processes.entrySet()) {
log.debug("Process " + process.getKey() + " in state " + process.getValue());
}
}
Set<QName> pids = processes.keySet();
// Name filter can be implemented using only the PIDs.
if (filter != null && filter.getNameFilter() != null) {
// adding escape sequences to [\^$.|?*+(){} characters
String nameFilter = filter.getNameFilter().replace("\\", "\\\\").replace("]", "\\]").replace("[", "\\[").replace("^", "\\^").replace("$", "\\$").replace("|", "\\|").replace("?", "\\?").replace(".", "\\.").replace("+", "\\+").replace("(", "\\(").replace(")", "\\)").replace("{", "\\{").replace("}", "\\}").replace("*", ".*");
final Pattern pattern = Pattern.compile(nameFilter + "(-\\d*)?");
CollectionsX.remove_if(pids, new MemberOfFunction<QName>() {
@Override
public boolean isMember(QName o) {
return !pattern.matcher(o.getLocalPart()).matches();
}
});
}
if (filter != null && filter.getNamespaceFilter() != null) {
// adding escape sequences to [\^$.|?*+(){} characters
String namespaceFilter = filter.getNamespaceFilter().replace("\\", "\\\\").replace("]", "\\]").replace("[", "\\[").replace("^", "\\^").replace("$", "\\$").replace("|", "\\|").replace("?", "\\?").replace(".", "\\.").replace("+", "\\+").replace("(", "\\(").replace(")", "\\)").replace("{", "\\{").replace("}", "\\}").replace("*", ".*");
final Pattern pattern = Pattern.compile(namespaceFilter);
CollectionsX.remove_if(pids, new MemberOfFunction<QName>() {
@Override
public boolean isMember(QName o) {
String ns = o.getNamespaceURI() == null ? "" : o.getNamespaceURI();
return !pattern.matcher(ns).matches();
}
});
}
// Now we need the process conf objects, we need to be
// careful since someone could have deleted them by now
List<ProcessConf> confs = new LinkedList<ProcessConf>();
for (QName pid : pids) {
ProcessConf pConf = tenantsProcessStore.getProcessConfiguration(pid);
if (pConf != null) {
confs.add(pConf);
}
}
if (filter != null) {
// Specific filter for deployment date.
if (filter.getDeployedDateFilter() != null) {
for (final String ddf : filter.getDeployedDateFilter()) {
final Date dd;
try {
dd = ISO8601DateParser.parse(Filter.getDateWithoutOp(ddf));
} catch (ParseException e) {
// Should never happen.
String errMsg = "Exception while parsing date";
log.error(errMsg, e);
throw new ProcessManagementException(errMsg, e);
}
CollectionsX.remove_if(confs, new MemberOfFunction<ProcessConf>() {
@Override
public boolean isMember(ProcessConf o) {
if (ddf.startsWith("=")) {
return !o.getDeployDate().equals(dd);
}
if (ddf.startsWith("<=")) {
return o.getDeployDate().getTime() > dd.getTime();
}
if (ddf.startsWith(">=")) {
return o.getDeployDate().getTime() < dd.getTime();
}
if (ddf.startsWith("<")) {
return o.getDeployDate().getTime() >= dd.getTime();
}
return ddf.startsWith(">") && (o.getDeployDate().getTime() <= dd.getTime());
}
});
}
}
// Ordering
if (filter.getOrders() != null) {
ComparatorChain cChain = new ComparatorChain();
for (String key : filter.getOrders()) {
boolean ascending = true;
String orderKey = key;
if (key.startsWith("+") || key.startsWith("-")) {
orderKey = key.substring(1, key.length());
if (key.startsWith("-")) {
ascending = false;
}
}
Comparator c;
if ("name".equals(orderKey)) {
c = new Comparator<ProcessConf>() {
public int compare(ProcessConf o1, ProcessConf o2) {
return o1.getProcessId().getLocalPart().compareTo(o2.getProcessId().getLocalPart());
}
};
} else if ("namespace".equals(orderKey)) {
c = new Comparator<ProcessConf>() {
public int compare(ProcessConf o1, ProcessConf o2) {
String ns1 = o1.getProcessId().getNamespaceURI() == null ? "" : o1.getProcessId().getNamespaceURI();
String ns2 = o2.getProcessId().getNamespaceURI() == null ? "" : o2.getProcessId().getNamespaceURI();
return ns1.compareTo(ns2);
}
};
} else if ("version".equals(orderKey)) {
c = new Comparator<ProcessConf>() {
public int compare(ProcessConf o1, ProcessConf o2) {
return (int) (o1.getVersion() - o2.getVersion());
}
};
} else if ("deployed".equals(orderKey)) {
c = new Comparator<ProcessConf>() {
public int compare(ProcessConf o1, ProcessConf o2) {
return o1.getDeployDate().compareTo(o2.getDeployDate());
}
};
} else if ("status".equals(orderKey)) {
c = new Comparator<ProcessConf>() {
public int compare(ProcessConf o1, ProcessConf o2) {
return o1.getState().compareTo(o2.getState());
}
};
} else {
// unrecognized
if (log.isDebugEnabled()) {
log.debug("unrecognized order key" + orderKey);
}
continue;
}
cChain.addComparator(c, !ascending);
}
Collections.sort(confs, cChain);
}
}
return confs;
}
Aggregations