|
@@ -7,8 +7,7 @@ import io.netty.channel.epoll.EpollEventLoopGroup;
|
|
|
import io.netty.channel.unix.DomainSocketAddress;
|
|
import io.netty.channel.unix.DomainSocketAddress;
|
|
|
import io.netty.channel.unix.UnixChannel;
|
|
import io.netty.channel.unix.UnixChannel;
|
|
|
import io.netty.handler.codec.http.*;
|
|
import io.netty.handler.codec.http.*;
|
|
|
-import org.slf4j.Logger;
|
|
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -17,8 +16,8 @@ import java.util.concurrent.TimeUnit;
|
|
|
* @author reghao
|
|
* @author reghao
|
|
|
* @date 2020-01-14 17:14:08
|
|
* @date 2020-01-14 17:14:08
|
|
|
*/
|
|
*/
|
|
|
|
|
+@Slf4j
|
|
|
public class UnixSocketClient {
|
|
public class UnixSocketClient {
|
|
|
- private static final Logger log = LoggerFactory.getLogger(UnixSocketClient.class);
|
|
|
|
|
// TODO 在配置中指定
|
|
// TODO 在配置中指定
|
|
|
private final String DEFAULT_UNIX_ENDPOINT = "/run/docker.sock";
|
|
private final String DEFAULT_UNIX_ENDPOINT = "/run/docker.sock";
|
|
|
private EventLoopGroup group;
|
|
private EventLoopGroup group;
|
|
@@ -54,6 +53,8 @@ public class UnixSocketClient {
|
|
|
if (future.isSuccess()) {
|
|
if (future.isSuccess()) {
|
|
|
log.info("已连接到 Unix Socket");
|
|
log.info("已连接到 Unix Socket");
|
|
|
channel = channelFuture.channel();
|
|
channel = channelFuture.channel();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.error("Unix Socket 连接失败, 检查 " + DEFAULT_UNIX_ENDPOINT + " 是否存在...");
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -72,9 +73,11 @@ public class UnixSocketClient {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public FullHttpResponse syncSend(FullHttpRequest request) throws InterruptedException, IOException {
|
|
public FullHttpResponse syncSend(FullHttpRequest request) throws InterruptedException, IOException {
|
|
|
|
|
+ /*
|
|
|
|
|
+ 错误用法,忽略了异步的本质
|
|
|
if (channel == null) {
|
|
if (channel == null) {
|
|
|
throw new IOException("Unix Socket 连接失败, 检查 " + DEFAULT_UNIX_ENDPOINT + " 是否存在...");
|
|
throw new IOException("Unix Socket 连接失败, 检查 " + DEFAULT_UNIX_ENDPOINT + " 是否存在...");
|
|
|
- }
|
|
|
|
|
|
|
+ }*/
|
|
|
|
|
|
|
|
ChannelPromise promise = clientHandler.sendRequest(request);
|
|
ChannelPromise promise = clientHandler.sendRequest(request);
|
|
|
if (promise == null) {
|
|
if (promise == null) {
|