QuerySubscriptionTriggered.java 文件源码

java
阅读 20 收藏 0 点赞 0 评论 0

项目:oliot-epcis 作者:
/**
 * {@inheritDoc} First checks on the trigger condition: if fulfilled then
 * execute Query.
 * 
 * @see org.fosstrak.epcis.repository.query.QuerySubscriptionScheduled#handleNotification(javax.management.Notification,
 *      java.lang.Object)
 */
@Override
public void handleNotification(final Notification pNotification, final Object pHandback) {
    if (pHandback == null) {
        LOG.error("The timer stating the next scheduled query execution time is null!");
        return;
    }
    Timer timer = (Timer) pHandback;

    if (!doItAgain.booleanValue()) {
        timer.stop();
    } else {
        try {
            LOG.debug("Checking trigger condition ...");
            String queryName = "SimpleEventQuery";
            QueryParams params = new QueryParams();

            // add MATCH_anyEPC query param
            QueryParam param = new QueryParam();
            param.setName("MATCH_anyEPC");
            ArrayOfString strings = new ArrayOfString();
            strings.getString().add(trigger);
            param.setValue(strings);
            params.getParam().add(param);

            // add GE_recordTime query param
            param = new QueryParam();
            param.setName("GE_recordTime");
            param.setValue(initialRecordTime);
            params.getParam().add(param);

            // send the query
            Poll poll = new Poll();
            poll.setParams(params);
            poll.setQueryName(queryName);
            QueryResults results = executePoll(poll);
            if (results != null && results.getResultsBody() != null
                    && results.getResultsBody().getEventList() != null) {
                LOG.debug("Trigger condition fulfilled!");
                LOG.debug("Executing subscribed query associated with trigger event ...");
                super.executeQuery();
                LOG.debug("Triggered query successfully executed!");
            }
        } catch (Exception e) {
            String msg = "An error occurred while checking trigger condition for query with subscriptionID '"
                    + subscriptionID + "': " + e.getMessage();
            LOG.error(msg, e);
        }

        // determine next scheduled execution time
        setNextScheduledExecutionTime(timer);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号