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 Details

    • TRACE_PREFIX

      public static final String TRACE_PREFIX
      See Also:
    • 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:
    • 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:
  • 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 - serverHost
      serverPort - serverPort
      props - props
      stats - stats
      p4Charset - p4Charset
      secure - 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 - serverHost
      serverPort - serverPort
      props - props
      stats - stats
      p4Charset - p4Charset
      socket - socket
      pool - pool
      secure - secure
      rsh - rsh
      Throws:
      ConnectionException - on error
  • Method Details

    • 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
    • getServerHostNamePort

      public String getServerHostNamePort()
      Specified by:
      getServerHostNamePort in class RpcConnection
    • getClientIpPort

      public String getClientIpPort()
      Description copied from class: RpcConnection
      Get the client's IP and port used for the RPC connection.
      Specified by:
      getClientIpPort in class RpcConnection
      Returns:
      - possibly null client IP and port
      See Also:
    • 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
      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 class RpcConnection
      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 class RpcConnection
      Parameters:
      fieldRule - fieldRule
      filterCallback - 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 class RpcConnection
      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 class RpcConnection
      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 class RpcConnection
      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
       it SENDBUF_REALLOC_INCR times each buffer increase.
       
      Specified by:
      putRpcPacket in class RpcConnection
      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 class RpcConnection
      Throws:
      ConnectionException - on error