Class ActionSet


  • class ActionSet
    extends java.lang.Object
    The ActionSet object represents a set of actions that are associated with a particular selection key. Here the set stores an Action for each of the interested operation types. In some situations a single action may be interested in several operations which must be remembered by the set.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.nio.channels.SelectionKey key
      This is the selection key associated with the action set.
      private Action[] set
      This contains the the actions indexed by operation type.
    • Constructor Summary

      Constructors 
      Constructor Description
      ActionSet​(java.nio.channels.SelectionKey key)
      Constructor for the ActionSet object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void attach​(Action action)
      This is used to attach an action to the set for a specific interest bitmask.
      void cancel()
      This is used to cancel the SelectionKey associated with the action set.
      java.nio.channels.SelectableChannel channel()
      This provides the channel associated with the action set.
      void clear()
      This is used to clear all interest from the set.
      private Action[] copyOf​(Action[] list, int count)
      This is used to create a copy of the specified list with only the first few non null values.
      Action[] get​(int interest)
      This is used to acquire the actions that match the bitmask of interest operations.
      int interest()
      This is used to acquire the operations that this is interested in.
      java.nio.channels.SelectionKey key()
      This provides the selection key associated with the action set.
      Action[] list()
      This provides an iterator of the actions that exist within the action set.
      Action[] ready()
      This is sued to acquire all actions that match the currently ready operations of the key.
      Action[] remove​(int interest)
      This is used to remove interest from the set.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • key

        private final java.nio.channels.SelectionKey key
        This is the selection key associated with the action set.
      • set

        private final Action[] set
        This contains the the actions indexed by operation type.
    • Constructor Detail

      • ActionSet

        public ActionSet​(java.nio.channels.SelectionKey key)
        Constructor for the ActionSet object. This is used to create a set for storing actions keyed by operation type. Only one action is kept per operation type.
        Parameters:
        key - this is the associated selection key
    • Method Detail

      • key

        public java.nio.channels.SelectionKey key()
        This provides the selection key associated with the action set. For each ready operation on the selection key the set contains an action that can be executed.
        Returns:
        this provides the selection key for this action set
      • channel

        public java.nio.channels.SelectableChannel channel()
        This provides the channel associated with the action set. This is the channel that is registered for selection using the interested operations for the set.
        Returns:
        this returns the selectable channel for the action set
      • list

        public Action[] list()
        This provides an iterator of the actions that exist within the action set. Regardless of whether a single action is interested is several operations this will return an iteration of unique actions. Modifications to the iterator do not affect the set.
        Returns:
        this returns an iterator of unique actions for the set
      • ready

        public Action[] ready()
        This is sued to acquire all actions that match the currently ready operations of the key. All actions returned by this will be executed and the interest will typically be removed.
        Returns:
        returns the array of ready operations for the set
      • attach

        public void attach​(Action action)
        This is used to attach an action to the set for a specific interest bitmask. If the bitmask contains several operations then the action is registered for each individual operation.
        Parameters:
        action - this is the action that is to be attached
        interest - this is the interest for the action
      • remove

        public Action[] remove​(int interest)
        This is used to remove interest from the set. Removal of interest from the set is performed by registering a null for the interest operation.
        Parameters:
        interest - this is the interest to be removed
      • get

        public Action[] get​(int interest)
        This is used to acquire the actions that match the bitmask of interest operations. If there are no actions representing the interest required an empty array will be returned.
        Parameters:
        interest - this is the interest to acquire actions for
        Returns:
        this will return an array of actions for the interest
      • copyOf

        private Action[] copyOf​(Action[] list,
                                int count)
        This is used to create a copy of the specified list with only the first few non null values. This ensures we can keep the internal array immutable and still use arrays.
        Parameters:
        list - this is the list that is to be copied to a new array
        count - this is the number of entries to copy from the list
        Returns:
        a copy of the original list up to the specified count
      • interest

        public int interest()
        This is used to acquire the operations that this is interested in. If there are currently no registered actions then this will return zero. Interest is represented by non-null actions only.
        Returns:
        this returns the interested operations for this
      • clear

        public void clear()
        This is used to clear all interest from the set. This will basically clear out any actions that have been registered with the set. After invocation the iterator will be empty.
      • cancel

        public void cancel()
        This is used to cancel the SelectionKey associated with the action set. Canceling the key in this manner ensures it is not returned in further selection operations.