Class Protocol
This class defines the protocol used to communicate between two virtual machines (e.g., Python and Java).
Currently, the protocol requires type information (e.g., is this string an integer, an object reference or a boolean?) to be embedded with each command part. The rational is that the source virtual machine is usually better at determining the type of objects it sends.
An input command is usually composed of:
- A command name (e.g., c for call)
- Optionally, a sub command name (e.g., 'a' for concatenate in the list command)
- A list of command parts (e.g., the name of a method, the value of a parameter, etc.)
- The End of Command marker (e)
The various parts of a command are separated by \n characters. These characters are automatically escaped and unescaped in Strings on both sides (Java and Python).
An output command is usually composed of:
- A success or error code (y for yes, x for exception)
- A return value (e.g., n for null, v for void, or any other value like a String)
This class should be used only if the user creates new commands.
- Author:
- Barthelemy Dagenais
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final char
static final String
static final char
static final char
static final char
static final char
static final String
static final char
static final char
static final char
static final String
static final char
static final String
static final char
static final String
static final char
static final char
static final char
static final char
static final char
static final char
static final char
static final String
static final char
static final char
static final String
static final String
static final String
static final char
static final char
static final char
static final char
static final String
static final char
static final char
static final char
static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
encodeBytes
(byte[] bytes) Transform the byte array into Base64 characters.static final String
getAuthCommand
(String authToken) static final boolean
getBoolean
(String commandPart) Assumes that commandPart is not empty.static final byte[]
Assumes that commandPart is not empty.static final BigDecimal
getDecimal
(String commandPart) Assumes that commandPart is not empty.static final double
Assumes that commandPart is not empty.static final int
getInteger
(String commandPart) Assumes that commandPart is not empty.static final long
Assumes that commandPart is not empty.static final String
getMemberOutputCommand
(char memberType) static final String
getMemberOutputCommand
(char memberType, String fqn) static String
static final Object
Method provided for consistency.static final Object
static final String
getOutputCommand
(ReturnObject rObject) static final String
static final String
getOutputErrorCommand
(String errorMessage) static final String
getOutputErrorCommand
(Throwable throwable) static final String
getOutputFatalErrorCommand
(Throwable throwable) static final String
static char
getPrimitiveType
(Object primitiveObject) static Object
getPythonProxy
(String commandPart, Gateway gateway) Assumes that commandPart is not empty.static Object
getPythonProxyHandler
(ClassLoader classLoader, Class[] interfacesToImplement, String objectId, Gateway gateway) Deprecated.static final Object
getReference
(String commandPart, Gateway gateway) Assumes that commandPart is not empty.static final Object
getReturnValue
(String returnMessage, Gateway gateway) static final Throwable
getRootThrowable
(Throwable throwable, boolean skipInvocation) static final String
Assumes that commandPart is not empty.static final String
getThrowableAsString
(Throwable throwable) static final boolean
Assumes that commandPart is not empty.static final boolean
Assumes that commandPart is not empty.static final boolean
Assumes that commandPart is not empty.static final boolean
Assumes that commandPart is not empty.static final boolean
static final boolean
Assumes that commandPart is not empty.static final boolean
Assumes that commandPart is not null.static final boolean
Assumes that commandPart is not empty.static final boolean
Assumes that commandPart is not empty.static final boolean
Assumes that commandPart is not empty.static final boolean
isPythonProxy
(String commandPart) Assumes that commandPart is not empty.static final boolean
isReference
(String commandPart) Assumes that commandPart is not empty.static final boolean
isReturnMessage
(String commandPart) static final boolean
Assumes that commandPart is not empty.
-
Field Details
-
BYTES_TYPE
public static final char BYTES_TYPE- See Also:
-
INTEGER_TYPE
public static final char INTEGER_TYPE- See Also:
-
LONG_TYPE
public static final char LONG_TYPE- See Also:
-
BOOLEAN_TYPE
public static final char BOOLEAN_TYPE- See Also:
-
DOUBLE_TYPE
public static final char DOUBLE_TYPE- See Also:
-
DECIMAL_TYPE
public static final char DECIMAL_TYPE- See Also:
-
STRING_TYPE
public static final char STRING_TYPE- See Also:
-
REFERENCE_TYPE
public static final char REFERENCE_TYPE- See Also:
-
LIST_TYPE
public static final char LIST_TYPE- See Also:
-
SET_TYPE
public static final char SET_TYPE- See Also:
-
ARRAY_TYPE
public static final char ARRAY_TYPE- See Also:
-
MAP_TYPE
public static final char MAP_TYPE- See Also:
-
ITERATOR_TYPE
public static final char ITERATOR_TYPE- See Also:
-
NULL_TYPE
public static final char NULL_TYPE- See Also:
-
PYTHON_PROXY_TYPE
public static final char PYTHON_PROXY_TYPE- See Also:
-
PACKAGE_TYPE
public static final char PACKAGE_TYPE- See Also:
-
CLASS_TYPE
public static final char CLASS_TYPE- See Also:
-
METHOD_TYPE
public static final char METHOD_TYPE- See Also:
-
NO_MEMBER
public static final char NO_MEMBER- See Also:
-
VOID
public static final char VOID- See Also:
-
RETURN_MESSAGE
public static final char RETURN_MESSAGE- See Also:
-
END
public static final char END- See Also:
-
END_OUTPUT
public static final char END_OUTPUT- See Also:
-
ERROR
public static final char ERROR- See Also:
-
FATAL_ERROR
public static final char FATAL_ERROR- See Also:
-
SUCCESS
public static final char SUCCESS- See Also:
-
AUTH_COMMAND_NAME
- See Also:
-
ERROR_COMMAND
- See Also:
-
VOID_COMMAND
- See Also:
-
NO_SUCH_FIELD
- See Also:
-
ENTRY_POINT_OBJECT_ID
- See Also:
-
DEFAULT_JVM_OBJECT_ID
- See Also:
-
GATEWAY_SERVER_ID
- See Also:
-
STATIC_PREFIX
- See Also:
-
PYTHON_NAN
- See Also:
-
PYTHON_INFINITY
- See Also:
-
PYTHON_NEGATIVE_INFINITY
- See Also:
-
-
Constructor Details
-
Protocol
public Protocol()
-
-
Method Details
-
encodeBytes
Transform the byte array into Base64 characters.
- Parameters:
bytes
-- Returns:
-
getBoolean
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- The boolean value corresponding to this command part.
-
getBytes
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- The byte array corresponding to this command part.
-
getDecimal
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- The decimal value corresponding to this command part.
-
getDouble
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- The double value corresponding to this command part.
-
getInteger
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- The integer value corresponding to this command part.
-
getLong
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- The long value corresponding to this command part.
-
getMemberOutputCommand
-
getMemberOutputCommand
-
getNoSuchFieldOutputCommand
-
getNull
Method provided for consistency. Just returns null.
- Parameters:
commandPart
-- Returns:
- null.
-
getObject
-
getOutputCommand
-
getOutputErrorCommand
-
getOutputErrorCommand
-
getOutputErrorCommand
-
getOutputFatalErrorCommand
-
getOutputVoidCommand
-
getAuthCommand
-
getPrimitiveType
-
getPythonProxy
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- A Python proxy specified in this command part.
-
getPythonProxyHandler
public static Object getPythonProxyHandler(ClassLoader classLoader, Class[] interfacesToImplement, String objectId, Gateway gateway) Deprecated.Legacy method. Please use Gateway.createProxy.
- Parameters:
classLoader
-interfacesToImplement
-objectId
-gateway
-- Returns:
-
getReference
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- The object referenced in this command part.
-
getReturnValue
- Throws:
Throwable
-
getRootThrowable
-
getString
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- The reference contained in this command part.
-
getThrowableAsString
-
isBoolean
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- True if the command part is a boolean
-
isReturnMessage
- Parameters:
commandPart
-- Returns:
- True if the command part is a return message
-
isBytes
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- True if the command part is a byte array
-
isDecimal
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- True if the command part is a decimal
-
isDouble
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- True if the command part is a double
-
isEmpty
-
isEnd
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- True if the command part is the end token
-
isError
Assumes that commandPart is not null.
- Parameters:
returnMessage
-- Returns:
- True if the return message is an error
-
isInteger
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- True if the command part is an integer
-
isLong
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- True if the command part is a long
-
isNull
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- True if the command part is null
-
isPythonProxy
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- True if the command part is a python proxy
-
isReference
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- True if the command part is a reference
-
isString
Assumes that commandPart is not empty.
- Parameters:
commandPart
-- Returns:
- True if the command part is a reference
-