Class InterceptedCommand
java.lang.Object
org.pipservices3.commons.commands.InterceptedCommand
- All Implemented Interfaces:
ICommand
,IExecutable
Implements a
ICommand
command wrapped by an interceptor.
It allows to build command call chains. The interceptor can alter execution
and delegate calls to a next command, which can be intercepted or concrete.
### Example ###
public class CommandLogger implements ICommandInterceptor {
public String getName(ICommand command) {
return command.getName();
}
public Object execute(String correlationId, ICommand command, Parameters args) {
System.out.println("Executed command " + command.getName());
return command.execute(correlationId, args);
}
private List<ValidationResult> validate(ICommand command, Parameters args) {
return command.validate(args);
}
}
CommandLogger logger = new CommandLogger();
InterceptedCommand loggedCommand = new InterceptedCommand(logger, command);
// Each called command will output: Executed command <command name>
- See Also:
-
Constructor Summary
ConstructorDescriptionInterceptedCommand
(ICommandInterceptor interceptor, ICommand next) Creates a new InterceptedCommand, which serves as a link in an execution chain. -
Method Summary
Modifier and TypeMethodDescriptionexecute
(String correlationId, Parameters args) Executes the next command in the execution chain using the given Parameters parameters (arguments).getName()
Gets the command name.validate
(Parameters args) Validates the Parameters args that are to be passed to the command that is next in the execution chain.
-
Constructor Details
-
InterceptedCommand
Creates a new InterceptedCommand, which serves as a link in an execution chain. Contains information about the interceptor that is being used and the next command in the chain.- Parameters:
interceptor
- the interceptor that is intercepting the command.next
- (link to) the next command in the command's execution chain.
-
-
Method Details
-
getName
Gets the command name. -
execute
Executes the next command in the execution chain using the given Parameters parameters (arguments).- Specified by:
execute
in interfaceIExecutable
- Parameters:
correlationId
- unique transaction id to trace calls across components.args
- the parameters (arguments) to pass to the command for execution.- Returns:
- execution result.
- Throws:
ApplicationException
- when execution fails for whatever reason.- See Also:
-
validate
Validates the Parameters args that are to be passed to the command that is next in the execution chain.
-