You are right. It looks there is no reason to let NettyServer extend from Thread class. :)
- why On Wed, Jul 14, 2010 at 5:57 AM, Patrick Linehan <[email protected]>wrote: > I'm having a bit of trouble using NettyServer (using Avro 1.3.3 plus the > "AVRO-405-coolwhy-new" patch). The server's socket isn't bound in the > constructor, it is bound in a thread started by the constructor, which > means there is a delay before methods like "getPort" can be used. > > Here's a snippet that exhibits the problem: > > public static void main(String[] args) { > Server server = new NettyServer( > new SpecificResponder( > Mail.class, > new MailImpl()), > new InetSocketAddress(0)); > while (true) { > try { > server.getPort(); > } catch (NullPointerException e) { > System.err.println("npe"); > continue; > } > break; > } > System.err.println("done"); > } > > The above code prints "npe" a number of times before finally > printing "done". There is no way to detect, AFAICT, when the server is > ready to start using. My current hack is to just sleep for a few seconds > after construction. > > Is there any reason the setup is done in a different thread? Would > you accept a patch to instead perform the initialization in the > constructor? >
