SDN Controller Programming Guide
87
@Override
public MarkPage<CassandraAlert> find(CassandraAlertFilter alertFilter,
SortSpecification<CassandraAlertSortAttribute> sortSpec,
MarkPageRequest<CassandraAlert> pageRequest) {
ReadQuery<MarkPage<CassandraAlert>, DataStoreContext> query =
queryService.getPageAlertsQuery(
alertFilter, sortSpec, pageRequest);
try {
return dataStoreService.execute(query);
} catch (Exception e) {
...
}
}
The two methods shown read from the database in different ways. The first one issues a find query
using a filter object. The filter specifies the pivot around which the query results are read. The
second method reads a page of alerts and is used when there is a need to paginate results. This is
mostly used by GUI where pages of Alerts are displayed instead of a single long list of Alerts.
The following is an example of filter object as defined in the demo application.
CassandraAlertFilter.java:
package com.hp.hm.model;
import com.hp.util.filter.EqualityCondition;
import com.hp.util.filter.SetCondition;
import com.hp.util.filter.StringCondition;
...
public class CasssandraAlertFilter {
private SetCondition<Severity> severityCondition;
private EqualityCondition<Boolean> stateCondition;
private StringCondition topicCondition;
private StringCondition originCondition;
...
// Implement setters and getters for all conditions.
// Good practice to override toString()
}
Every application needs to define its filter parameters as in the above code. In the demo
application, there is severity filter to “find Alerts where Severity = CRITICAL, WARNING” for
example. So, Severity is a Set condition. The find method returns the row if one of the values in a
set condition match. The other conditions in the demo follow similar principles.