Interface ContextProxy


  • public interface ContextProxy
    A ContextProxy provides an API for event handler functions or closures to (relatively) safely manipulate the underlying Context in response to Aio operations (e.g. send, receive, sleep). Each of the methods provided returns immediately and will not block.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.lang.Object get​(java.lang.String key)
      Get an object from the Context's state using the given key, if it exists.
      java.lang.Object getOrDefault​(java.lang.Object key, java.lang.Object defaultValue)
      Get an object from the Context's state using the given key, returning the value if found or the provided defaultValue if not.
      void put​(java.lang.String key, java.lang.Object value)
      Put the given object value into the backing state of the underlying Context using the given key as a reference.
      void receive()
      Attempt a receive operation on the Context.
      void send​(Message message)
      Send the given Message asynchronously via the Context.
      void sleep​(int millis)
      Suspend the Context for the given duration, triggering the wake handler upon timeout.
    • Method Detail

      • send

        void send​(Message message)
        Send the given Message asynchronously via the Context. Will not block.
        Parameters:
        message - the Message to send
      • receive

        void receive()
        Attempt a receive operation on the Context. Returns immediately after adding the operation to the underlying queue.
      • sleep

        void sleep​(int millis)
        Suspend the Context for the given duration, triggering the wake handler upon timeout. Does not block.
        Parameters:
        millis - the time in milliseconds to sleep for
      • put

        void put​(java.lang.String key,
                 java.lang.Object value)
        Put the given object value into the backing state of the underlying Context using the given key as a reference. The object is then available for retrieval by get(String) in other event handlers. If an object for the key already exists, it is replaced.
        Parameters:
        key - a String value to use as the key
        value - the object to store in the Context
      • get

        java.lang.Object get​(java.lang.String key)
        Get an object from the Context's state using the given key, if it exists. Otherwise, returns null.
        Parameters:
        key - a String value used as the key
        Returns:
        the Object if found, or null if not present
      • getOrDefault

        java.lang.Object getOrDefault​(java.lang.Object key,
                                      java.lang.Object defaultValue)
        Get an object from the Context's state using the given key, returning the value if found or the provided defaultValue if not.
        Parameters:
        key - a String value used as the key
        defaultValue - an object to return if the key is not found
        Returns:
        the found Object or the provided default value