Package py4j.commands
Class AbstractCommand
java.lang.Object
py4j.commands.AbstractCommand
- All Implemented Interfaces:
Command
- Direct Known Subclasses:
ArrayCommand
,AuthCommand
,CallCommand
,ConstructorCommand
,DirCommand
,ExceptionCommand
,FieldCommand
,HelpPageCommand
,JVMViewCommand
,ListCommand
,MemoryCommand
,ReflectionCommand
,ShutdownGatewayServerCommand
,StreamCommand
Abstract base class for commands. Provides useful methods allowing the parsing of command arguments.
- Author:
- Barthelemy Dagenais
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
protected Py4JServerConnection
protected Gateway
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract void
execute
(String commandName, BufferedReader reader, BufferedWriter writer) getArguments
(BufferedReader reader) getStringArguments
(BufferedReader reader) void
init
(Gateway gateway, Py4JServerConnection connection) Called when a command instance is created and assigned to a connection.protected ReturnObject
invokeMethod
(String methodName, String targetObjectId, List<Object> arguments) Convenient shortcut to invoke a method dynamically.
-
Field Details
-
gateway
-
commandName
-
connection
-
-
Constructor Details
-
AbstractCommand
public AbstractCommand()
-
-
Method Details
-
execute
public abstract void execute(String commandName, BufferedReader reader, BufferedWriter writer) throws Py4JException, IOException - Specified by:
execute
in interfaceCommand
- Parameters:
commandName
- The command name that was extracted of the command.reader
- The reader from which to read the command parts. Each command part are expected to be on a separate line and readable throughBufferedReader.readLine()
.writer
- The writer to which the return value should be written.- Throws:
Py4JException
- If an error occurs while executing the command. All exceptions except IOException caused by the reader and the writer should be wrapper in aPy4JException
instance.IOException
- If an error occurs while using the reader or the writer.
-
getArguments
- Parameters:
reader
-- Returns:
- A list of the remaining arguments (converted using Protocol.getObject) in the reader. Consumes the end of command part.
- Throws:
IOException
-
getCommandName
- Specified by:
getCommandName
in interfaceCommand
-
getStringArguments
- Parameters:
reader
-- Returns:
- A list of the remaining arguments (as strings) in the reader. Consumes the end of command part.
- Throws:
IOException
-
init
Description copied from interface:Command
Called when a command instance is created and assigned to a connection.
- Specified by:
init
in interfaceCommand
connection
- thePy4JServerConnection
this socket is assigned to
-
invokeMethod
protected ReturnObject invokeMethod(String methodName, String targetObjectId, List<Object> arguments) Convenient shortcut to invoke a method dynamically.
- Parameters:
methodName
-targetObjectId
-arguments
-- Returns:
-