Class RpcDelegate
- All Implemented Interfaces:
RpcRouter
RpcRouter
from object(s) that implement an RPC interface.
Each object passed in must implement an interface annotated with RpcInterface
.
All methods on the annotated interface will be exposed as RPC functions.
Use RunsOnClient
and RunsOnBackup
annotations to allow a particular method
to run in additional contexts.
Specify a client permission constant in the RpcDelegate.RunsOnClient
annotation to restrict a method to certain roles.
By default, RPC methods will only run when invoked from the Designer on an active or independent node.
Use the RpcDelegate.RequiredMutabilityMode
annotation to indicate that a given RPC method can only be run by sessions
with at least a particular mutability (aka comm) mode - as in, require read/write so that a read only session cannot
run your RPC method.
Note: if the call is rejected because of one of the above restrictions, an RpcException
will be thrown.
If your interface doesn't declare this exception, it will be wrapped in an UndeclaredThrowableException
,
which you may need special handling for in your client/designer code invoking RPC.
Use CURRENT_CONTEXT
to access the current RpcContext
from within the method, or use
the static accessors (e.g. getRequest()
) to access specific elements of the context.
This class implements RpcRouter
, using RpcInterface.packageId()
to route by
packageId
, and the exposed method's name to route by function
.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interface
Annotate a particular method on your RPC implementation withRequiredMutabilityMode
to indicate that the client must have at least the givenMutabilityMode
, or the call will be rejected.static @interface
Annotate a particular method on your RPC implementation withRunsOnBackup
to allow it to be invoked on a backup node.static @interface
Annotate a particular method or your entire RPC implementation withRunsOnClient
to allow it to be invoked by a client. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRpcDelegate
(Object... instances) Create a newRpcDelegate
from the provided instances, which each must implement an interface annotated withRpcInterface
. -
Method Summary
Modifier and TypeMethodDescriptionstatic RequestContext
Get the current RPC call'sRpcContext
from the current thread.static jakarta.servlet.http.HttpServletResponse
Get the current RPC call'sHttpServletResponse
from the current thread.@NotNull Optional<RpcHandler>
getRpcHandler
(RpcCall call) static String
Get the project name the RPC call on the current thread originated from.static RpcCall
rpcCall()
Get the current RPC call'sRpcCall
from the current thread.static ClientReqSession
session()
Get the current RPC call'sClientReqSession
from the current thread.
-
Field Details
-
CURRENT_CONTEXT
-
-
Constructor Details
-
RpcDelegate
Create a newRpcDelegate
from the provided instances, which each must implement an interface annotated withRpcInterface
.- Throws:
IllegalArgumentException
- if any preconditions mentioned in the class descriptor are not met.IllegalArgumentException
- if the provided instances array is empty.
-
-
Method Details
-
getRpcHandler
- Specified by:
getRpcHandler
in interfaceRpcRouter
-
getRequest
Get the current RPC call'sRpcContext
from the current thread.- Throws:
IllegalStateException
- if no context is available- See Also:
-
getResponse
public static jakarta.servlet.http.HttpServletResponse getResponse()Get the current RPC call'sHttpServletResponse
from the current thread.- Throws:
IllegalStateException
- if no context is available- See Also:
-
session
Get the current RPC call'sClientReqSession
from the current thread.- Throws:
IllegalStateException
- if no context is available- See Also:
-
projectName
Get the project name the RPC call on the current thread originated from.- Throws:
IllegalStateException
- if no context is available- See Also:
-
rpcCall
Get the current RPC call'sRpcCall
from the current thread.- Throws:
IllegalStateException
- if no context is available- See Also:
-