Skip to content
Permalink
Browse files
chore: support run on macos (#103)
  • Loading branch information
tzssangglass committed Dec 31, 2021
1 parent 0d15720 commit 3da21b98fc435dc239af6f1d8a9ceebdd6f1686f
Showing 3 changed files with 33 additions and 24 deletions.
@@ -22,8 +22,12 @@
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.epoll.Epoll;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.epoll.EpollServerDomainSocketChannel;
import io.netty.channel.kqueue.KQueue;
import io.netty.channel.kqueue.KQueueEventLoopGroup;
import io.netty.channel.kqueue.KQueueServerDomainSocketChannel;
import io.netty.channel.unix.DomainSocketAddress;
import io.netty.channel.unix.DomainSocketChannel;
import io.netty.handler.logging.LoggingHandler;
@@ -84,10 +88,22 @@ public HTTPReqCallHandler createA6HttpHandler(Cache<Long, A6Conf> cache) {
}

public void start(String path) throws Exception {
EventLoopGroup group = new EpollEventLoopGroup();
EventLoopGroup group;
ServerBootstrap bootstrap = new ServerBootstrap();
if (KQueue.isAvailable()) {
group = new KQueueEventLoopGroup();
bootstrap.group(group).channel(KQueueServerDomainSocketChannel.class);
} else if (Epoll.isAvailable()) {
group = new EpollEventLoopGroup();
bootstrap.group(group).channel(EpollServerDomainSocketChannel.class);
} else {
String errMsg = "java runner is only support epoll or kqueue";
logger.warn(errMsg);
throw new RuntimeException(errMsg);
}

try {
ServerBootstrap bootstrap = new ServerBootstrap();
initServerBootstrap(group, bootstrap);
initServerBootstrap(bootstrap);
ChannelFuture future = bootstrap.bind(new DomainSocketAddress(path)).sync();
Runtime.getRuntime().exec("chmod 777 " + socketFile);
logger.warn("java runner is listening on the socket file: {}", socketFile);
@@ -98,21 +114,19 @@ public void start(String path) throws Exception {
}
}

private ServerBootstrap initServerBootstrap(EventLoopGroup group, ServerBootstrap bootstrap) {
return bootstrap.group(group)
.channel(EpollServerDomainSocketChannel.class)
.childHandler(new ChannelInitializer<DomainSocketChannel>() {
@Override
protected void initChannel(DomainSocketChannel channel) {
channel.pipeline().addFirst("logger", new LoggingHandler())
.addAfter("logger", "payloadEncoder", new PayloadEncoder())
.addAfter("payloadEncoder", "delayedDecoder", new BinaryProtocolDecoder())
.addLast("payloadDecoder", new PayloadDecoder())
.addAfter("payloadDecoder", "prepareConfHandler", createConfigReqHandler(cache, beanProvider))
.addAfter("prepareConfHandler", "hTTPReqCallHandler", createA6HttpHandler(cache));

}
});
private void initServerBootstrap(ServerBootstrap bootstrap) {
bootstrap.childHandler(new ChannelInitializer<DomainSocketChannel>() {
@Override
protected void initChannel(DomainSocketChannel channel) {
channel.pipeline().addFirst("logger", new LoggingHandler())
.addAfter("logger", "payloadEncoder", new PayloadEncoder())
.addAfter("payloadEncoder", "delayedDecoder", new BinaryProtocolDecoder())
.addLast("payloadDecoder", new PayloadDecoder())
.addAfter("payloadDecoder", "prepareConfHandler", createConfigReqHandler(cache, beanProvider))
.addAfter("prepareConfHandler", "hTTPReqCallHandler", createA6HttpHandler(cache));

}
});
}

@Override
@@ -16,6 +16,4 @@
#
#

#spring.rsocket.server.port=7000

#logging.level.root=DEBUG
# logging.level.root=DEBUG
@@ -51,9 +51,6 @@ public void filter(HttpRequest request, HttpResponse response) {
PluginFilterChain next = new PluginFilterChain(this,
this.index + 1);
filter.filter(request, response, next);
} else {
//TODO log error
return;
}
}
}

0 comments on commit 3da21b9

Please sign in to comment.