Class RpcStreamConnection
- java.lang.Object
-
- com.perforce.p4java.impl.mapbased.rpc.connection.RpcConnection
-
- com.perforce.p4java.impl.mapbased.rpc.stream.RpcStreamConnection
-
public class RpcStreamConnection extends RpcConnection
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
Fields Modifier and Type Field Description protected static int
INITIAL_SENDBUF_SIZE
Number of bytes we allocate for initial byte arrays for sending RPC packets.protected static int
SENDBUF_REALLOC_INCR
When 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 java.lang.String
TRACE_PREFIX
-
Fields 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, secure, selfSigned, serverCerts, stats, trusted, UNICODE_SERVER_CHARSET, UNICODE_SERVER_CHARSET_NAME, unicodeServer, UNKNOWN_SERVER_HOST, UNKNOWN_SERVER_PORT, usingCompression
-
-
Constructor Summary
Constructors Constructor Description RpcStreamConnection(java.lang.String serverHost, int serverPort, java.util.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(java.lang.String serverHost, int serverPort, java.util.Properties props, ServerStats stats, P4Charset p4Charset, java.net.Socket socket, RpcSocketPool pool, boolean secure, java.lang.String rsh)
Construct a new Perforce RPC connection to the named Perforce server using java.io socket streams at the lowest level.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
disconnect(RpcPacketDispatcher dispatcher)
Disconnect this server.java.lang.String
getClientIpPort()
Get the client's IP and port used for the RPC connection.RpcPacket
getRpcPacket()
Get a Perforce RPC packet from the underlying stream.RpcPacket
getRpcPacket(RpcPacketFieldRule fieldRule, IFilterCallback filterCallback)
Get a Perforce RPC packet from the underlying stream with an optional rule to handle the RPC packet fields.java.lang.String
getServerHostNamePort()
java.lang.String
getServerIpPort()
Get the server's IP and port used for the RPC connection.int
getSystemRecvBufferSize()
Return the system (i.e.int
getSystemSendBufferSize()
Return the system (i.e.long
putRpcPacket(RpcPacket packet)
Put a Perforce RPC packet onto the output stream.long
putRpcPackets(RpcPacket[] packets)
Put an array of RPC packets.void
useConnectionCompression()
If 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, 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 Detail
-
TRACE_PREFIX
public static final java.lang.String TRACE_PREFIX
- See Also:
- Constant Field Values
-
INITIAL_SENDBUF_SIZE
protected static final int INITIAL_SENDBUF_SIZE
Number 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:
- Constant Field Values
-
SENDBUF_REALLOC_INCR
protected static final int SENDBUF_REALLOC_INCR
When 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:
- Constant Field Values
-
-
Constructor Detail
-
RpcStreamConnection
public RpcStreamConnection(java.lang.String serverHost, int serverPort, java.util.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(java.lang.String serverHost, int serverPort, java.util.Properties props, ServerStats stats, P4Charset p4Charset, java.net.Socket socket, RpcSocketPool pool, boolean secure, java.lang.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 Detail
-
getServerIpPort
public java.lang.String getServerIpPort()
Description copied from class:RpcConnection
Get the server's IP and port used for the RPC connection.- Specified by:
getServerIpPort
in classRpcConnection
- Returns:
- - possibly null server IP and port
-
getServerHostNamePort
public java.lang.String getServerHostNamePort()
- Specified by:
getServerHostNamePort
in classRpcConnection
-
getClientIpPort
public java.lang.String getClientIpPort()
Description copied from class:RpcConnection
Get the client's IP and port used for the RPC connection.- Specified by:
getClientIpPort
in classRpcConnection
- Returns:
- - possibly null client IP and port
- See Also:
RpcConnection.getClientIpPort()
-
disconnect
public void disconnect(RpcPacketDispatcher dispatcher) throws ConnectionException
Description copied from class:RpcConnection
Disconnect 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:
disconnect
in classRpcConnection
- Parameters:
dispatcher
- dispatcher- Throws:
ConnectionException
- on error
-
getRpcPacket
public RpcPacket getRpcPacket() throws ConnectionException
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:
getRpcPacket
in 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:
getRpcPacket
in classRpcConnection
- Parameters:
fieldRule
- fieldRulefilterCallback
- filterCallback- Returns:
- RpcPacket
- Throws:
ConnectionException
- on error
-
getSystemRecvBufferSize
public int getSystemRecvBufferSize()
Description copied from class:RpcConnection
Return the system (i.e. underlying implementation) receive buffer size.- Specified by:
getSystemRecvBufferSize
in classRpcConnection
- Returns:
- size
-
getSystemSendBufferSize
public int getSystemSendBufferSize()
Description copied from class:RpcConnection
Return the system (i.e. underlying implementation) send buffer size.- Specified by:
getSystemSendBufferSize
in classRpcConnection
- Returns:
- size
-
putRpcPackets
public long putRpcPackets(@Nonnull RpcPacket[] packets) throws ConnectionException
Description copied from class:RpcConnection
Put an array of RPC packets. A convenience method wrapping putRpcPacket(packet) in the obvious way.- Specified by:
putRpcPackets
in classRpcConnection
- Parameters:
packets
- rpcPackets- Returns:
- number of bytes
- Throws:
ConnectionException
- on error
-
putRpcPacket
public long putRpcPacket(@Nonnull RpcPacket packet) throws ConnectionException
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_SIZE
bytes; we grow the buffer by increasing itSENDBUF_REALLOC_INCR
times each buffer increase.- Specified by:
putRpcPacket
in classRpcConnection
- Parameters:
packet
- rpcPacket- Returns:
- number of bytes
- Throws:
ConnectionException
- on error
-
useConnectionCompression
public void useConnectionCompression() throws ConnectionException
Description copied from class:RpcConnection
If 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:
useConnectionCompression
in classRpcConnection
- Throws:
ConnectionException
- on error
-
-