Factory that creates Gateway implementations from custom interface definitions. The behavior of the method is defined
by the parameters, declared exceptions and return type of the method.
Supported parameter types:
- The first parameter of the method is considered the payload of the
message. If the first parameter is a Message itself, a new message is created using the payload and metadata of the
message passed as parameter.
- Parameters that are annotated with
MetaDataValue will
cause the parameter values to be added as meta data values to the outgoing message.
- If the last two
parameters are of type
Long and
TimeUnit, they are considered to represent the timeout for the
command. The method will block for as long as the command requires to execute, or until the timeout expires.
Effect of return values
-
void return types are always allowed. Unless another parameter makes
the method blocking, void methods are non-blocking by default.
- Declaring a
Future return type will
always result in a non-blocking operation. A future is returned that allows you to retrieve the execution's result at
your own convenience. Note that declared exceptions and timeouts are ignored.
- Any other return type will
cause the dispatch to block (optionally with timeout) until a result is available
Effect of declared exceptions
- Any checked exception declared on the method will cause it to block
(optionally with timeout). If the command results in a declared checked exception, that exception is thrown from the
method.
- Declaring a
TimeoutException will throw that exception when a configured timeout expires. If
no such exception is declared, but a timeout is configured, the method will return
null.
- Declaring
an
InterruptedException will throw that exception when a thread blocked while waiting for a response is
interrupted. Not declaring the exception will have the method return
null when a blocked thread is
interrupted. Note that when no InterruptedException is declared, the interrupt flag is set back on the interrupted
thread
Effect of unchecked exceptions
- Any unchecked exception thrown during command handling will cause it
to block. If the method is blocking (see below) the unchecked exception will be thrown from the method
Finally, the
Timeout annotation can be used to define a timeout on a method. This will always cause
a method invocation to block until a response is available, or the timeout expires.
Any method will be blocking if:
- It declares a return type other than
void or
Future, or
- It declares an exception, or
- The last two parameters are of type
TimeUnit and
Long,
or
- The method is annotated with
Timeout
In other cases, the method is
non-blocking and will return immediately after dispatching a command.
This factory is thread safe once configured, and so are the gateways it creates.