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
public abstract class AbstractCommand extends java.lang.Object implements Command
Abstract base class for commands. Provides useful methods allowing the parsing of command arguments.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringcommandNameprotected Py4JServerConnectionconnectionprotected Gatewaygateway
-
Constructor Summary
Constructors Constructor Description AbstractCommand()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidexecute(java.lang.String commandName, java.io.BufferedReader reader, java.io.BufferedWriter writer)protected java.util.List<java.lang.Object>getArguments(java.io.BufferedReader reader)java.lang.StringgetCommandName()protected java.util.List<java.lang.String>getStringArguments(java.io.BufferedReader reader)voidinit(Gateway gateway, Py4JServerConnection connection)Called when a command instance is created and assigned to a connection.protected ReturnObjectinvokeMethod(java.lang.String methodName, java.lang.String targetObjectId, java.util.List<java.lang.Object> arguments)Convenient shortcut to invoke a method dynamically.
-
-
-
Field Detail
-
gateway
protected Gateway gateway
-
commandName
protected java.lang.String commandName
-
connection
protected Py4JServerConnection connection
-
-
Method Detail
-
execute
public abstract void execute(java.lang.String commandName, java.io.BufferedReader reader, java.io.BufferedWriter writer) throws Py4JException, java.io.IOException- Specified by:
executein 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 aPy4JExceptioninstance.java.io.IOException- If an error occurs while using the reader or the writer.
-
getArguments
protected java.util.List<java.lang.Object> getArguments(java.io.BufferedReader reader) throws java.io.IOException- Parameters:
reader-- Returns:
- A list of the remaining arguments (converted using Protocol.getObject) in the reader. Consumes the end of command part.
- Throws:
java.io.IOException
-
getCommandName
public java.lang.String getCommandName()
- Specified by:
getCommandNamein interfaceCommand
-
getStringArguments
protected java.util.List<java.lang.String> getStringArguments(java.io.BufferedReader reader) throws java.io.IOException- Parameters:
reader-- Returns:
- A list of the remaining arguments (as strings) in the reader. Consumes the end of command part.
- Throws:
java.io.IOException
-
init
public void init(Gateway gateway, Py4JServerConnection connection)
Description copied from interface:CommandCalled when a command instance is created and assigned to a connection.
- Specified by:
initin interfaceCommandconnection- thePy4JServerConnectionthis socket is assigned to
-
invokeMethod
protected ReturnObject invokeMethod(java.lang.String methodName, java.lang.String targetObjectId, java.util.List<java.lang.Object> arguments)
Convenient shortcut to invoke a method dynamically.
- Parameters:
methodName-targetObjectId-arguments-- Returns:
-
-