Skip to content

Instantly share code, notes, and snippets.

View zeroFruit's full-sized avatar
🎯
Focusing

JooHyung Kim zeroFruit

🎯
Focusing
View GitHub Profile
@zeroFruit
zeroFruit / LocalChannel.java
Created July 23, 2022 00:38
Channel concept & implementation— el Project (2)
public class LocalChannel extends AbstractChannel {
...
protected void doConnect(LocalServerChannel server, ChannelPromise result) {
this.server = server;
server.connectFrom(this);
state = State.CONNECTED;
remoteAddress = this.server.localAddress();
result.setSuccess(null);
}
...
@zeroFruit
zeroFruit / LocalServerChannel.java
Created July 23, 2022 00:37
Channel concept & implementation— el Project (2)
public class LocalServerChannel extends AbstractServerChannel {
...
private class LocalServerInternal extends AbstractInternal {
@Override
public void doBind(SocketAddress localAddress) {
ObjectUtil.checkNotNull(localAddress, "localAddress");
LocalServerChannel.this.localAddress =
LocalChannelRegistry.register(LocalServerChannel.this, localAddress);
state = State.BOUND;
}
@zeroFruit
zeroFruit / LocalChannelTransportTests.java
Created July 23, 2022 00:36
Channel concept & implementation— el Project (2)
public class LocalChannelTransportTests {
private static final String SERVER_ADDRESS = "server:addr";
private DefaultChannelEventLoopGroup group1, group2;
@BeforeEach
public void setUp() {
group1 = new DefaultChannelEventLoopGroup(1);
group2 = new DefaultChannelEventLoopGroup(1);
}
@zeroFruit
zeroFruit / AbstractTransport.java
Created July 23, 2022 00:35
Channel concept & implementation— el Project (2)
public abstract class AbstractTransport<T extends AbstractTransport<T, C>, C extends Channel> {
public ChannelPromise bind(SocketAddress localAddress) {
doBind(...);
}
private void doBind(
final ChannelPromise registered,
final Channel channel,
final SocketAddress localAddress,
@zeroFruit
zeroFruit / AbstractChannelHandlerContext.java
Created July 23, 2022 00:34
Channel concept & implementation— el Project (2)
public abstract class AbstractChannelHandlerContext implements ChannelHandlerContext {
...
@Override
public ChannelPromise bind(SocketAddress localAddress, ChannelPromise promise) {
ObjectUtil.checkNotNull(localAddress, "localAddress");
if (isNotValidPromise(promise)) {
// canceled
return promise;
}
@zeroFruit
zeroFruit / HeadContextHandler.java
Created July 23, 2022 00:33
Channel concept & implementation— el Project (2)
private static final class HeadContextHandler
implements ChannelOutboundHandler, ChannelInboundHandler {
@Override
public void bind(
ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) {
ctx.channel().internal().bind(localAddress, promise);
}
@Override
@zeroFruit
zeroFruit / AbstractChannelHandlerContext.java
Created July 23, 2022 00:31
Channel concept & implementation— el Project (2)
public abstract class AbstractChannelHandlerContext implements ChannelHandlerContext {
static void invokeExceptionCaught(
final AbstractChannelHandlerContext next, final Throwable cause) {
EventLoop eventLoop = next.eventLoop();
if (eventLoop.inEventLoop()) {
next.invokeExceptionCaught(cause);
} else {
eventLoop.execute(() -> next.invokeExceptionCaught(cause));
}
@zeroFruit
zeroFruit / AbstractChannelHandlerContext.java
Created July 23, 2022 00:30
Channel concept & implementation— el Project (2)
public abstract class AbstractChannelHandlerContext implements ChannelHandlerContext {
AbstractChannelHandlerContext(
String name,
ChannelPipeline pipeline,
EventLoop eventLoop,
Class<? extends ChannelHandler> handlerClass) {
this.name = ObjectUtil.checkNotNull(name, "name");
this.pipeline = pipeline;
this.executionFlag = ChannelHandlerFlag.flag(handlerClass);
this.eventLoop = eventLoop;
@zeroFruit
zeroFruit / ChannelOutboundHandler.java
Created July 23, 2022 00:29
Channel concept & implementation— el Project (2)
public interface ChannelOutboundHandler extends ChannelHandler {
/**
* Called once a bind operation is made.
*/
void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise)
throws Exception;
/**
* Called once a connect operation is made.
*/
@zeroFruit
zeroFruit / ChannelInboundHandler.java
Created July 23, 2022 00:28
Channel concept & implementation— el Project (2)
/**
* {@link ChannelHandler} which adds callbacks for state changes. This allows the user to hook in to
* state changes easily.
*/
public interface ChannelInboundHandler extends ChannelHandler {
/**
* Called when {@link Channel} of the {@link ChannelHandlerContext} was registered with its {@link
* ChannelEventLoop}
*/
void channelRegistered(ChannelHandlerContext ctx) throws Exception;