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 @interfaceAnnotate a particular method on your RPC implementation withRequiredMutabilityModeto indicate that the client must have at least the givenMutabilityMode, or the call will be rejected.static @interfaceAnnotate a particular method on your RPC implementation withRunsOnBackupto allow it to be invoked on a backup node.static @interfaceAnnotate a particular method or your entire RPC implementation withRunsOnClientto allow it to be invoked by a client. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRpcDelegate(Object... instances) Create a newRpcDelegatefrom the provided instances, which each must implement an interface annotated withRpcInterface. -
Method Summary
Modifier and TypeMethodDescriptionstatic RequestContextGet the current RPC call'sRpcContextfrom the current thread.static jakarta.servlet.http.HttpServletResponseGet the current RPC call'sHttpServletResponsefrom the current thread.@NotNull Optional<RpcHandler>getRpcHandler(RpcCall call) static StringGet the project name the RPC call on the current thread originated from.static RpcCallrpcCall()Get the current RPC call'sRpcCallfrom the current thread.static ClientReqSessionsession()Get the current RPC call'sClientReqSessionfrom the current thread.
-
Field Details
-
CURRENT_CONTEXT
-
-
Constructor Details
-
RpcDelegate
Create a newRpcDelegatefrom 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:
getRpcHandlerin interfaceRpcRouter
-
getRequest
Get the current RPC call'sRpcContextfrom 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'sHttpServletResponsefrom the current thread.- Throws:
IllegalStateException- if no context is available- See Also:
-
session
Get the current RPC call'sClientReqSessionfrom 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'sRpcCallfrom the current thread.- Throws:
IllegalStateException- if no context is available- See Also:
-