private void forwardToPostgres(QueryTask task, Operation get) { try { Operation localPatch = Operation.createPatch(UriUtils.buildUri(getHost(), task.indexLink)) .setBodyNoCloning(task) .setCompletion((o, e) -> { if (e == null) { task.results = (ServiceDocumentQueryResult) o.getBodyRaw(); } handleQueryCompletion(task, e, get); }); sendRequest(localPatch); } catch (Exception e) { handleQueryCompletion(task, e, get); } }
@Override public void handleStart(Operation post) { ServiceDocument initState = post.getBody(ServiceDocument.class); this.documentSelfLink = initState.documentSelfLink; this.documentExpirationTimeMicros = initState.documentExpirationTimeMicros; long ttl = this.documentExpirationTimeMicros - Utils.getSystemNowMicrosUtc(); if (ttl < 0) { logWarning("Task expiration is in the past, extending it"); // task has already expired. Add some more time instead of failing ttl = Math.max(getHost().getMaintenanceIntervalMicros() * 2, DEFAULT_TTL_MICROS); } super.toggleOption(ServiceOption.PERIODIC_MAINTENANCE, true); super.setMaintenanceIntervalMicros(ttl); post.complete(); }
&& !getHost().isStopping()) { logWarning("Retrying query because index context is out of date"); task.querySpec.context.nativeSearcher = null; forwardToPostgres(task, get); return; boolean singleUse = task.querySpec.options.contains(QueryOption.SINGLE_USE); if (singleUse) { getHost().stopService(this); task.querySpec.context = null; task.taskInfo.stage = TaskStage.FINISHED; QueryTaskUtils.expandLinks(getHost(), task, get); .setCompletion((op, ex) -> { if (ex != null) { logWarning("Failed to delete runtime context: %s", Utils.toString(ex)); sendRequest(patch);
@Override public void handlePeriodicMaintenance(Operation op) { op.complete(); // This service only lives as long as its parent QueryTask getHost().stopService(this); }
@Override public void handleGet(Operation get) { QuerySpecification clonedSpec = new QuerySpecification(); // shallow copy specification this.spec.copyTo(clonedSpec); QueryTask task = QueryTask.create(clonedSpec); task.documentKind = KIND; task.documentSelfLink = this.documentSelfLink; task.documentExpirationTimeMicros = this.documentExpirationTimeMicros; task.taskInfo.stage = TaskStage.CREATED; task.taskInfo.isDirect = true; task.indexLink = this.indexLink; task.nodeSelectorLink = this.nodeSelectorPath; // the client can supply a URI parameter to modify the result limit. This // only affects the current GET operation and not the page service itself and any // future GETs from other clients. The generated nextPageLink, for this GET, will // of course be different than other operations with the original limit Integer limit = UriUtils.getODataLimitParamValue(get.getUri()); if (limit != null) { task.querySpec.resultLimit = limit; } forwardToPostgres(task, get); }
new PostgresQueryPageService(spec, indexLink, nodeSelectorLink));