@Override public void handleStart(Operation startPost) { startPost.complete(); CommonContinuousQueries.subscribeTo(this.getHost(), ContinuousQueryId.COMPUTES, this::onComputeChange); }
task.documentSelfLink = getTaskSelfLink(queryId); task.documentExpirationTimeMicros = Utils.fromNowMicrosUtc( TimeUnit.DAYS.toMicros(QUERY_TASK_EXPIRATION_DAYS));
/** * Subscribes a consumer to the given continuous query. */ public static void subscribeTo(ServiceHost host, ContinuousQueryId queryId, Consumer<Operation> consumer) { QueryTask task = getQueryTask(host, queryId); Operation.createPost(host, ServiceUriPaths.CORE_LOCAL_QUERY_TASKS) .setBody(task) .setReferer(host.getUri()) .setCompletion((o, e) -> { if (e != null && o.getStatusCode() != Operation.STATUS_CODE_CONFLICT) { host.log(Level.SEVERE, Utils.toString(e)); return; } String taskUriPath = UriUtils.buildUriPath( ServiceUriPaths.CORE_LOCAL_QUERY_TASKS, task.documentSelfLink); Operation subscribePost = Operation.createPost(host, taskUriPath) .setReferer(host.getUri()) .setCompletion((op, ex) -> { if (ex != null) { host.log(Level.SEVERE, Utils.toString(ex)); } }); host.log(Level.INFO, "Subscribing to a continuous task: %s", taskUriPath); host.startSubscriptionService(subscribePost, consumer, ServiceSubscriber.create(false)); }).sendWith(host); }
@Override public void handleStart(Operation startPost) { startPost.complete(); CommonContinuousQueries.subscribeTo(this.getHost(), ContinuousQueryId.COMPUTES, this::onComputeChange); }
private DeferredResult<Void> subscribeForSubscriptions() { DeferredResult<Void> subscriptionsRead = new DeferredResult<Void>(); CommonContinuousQueries .subscribeTo(this.getHost(), ContinuousQueryId.EXTENSIBILITY_SUBSCRIPTIONS, op -> onSubscriptionChange(op, subscriptionsRead)); return subscriptionsRead; }
private DeferredResult<Void> subscribeForTopics() { DeferredResult<Void> topicsRead = new DeferredResult<Void>(); CommonContinuousQueries.subscribeTo(this.getHost(), ContinuousQueryId.EVENT_TOPICS, op -> onEventTopicChange(op, topicsRead)); return topicsRead; }