Package io.sisu.nng.aio
Class AioCallback<T>
- java.lang.Object
-
- io.sisu.nng.aio.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.)
-
-
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)
-
-
-
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 BiConsumerargs
- 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 ofargs
. This method simply wraps calling our provided BiConsumer.- Specified by:
callback
in interfaceNngCallback
- Parameters:
p
- unused JNA Pointer to the callback arguments, in practice should be a null pointer
-
-