Package org.eclipse.jgit.transport

## Class BaseConnection

- java.lang.Object
- - org.eclipse.jgit.transport.BaseConnection

All Implemented Interfaces:
  `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
`BaseConnection()`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`protected void` `available​(Map<String,​Ref> all)` Denote the list of refs available on the remote repository.
`abstract void` `close()` Close any resources used by this connection.
`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.
`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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### BaseConnection

    public BaseConnection()

### Method Detail

#### getRefsMap

    public Map<String,​Ref> getRefsMap()

Description copied from interface: `Connection`
Get the complete map of refs advertised as available for fetching or pushing.

Specified by:
  `getRefsMap` in interface `Connection`
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()

Description copied from interface: `Connection`
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 interface `Connection`
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)

Description copied from interface: `Connection`
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 interface `Connection`
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()

Description copied from interface: `Connection`
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 interface `Connection`
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.

#### close

    public abstract void close()

Description copied from interface: `Connection`
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()`.

Specified by:
  `close` in interface `Connection`

#### 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's `toString()` method should be overridden to return the complete contents.