Class BasePackConnection
- java.lang.Object
-
- org.eclipse.jgit.transport.BaseConnection
-
- org.eclipse.jgit.transport.BasePackConnection
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,Connection
- Direct Known Subclasses:
BasePackFetchConnection
,BasePackPushConnection
abstract class BasePackConnection extends BaseConnection
Base helper class for pack-based operations implementations. Provides partial implementation of pack-protocol - refs advertising and capabilities support, and some other helper methods.- See Also:
BasePackFetchConnection
,BasePackPushConnection
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Set<ObjectId>
additionalHaves
Extra objects the remote has, but which aren't offered as refs.protected java.io.InputStream
in
Input stream reading from the remote.protected Repository
local
The repository this transport fetches into, or pushes out of.private InterruptTimer
myTimer
Timer to managetimeoutIn
andtimeoutOut
.protected java.io.OutputStream
out
Output stream sending to the remote.protected boolean
outNeedsEnd
SendPacketLineOut.end()
before closingout
?protected PacketLineIn
pckIn
Packet line decoder aroundin
.protected PacketLineOut
pckOut
Packet line encoder aroundout
.private java.util.Set<java.lang.String>
remoteCapablities
Capability tokens advertised by the remote side.protected boolean
statelessRPC
True if this is a stateless RPC connection.protected TimeoutInputStream
timeoutIn
Low-level input stream, if a timeout was configured.protected TimeoutOutputStream
timeoutOut
Low-level output stream, if a timeout was configured.protected Transport
transport
A transport connected touri
.protected URIish
uri
Remote repository location.
-
Constructor Summary
Constructors Constructor Description BasePackConnection(PackTransport packTransport)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addUserAgentCapability(java.lang.StringBuilder b)
Add user agent capabilityvoid
close()
private PackProtocolException
duplicateAdvertisement(java.lang.String name)
protected void
endOut()
Tell the peer we are disconnecting, if it cares to know.java.lang.String
getPeerUserAgent()
User agent advertised by the remote server.protected void
init(java.io.InputStream myIn, java.io.OutputStream myOut)
Configure this connection with the directional pipes.private PackProtocolException
invalidRefAdvertisementLine(java.lang.String line)
protected boolean
isCapableOf(java.lang.String option)
Whether this option is supportedprotected TransportException
noRepository()
Create an exception to indicate problems finding a remote repository.protected void
readAdvertisedRefs()
Reads the advertised references through the initialized stream.private void
readAdvertisedRefsImpl()
protected boolean
wantCapability(java.lang.StringBuilder b, java.lang.String option)
Request capability-
Methods inherited from class org.eclipse.jgit.transport.BaseConnection
available, getMessages, getMessageWriter, getRef, getRefs, getRefsMap, markStartedOperation, setMessageWriter, setPeerUserAgent
-
-
-
-
Field Detail
-
local
protected final Repository local
The repository this transport fetches into, or pushes out of.
-
uri
protected final URIish uri
Remote repository location.
-
timeoutIn
protected TimeoutInputStream timeoutIn
Low-level input stream, if a timeout was configured.
-
timeoutOut
protected TimeoutOutputStream timeoutOut
Low-level output stream, if a timeout was configured.
-
myTimer
private InterruptTimer myTimer
Timer to managetimeoutIn
andtimeoutOut
.
-
in
protected java.io.InputStream in
Input stream reading from the remote.
-
out
protected java.io.OutputStream out
Output stream sending to the remote.
-
pckIn
protected PacketLineIn pckIn
Packet line decoder aroundin
.
-
pckOut
protected PacketLineOut pckOut
Packet line encoder aroundout
.
-
outNeedsEnd
protected boolean outNeedsEnd
SendPacketLineOut.end()
before closingout
?
-
statelessRPC
protected boolean statelessRPC
True if this is a stateless RPC connection.
-
remoteCapablities
private final java.util.Set<java.lang.String> remoteCapablities
Capability tokens advertised by the remote side.
-
additionalHaves
protected final java.util.Set<ObjectId> additionalHaves
Extra objects the remote has, but which aren't offered as refs.
-
-
Constructor Detail
-
BasePackConnection
BasePackConnection(PackTransport packTransport)
-
-
Method Detail
-
init
protected final void init(java.io.InputStream myIn, java.io.OutputStream myOut)
Configure this connection with the directional pipes.- Parameters:
myIn
- input stream to receive data from the peer. Caller must ensure the input is buffered, otherwise read performance may suffer.myOut
- output stream to transmit data to the peer. Caller must ensure the output is buffered, otherwise write performance may suffer.
-
readAdvertisedRefs
protected void readAdvertisedRefs() throws TransportException
Reads the advertised references through the initialized stream.Subclass implementations may call this method only after setting up the input and output streams with
init(InputStream, OutputStream)
.If any errors occur, this connection is automatically closed by invoking
close()
and the exception is wrapped (if necessary) and thrown as aTransportException
.- Throws:
TransportException
- the reference list could not be scanned.
-
readAdvertisedRefsImpl
private void readAdvertisedRefsImpl() throws java.io.IOException
- Throws:
java.io.IOException
-
noRepository
protected TransportException noRepository()
Create an exception to indicate problems finding a remote repository. The caller is expected to throw the returned exception. Subclasses may override this method to provide better diagnostics.- Returns:
- a TransportException saying a repository cannot be found and possibly why.
-
isCapableOf
protected boolean isCapableOf(java.lang.String option)
Whether this option is supported- Parameters:
option
- option string- Returns:
- whether this option is supported
-
wantCapability
protected boolean wantCapability(java.lang.StringBuilder b, java.lang.String option)
Request capability- Parameters:
b
- bufferoption
- option we want- Returns:
true
if the requested option is supported
-
addUserAgentCapability
protected void addUserAgentCapability(java.lang.StringBuilder b)
Add user agent capability- Parameters:
b
- aStringBuilder
object.
-
getPeerUserAgent
public java.lang.String getPeerUserAgent()
User agent advertised by the remote server. User agent advertised by the remote server.- Specified by:
getPeerUserAgent
in interfaceConnection
- Overrides:
getPeerUserAgent
in classBaseConnection
- Returns:
- agent (version of Git) running on the remote server. Null if the server does not advertise this version.
-
duplicateAdvertisement
private PackProtocolException duplicateAdvertisement(java.lang.String name)
-
invalidRefAdvertisementLine
private PackProtocolException invalidRefAdvertisementLine(java.lang.String line)
-
close
public void close()
Close any resources used by this connection.
If the remote repository is contacted by a network socket this method must close that network socket, disconnecting the two peers. If the remote repository is actually local (same system) this method must close any open file handles used to read the "remote" repository.
If additional messages were produced by the remote peer, these should still be retained in the connection instance for
Connection.getMessages()
.AutoClosable.close()
declares that it throwsException
. Implementers shouldn't throw checked exceptions. This override narrows the signature to prevent them from doing so.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceConnection
- Specified by:
close
in classBaseConnection
-
endOut
protected void endOut()
Tell the peer we are disconnecting, if it cares to know.
-
-