private void selfDeleteDueToFailure(Operation o, Throwable e) { if (getHost().isStopping()) { return; } logSevere("%s to %s failed with %s :", o.getAction(), o.getUri(), e.toString()); // self DELETE. The client, if they implemented handleRequest on the service instance // will be able to tell something went wrong sendRequest(Operation.createDelete(getUri()) .addPragmaDirective(Operation.PRAGMA_DIRECTIVE_NOTIFICATION) .addPragmaDirective(Operation.PRAGMA_DIRECTIVE_SKIPPED_NOTIFICATIONS)); } }
@Override public void handleStop(Operation op) { // Delete the node group subscription which was created at handleStart. sendRequest(Operation.createGet(this, getPeerNodeSelectorPath()).setCompletion( (o, e) -> { if (e != null) { op.fail(e); return; } NodeSelectorState nss = o.getBody(NodeSelectorState.class); Operation delete = Operation.createDelete(this, nss.nodeGroupLink).setReferer(getUri()); getHost().stopSubscriptionService(delete, this.nodeGroupCallbackUri); op.complete(); })); }
@Override public void handleStart(Operation startPost) { this.subscribeRequest.reference = UriUtils.buildPublicUri(getHost(), getSelfLink()); // we subscribe to the node group associated with our instance. The client should // set the node selector on this service, to match the one on the publisher sendRequest(Operation.createGet(this, getPeerNodeSelectorPath()).setCompletion( (o, e) -> { if (e != null) { startPost.fail(e); return; } NodeSelectorState nss = o.getBody(NodeSelectorState.class); URI callbackUri = getHost().startSubscriptionService( Operation.createPost(this, nss.nodeGroupLink).setReferer(getUri()), this::handleNodeGroupNotification); this.nodeGroupCallbackUri = callbackUri; startPost.complete(); })); }