com.perforce.p4java.impl.mapbased.rpc.stream
Class RpcStreamConnection

java.lang.Object
  extended by com.perforce.p4java.impl.mapbased.rpc.connection.RpcConnection
      extended by 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
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 String TRACE_PREFIX
           
 
Fields inherited from class com.perforce.p4java.impl.mapbased.rpc.connection.RpcConnection
clientCharset, fingerprint, flowController, hostIp, hostName, hostPort, NON_UNICODE_SERVER_CHARSET, NON_UNICODE_SERVER_CHARSET_NAME, props, secure, stats, trusted, UNICODE_SERVER_CHARSET, UNICODE_SERVER_CHARSET_NAME, unicodeServer, UNKNOWN_SERVER_HOST, UNKNOWN_SERVER_PORT, usingCompression
 
Constructor Summary
RpcStreamConnection(String serverHost, int serverPort, Properties props, ServerStats stats, Charset charset)
          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, Charset charset, 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, Charset charset, RpcSocketPool pool)
          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, Charset charset, RpcSocketPool pool, 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, Charset charset, Socket socket)
          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, Charset charset, Socket socket, 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, Charset charset, Socket socket, RpcSocketPool pool, 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, Charset charset, 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
 void disconnect(RpcPacketDispatcher dispatcher)
          Disconnect this server.
 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.
 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
getClientCharset, getFingerprint, getFlowController, getHostIp, getHostName, getHostPort, getNormalizedBytes, getNormalizedString, getProps, getStats, isSecure, isTrusted, isUnicodeServer, isUsingCompression, marshalPacketField, marshalPacketValue, setClientCharset, setFingerprint, setFlowController, setHostIp, setHostName, setHostPort, setProps, setSecure, setStats, setTrusted, setUnicodeServer, setUsingCompression
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRACE_PREFIX

public static final 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(String serverHost,
                           int serverPort,
                           Properties props,
                           ServerStats stats,
                           Charset charset)
                    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 -
serverPort -
props -
stats -
charset -
Throws:
ConnectionException

RpcStreamConnection

public RpcStreamConnection(String serverHost,
                           int serverPort,
                           Properties props,
                           ServerStats stats,
                           Charset charset,
                           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 -
serverPort -
props -
stats -
charset -
Throws:
ConnectionException

RpcStreamConnection

public RpcStreamConnection(String serverHost,
                           int serverPort,
                           Properties props,
                           ServerStats stats,
                           Charset charset,
                           Socket socket)
                    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 -
serverPort -
props -
stats -
charset -
socket -
Throws:
ConnectionException

RpcStreamConnection

public RpcStreamConnection(String serverHost,
                           int serverPort,
                           Properties props,
                           ServerStats stats,
                           Charset charset,
                           Socket socket,
                           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 -
serverPort -
props -
stats -
charset -
socket -
secure -
Throws:
ConnectionException

RpcStreamConnection

public RpcStreamConnection(String serverHost,
                           int serverPort,
                           Properties props,
                           ServerStats stats,
                           Charset charset,
                           RpcSocketPool pool)
                    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 -
serverPort -
props -
stats -
charset -
pool -
Throws:
ConnectionException

RpcStreamConnection

public RpcStreamConnection(String serverHost,
                           int serverPort,
                           Properties props,
                           ServerStats stats,
                           Charset charset,
                           RpcSocketPool pool,
                           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 -
serverPort -
props -
stats -
charset -
pool -
secure -
Throws:
ConnectionException

RpcStreamConnection

public RpcStreamConnection(String serverHost,
                           int serverPort,
                           Properties props,
                           ServerStats stats,
                           Charset charset,
                           Socket socket,
                           RpcSocketPool pool,
                           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 -
serverPort -
props -
stats -
charset -
socket -
pool -
secure -
Throws:
ConnectionException

RpcStreamConnection

public RpcStreamConnection(String serverHost,
                           int serverPort,
                           Properties props,
                           ServerStats stats,
                           Charset charset,
                           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 -
serverPort -
props -
stats -
charset -
socket -
pool -
secure -
rsh -
Throws:
ConnectionException
Method Detail

getServerIpPort

public String getServerIpPort()
Description copied from class: RpcConnection
Get the server's IP and port used for the RPC connection.

Specified by:
getServerIpPort in class RpcConnection
Returns:
- possibly null server IP and port
See Also:
RpcConnection.getServerIpPort()

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 class RpcConnection
Throws:
ConnectionException
See Also:
com.perforce.p4java.impl.mapbased.rpc.connection.RpcConnection#disconnect()

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 class RpcConnection
Throws:
ConnectionException
See Also:
RpcConnection.useConnectionCompression()

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 class RpcConnection
Throws:
ConnectionException

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 class RpcConnection
Throws:
ConnectionException

putRpcPacket

public long putRpcPacket(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.

Specified by:
putRpcPacket in class RpcConnection
Throws:
ConnectionException

putRpcPackets

public long putRpcPackets(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 class RpcConnection
Throws:
ConnectionException
See Also:
RpcConnection.putRpcPackets(com.perforce.p4java.impl.mapbased.rpc.packet.RpcPacket[])

getSystemSendBufferSize

public int getSystemSendBufferSize()
Description copied from class: RpcConnection
Return the system (i.e. underlying implementation) send buffer size.

Specified by:
getSystemSendBufferSize in class RpcConnection
See Also:
RpcConnection.getSystemSendBufferSize()

getSystemRecvBufferSize

public int getSystemRecvBufferSize()
Description copied from class: RpcConnection
Return the system (i.e. underlying implementation) receive buffer size.

Specified by:
getSystemRecvBufferSize in class RpcConnection
See Also:
RpcConnection.getSystemRecvBufferSize()


Copyright © 2015 Perforce Software. All Rights Reserved.