Skip to content

Commit 16cb0f1

Browse files
committed
Add OSGiService Support
1 parent 167d981 commit 16cb0f1

4 files changed

Lines changed: 94 additions & 0 deletions

File tree

docker-java-transport-httpclient5/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@
3434
</exclusions>
3535
</dependency>
3636

37+
<dependency>
38+
<groupId>org.osgi</groupId>
39+
<artifactId>org.osgi.service.component.annotations</artifactId>
40+
<version>1.5.0</version>
41+
<scope>provided</scope>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>org.osgi</groupId>
46+
<artifactId>org.osgi.service.metatype.annotations</artifactId>
47+
<version>1.4.1</version>
48+
<scope>provided</scope>
49+
</dependency>
50+
3751
<dependency>
3852
<groupId>net.java.dev.jna</groupId>
3953
<artifactId>jna</artifactId>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.github.dockerjava.httpclient5;
2+
3+
import java.io.IOException;
4+
import java.net.URI;
5+
import java.time.Duration;
6+
7+
import org.osgi.service.component.annotations.Activate;
8+
import org.osgi.service.component.annotations.Component;
9+
import org.osgi.service.component.annotations.Deactivate;
10+
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
11+
12+
import com.github.dockerjava.transport.DockerHttpClient;
13+
import com.github.dockerjava.transport.DockerHttpClientType;
14+
15+
@DockerHttpClientType(value = OSGiApacheDockerHttpClientService.APACHE_HTTPCLIENT_5, transports = { DockerHttpClientType.TRANSPORT_STDIN_ATTACHMENT,
16+
DockerHttpClientType.TRANSPORT_WINDOWS_NPIPE, DockerHttpClientType.TRANSPORT_UNIX_SOCKETS })
17+
@Component(service = DockerHttpClient.class, immediate = true, name = OSGiApacheDockerHttpClientService.PID)
18+
public class OSGiApacheDockerHttpClientService extends ApacheDockerHttpClientImpl {
19+
20+
static final String APACHE_HTTPCLIENT_5 = "apache.httpclient.5";
21+
public static final String PID = "com.github.dockerjava.httpclient5.basic";
22+
23+
@ObjectClassDefinition(pid = PID)
24+
@interface Config {
25+
String dockerHost() default "localhost";
26+
27+
int maxConnections() default Integer.MAX_VALUE;;
28+
29+
long connectionTimeoutNanos() default -1;
30+
31+
long responseTimeoutNanos() default -1;
32+
}
33+
34+
@Activate
35+
protected OSGiApacheDockerHttpClientService(Config config) {
36+
super(toDockerHost(config.dockerHost()), null, config.maxConnections(),
37+
toDurationNanos(config.connectionTimeoutNanos()), toDurationNanos(config.responseTimeoutNanos()));
38+
}
39+
40+
private static Duration toDurationNanos(long value) {
41+
if (value < 0) {
42+
return null;
43+
}
44+
return Duration.ofNanos(value);
45+
}
46+
47+
private static URI toDockerHost(String config) {
48+
return URI.create(config);
49+
}
50+
51+
@Deactivate
52+
public void deactivate() throws IOException {
53+
close();
54+
}
55+
56+
}

docker-java-transport/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
<version>5.8.0</version>
3737
<scope>provided</scope>
3838
</dependency>
39+
40+
<dependency>
41+
<groupId>org.osgi</groupId>
42+
<artifactId>org.osgi.service.component.annotations</artifactId>
43+
<version>1.5.0</version>
44+
<scope>provided</scope>
45+
</dependency>
3946
</dependencies>
4047

4148
<build>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.github.dockerjava.transport;
2+
3+
import org.osgi.service.component.annotations.ComponentPropertyType;
4+
5+
@ComponentPropertyType
6+
public @interface DockerHttpClientType {
7+
8+
public static final String TRANSPORT_UNIX_SOCKETS = "unix.sockets";
9+
10+
public static final String TRANSPORT_WINDOWS_NPIPE = "windows.npipe";
11+
12+
public static final String TRANSPORT_STDIN_ATTACHMENT = "stdin.attacgment";
13+
14+
String value();
15+
16+
String[] transports();
17+
}

0 commit comments

Comments
 (0)