Interface ContainerModel
ContainerMessages.
Note: You do not have to use this interface to process
ContainerMessages. You can instead use the basic approach, as
explained in ContainerMessage.getOperations().
To use the ContainerModel interface:
- Create a class that implements
ContainerModeland represents (models) a container. - Ensure the class also implements
SubscriptionListener. - In the callback method
SubscriptionListener.containerUpdated(com.caplin.datasource.subscription.Subscription, com.caplin.datasource.Peer, ContainerMessage), iterate through theContainerOperations and callContainerOperation.updateContainer(ContainerModel)on each in turn. - Each call to
ContainerOperation.updateContainer(ContainerModel)invokes the appropriate callback method on your implementation ofContainerModel:addElement(String),removeElement(String),insertElement(String, int)orremoveElementsWithPrefix(String). - Implement the above callback methods to apply the correct transformations to the list of container elements in
your
ContainerModel.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddElement(String subject) Called to indicate that you should add (append) an element with the given subject to the container.voidinsertElement(String subject, int position) Called to indicate that you should insert an element with the given subject at the given position within the container.voidremoveElement(String subject) Called to indicate that you should remove the element with the given subject from the container.voidremoveElementsWithPrefix(String prefix) Called to indicate that you should remove all elements from the container that have a subject that matches the specified prefix.
-
Method Details
-
addElement
Called to indicate that you should add (append) an element with the given subject to the container.The element must be added to the end of the container. For example, if there are three elements already in the container at positions 0, 1, and 2 respectively, adding a fourth element places it at position 3.
- Parameters:
subject- The subject of the element to add.
-
removeElement
Called to indicate that you should remove the element with the given subject from the container.- Parameters:
subject- The subject of the element to be to removed.
-
insertElement
Called to indicate that you should insert an element with the given subject at the given position within the container.- Parameters:
subject- The subject of the element to be inserted.position- The position at which to insert the element. The first element in a container is at position 0.
-
removeElementsWithPrefix
Called to indicate that you should remove all elements from the container that have a subject that matches the specified prefix.Instructions should be processed in the order in which they are retrieved from the
ContainerMessageand this affects earlier instructions. For example, assume that in the same message you received these operations:- Add a container element with subject /A/1,
- Remove all container elements with prefix /A,
- Add a container element with subject /A/2.
When this sequence has been processed, the container should only contain the element /A/2, because /A/1 was removed at step 2.
- Parameters:
prefix- The prefix to match subjects for which elements are to be removed from the container.
-