org.zodiac.sdk.simplenetty.handler.DefaultChannelPipeline Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zodiac-sdk-nio Show documentation
Show all versions of zodiac-sdk-nio Show documentation
Zodiac SDK NIO2(New Non-Blocking IO)
package org.zodiac.sdk.simplenetty.handler;
import java.util.LinkedList;
import java.util.ListIterator;
import org.zodiac.sdk.simplenetty.channel.Channel;
public class DefaultChannelPipeline implements ChannelPipeline {
LinkedList handlers;
ChannelHandlerContext context;
public DefaultChannelPipeline() {
handlers = new LinkedList<>();
}
public void setContext(ChannelHandlerContext context) {
this.context = context;
}
@Override
public Channel channel() {
return null;
}
@Override
public ChannelHandlerContext context() {
return context;
}
@Override
public ChannelHandler head() {
return handlers.getFirst();
}
@Override
public ChannelHandler tail() {
return handlers.getLast();
}
@Override
public void addBefore(ChannelHandler reference, ChannelHandler handler) {
ListIterator list = handlers.listIterator();
while (list.hasNext()) {
ChannelHandler next = list.next();
if (next.equals(reference)) {
handlers.add(list.previousIndex(), handler);
break;
}
}
}
@Override
public void addAfter(ChannelHandler reference, ChannelHandler handler) {
ListIterator list = handlers.listIterator();
while (list.hasNext()) {
ChannelHandler next = list.next();
if (next.equals(reference)) {
handlers.add(list.nextIndex(), handler);
break;
}
}
}
@Override
public void addLast(ChannelHandler handler) {
handlers.addLast(handler);
}
@Override
public void addFirst(ChannelHandler handler) {
handlers.addFirst(handler);
}
}