Notification-Entity.twiki 1.27 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
---+ Entity Change Notifications

To receive Atlas entity notifications a consumer should be obtained through the notification interface.  Entity change notifications are sent every time a change is made to an entity.  Operations that result in an entity change notification are:
   * <code>ENTITY_CREATE</code> - Create a new entity.
   * <code>ENTITY_UPDATE</code> - Update an attribute of an existing entity.
   * <code>TRAIT_ADD</code> - Add a trait to an entity.
   * <code>TRAIT_DELETE</code> - Delete a trait from an entity.

 <verbatim>
    // Obtain provider through injection…
    Provider<NotificationInterface> provider;

    // Get the notification interface
    NotificationInterface notification = provider.get();

    // Create consumers
    List<NotificationConsumer<EntityNotification>> consumers =
       notification.createConsumers(NotificationInterface.NotificationType.ENTITIES, 1);
</verbatim>


The consumer exposes the Iterator interface that should be used to get the entity notifications as they are posted.  The hasNext() method blocks until a notification is available.

<verbatim>
    while(consumer.hasNext()) {
        EntityNotification notification = consumer.next();

        IReferenceableInstance entity = notification.getEntity();

    }
</verbatim>