public class SocketImpl extends SensitiveResource implements Socket, Sensitive, Connectable, SslServerAttribute
| Modifier and Type | Class and Description |
|---|---|
private static class |
SocketImpl.ServerSocketMapping
Mapping of a legacy server socket data to post-migration server socket.
|
private static class |
SocketImpl.WorkArea
Container for context-local state.
|
| Modifier and Type | Field and Description |
|---|---|
private long |
bytesRead
The total bytes read by the last
read(com.goldencode.p2j.util.memptr, double, double) call. |
private long |
bytesWritten
The total bytes read by the last
write(com.goldencode.p2j.util.memptr, double, double) call. |
private static boolean |
initialized
Flag indicating that the sockets were read from the directory or not.
|
private static ContextLocal<SocketImpl.WorkArea> |
local
Client side network instance for handling sockets.
|
private static CentralLogger |
LOG
Logger
|
private java.util.Set<java.lang.Integer> |
pendingEvents
A set of pending READ-RESPONSE events which were not processed by PROCESS EVENTS or a
UI blocking statement.
|
private static InvokeConfig |
READ_RESPONSE_CALL_SITE
The call-site for the READ-RESPONSE event callback.
|
private WrappedResource |
readResponseContext
The context of the procedure to be executed when data is received, if any.
|
private java.lang.String |
readResponseProcedure
The name of the procedure to be executed when data is received, if any.
|
private static java.util.Set<SocketImpl.ServerSocketMapping> |
serverSockets
Set of remapped target server sockets.
|
private static java.lang.String |
SO_KEEPALIVE
SO-KEEPALIVE socket option name
|
private static java.lang.String |
SO_LINGER
SO-LINGER socket option name
|
private static java.lang.String |
SO_RCVBUF
SO-RCVBUF socket option name
|
private static java.lang.String |
SO_RCVTIMEO
SO-RCVTIMEO socket option name
|
private static java.lang.String |
SO_REUSEADDR
SO-REUSEADDR socket option name
|
private static java.lang.String |
SO_SNDBUF
SO-SNDBUF socket option name
|
private int |
socketId
The associated socket id on P2J client side.
|
private java.lang.String |
targetHost
After a connect call, this will contain the target host (-H option).
|
private java.lang.String |
targetService
After a connect call, this will contain the target service (-S option).
|
private static java.lang.String |
TCP_NO_DELAY
TCP-NODELAY socket option name
|
private boolean |
valid
Flag to track the valid state of this resource.
|
private boolean |
valueParseError
Flag indicating something went wrong during parsing of a socket option, when
setSocketOption(java.lang.String, java.lang.String) is called. |
private SocketImpl.WorkArea |
workArea
Cache the
local instance. |
name, nextSibling, prevSibling, wainstProc, pmREAD_AVAILABLE, READ_EXACT_NUM| Modifier | Constructor and Description |
|---|---|
|
SocketImpl()
Default constructor which initializes SOCKET specific settings.
|
private |
SocketImpl(int socketId)
Create a new socket resource on server side and associate it with the given
LowLevelSocketImpl instance from P2J client side. |
| Modifier and Type | Method and Description |
|---|---|
private boolean |
asBoolean(java.lang.String val,
java.lang.String option)
Parse the value for the given option as a boolean.
|
private int |
asInt(java.lang.String val,
java.lang.String option)
Parse the value for the given option as an int.
|
logical |
connect(character options)
Java implementation for the CONNECT() SOCKET method, this will attempt to connect to the
host and port specified by the options argument.
|
logical |
connect(java.lang.String options)
Java implementation for the CONNECT() SOCKET method, this will attempt to connect to the
host and port specified by the options argument.
|
logical |
connected()
Java implementation for the CONNECTED() SOCKET method, this will return
true
if the socket is connected or false otherwise. |
static long |
createSocket(int id)
Create a socket resource and associate it with the given
LowLevelSocketImpl instance
from P2J client side. |
logical |
disconnect()
Java implementation for the DISCONECT() SOCKET method.
|
integer |
getBytesAvailable()
Java implementation for the GET-BYTES-AVAILABLE() SOCKET method, this will return the number
of bytes that can be read at the current moment from the socket.
|
integer |
getBytesRead()
Java implementation for getting the BYTES-READ SOCKET attribute which contains the number
of bytes the last read() method call returned from the socket.
|
integer |
getBytesWritten()
Java implementation for getting the BYTES-WRITTEN SOCKET attribute which contains the
number of bytes the last write() method has put in the socket.
|
character |
getLocalHost()
Java implementation for getting the LOCAL-HOST SOCKET attribute which contains the address
in IP form of the machine to which the Socket is connected.
|
integer |
getLocalPort()
Java implementation for getting the LOCAL-PORT SOCKET attribute which contains the local
port of the machine to which the Socket is connected.
|
character |
getRemoteHost()
Java implementation for getting the REMOTE-HOST SOCKET attribute which contains the address
in IP form of the machine to which the Socket is connected.
|
integer |
getRemotePort()
Java implementation for getting the REMOTE-PORT SOCKET attribute which contains the local
port of the machine to which the Socket is connected.
|
character |
getSocketOption(character optionName)
Java implementation for the GET-SOCKET-OPTION() SOCKET method.
|
character |
getSocketOption(java.lang.String optionName)
Java implementation for the GET-SOCKET-OPTION() SOCKET method.
|
character |
getSslServerName()
Java implementation for getting the SSL-SERVER-NAME SOCKET attribute
which contains the SSL server name if the connection is made as SSL.
|
private static void |
initialize()
Initialize the mappings of legacy to post-migration server socket mappings.
|
private void |
invokeReadResponseProcedure(int eventId)
Invoke the
connect procedure, as data is being received by
this socket. |
private boolean |
isConnected()
Check if the java socket (from P2J client side) is still connected.
|
private java.util.Map<java.lang.String,java.lang.String> |
parseOptions(character options)
Utility method for parsing the
connect(java.lang.String) parameters. |
logical |
read(memptr buffer,
double pos,
double len)
Java implementation for the READ() SOCKET method, this will read the specified number of
bytes from the available data on the socket, and put it inside the memory buffer
argument at the specified position.
|
logical |
read(memptr buffer,
double pos,
double len,
double mode)
Java implementation for the READ() SOCKET method, this will read the specified number of
bytes from the available data on the socket, and put it inside the memory buffer
argument at the specified position.
|
logical |
read(memptr buffer,
double pos,
double len,
NumberType mode)
Java implementation for the READ() SOCKET method, this will read the specified number of
bytes from the available data on the socket, and put it inside the memory buffer
argument at the specified position.
|
logical |
read(memptr buffer,
double pos,
NumberType len)
Java implementation for the READ() SOCKET method, this will read the specified number of
bytes from the available data on the socket, and put it inside the memory buffer
argument at the specified position.
|
logical |
read(memptr buffer,
double pos,
NumberType len,
double mode)
Java implementation for the READ() SOCKET method, this will read the specified number of
bytes from the available data on the socket, and put it inside the memory buffer
argument at the specified position.
|
logical |
read(memptr buffer,
double pos,
NumberType len,
NumberType mode)
Java implementation for the READ() SOCKET method, this will read the specified number of
bytes from the available data on the socket, and put it inside the memory buffer
argument at the specified position.
|
logical |
read(memptr buffer,
NumberType pos,
double len)
Java implementation for the READ() SOCKET method, this will read the specified number of
bytes from the available data on the socket, and put it inside the memory buffer
argument at the specified position.
|
logical |
read(memptr buffer,
NumberType pos,
double len,
double mode)
Java implementation for the READ() SOCKET method, this will read the specified number of
bytes from the available data on the socket, and put it inside the memory buffer
argument at the specified position.
|
logical |
read(memptr buffer,
NumberType pos,
double len,
NumberType mode)
Java implementation for the READ() SOCKET method, this will read the specified number of
bytes from the available data on the socket, and put it inside the memory buffer
argument at the specified position.
|
logical |
read(memptr buffer,
NumberType pos,
NumberType len)
Java implementation for the READ() SOCKET method, this will read the specified number of
bytes from the available data on the socket, and put it inside the memory buffer
argument at the specified position.
|
logical |
read(memptr buffer,
NumberType pos,
NumberType len,
double mode)
Java implementation for the READ() SOCKET method, this will read the specified number of
bytes from the available data on the socket, and put it inside the memory buffer
argument at the specified position.
|
logical |
read(memptr buffer,
NumberType pos,
NumberType len,
NumberType mode)
Java implementation for the READ() SOCKET method, this will read the specified number of
bytes from the available data on the socket, and put it inside the memory buffer
argument at the specified position.
|
int |
readResponseEvent()
Called by the P2J client side, it will inform the server that a server-event was generated.
|
private static SocketImpl.ServerSocketMapping |
resolve(java.lang.String host,
java.lang.Integer port,
java.lang.String service)
Attempt to map the given legacy server socket details to a post-migration server socket.
|
protected boolean |
resourceDelete()
Delete the resource.
|
logical |
setReadResponseProcedure(character procedureName)
Java implementation for the SET-READ-RESPONSE-PROCEDURE() SOCKET method.
|
logical |
setReadResponseProcedure(character procedureName,
handle procHandle)
Java implementation for the SET-READ-RESPONSE-PROCEDURE() SOCKET method.
|
logical |
setReadResponseProcedure(java.lang.String procedureName)
Java implementation for the SET-READ-RESPONSE-PROCEDURE() SOCKET method.
|
logical |
setReadResponseProcedure(java.lang.String procedureName,
handle procHandle)
Java implementation for the SET-READ-RESPONSE-PROCEDURE() SOCKET method.
|
logical |
setSocketOption(character optionName,
character optionVal)
Java implementation for the SET-SOCKET-OPTION method.
|
logical |
setSocketOption(character optionName,
java.lang.String optionVal)
Java implementation for the SET-SOCKET-OPTION method.
|
logical |
setSocketOption(java.lang.String optionName,
character optionVal)
Java implementation for the SET-SOCKET-OPTION method.
|
logical |
setSocketOption(java.lang.String optionName,
java.lang.String optionVal)
Java implementation for the SET-SOCKET-OPTION method.
|
boolean |
valid()
Reports if this object is valid for use.
|
logical |
write(memptr buffer,
double pos,
double len)
Java implementation for the WRITE() SOCKET method, this will write data from the specified
buffer location (position and number of bytes) to the socket.
|
logical |
write(memptr buffer,
double pos,
NumberType len)
Java implementation for the WRITE() SOCKET method, this will write data from the specified
buffer location (position and number of bytes) to the socket.
|
logical |
write(memptr buffer,
NumberType pos,
double len)
Java implementation for the WRITE() SOCKET method, this will write data from the specified
buffer location (position and number of bytes) to the socket.
|
logical |
write(memptr buffer,
NumberType pos,
NumberType len)
Java implementation for the WRITE() SOCKET method, this will write data from the specified
buffer location (position and number of bytes) to the socket.
|
isSensitive, setSensitive, setSensitive, setSensitive, setSensitive_name, delete, firstResource, firstResource, getHead, getNextSibling, getNextSibling, getPrevSibling, getPrevSibling, getPrivateData, getTail, hasName, hasNameConstraints, hasNameReadOnly, hasNextSibling, hasParent, hasPrevSibling, hasPrivateData, interlink, isChained, lastResource, lastResource, moveInChain, name, name, name, readOnlyError, readOnlyError, resolveChainType, setHead, setNextSibling, setNextSibling, setPrevSibling, setPrevSibling, setPrivateData, setPrivateData, setPrivateData, validateName_instantiatingProcedure, addToPool, doDelete, equals, hashCode, id, id, implicitDeletion, incrementTrigger, instantiatingProcedure, invalidAttribute, processResource, registerResource, resourceType, setInstantiatingProcedure, toString, type, unableToAssignUnknown, unknownclone, finalize, getClass, notify, notifyAll, wait, wait, waitgetNextSibling, getPrevSibling, getPrivateData, setPrivateData, setPrivateDatareadOnlyError, readOnlyError, resourceTypeid, id, unknownisSensitive, setSensitive, setSensitive, setSensitive, setSensitiveallowDeleteprivate static final CentralLogger LOG
private static final java.lang.String TCP_NO_DELAY
private static final java.lang.String SO_LINGER
private static final java.lang.String SO_KEEPALIVE
private static final java.lang.String SO_REUSEADDR
private static final java.lang.String SO_RCVBUF
private static final java.lang.String SO_SNDBUF
private static final java.lang.String SO_RCVTIMEO
private static final InvokeConfig READ_RESPONSE_CALL_SITE
private static final ContextLocal<SocketImpl.WorkArea> local
private static java.util.Set<SocketImpl.ServerSocketMapping> serverSockets
private static boolean initialized
private java.lang.String readResponseProcedure
private WrappedResource readResponseContext
private final java.util.Set<java.lang.Integer> pendingEvents
read(com.goldencode.p2j.util.memptr, double, double) is executed.private long bytesRead
read(com.goldencode.p2j.util.memptr, double, double) call.private long bytesWritten
write(com.goldencode.p2j.util.memptr, double, double) call.private int socketId
private boolean valueParseError
setSocketOption(java.lang.String, java.lang.String) is called.private boolean valid
private java.lang.String targetHost
private java.lang.String targetService
private SocketImpl.WorkArea workArea
local instance.public SocketImpl()
private SocketImpl(int socketId)
LowLevelSocketImpl instance from P2J client side.socketId - The associated socket id on P2J client side.public static long createSocket(int id)
LowLevelSocketImpl instance
from P2J client side.id - The associated socket id on P2J client side.SocketImpl resource.private static SocketImpl.ServerSocketMapping resolve(java.lang.String host, java.lang.Integer port, java.lang.String service)
If no mapping is found, return null.
host - The legacy server socket host.port - The legacy server socket port.service - The legacy server socket service.null if no mapping is possible.private static void initialize()
public boolean valid()
valid in interface WrappedResourcetrue if we are valid (can be used).public character getLocalHost()
getLocalHost in interface Socketpublic integer getLocalPort()
getLocalPort in interface Socketpublic character getRemoteHost()
getRemoteHost in interface Socketpublic integer getRemotePort()
getRemotePort in interface Socketpublic integer getBytesRead()
getBytesRead in interface Socketpublic integer getBytesWritten()
getBytesWritten in interface Socketpublic character getSslServerName()
getSslServerName in interface SslServerAttributepublic logical connect(java.lang.String options)
Returns true if connection succeeded, or false otherwise.
The following options can be specified as valid connect() options:
connect in interface Connectableoptions - The set of parameters for socket connection.true if connection succeeded, or false otherwisepublic logical connect(character options)
Returns true if connection succeeded, or false otherwise.
The following options can be specified as valid connect() options:
connect in interface Connectableoptions - The set of parameters for socket connection.true if connection succeeded, or false otherwisepublic logical connected()
true
if the socket is connected or false otherwise.connected in interface Connectabletrue if the socket is connected or false otherwise.public logical disconnect()
true if succeeded or false otherwise.disconnect in interface Connectabletrue if disconnect succeeded or false otherwise.public character getSocketOption(java.lang.String optionName)
The following options names can be used:
getSocketOption in interface SocketoptionName - The name of the socket option we want to retrieve.public character getSocketOption(character optionName)
The following options names can be used:
getSocketOption in interface SocketoptionName - The name of the socket option we want to retrieve.public integer getBytesAvailable()
getBytesAvailable in interface Socketpublic logical read(memptr buffer, double pos, double len)
Optionally the read mode can be set by the following values:
public logical read(memptr buffer, NumberType pos, double len)
Optionally the read mode can be set by the following values:
public logical read(memptr buffer, double pos, NumberType len)
Optionally the read mode can be set by the following values:
public logical read(memptr buffer, NumberType pos, NumberType len)
Optionally the read mode can be set by the following values:
public logical read(memptr buffer, double pos, double len, double mode)
Optionally the read mode can be set by the following values:
read in interface Socketbuffer - The memory buffer where read() puts the data.pos - The position in the memory buffer where the data is added.len - The number of bytes to read from the socket.mode - The mode to set for the reading operation.true if the read was successful or false otherwise.public logical read(memptr buffer, NumberType pos, double len, double mode)
Optionally the read mode can be set by the following values:
read in interface Socketbuffer - The memory buffer where read() puts the data.pos - The position in the memory buffer where the data is added.len - The number of bytes to read from the socket.mode - The mode to set for the reading operation.true if the read was successful or false otherwise.public logical read(memptr buffer, double pos, NumberType len, double mode)
Optionally the read mode can be set by the following values:
read in interface Socketbuffer - The memory buffer where read() puts the data.pos - The position in the memory buffer where the data is added.len - The number of bytes to read from the socket.mode - The mode to set for the reading operation.true if the read was successful or false otherwise.public logical read(memptr buffer, NumberType pos, NumberType len, double mode)
Optionally the read mode can be set by the following values:
read in interface Socketbuffer - The memory buffer where read() puts the data.pos - The position in the memory buffer where the data is added.len - The number of bytes to read from the socket.mode - The mode to set for the reading operation.true if the read was successful or false otherwise.public logical read(memptr buffer, double pos, double len, NumberType mode)
Optionally the read mode can be set by the following values:
read in interface Socketbuffer - The memory buffer where read() puts the data.pos - The position in the memory buffer where the data is added.len - The number of bytes to read from the socket.mode - The mode to set for the reading operation.true if the read was successful or false otherwise.public logical read(memptr buffer, NumberType pos, double len, NumberType mode)
Optionally the read mode can be set by the following values:
read in interface Socketbuffer - The memory buffer where read() puts the data.pos - The position in the memory buffer where the data is added.len - The number of bytes to read from the socket.mode - The mode to set for the reading operation.true if the read was successful or false otherwise.public logical read(memptr buffer, double pos, NumberType len, NumberType mode)
Optionally the read mode can be set by the following values:
read in interface Socketbuffer - The memory buffer where read() puts the data.pos - The position in the memory buffer where the data is added.len - The number of bytes to read from the socket.mode - The mode to set for the reading operation.true if the read was successful or false otherwise.public logical read(memptr buffer, NumberType pos, NumberType len, NumberType mode)
Optionally the read mode can be set by the following values:
read in interface Socketbuffer - The memory buffer where read() puts the data.pos - The position in the memory buffer where the data is added.len - The number of bytes to read from the socket.mode - The mode to set for the reading operation.true if the read was successful or false otherwise.public logical write(memptr buffer, double pos, double len)
write in interface Socketbuffer - The memory buffer from which the data will be written to the socket.pos - The position in the memory buffer from where the data to be taken starts.len - The number of bytes to take from the memory buffer.true if the write was successful or false otherwise.public logical write(memptr buffer, NumberType pos, double len)
write in interface Socketbuffer - The memory buffer from which the data will be written to the socket.pos - The position in the memory buffer from where the data to be taken starts.len - The number of bytes to take from the memory buffer.true if the write was successful or false otherwise.public logical write(memptr buffer, double pos, NumberType len)
write in interface Socketbuffer - The memory buffer from which the data will be written to the socket.pos - The position in the memory buffer from where the data to be taken starts.len - The number of bytes to take from the memory buffer.true if the write was successful or false otherwise.public logical write(memptr buffer, NumberType pos, NumberType len)
write in interface Socketbuffer - The memory buffer from which the data will be written to the socket.pos - The position in the memory buffer from where the data to be taken starts.len - The number of bytes to take from the memory buffer.true if the write was successful or false otherwise.public logical setReadResponseProcedure(java.lang.String procedureName)
setReadResponseProcedure in interface SocketprocedureName - The name of the procedure to be executed on READ-RESPONSE event.true if the operation was successful or false otherwise.public logical setReadResponseProcedure(character procedureName)
setReadResponseProcedure in interface SocketprocedureName - The name of the procedure to be executed on READ-RESPONSE event.true if the operation was successful or false otherwise.public logical setReadResponseProcedure(java.lang.String procedureName, handle procHandle)
setReadResponseProcedure in interface SocketprocedureName - The name of the procedure to be executed on READ-RESPONSE event.procHandle - The context where the specified procedure belongs. Validation will be performed
when the READ-RESPONSE event is executed.true if the operation was successful or false otherwise.public logical setReadResponseProcedure(character procedureName, handle procHandle)
setReadResponseProcedure in interface SocketprocedureName - The name of the procedure to be executed on READ-RESPONSE event.procHandle - The context where the specified procedure belongs. Validation will be performed
when the READ-RESPONSE event is executed.true if the operation was successful or false otherwise.public logical setSocketOption(java.lang.String optionName, java.lang.String optionVal)
The following options are available:
setSocketOption in interface SocketoptionName - The name of the socket option we want to set.optionVal - The value of the option we want to settrue if the operation was successful or false otherwise.public logical setSocketOption(character optionName, java.lang.String optionVal)
The following options are available:
setSocketOption in interface SocketoptionName - The name of the socket option we want to set.optionVal - The value of the option we want to settrue if the operation was successful or false otherwise.public logical setSocketOption(java.lang.String optionName, character optionVal)
The following options are available:
setSocketOption in interface SocketoptionName - The name of the socket option we want to set.optionVal - The value of the option we want to settrue if the operation was successful or false otherwise.public logical setSocketOption(character optionName, character optionVal)
The following options are available:
setSocketOption in interface SocketoptionName - The name of the socket option we want to set.optionVal - The value of the option we want to settrue if the operation was successful or false otherwise.public int readResponseEvent()
-1 if a event could not be
posted (i.e. the resource is not SENSITIVE).protected boolean resourceDelete()
resourceDelete in class HandleResourcetrue if the resource was deleted.private boolean isConnected()
private void invokeReadResponseProcedure(int eventId)
connect procedure, as data is being received by
this socket. If readResponseProcedure is unknown, this is a no-op.
This will also remove the server event from the list of pendingEvents.
eventId - The ID of the server event being executed.private int asInt(java.lang.String val,
java.lang.String option)
val - The value to be parsed.option - The option name.private boolean asBoolean(java.lang.String val,
java.lang.String option)
TRUE or FALSE values (case
insensitive) for the value to be treated as a boolean.val - The value to be parsed.option - The option name.private java.util.Map<java.lang.String,java.lang.String> parseOptions(character options)
connect(java.lang.String) parameters.options - The string to parse.null if something could not be parsed.