Class RelationSet

java.lang.Object
com.caplin.management.jmx.relations.RelationSet
All Implemented Interfaces:
Serializable, Iterable, Collection, Set

public class RelationSet extends Object implements Set, Serializable

Represents a "to many" relationship, where a particular MBean attribute defines a link between that MBean and many other MBeans. All of the elements returned from a RelationSet should be of the type ObjectNameLink.

Once the initial state of a RelationSet has been obtained, it can be kept up to date with the server by registering the NotificationListener returned by the getNotificationListener() method and the NotificationFilter returned by the getNotificationFilter() method with the MBean server (e.g. mbeanServer.addNotificationListener(objectName, relationSet.getNotificationListener(), relationSet.getNotificationFilter(), null);). Updates to the RelationSet can be handled by registering a RelationSetUpdateListener via the addUpdateListener(RelationSetUpdateListener) method.

See Also:
  • Constructor Details

    • RelationSet

      public RelationSet(ObjectName sourceObjectName, String attributeName)

      Constructs a RelationSet with the specified source ObjectName and attribte name.

      Parameters:
      sourceObjectName - The ObjectName of the MBean that the RelationSet belongs to.
      attributeName - The name of the attribute the RelationSet was obtained from.
      Throws:
      IllegalArgumentException - If either the sourceObjectName or attributeName arguments are null.
  • Method Details

    • size

      public int size()

      Returns the number of elements in this set (its cardinality).

      Specified by:
      size in interface Collection
      Specified by:
      size in interface Set
      Returns:
      The number of elements in this set (its cardinality).
    • isEmpty

      public boolean isEmpty()

      Returns true if this set contains no elements.

      Specified by:
      isEmpty in interface Collection
      Specified by:
      isEmpty in interface Set
      Returns:
      true if this set contains no elements.
    • contains

      public boolean contains(Object object)

      Returns true if this set contains the specified element.

      Specified by:
      contains in interface Collection
      Specified by:
      contains in interface Set
      Parameters:
      object - Element whose presence in this set is to be tested.
      Returns:
      true if this set contains the specified element.
    • iterator

      public Iterator iterator()

      Returns an iterator over the elements in this set. The elements are returned in no particular order.

      Specified by:
      iterator in interface Collection
      Specified by:
      iterator in interface Iterable
      Specified by:
      iterator in interface Set
      Returns:
      An Iterator over the elements in this set.
    • toArray

      public Object[] toArray()

      Returns an array containing all of the elements in this set. Obeys the general contract of the Collection.toArray method.

      Specified by:
      toArray in interface Collection
      Specified by:
      toArray in interface Set
      Returns:
      An array containing all of the elements in this set.
    • toArray

      public Object[] toArray(Object[] array)

      Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array. Obeys the general contract of the Collection.toArray(Object[]) method.

      Specified by:
      toArray in interface Collection
      Specified by:
      toArray in interface Set
      Parameters:
      array - the array into which the elements of this set are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
      Returns:
      An array containing the elements of this set.
      Throws:
      ArrayStoreException - If the runtime type of a is not a supertype of the runtime type of every element in this set.
      NullPointerException - If the specified array is null.
    • add

      public boolean add(Object object)

      Adds the specified element to this set if it is not already present.

      Specified by:
      add in interface Collection
      Specified by:
      add in interface Set
      Parameters:
      object - element to be added to this set.
      Returns:
      true if the set did not already contain the specified element.
    • remove

      public boolean remove(Object object)

      Removes the specified element from this set if it is present.

      Specified by:
      remove in interface Collection
      Specified by:
      remove in interface Set
      Parameters:
      object - Object to be removed from this set, if present.
      Returns:
      true if the set contained the specified element.
    • containsAll

      public boolean containsAll(Collection collection)

      Returns true if this set contains all of the elements of the specified collection. If the specified collection is also a set, this method returns true if it is a subset of this set.

      Specified by:
      containsAll in interface Collection
      Specified by:
      containsAll in interface Set
      Parameters:
      collection - Collection to be checked for containment in this set.
      Returns:
      true if this set contains all of the elements of the specified collection.
      Throws:
      NullPointerException - if the specified collection is null.
      See Also:
    • addAll

      public boolean addAll(Collection collection)

      Adds all of the elements in the specified collection to this set if they're not already present. If the specified collection is also a set, the addAll operation effectively modifies this set so that its value is the union of the two sets. The behavior of this operation is unspecified if the specified collection is modified while the operation is in progress.

      Specified by:
      addAll in interface Collection
      Specified by:
      addAll in interface Set
      Parameters:
      collection - Collection whose elements are to be added to this set.
      Returns:
      true if this set changed as a result of the call.
      Throws:
      IllegalArgumentException - If some aspect of some element of the specified collection prevents it from being added to this set.
      See Also:
    • retainAll

      public boolean retainAll(Collection collection)

      Retains only the elements in this set that are contained in the specified collection. In other words, removes from this set all of its elements that are not contained in the specified collection. If the specified collection is also a set, this operation effectively modifies this set so that its value is the intersection of the two sets.

      Specified by:
      retainAll in interface Collection
      Specified by:
      retainAll in interface Set
      Parameters:
      collection - Collection that defines which elements this set will retain.
      Returns:
      true if this collection changed as a result of the call.
      Throws:
      NullPointerException - If the specified collection is null.
      See Also:
    • removeAll

      public boolean removeAll(Collection collection)

      Removes from this set all of its elements that are contained in the specified collection. If the specified collection is also a set, this operation effectively modifies this set so that its value is the asymmetric set difference of the two sets.

      Specified by:
      removeAll in interface Collection
      Specified by:
      removeAll in interface Set
      Parameters:
      collection - Collection that defines which elements will be removed from this set.
      Returns:
      true if this set changed as a result of the call.
      Throws:
      NullPointerException - If the specified collection is null.
      See Also:
    • clear

      public void clear()

      Removes all of the elements from this set.

      Specified by:
      clear in interface Collection
      Specified by:
      clear in interface Set
    • getNotificationFilter

      public NotificationFilter getNotificationFilter()

      Gets a notification filter that will only enable notifications that apply to this RelationSet. It is recommended that this is used in conjunction with the NotificationListener returned by getNotificationListener().

      Returns:
      A notification filter that will only enable notifications that apply to this RelationSet.
    • getNotificationListener

      public NotificationListener getNotificationListener()

      Gets a notification listener that will automatically process any Notifications it receives to update this RelationSet's internal state. It is recommended that this is used in conjunction with the NotificationFilter returned by getNotificationFilter().

      Returns:
      A notification listener that will automatically process any Notifications it receives to update this RelationSet's internal state.
    • addUpdateListener

      public boolean addUpdateListener(RelationSetUpdateListener updateListener)

      Adds the specified RelationSetUpdateListener to the RelationSet. Every update listener that has been registered with the RelationSet will be informed whenever the RelationSet receives a notification that an element has been added or removed.

      Parameters:
      updateListener - The update listener to add to the RelationSet.
      Returns:
      true if the specified update listener has not previously been added to the RelationSet, otherwise false.
      Throws:
      IllegalArgumentException - If the updateListener argument is null.
    • removeUpdateListener

      public boolean removeUpdateListener(RelationSetUpdateListener updateListener)

      Removes the specified RelationSetUpdateListener from the RelationSet. The update listener will no longer be informed of any element added/removed changes to the RelationSet.

      Parameters:
      updateListener - The update listener to remove from the RelationSet.
      Returns:
      true if the specified update listener had been registered with the RelationSet, otherwise false.
      Throws:
      IllegalArgumentException - If the updateListener argument is null.