Class NeovimHandlerManager
java.lang.Object
com.ensarsarajcic.neovim.java.handler.NeovimHandlerManager
Simple class used to register and connect
NeovimNotificationHandler
and NeovimRequestHandler
It provides methods to register/unregister any kind of object as neovim handler, but only classes with methods
annotated with NeovimNotificationHandler
or NeovimRequestHandler
can be useful, since this will
find such methods and call them once notifications/requests arrive
To get notifications/requests it should first be attached to a RpcStreamer
using attachToStream(RpcStreamer)
Underneath, NeovimHandlerProxy
is used to dispatch notifications/requests, which delegates thread management to it
Examples:
NeovimHandlerManager neovimHandlerManager = new NeovimHandlerManager();
neovimHandlerManager.registerNeovimHandler(uiEventHandler);
neovimHandlerManager.attachToStream(neovimStream);
-
Constructor Summary
ConstructorDescriptionNeovimHandlerManager
(NeovimHandlerProxy neovimHandlerProxy) Creates a newNeovimHandlerManager
with givenNeovimHandlerProxy
NeovimHandlerManager
(NeovimHandlerProxy neovimHandlerProxy, BiFunction<Class<?>, Object, Object> typeMapper) Creates a newNeovimHandlerManager
with givenNeovimHandlerProxy
and type mapper -
Method Summary
Modifier and TypeMethodDescriptionvoid
attachToStream
(RpcStreamer rpcStreamer) Attaches to givenRpcStreamer
RpcStreamer
does not have to be attached to an actual connection at the time of this call, since this only sets up the notification/request callbacksvoid
registerNeovimHandler
(Object handler) Registers a new handler If this object is already registered, this is a no-op If this object has methods annotated withNeovimNotificationHandler
orNeovimRequestHandler
, this method will have no effect, but it will still reflectively look for such methodsvoid
unregisterNeovimHandler
(Object handler) Unregisters passed handler If it was not registered previously, this is a no-op It will no longer receive notifications/requests after this point, unless it is registered again
-
Constructor Details
-
NeovimHandlerManager
public NeovimHandlerManager() -
NeovimHandlerManager
Creates a newNeovimHandlerManager
with givenNeovimHandlerProxy
- Parameters:
neovimHandlerProxy
- proxy to use for dispatching notifications/messages- Throws:
NullPointerException
- if passedNeovimHandlerProxy
is null
-
NeovimHandlerManager
public NeovimHandlerManager(NeovimHandlerProxy neovimHandlerProxy, BiFunction<Class<?>, Object, Object> typeMapper) Creates a newNeovimHandlerManager
with givenNeovimHandlerProxy
and type mapper- Parameters:
neovimHandlerProxy
- proxy to use for dispatching notifications/messagestypeMapper
- function that attempts to map given argument to the given class- Throws:
NullPointerException
- if passedNeovimHandlerProxy
is null
-
-
Method Details
-
attachToStream
Attaches to givenRpcStreamer
RpcStreamer
does not have to be attached to an actual connection at the time of this call, since this only sets up the notification/request callbacks- Parameters:
rpcStreamer
- streamer whose notifications/requests should be analysed- Throws:
NullPointerException
- ifRpcStreamer
is null
-
registerNeovimHandler
Registers a new handler If this object is already registered, this is a no-op If this object has methods annotated withNeovimNotificationHandler
orNeovimRequestHandler
, this method will have no effect, but it will still reflectively look for such methodsThis works for both static and instance methods
Passed objects methods are prepared to be called when new notifications/requests arrive from attached
RpcStreamer
This may be called prior to attaching, but no notifications/requests can arrive before attaching- Parameters:
handler
- object to search for annotated methods
-
unregisterNeovimHandler
Unregisters passed handler If it was not registered previously, this is a no-op It will no longer receive notifications/requests after this point, unless it is registered again- Parameters:
handler
- object to unregister
-