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 intINITIAL_SENDBUF_SIZENumber of bytes we allocate for initial byte arrays for sending RPC packets.protected static intSENDBUF_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.static java.lang.StringTRACE_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 voiddisconnect(RpcPacketDispatcher dispatcher)Disconnect this server.java.lang.StringgetClientIpPort()Get the client's IP and port used for the RPC connection.RpcPacketgetRpcPacket()Get a Perforce RPC packet from the underlying stream.RpcPacketgetRpcPacket(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.StringgetServerHostNamePort()java.lang.StringgetServerIpPort()Get the server's IP and port used for the RPC connection.intgetSystemRecvBufferSize()Return the system (i.e.intgetSystemSendBufferSize()Return 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.voiduseConnectionCompression()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, 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 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 ConnectionExceptionConstruct 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 ConnectionExceptionConstruct 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:RpcConnectionGet the server's IP and port used for the RPC connection.- Specified by:
getServerIpPortin classRpcConnection- Returns:
- - possibly null server IP and port
-
getServerHostNamePort
public java.lang.String getServerHostNamePort()
- Specified by:
getServerHostNamePortin classRpcConnection
-
getClientIpPort
public java.lang.String 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:
RpcConnection.getClientIpPort()
-
disconnect
public void disconnect(RpcPacketDispatcher dispatcher) throws ConnectionException
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
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:
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
public long putRpcPackets(@Nonnull RpcPacket[] packets) throws ConnectionExceptionDescription 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
public long putRpcPacket(@Nonnull RpcPacket packet) throws ConnectionExceptionPut 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
public void useConnectionCompression() throws ConnectionExceptionDescription 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
-
-