Class AioCallback<T>

  • All Implemented Interfaces:
    com.sun.jna.Callback, NngCallback

    public class AioCallback<T>
    extends java.lang.Object
    implements NngCallback
    Convenience wrapper around NNG's aio callback functions. The general design is to allow for leaning into Java's design more than NNG's C design, keeping state in the JVM and allowing for the consumer to have limited access to the aio api via a reference to an AioProxy. (This provides a way to perform aio operations like setting or getting a Message, calling send, sleep, etc.)
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface com.sun.jna.Callback

        com.sun.jna.Callback.UncaughtExceptionHandler
    • Field Summary

      Fields 
      Modifier and Type Field Description
      T args  
      java.util.function.BiConsumer<AioProxy,​T> consumer  
      protected AioProxy proxy  
      • Fields inherited from interface com.sun.jna.Callback

        FORBIDDEN_NAMES, METHOD_NAME
    • Constructor Summary

      Constructors 
      Constructor Description
      AioCallback()  
      AioCallback​(java.util.function.BiConsumer<AioProxy,​T> consumer, T args)
      Configure a new AioCallback with the given BiConsumer that will be called with both a proxy implementation to the underlying Aio instance and the given args object T.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void callback​(com.sun.jna.Pointer p)
      This is the actual entrypoint for the underlying NNG callback function and will be triggered from native code.
      protected void setAioProxy​(AioProxy proxy)  
      • Methods inherited from class java.lang.Object

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

      • args

        public T args
      • consumer

        public java.util.function.BiConsumer<AioProxy,​T> consumer
    • Constructor Detail

      • AioCallback

        public AioCallback()
      • AioCallback

        public AioCallback​(java.util.function.BiConsumer<AioProxy,​T> consumer,
                           T args)
        Configure a new AioCallback with the given BiConsumer that will be called with both a proxy implementation to the underlying Aio instance and the given args object T.
        Parameters:
        consumer - the callback logic in the form of a BiConsumer
        args - reference to a Java object to pass with each call of the callback
    • Method Detail

      • setAioProxy

        protected void setAioProxy​(AioProxy proxy)
      • callback

        public void callback​(com.sun.jna.Pointer p)
        This is the actual entrypoint for the underlying NNG callback function and will be triggered from native code. We don't use the given Pointer p as we keep the callback arg on the JVM in the form of
        args
        . This method simply wraps calling our provided BiConsumer.
        Specified by:
        callback in interface NngCallback
        Parameters:
        p - unused JNA Pointer to the callback arguments, in practice should be a null pointer