Class RpcStreamConnection
java.lang.Object
com.perforce.p4java.impl.mapbased.rpc.connection.RpcConnection
com.perforce.p4java.impl.mapbased.rpc.stream.RpcStreamConnection
Socket stream I/O based implementation of the RpcConnection class.
The implementation here uses a small stack of input and output streams based on socket streams at the lowest level, with (at least) an optional connection compression stream on top of that layer, and with charset conversion where necessary.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intNumber of bytes we allocate for initial byte arrays for sending RPC packets.protected static final intWhen we run out of send buffer space in putPacket, we allocate another, larger, buffer; this constant determines how much larger than the existing buffer the new one should be, or, alternatively, how much bigger than the incoming field length the new buffer should be.static final StringFields inherited from class com.perforce.p4java.impl.mapbased.rpc.connection.RpcConnection
fingerprint, flowController, hostIp, hostName, hostPort, NON_UNICODE_SERVER_CHARSET, NON_UNICODE_SERVER_CHARSET_NAME, ourIp, ourPort, p4Charset, props, rawTextValues, secure, selfSigned, serverCerts, stats, trusted, UNICODE_SERVER_CHARSET, UNICODE_SERVER_CHARSET_NAME, unicodeServer, UNKNOWN_SERVER_HOST, UNKNOWN_SERVER_PORT, usingCompression -
Constructor Summary
ConstructorsConstructorDescriptionRpcStreamConnection(String serverHost, int serverPort, Properties props, ServerStats stats, P4Charset p4Charset, boolean secure) Construct a new Perforce RPC connection to the named Perforce server using java.io socket streams at the lowest level.RpcStreamConnection(String serverHost, int serverPort, Properties props, ServerStats stats, P4Charset p4Charset, Socket socket, RpcSocketPool pool, boolean secure, String rsh) Construct a new Perforce RPC connection to the named Perforce server using java.io socket streams at the lowest level. -
Method Summary
Modifier and TypeMethodDescriptionvoiddisconnect(RpcPacketDispatcher dispatcher) Disconnect this server.Get the client's IP and port used for the RPC connection.Get a Perforce RPC packet from the underlying stream.getRpcPacket(RpcPacketFieldRule fieldRule, IFilterCallback filterCallback) Get a Perforce RPC packet from the underlying stream with an optional rule to handle the RPC packet fields.Get the server's IP and port used for the RPC connection.intReturn the system (i.e.intReturn the system (i.e.longputRpcPacket(RpcPacket packet) Put a Perforce RPC packet onto the output stream.longputRpcPackets(RpcPacket[] packets) Put an array of RPC packets.voidIf called, will set this connection to use (GZIP) compression for all traffic on this connection from this point on.Methods inherited from class com.perforce.p4java.impl.mapbased.rpc.connection.RpcConnection
clientConfirm, getClientCharset, getDigest, getDigest, getDigestAndSizeOfFile, getFilesysRestrictedSymlinks, getFilesysUtf8bom, getFingerprint, getFlowController, getHostIp, getHostName, getHostPort, getNormalizedBytes, getNormalizedString, getP4Charset, getProps, getServerCerts, getStats, isSecure, isSelfSigned, isTrusted, isUnicodeServer, isUsingCompression, marshalPacketField, marshalPacketValue, setClientCharset, setFingerprint, setFlowController, setHostIp, setHostName, setHostPort, setProps, setSecure, setStats, setTrusted, setUnicodeServer, setUsingCompression
-
Field Details
-
TRACE_PREFIX
- See Also:
-
INITIAL_SENDBUF_SIZE
protected static final int INITIAL_SENDBUF_SIZENumber of bytes we allocate for initial byte arrays for sending RPC packets. In general we don't know how big the final buffer is, so this figure is a bit of a guessed compromise between over-allocation and frequent resizing.- See Also:
-
SENDBUF_REALLOC_INCR
protected static final int SENDBUF_REALLOC_INCRWhen we run out of send buffer space in putPacket, we allocate another, larger, buffer; this constant determines how much larger than the existing buffer the new one should be, or, alternatively, how much bigger than the incoming field length the new buffer should be. Should probably be more tunable...- See Also:
-
-
Constructor Details
-
RpcStreamConnection
public RpcStreamConnection(String serverHost, int serverPort, Properties props, ServerStats stats, P4Charset p4Charset, boolean secure) throws ConnectionException Construct a new Perforce RPC connection to the named Perforce server using java.io socket streams at the lowest level. This constructor sets up the default non-compressed stack; in general this means just a couple of simple socket streams.- Parameters:
serverHost- serverHostserverPort- serverPortprops- propsstats- statsp4Charset- p4Charsetsecure- secure- Throws:
ConnectionException- on error
-
RpcStreamConnection
public RpcStreamConnection(String serverHost, int serverPort, Properties props, ServerStats stats, P4Charset p4Charset, Socket socket, RpcSocketPool pool, boolean secure, String rsh) throws ConnectionException Construct a new Perforce RPC connection to the named Perforce server using java.io socket streams at the lowest level. This constructor sets up the default non-compressed stack; in general this means just a couple of simple socket streams.- Parameters:
serverHost- serverHostserverPort- serverPortprops- propsstats- statsp4Charset- p4Charsetsocket- socketpool- poolsecure- securersh- rsh- Throws:
ConnectionException- on error
-
-
Method Details
-
getServerIpPort
Description copied from class:RpcConnectionGet the server's IP and port used for the RPC connection.- Specified by:
getServerIpPortin classRpcConnection- Returns:
- - possibly null server IP and port
-
getServerHostNamePort
- Specified by:
getServerHostNamePortin classRpcConnection
-
getClientIpPort
Description copied from class:RpcConnectionGet the client's IP and port used for the RPC connection.- Specified by:
getClientIpPortin classRpcConnection- Returns:
- - possibly null client IP and port
- See Also:
-
disconnect
Description copied from class:RpcConnectionDisconnect this server. Assumes the connection is quiescent -- no further sends or receives will be possible after this call, and only the output stream is flushed (no attempt is made to look at anything still on the wire coming in to the socket).- Specified by:
disconnectin classRpcConnection- Parameters:
dispatcher- dispatcher- Throws:
ConnectionException- on error
-
getRpcPacket
Get a Perforce RPC packet from the underlying stream. If we're talking to a Unicode-enabled Perforce server, we attempt to translate the incoming bytes to the relevant client-side charsets where appropriate based on packet field type, etc.- Specified by:
getRpcPacketin classRpcConnection- Returns:
- RpcPacket
- Throws:
ConnectionException- on error
-
getRpcPacket
public RpcPacket getRpcPacket(RpcPacketFieldRule fieldRule, IFilterCallback filterCallback) throws ConnectionException Get a Perforce RPC packet from the underlying stream with an optional rule to handle the RPC packet fields.- Specified by:
getRpcPacketin classRpcConnection- Parameters:
fieldRule- fieldRulefilterCallback- filterCallback- Returns:
- RpcPacket
- Throws:
ConnectionException- on error
-
getSystemRecvBufferSize
public int getSystemRecvBufferSize()Description copied from class:RpcConnectionReturn the system (i.e. underlying implementation) receive buffer size.- Specified by:
getSystemRecvBufferSizein classRpcConnection- Returns:
- size
-
getSystemSendBufferSize
public int getSystemSendBufferSize()Description copied from class:RpcConnectionReturn the system (i.e. underlying implementation) send buffer size.- Specified by:
getSystemSendBufferSizein classRpcConnection- Returns:
- size
-
putRpcPackets
Description copied from class:RpcConnectionPut an array of RPC packets. A convenience method wrapping putRpcPacket(packet) in the obvious way.- Specified by:
putRpcPacketsin classRpcConnection- Parameters:
packets- rpcPackets- Returns:
- number of bytes
- Throws:
ConnectionException- on error
-
putRpcPacket
Put a Perforce RPC packet onto the output stream. In some cases this may require considerable processing and things like charset translation here and downstream, but it's normally fairly straightforward.Note that in general, we don't know how large the packet's output byte buffer is going to have to be until we've finished the packet contents marshaling, so we implement buffer resizing when needed. Our initial guess is
INITIAL_SENDBUF_SIZEbytes; we grow the buffer by increasing itSENDBUF_REALLOC_INCRtimes each buffer increase.- Specified by:
putRpcPacketin classRpcConnection- Parameters:
packet- rpcPacket- Returns:
- number of bytes
- Throws:
ConnectionException- on error
-
useConnectionCompression
Description copied from class:RpcConnectionIf called, will set this connection to use (GZIP) compression for all traffic on this connection from this point on. Can not be turned back off again. See the main P4 help documentation (and C++ API code) for "client compression" (etc.) for details.- Overrides:
useConnectionCompressionin classRpcConnection- Throws:
ConnectionException- on error
-