py4j
Class AbstractCommand
java.lang.Object
py4j.AbstractCommand
- All Implemented Interfaces:
- Command
- Direct Known Subclasses:
- ArrayCommand, CallCommand, ConstructorCommand, FieldCommand, HelpPageCommand, ListCommand, MemoryCommand, ReflectionCommand, ShutdownGatewayServerCommand
public abstract class AbstractCommand
- extends Object
- implements Command
Abstract base class for commands. Provides useful methods allowing the
parsing of command arguments.
- Author:
- Barthelemy Dagenais
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
gateway
protected Gateway gateway
AbstractCommand
public AbstractCommand()
execute
public abstract void execute(String commandName,
BufferedReader reader,
BufferedWriter writer)
throws Py4JException,
IOException
- Specified by:
execute
in interface Command
- 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
through BufferedReader.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 a Py4JException
instance.
IOException
- If an error occurs while using the reader or the writer.
init
public void init(Gateway gateway)
- Description copied from interface:
Command
Called when a command instance is created and assigned to a connection.
Called by GatewayConnection.initCommands(Gateway)
- Specified by:
init
in interface Command
getStringArguments
protected List<String> getStringArguments(BufferedReader reader)
throws IOException
- Parameters:
reader
-
- Returns:
- A list of the remaining arguments (as strings) in the reader.
Consumes the end of command part.
- Throws:
IOException
getArguments
protected List<Object> getArguments(BufferedReader reader)
throws IOException
- Parameters:
reader
-
- Returns:
- A list of the remaining arguments (converted using
Protocol.getObject) in the reader. Consumes the end of command
part.
- Throws:
IOException
invokeMethod
protected ReturnObject invokeMethod(String methodName,
String targetObjectId,
List<Object> arguments)
Convenient shortcut to invoke a method dynamically.
- Parameters:
methodName
- targetObjectId
- arguments
-
- Returns: