public abstract class RpcConnection
extends java.lang.Object
Note that charset conversion should never be necessary on connections to non-Unicode servers, as any bytes in the incoming stream that are marked as "text" should be interpreted as ASCII (seven or eight bits). Unfortunately, in Java land, there's no such thing as non-interpreted bytes -- bytes are converted to strings according to *some* charset or other (and Java uses UTF-16 as the native encoding for strings under the covers). This explains why we always do a conversion below -- if we didn't use an explicit "from" charset, the current JVM's charset would be used, which would quite probably be wrong. Similar observations apply for conversions in the other direction -- all conversions must be with an explicit charset in case the JVM's charset isn't the one we actually need.
Note that, in general, we "know" that the Perforce server on the other end of this connection is -- or should be -- a Unicode server by the fact that the incoming clientCharset is not null. This probably isn't infallible, but it's supposed to be true, so we use it as a proxy for IServer.supportsUnicode().
See http://computer.perforce.com/newwiki/index.php?title=P4Java_and_Charset_Support for a detailed discussion of P4Java and server charset issues...
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
fingerprint |
protected RpcConnectionFlowControl |
flowController |
protected java.lang.String |
hostIp |
protected java.lang.String |
hostName |
protected int |
hostPort |
static java.nio.charset.Charset |
NON_UNICODE_SERVER_CHARSET
Charset assumed when the server is non in Unicode mode.
|
static java.lang.String |
NON_UNICODE_SERVER_CHARSET_NAME
The name of the assumed non-Unicode server charset.
|
protected java.lang.String |
ourIp |
protected int |
ourPort |
protected P4Charset |
p4Charset |
protected java.util.Properties |
props |
protected boolean |
secure |
protected boolean |
selfSigned |
protected java.security.cert.Certificate[] |
serverCerts |
protected ServerStats |
stats |
static java.lang.String |
TRACE_PREFIX |
protected boolean |
trusted |
static java.nio.charset.Charset |
UNICODE_SERVER_CHARSET
The charset used internally by a Perforce Unicode-enabled server.
|
static java.lang.String |
UNICODE_SERVER_CHARSET_NAME
The name of the assumed Unicode server internal charset.
|
protected boolean |
unicodeServer |
protected static java.lang.String |
UNKNOWN_SERVER_HOST |
protected static int |
UNKNOWN_SERVER_PORT |
protected boolean |
usingCompression |
Constructor and Description |
---|
RpcConnection(java.lang.String serverHost,
int serverPort,
java.util.Properties props,
ServerStats stats,
P4Charset p4Charset)
Create a Perforce RPC connection to a given host and port number pair.
|
RpcConnection(java.lang.String serverHost,
int serverPort,
java.util.Properties props,
ServerStats stats,
P4Charset p4Charset,
boolean secure)
Create a Perforce RPC connection to a given host and port number pair.
|
Modifier and Type | Method and Description |
---|---|
RpcPacketDispatcher.RpcPacketDispatcherResult |
clientConfirm(java.lang.String confirm,
java.util.Map<java.lang.String,java.lang.Object> resultsMap) |
abstract void |
disconnect(RpcPacketDispatcher dispatcher)
Disconnect this server.
|
java.nio.charset.Charset |
getClientCharset() |
abstract java.lang.String |
getClientIpPort()
Get the client's IP and port used for the RPC connection.
|
java.lang.String |
getDigest(RpcPerforceFileType fileType,
java.io.File file) |
java.lang.String |
getDigest(RpcPerforceFileType fileType,
java.io.File file,
RpcPerforceDigestType digest) |
int |
getFilesysRestrictedSymlinks() |
int |
getFilesysUtf8bom() |
java.lang.String |
getFingerprint() |
RpcConnectionFlowControl |
getFlowController() |
java.lang.String |
getHostIp() |
java.lang.String |
getHostName() |
int |
getHostPort() |
protected byte[] |
getNormalizedBytes(java.lang.String str)
Encode the passed-in string properly for the server.
|
protected java.lang.String |
getNormalizedString(byte[] bytes)
Decode the passed-in bytes from the server into a suitable string.
|
P4Charset |
getP4Charset() |
java.util.Properties |
getProps() |
abstract RpcPacket |
getRpcPacket()
Get the next RPC packet from the receive queue.
|
abstract RpcPacket |
getRpcPacket(RpcPacketFieldRule fieldRule,
IFilterCallback filterCallback)
Get the next RPC packet from the receive queue with an optional rule to
handle the RPC packet fields.
|
java.security.cert.X509Certificate[] |
getServerCerts() |
abstract java.lang.String |
getServerHostNamePort() |
abstract java.lang.String |
getServerIpPort()
Get the server's IP and port used for the RPC connection.
|
ServerStats |
getStats() |
abstract int |
getSystemRecvBufferSize()
Return the system (i.e.
|
abstract int |
getSystemSendBufferSize()
Return the system (i.e.
|
boolean |
isSecure() |
boolean |
isSelfSigned() |
boolean |
isTrusted() |
boolean |
isUnicodeServer() |
boolean |
isUsingCompression() |
byte[] |
marshalPacketField(java.lang.String key,
java.lang.Object value)
Marshal a packet field into a key value byte array pair.
|
protected byte[] |
marshalPacketValue(java.lang.Object value)
Marshal a packet field value onto a byte array and return that array.
|
abstract long |
putRpcPacket(RpcPacket rpcPacket)
Put a Perforce RPC packet onto the output stream.
|
abstract long |
putRpcPackets(RpcPacket[] rpcPackets)
Put an array of RPC packets.
|
void |
setClientCharset(P4Charset p4Charset) |
void |
setFingerprint(java.lang.String fingerprint) |
void |
setFlowController(RpcConnectionFlowControl flowController) |
void |
setHostIp(java.lang.String hostIp) |
void |
setHostName(java.lang.String hostName) |
void |
setHostPort(int hostPort) |
void |
setProps(java.util.Properties props) |
void |
setSecure(boolean secure) |
void |
setStats(ServerStats stats) |
void |
setTrusted(boolean trusted) |
void |
setUnicodeServer(boolean unicodeServer) |
void |
setUsingCompression(boolean usingCompression) |
void |
useConnectionCompression()
If called, will set this connection to use (GZIP) compression for all
traffic on this connection from this point on.
|
public static final java.lang.String TRACE_PREFIX
public static final java.nio.charset.Charset UNICODE_SERVER_CHARSET
Do not change this unless you want all hell to break loose.
public static final java.lang.String UNICODE_SERVER_CHARSET_NAME
public static final java.nio.charset.Charset NON_UNICODE_SERVER_CHARSET
public static final java.lang.String NON_UNICODE_SERVER_CHARSET_NAME
protected static final java.lang.String UNKNOWN_SERVER_HOST
protected static final int UNKNOWN_SERVER_PORT
protected java.util.Properties props
protected RpcConnectionFlowControl flowController
protected ServerStats stats
protected P4Charset p4Charset
protected java.lang.String hostIp
protected java.lang.String ourIp
protected java.lang.String hostName
protected int hostPort
protected int ourPort
protected boolean usingCompression
protected boolean unicodeServer
protected boolean secure
protected java.lang.String fingerprint
protected boolean trusted
protected java.security.cert.Certificate[] serverCerts
protected boolean selfSigned
public RpcConnection(java.lang.String serverHost, int serverPort, java.util.Properties props, ServerStats stats, P4Charset p4Charset) throws ConnectionException
This method will also implicitly connect to the server. Note that new connections are never using connection compression -- this has to come as an explicit command from the server after the connection has been established.
serverHost
- non-null Perforce server host name or IP address.serverPort
- Perforce server host port number.props
- if not null, use the Properties for any connection- or
implementation-specific values (such as buffer sizes, etc.).stats
- if not null, attempt to fill in these connection stats
appropriately.p4Charset
- if non-null, sets the connection's idea of what the current
client charset is. If null, CharsetDefs.DEFAULT is used.ConnectionException
- if any user-reportable error occurred under the covers.public RpcConnection(@Nonnull java.lang.String serverHost, int serverPort, java.util.Properties props, ServerStats stats, P4Charset p4Charset, boolean secure) throws ConnectionException
This method will also implicitly connect to the server. Note that new connections are never using connection compression -- this has to come as an explicit command from the server after the connection has been established.
serverHost
- non-null Perforce server host name or IP address.serverPort
- Perforce server host port number.props
- if not null, use the Properties for any connection- or
implementation-specific values (such as buffer sizes, etc.).stats
- if not null, attempt to fill in these connection stats
appropriately.p4Charset
- if non-null, sets the connection's idea of what the current
client charset is. If null, CharsetDefs.DEFAULT is used.secure
- indicate whether the connection is secure (SSL) or not.ConnectionException
- if any user-reportable error occurred under the covers.public java.security.cert.X509Certificate[] getServerCerts()
public boolean isSelfSigned()
public abstract java.lang.String getServerIpPort()
public abstract java.lang.String getServerHostNamePort()
public abstract java.lang.String getClientIpPort()
public abstract void disconnect(RpcPacketDispatcher dispatcher) throws ConnectionException
dispatcher
- dispatcherConnectionException
- on errorpublic abstract long putRpcPacket(RpcPacket rpcPacket) throws ConnectionException
Returns the number of bytes actually sent to the Perforce server, which may not bear any relationship at all to the size of the passed-in packet.
rpcPacket
- rpcPacketConnectionException
- on errorpublic abstract long putRpcPackets(RpcPacket[] rpcPackets) throws ConnectionException
rpcPackets
- rpcPacketsConnectionException
- on errorpublic abstract RpcPacket getRpcPacket() throws ConnectionException
Will wait until either a timeout occurs (if the stream's been set up appropriately), the underlying stream returns EOF or error, or we get a complete packet.
ConnectionException
- on errorpublic abstract RpcPacket getRpcPacket(RpcPacketFieldRule fieldRule, IFilterCallback filterCallback) throws ConnectionException
fieldRule
- fieldRulefilterCallback
- filterCallbackConnectionException
- on errorpublic abstract int getSystemSendBufferSize()
public abstract int getSystemRecvBufferSize()
public byte[] marshalPacketField(java.lang.String key, java.lang.Object value)
key
- keyvalue
- valueprotected byte[] marshalPacketValue(java.lang.Object value)
For strings and similar types (e.g. StringBuilder, StringBuffer), we may need to do a translation to the server charset (normally UTF-8) before enbyteifying the underlying value. Other field types are sent as-is, and are assumed to have been encoded properly upstream (and are almost always just file contents).
Note: if the value object passed in is a ByteBuffer, it must have been flipped ready for use; this method will (of course) have predictable side effects on that ByteBuffer.
value
- valuepublic void useConnectionCompression() throws ConnectionException
ConnectionException
- on errorprotected byte[] getNormalizedBytes(java.lang.String str)
FIXME: use proper encoding / decoding with error handling -- HR.
str
- strprotected java.lang.String getNormalizedString(byte[] bytes)
FIXME: use proper encoding / decoding with error handling -- HR.
bytes
- bytespublic boolean isUsingCompression()
public RpcConnectionFlowControl getFlowController()
public void setFlowController(RpcConnectionFlowControl flowController)
public java.util.Properties getProps()
public void setProps(java.util.Properties props)
public java.nio.charset.Charset getClientCharset()
public P4Charset getP4Charset()
public void setClientCharset(P4Charset p4Charset)
public ServerStats getStats()
public void setStats(ServerStats stats)
public java.lang.String getHostIp()
public void setHostIp(java.lang.String hostIp)
public java.lang.String getHostName()
public void setHostName(java.lang.String hostName)
public int getHostPort()
public void setHostPort(int hostPort)
public void setUsingCompression(boolean usingCompression)
public boolean isUnicodeServer()
public void setUnicodeServer(boolean unicodeServer)
public int getFilesysUtf8bom()
public int getFilesysRestrictedSymlinks()
public boolean isSecure()
public void setSecure(boolean secure)
public java.lang.String getFingerprint()
public void setFingerprint(java.lang.String fingerprint)
public boolean isTrusted()
public void setTrusted(boolean trusted)
public RpcPacketDispatcher.RpcPacketDispatcherResult clientConfirm(java.lang.String confirm, java.util.Map<java.lang.String,java.lang.Object> resultsMap) throws ConnectionException
ConnectionException
public java.lang.String getDigest(RpcPerforceFileType fileType, java.io.File file)
public java.lang.String getDigest(RpcPerforceFileType fileType, java.io.File file, RpcPerforceDigestType digest)