Package org.mandas.docker.client.builder
Class BaseDockerClientBuilder<B extends BaseDockerClientBuilder<B>>
- java.lang.Object
-
- org.mandas.docker.client.builder.BaseDockerClientBuilder<B>
-
- Type Parameters:
B- the type of the builder
- All Implemented Interfaces:
DockerClientBuilder<B>
- Direct Known Subclasses:
JerseyDockerClientBuilder,ResteasyDockerClientBuilder
public abstract class BaseDockerClientBuilder<B extends BaseDockerClientBuilder<B>> extends Object implements DockerClientBuilder<B>
A convenience base class for implementingDockerClientBuilders- Author:
- Dimitris Mandalidis
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.mandas.docker.client.builder.DockerClientBuilder
DockerClientBuilder.EntityProcessing
-
-
Field Summary
Fields Modifier and Type Field Description protected StringapiVersionprotected javax.ws.rs.client.Clientclientprotected intconnectionPoolSizeprotected longconnectTimeoutMillisprotected longDEFAULT_CONNECT_TIMEOUT_MILLISprotected intDEFAULT_CONNECTION_POOL_SIZEprotected longDEFAULT_READ_TIMEOUT_MILLISprotected DockerCertificatesStoredockerCertificatesStoreprotected DockerClientBuilder.EntityProcessingentityProcessingprotected StringERROR_MESSAGEprotected Map<String,Object>headersprotected javax.ws.rs.client.ClientnoTimeoutClientprotected StringNPIPE_SCHEMEprotected longreadTimeoutMillisprotected RegistryAuthSupplierregistryAuthSupplierprotected StringUNIX_SCHEMEprotected URIuriprotected booleanuseProxy
-
Constructor Summary
Constructors Constructor Description BaseDockerClientBuilder()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description BapiVersion(String apiVersion)Set the Docker API version that will be used in the HTTP requests to Docker daemon.DefaultDockerClientbuild()BconnectionPoolSize(int connectionPoolSize)Set the size of the connection pool for connections to Docker.BconnectTimeoutMillis(long connectTimeoutMillis)Set the timeout in milliseconds until a connection to Docker is established.protected abstract javax.ws.rs.client.ClientcreateClient()protected abstract javax.ws.rs.client.ClientcreateNoTimeoutClient()BdockerCertificates(DockerCertificatesStore dockerCertificatesStore)Provide certificates to secure the connection to Docker.BentityProcessing(DockerClientBuilder.EntityProcessing entityProcessing)Allows setting transfer encoding.BfromEnv()Sets or overwritesuri()anddockerCertificates(DockerCertificatesStore)according to the values present in DOCKER_HOST and DOCKER_CERT_PATH environment variables.protected org.apache.http.conn.HttpClientConnectionManagergetConnectionManager(URI uri, org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory> schemeRegistry, int connectionPoolSize)protected org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory>getSchemeRegistry(URI uri, DockerCertificatesStore certificateStore)Bheader(String name, Object value)Adds additional headers to be sent in all requests to the Docker Remote API.protected ProxyConfigurationproxyFromEnv()BreadTimeoutMillis(long readTimeoutMillis)Set the SO_TIMEOUT in milliseconds.BregistryAuthSupplier(RegistryAuthSupplier registryAuthSupplier)URIuri()Buri(String uri)Set the URI for connections to Docker.Buri(URI uri)BuseProxy(boolean useProxy)Allows connecting to Docker Daemon using HTTP proxy.
-
-
-
Field Detail
-
UNIX_SCHEME
protected String UNIX_SCHEME
-
NPIPE_SCHEME
protected String NPIPE_SCHEME
-
DEFAULT_CONNECT_TIMEOUT_MILLIS
protected long DEFAULT_CONNECT_TIMEOUT_MILLIS
-
DEFAULT_READ_TIMEOUT_MILLIS
protected long DEFAULT_READ_TIMEOUT_MILLIS
-
DEFAULT_CONNECTION_POOL_SIZE
protected int DEFAULT_CONNECTION_POOL_SIZE
-
ERROR_MESSAGE
protected String ERROR_MESSAGE
-
uri
protected URI uri
-
apiVersion
protected String apiVersion
-
connectTimeoutMillis
protected long connectTimeoutMillis
-
readTimeoutMillis
protected long readTimeoutMillis
-
connectionPoolSize
protected int connectionPoolSize
-
dockerCertificatesStore
protected DockerCertificatesStore dockerCertificatesStore
-
useProxy
protected boolean useProxy
-
registryAuthSupplier
protected RegistryAuthSupplier registryAuthSupplier
-
client
protected javax.ws.rs.client.Client client
-
noTimeoutClient
protected javax.ws.rs.client.Client noTimeoutClient
-
entityProcessing
protected DockerClientBuilder.EntityProcessing entityProcessing
-
-
Method Detail
-
fromEnv
public B fromEnv() throws DockerCertificateException
Sets or overwritesuri()anddockerCertificates(DockerCertificatesStore)according to the values present in DOCKER_HOST and DOCKER_CERT_PATH environment variables.- Specified by:
fromEnvin interfaceDockerClientBuilder<B extends BaseDockerClientBuilder<B>>- Returns:
- Modifies a builder that can be used to further customize and then build the client.
- Throws:
DockerCertificateException- if we could not build a DockerCertificates object
-
uri
public B uri(URI uri)
- Specified by:
uriin interfaceDockerClientBuilder<B extends BaseDockerClientBuilder<B>>
-
uri
public B uri(String uri)
Set the URI for connections to Docker.- Specified by:
uriin interfaceDockerClientBuilder<B extends BaseDockerClientBuilder<B>>- Parameters:
uri- URI String for connections to Docker- Returns:
- Builder
-
apiVersion
public B apiVersion(String apiVersion)
Set the Docker API version that will be used in the HTTP requests to Docker daemon.- Specified by:
apiVersionin interfaceDockerClientBuilder<B extends BaseDockerClientBuilder<B>>- Parameters:
apiVersion- String for Docker API version- Returns:
- Builder
-
connectTimeoutMillis
public B connectTimeoutMillis(long connectTimeoutMillis)
Description copied from interface:DockerClientBuilderSet the timeout in milliseconds until a connection to Docker is established. A timeout value of zero is interpreted as an infinite timeout.- Specified by:
connectTimeoutMillisin interfaceDockerClientBuilder<B extends BaseDockerClientBuilder<B>>- Parameters:
connectTimeoutMillis- connection timeout to Docker daemon in milliseconds- Returns:
- Builder
-
readTimeoutMillis
public B readTimeoutMillis(long readTimeoutMillis)
Description copied from interface:DockerClientBuilderSet the SO_TIMEOUT in milliseconds. This is the maximum period of inactivity between receiving two consecutive data packets from Docker.- Specified by:
readTimeoutMillisin interfaceDockerClientBuilder<B extends BaseDockerClientBuilder<B>>- Parameters:
readTimeoutMillis- read timeout to Docker daemon in milliseconds- Returns:
- Builder
-
dockerCertificates
public B dockerCertificates(DockerCertificatesStore dockerCertificatesStore)
Description copied from interface:DockerClientBuilderProvide certificates to secure the connection to Docker.- Specified by:
dockerCertificatesin interfaceDockerClientBuilder<B extends BaseDockerClientBuilder<B>>- Parameters:
dockerCertificatesStore- DockerCertificatesStore object- Returns:
- Builder
-
connectionPoolSize
public B connectionPoolSize(int connectionPoolSize)
Description copied from interface:DockerClientBuilderSet the size of the connection pool for connections to Docker. Note that due to a known issue, DefaultDockerClient maintains two separate connection pools, each of which is capped at this size. Therefore, the maximum number of concurrent connections to Docker may be up to 2 * connectionPoolSize.- Specified by:
connectionPoolSizein interfaceDockerClientBuilder<B extends BaseDockerClientBuilder<B>>- Parameters:
connectionPoolSize- connection pool size- Returns:
- Builder
-
useProxy
public B useProxy(boolean useProxy)
Description copied from interface:DockerClientBuilderAllows connecting to Docker Daemon using HTTP proxy.- Specified by:
useProxyin interfaceDockerClientBuilder<B extends BaseDockerClientBuilder<B>>- Parameters:
useProxy- tells if Docker Client has to connect to docker daemon using HTTP Proxy- Returns:
- Builder
-
registryAuthSupplier
public B registryAuthSupplier(RegistryAuthSupplier registryAuthSupplier)
- Specified by:
registryAuthSupplierin interfaceDockerClientBuilder<B extends BaseDockerClientBuilder<B>>
-
header
public B header(String name, Object value)
Description copied from interface:DockerClientBuilderAdds additional headers to be sent in all requests to the Docker Remote API.- Specified by:
headerin interfaceDockerClientBuilder<B extends BaseDockerClientBuilder<B>>- Parameters:
name- the header namevalue- the header value- Returns:
- this
-
uri
public URI uri()
- Specified by:
uriin interfaceDockerClientBuilder<B extends BaseDockerClientBuilder<B>>- Returns:
- the URI of the Docker engine
-
entityProcessing
public B entityProcessing(DockerClientBuilder.EntityProcessing entityProcessing)
Description copied from interface:DockerClientBuilderAllows setting transfer encoding. CHUNKED does not send the content-length header while BUFFERED does.By default ApacheConnectorProvider uses CHUNKED mode. Some Docker API end-points seems to fail when no content-length is specified but a body is sent.
- Specified by:
entityProcessingin interfaceDockerClientBuilder<B extends BaseDockerClientBuilder<B>>- Parameters:
entityProcessing- is the requested entity processing to use when calling docker daemon (tcp protocol).- Returns:
- Builder
-
createClient
protected abstract javax.ws.rs.client.Client createClient()
-
createNoTimeoutClient
protected abstract javax.ws.rs.client.Client createNoTimeoutClient()
-
proxyFromEnv
protected ProxyConfiguration proxyFromEnv()
-
build
public DefaultDockerClient build()
- Specified by:
buildin interfaceDockerClientBuilder<B extends BaseDockerClientBuilder<B>>
-
getConnectionManager
protected org.apache.http.conn.HttpClientConnectionManager getConnectionManager(URI uri, org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory> schemeRegistry, int connectionPoolSize)
-
getSchemeRegistry
protected org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory> getSchemeRegistry(URI uri, DockerCertificatesStore certificateStore)
-
-