I could reproduce this issue by instantiating a couchbase server inside a handler. If you instantiate the connection outside it works. Here is the code to reproduce it:
when you run it in the IDE and telnet to localhost 8080 it will die and throw the exception:
package com.couchbase.nettyexample;
import com.couchbase.client.CouchbaseClient;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.Arrays;
import java.util.concurrent.Executors;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
/**
* Hello world!
*
*/
public class App {
private final int port = 8080;
private CouchbaseClient client;
public void run() throws IOException {
ServerBootstrap bootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()
)
);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(new EchoServerHandler());
}
});
bootstrap.bind(new InetSocketAddress(port));
}
public static void main(String[] args) throws IOException {
new App().run();
}
class EchoServerHandler extends SimpleChannelUpstreamHandler {
private CouchbaseClient client;
public EchoServerHandler() throws IOException {
this.client = new CouchbaseClient(
Arrays.asList(URI.create("
http://localhost:8091/pools")),
"default",
""
);
this.client.set("received", 0, "foo");
}
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
System.out.println("Received Message");
System.out.println(client.get("received"));
}
}
}