Class BaseConnection
- java.lang.Object
-
- org.eclipse.jgit.transport.BaseConnection
-
- All Implemented Interfaces:
AutoCloseable
,Connection
- Direct Known Subclasses:
BasePackFetchConnection
,BasePackPushConnection
public abstract class BaseConnection extends Object implements Connection
Base helper class for implementing operations connections.- See Also:
BasePackConnection
,BaseFetchConnection
-
-
Constructor Summary
Constructors Constructor Description BaseConnection()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
available(Map<String,Ref> all)
Denote the list of refs available on the remote repository.abstract void
close()
String
getMessages()
Get the additional messages, if any, returned by the remote process.protected Writer
getMessageWriter()
Get the writer that buffers messages from the remote side.String
getPeerUserAgent()
User agent advertised by the remote server.Ref
getRef(String name)
Get a single advertised ref by name.Collection<Ref>
getRefs()
Get the complete list of refs advertised as available for fetching or pushing.Map<String,Ref>
getRefsMap()
Get the complete map of refs advertised as available for fetching or pushing.protected void
markStartedOperation()
Helper method for ensuring one-operation per connection.protected void
setMessageWriter(Writer writer)
Set the writer that buffers messages from the remote side.protected void
setPeerUserAgent(String agent)
Remember the remote peer's agent.
-
-
-
Method Detail
-
getRefsMap
public Map<String,Ref> getRefsMap()
Get the complete map of refs advertised as available for fetching or pushing.- Specified by:
getRefsMap
in interfaceConnection
- Returns:
- available/advertised refs: map of refname to ref. Never null. Not modifiable. The collection can be empty if the remote side has no refs (it is an empty/newly created repository).
-
getRefs
public final Collection<Ref> getRefs()
Get the complete list of refs advertised as available for fetching or pushing.The returned refs may appear in any order. If the caller needs these to be sorted, they should be copied into a new array or List and then sorted by the caller as necessary.
- Specified by:
getRefs
in interfaceConnection
- Returns:
- available/advertised refs. Never null. Not modifiable. The collection can be empty if the remote side has no refs (it is an empty/newly created repository).
-
getRef
public final Ref getRef(String name)
Get a single advertised ref by name.The name supplied should be valid ref name. To get a peeled value for a ref (aka
refs/tags/v1.0^{}
) use the base name (without the^{}
suffix) and look at the peeled object id.- Specified by:
getRef
in interfaceConnection
- Parameters:
name
- name of the ref to obtain.- Returns:
- the requested ref; null if the remote did not advertise this ref.
-
getMessages
public String getMessages()
Get the additional messages, if any, returned by the remote process.These messages are most likely informational or error messages, sent by the remote peer, to help the end-user correct any problems that may have prevented the operation from completing successfully. Application UIs should try to show these in an appropriate context.
The message buffer is available after
Connection.close()
has been called. Prior to closing the connection, the message buffer may be empty.- Specified by:
getMessages
in interfaceConnection
- Returns:
- the messages returned by the remote, most likely terminated by a newline (LF) character. The empty string is returned if the remote produced no additional messages.
-
getPeerUserAgent
public String getPeerUserAgent()
User agent advertised by the remote server. User agent advertised by the remote server.- Specified by:
getPeerUserAgent
in interfaceConnection
- Returns:
- agent (version of Git) running on the remote server. Null if the server does not advertise this version.
- Since:
- 4.0
-
setPeerUserAgent
protected void setPeerUserAgent(String agent)
Remember the remote peer's agent.- Parameters:
agent
- remote peer agent string.- Since:
- 4.0
-
close
public abstract 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 interfaceAutoCloseable
- Specified by:
close
in interfaceConnection
-
available
protected void available(Map<String,Ref> all)
Denote the list of refs available on the remote repository.Implementors should invoke this method once they have obtained the refs that are available from the remote repository.
- Parameters:
all
- the complete list of refs the remote has to offer. This map will be wrapped in an unmodifiable way to protect it, but it does not get copied.
-
markStartedOperation
protected void markStartedOperation() throws TransportException
Helper method for ensuring one-operation per connection. Check whether operation was already marked as started, and mark it as started.- Throws:
TransportException
- if operation was already marked as started.
-
getMessageWriter
protected Writer getMessageWriter()
Get the writer that buffers messages from the remote side.- Returns:
- writer to store messages from the remote.
-
setMessageWriter
protected void setMessageWriter(Writer writer)
Set the writer that buffers messages from the remote side.- Parameters:
writer
- the writer that messages will be delivered to. The writer'stoString()
method should be overridden to return the complete contents.
-
-