Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create Channel from class AioServerSocketChannel #725

Closed
ghost opened this issue Nov 10, 2012 · 8 comments
Closed

Unable to create Channel from class AioServerSocketChannel #725

ghost opened this issue Nov 10, 2012 · 8 comments
Assignees
Labels
Milestone

Comments

@ghost
Copy link

ghost commented Nov 10, 2012

Well, I am trying to launch a server using AioServerSocketChannel.
The code is like this:

bootstrap = new ServerBootstrap();
        bootstrap.group(new AioEventLoopGroup(), new AioEventLoopGroup())
                .channel(AioServerSocketChannel.class)
                .localAddress(isa)
                .option(ChannelOption.SO_BACKLOG, 100)
                .childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, 100)
                .childOption(ChannelOption.SO_REUSEADDR, true)
                .childOption(ChannelOption.TCP_NODELAY, true)
                .childHandler(channelInitializer);
bootstrap.bind();

The problem is when I launch application such exception occures:

io.netty.channel.ChannelException: Unable to create Channel from class class io.netty.channel.socket.aio.AioServerSocketChannel
    at io.netty.bootstrap.AbstractBootstrap$BootstrapChannelFactory.newChannel(AbstractBootstrap.java:239) ~[netty-4.0.0.Alpha5.jar:na]
    at io.netty.bootstrap.AbstractBootstrap.bind(AbstractBootstrap.java:176) ~[netty-4.0.0.Alpha5.jar:na]
...
Caused by: java.lang.InstantiationException: io.netty.channel.socket.aio.AioServerSocketChannel
    at java.lang.Class.newInstance0(Class.java:357) ~[na:1.7.0_07]
    at java.lang.Class.newInstance(Class.java:325) ~[na:1.7.0_07]
    at io.netty.bootstrap.AbstractBootstrap$BootstrapChannelFactory.newChannel(AbstractBootstrap.java:237) ~[netty-4.0.0.Alpha5.jar:na]
    ... 13 common frames omitted

When I rewrite code to use NIO implementation it works fine.

Where can be the problem? Do I initialize AIO server correctly?

P.S. Sorry for my ban English.

@ghost
Copy link
Author

ghost commented Nov 10, 2012

I think that the problem is in AioServerSocketChannel: class has no nullary constructor which is needed for newInstance() function.

@normanmaurer
Copy link
Member

Normally you would need to use this for ServerChannel implementations that not contain a no-args constructor:

        AioEventLoopGroup parentGroup = new AioEventLoopGroup();
        AioEventLoopGroup childGroup = new AioEventLoopGroup(); 
        bootstrap = new ServerBootstrap();
        bootstrap.group(parentGroup, childGroup)
                .channelFactory(new ChannelFactory() {

                    @Override
                    public Channel newChannel() {
                        return new AioServerSocketChannel(parentGroup, childGroup);
                    }
                })
                .localAddress(isa)
                .option(ChannelOption.SO_BACKLOG, 100)
                .childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, 100)
                .childOption(ChannelOption.SO_REUSEADDR, true)
                .childOption(ChannelOption.TCP_NODELAY, true)
                .childHandler(channelInitializer);
         bootstrap.bind();

But I think we should make that easier.. Let me take care of this

@ghost
Copy link
Author

ghost commented Nov 10, 2012

Thanks a lot for help! This is a little bit confusing but works perfect.

@normanmaurer
Copy link
Member

np... in the next release it should also work without the need of create the factory by yourself.

fa805c4

ankurcha pushed a commit to ankurcha/netty that referenced this issue Nov 11, 2012
* 'master' of git://github.com/netty/netty: (45 commits)
  Allow easier use of AIO transport via bootstrap. Related to [netty#725]
  Fix a compilation error
  Fix a failing test
  Fix a compilation error (sorry!)
  More robust localhost resolution
  Use 'x' over "x" wherever possible / String.equals("") -> isEmpty()
  Add 'static' modifier to the methods that don't need to be member methods
  Replace keySet() + unnecessary map lookup with entrySet()
  Make classes static wherever possible
  Fix unchecked warnings
  Use foreach loop wherever possible / Prefer String.contains() to indexOf() >= 0 / Prefer StringUtil.split() to String.split()
  DefaultHttpDataFactory.MINSIZE must be final
  Remove methods overridden but identical with the super implementation / Make constructors of abstract classes protected rather than non-sense public
  Remove unnecessary throws clauses for unchecked exceptions
  Remove unused imports
  Remove various unnecessary qualifiers
  Remove redundant field initialization
  Suppress false positives related with utility class inspections.
  Remove redundant throws clauses / Suppress inspections for some false positives
  [netty#719] Handle http requests without an absolute path the right way when encoding them, which is adding / to it
  ...
@dantran
Copy link
Contributor

dantran commented Nov 12, 2012

just tested with the latest changes using the starting template but running into 'factory already set'. Ended up the use the mentioned work around

@normanmaurer
Copy link
Member

@dantran intresting.. could you add the stacktrace into here ?

@trustin
Copy link
Member

trustin commented Nov 12, 2012

@dantran, it should be fixed now.

@trustin
Copy link
Member

trustin commented Nov 12, 2012

See b3be152 for the diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants