You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by Patrick Linehan <pl...@plinehan.com> on 2010/07/13 23:57:37 UTC
NettyServer initialization
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?
Re: NettyServer initialization
Posted by harry wang <co...@gmail.com>.
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 <pl...@plinehan.com>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?
>
Re: NettyServer initialization
Posted by Patrick Linehan <pl...@plinehan.com>.
On Tue, Jul 13, 2010 at 3:11 PM, Doug Cutting <cu...@apache.org> wrote:
> On 07/13/2010 02:57 PM, Patrick Linehan wrote:
>
>> Would
>> you accept a patch to instead perform the initialization in the
>> constructor?
>>
>
> This sounds like a reasonable change to me. Please file an issue in Avro's
> Jira bug database and attach a patch file there.
>
> Thanks,
>
> Doug
>
https://issues.apache.org/jira/browse/AVRO-596
Re: NettyServer initialization
Posted by Doug Cutting <cu...@apache.org>.
On 07/13/2010 02:57 PM, Patrick Linehan wrote:
> Would
> you accept a patch to instead perform the initialization in the constructor?
This sounds like a reasonable change to me. Please file an issue in
Avro's Jira bug database and attach a patch file there.
Thanks,
Doug