001package org.xbib.elasticsearch.http.netty;
002
003import org.elasticsearch.common.xcontent.XContentBuilder;
004import org.jboss.netty.channel.Channel;
005import org.xbib.elasticsearch.websocket.InteractiveChannel;
006import org.xbib.elasticsearch.websocket.InteractiveResponse;
007
008import java.io.IOException;
009
010/**
011 * Netty implementation for an interactive channel
012 */
013public class NettyInteractiveChannel implements InteractiveChannel {
014
015    private final Channel channel;
016
017    public NettyInteractiveChannel(Channel channel) {
018        this.channel = channel;
019    }
020
021    @Override
022    public Channel getChannel() {
023        return channel;
024    }
025
026    @Override
027    public void sendResponse(InteractiveResponse response) throws IOException {
028        channel.write(response.response());
029    }
030
031    @Override
032    public void sendResponse(String type, Throwable t) throws IOException {
033        channel.write(new NettyInteractiveResponse(type, t).response());
034    }
035
036    @Override
037    public void sendResponse(String type, XContentBuilder builder) throws IOException {
038        channel.write(new NettyInteractiveResponse(type, builder).response());
039    }
040}