All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.sdk.simplenetty.handler.DefaultChannelPipeline Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
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);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy