ContainerHostRemovalTaskState.class); sm.start(notification -> { ContainerHostRemovalTaskState eats = notification.getResult(); EnumSet<TaskStage> terminalStages = of(TaskStage.FINISHED, TaskStage.FAILED, TaskStage.CANCELLED);
cluster.getInProcessHostMap().values().forEach((h) -> { subscribe(h, this.exampleState, (notification) -> { String documentLink = notification.getResult().documentSelfLink; if (notification.isDelete()) { cluster.log(Level.INFO, String.format( documentLink)); if (notification.isUpdate()) { cluster.log(Level.INFO, String.format( "Update notification received for %s. Counting down.", documentLink));
r.throwRunTimeException(); } else if (r.hasResult()) { SubscriptionNotification<T> notification = new SubscriptionNotification<>(); notification.result = r.getResult(); notification.operation = ServiceDocument.isDeleted(r
ContainerHostRemovalTaskState.class); subscriptionManager.start(notification -> { ContainerHostRemovalTaskState eats = notification.getResult(); EnumSet<TaskStage> terminalStages = of(TaskStage.FINISHED, TaskStage.FAILED, TaskStage.CANCELLED);
assertNotNull(notification.getResult()); assertTrue(notification.isUpdate()); updatedState = notification.getResult(); assertEquals(updatedTestId, updatedState.id); assertEquals(updatedTestValue, updatedState.image); assertNotNull(notification.getResult()); assertTrue(notification.isUpdate()); updatedState = notification.getResult(); assertEquals(updatedTestValue + updatedTestId, updatedState.id); assertEquals(updatedTestValue, updatedState.image); assertNotNull(notification.getResult()); assertTrue(notification.isDelete());
private void handleNotification(Operation op, Consumer<SubscriptionNotification<T>> notificationHandler) { try { host.log(Level.INFO, "Notification received for action: [%s] and uri: [%s]", op.getAction(), op.getUri()); SubscriptionNotification<T> notification = new SubscriptionNotification<>(); if (Action.DELETE == op.getAction()) { if (!op.hasBody()) { // service stopped. no changes to the state. op.complete(); return; } else { notification.operation = NotificationOperation.DELETE; // the subscription is already deleted with the deletion of the document // just reset the subscription link. this.subscriptionLink = null; } } else { notification.operation = NotificationOperation.UPDATE; } if (op.hasBody()) { notification.result = op.getBody(this.type); } notificationHandler.accept(notification); op.complete(); } catch (Throwable e) { Utils.logWarning("Error handling notifications. Error: %s", Utils.toString(e)); op.fail(e); } }
@Test public void testNotificationSubscriptionUpdates() throws Throwable { subscribe(); state.documentSelfLink = state.documentSelfLink; doOperation(Action.PUT, state); notification = getNotification(); assertNotNull(notification); assertNotNull(notification.getResult()); assertTrue(notification.isUpdate()); updatedState = notification.getResult(); assertEquals(updatedTestId, updatedState.id); assertEquals(updatedTestValue, updatedState.image); state.id = updatedTestValue + updatedTestId; doOperation(Action.PATCH, state); notification = getNotification(); assertNotNull(notification.getResult()); assertTrue(notification.isUpdate()); updatedState = notification.getResult(); assertEquals(updatedTestValue + updatedTestId, updatedState.id); assertEquals(updatedTestValue, updatedState.image); doOperation(Action.DELETE, new ServiceDocument()); notification = getNotification(); assertNotNull(notification.getResult()); assertTrue(notification.isDelete()); assertFalse(subscriptionManager.isSubscribed()); }