Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #8925 > unrolled thread

Channel Switch in GO, can I do this with java.nio

Started byJan Burse <janburse@fastmail.fm>
First post2011-10-17 19:02 +0200
Last post2011-11-06 16:32 -0500
Articles 11 — 4 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  Channel Switch in GO, can I do this with java.nio Jan Burse <janburse@fastmail.fm> - 2011-10-17 19:02 +0200
    Re: Channel Switch in GO, can I do this with java.nio markspace <-@.> - 2011-10-17 10:22 -0700
      Re: Channel Switch in GO, can I do this with java.nio Jan Burse <janburse@fastmail.fm> - 2011-10-17 20:15 +0200
        Re: Channel Switch in GO, can I do this with java.nio markspace <-@.> - 2011-10-17 12:44 -0700
          Re: Channel Switch in GO, can I do this with java.nio Lew <lewbloch@gmail.com> - 2011-10-17 15:58 -0700
            Re: Channel Switch in GO, can I do this with java.nio markspace <-@.> - 2011-10-17 18:59 -0700
              Re: Channel Switch in GO, can I do this with java.nio Jan Burse <janburse@fastmail.fm> - 2011-10-18 09:16 +0200
              Re: Channel Switch in GO, can I do this with java.nio Jan Burse <janburse@fastmail.fm> - 2011-10-18 09:20 +0200
                Re: Channel Switch in GO, can I do this with java.nio markspace <-@.> - 2011-10-18 07:49 -0700
                  Re: Channel Switch in GO, can I do this with java.nio Jan Burse <janburse@fastmail.fm> - 2011-10-19 16:17 +0200
                  Re: Channel Switch in GO, can I do this with java.nio Arne Vajhøj <arne@vajhoej.dk> - 2011-11-06 16:32 -0500

#8925 — Channel Switch in GO, can I do this with java.nio

FromJan Burse <janburse@fastmail.fm>
Date2011-10-17 19:02 +0200
SubjectChannel Switch in GO, can I do this with java.nio
Message-ID<j7hn3d$pmt$1@news.albasani.net>
Dear All,

I am just wondering whether a Go programming
language construct can be done in Java by
means of some standard packages.

The Go programming language construct, is the
switch statement over channels:

   switch {
     c <- channel1:
        /* do something 1 */
     c <- channel2:
        /* do something 2 */
   }

I interpret this that the code will try to fetch
data from channel1 and channel2, and depending on
which channel has fist some data, the corresponding
code will be executed?

How could this be done in Java? I have the feeling
that read() does not work since it blocks, and that
available() would not work since it would involve
polling. So something else could solve the problem...

Best Regards

[toc] | [next] | [standalone]


#8926

Frommarkspace <-@.>
Date2011-10-17 10:22 -0700
Message-ID<j7ho8o$32h$1@dont-email.me>
In reply to#8925
On 10/17/2011 10:02 AM, Jan Burse wrote:

> I interpret this that the code will try to fetch
> data from channel1 and channel2, and depending on
> which channel has fist some data, the corresponding
> code will be executed?


<http://download.oracle.com/javase/7/docs/api/java/nio/channels/Selector.html>

[toc] | [prev] | [next] | [standalone]


#8927

FromJan Burse <janburse@fastmail.fm>
Date2011-10-17 20:15 +0200
Message-ID<j7hrct$4f4$1@news.albasani.net>
In reply to#8926
markspace schrieb:
> On 10/17/2011 10:02 AM, Jan Burse wrote:
>
>> I interpret this that the code will try to fetch
>> data from channel1 and channel2, and depending on
>> which channel has fist some data, the corresponding
>> code will be executed?
>
>
> <http://download.oracle.com/javase/7/docs/api/java/nio/channels/Selector.html>
>
>
>

Thank you for the link.

I guess I will find code examples (to gradually help me
understanding the API) by myself via googling the net.
Any prefered site to start with?

Best Regards

[toc] | [prev] | [next] | [standalone]


#8928

Frommarkspace <-@.>
Date2011-10-17 12:44 -0700
Message-ID<j7i0jd$oj$1@dont-email.me>
In reply to#8927
On 10/17/2011 11:15 AM, Jan Burse wrote:
>
> I guess I will find code examples (to gradually help me
> understanding the API) by myself via googling the net.
> Any prefered site to start with?


Unfortunately I use hard copy for that.  Learning Java, by O'Reilly. 
Perhaps you can find an online copy.

[toc] | [prev] | [next] | [standalone]


#8932

FromLew <lewbloch@gmail.com>
Date2011-10-17 15:58 -0700
Message-ID<8140673.542.1318892303608.JavaMail.geo-discussion-forums@prfk19>
In reply to#8928
markspace wrote:
> Jan Burse wrote:
>> I guess I will find code examples (to gradually help me
>> understanding the API) by myself via googling the net.
>> Any prefered site to start with?
> 
> Unfortunately I use hard copy for that.  Learning Java, by O'Reilly. 
> Perhaps you can find an online copy.

Developerworks has a number of useful articles.
<https://www.ibm.com/search/csass/search/?sn=dw&en=utf&hpp=20&dws=dw&q=Java+NIO&Search=Search>

-- 
Lew

[toc] | [prev] | [next] | [standalone]


#8937

Frommarkspace <-@.>
Date2011-10-17 18:59 -0700
Message-ID<j7imh9$d7q$1@dont-email.me>
In reply to#8932
On 10/17/2011 3:58 PM, Lew wrote:
> markspace wrote:
>> Jan Burse wrote:
>>> I guess I will find code examples (to gradually help me
>>> understanding the API) by myself via googling the net.
>>> Any prefered site to start with?
>>
>> Unfortunately I use hard copy for that.  Learning Java, by O'Reilly.
>> Perhaps you can find an online copy.
>
> Developerworks has a number of useful articles.
> <https://www.ibm.com/search/csass/search/?sn=dw&en=utf&hpp=20&dws=dw&q=Java+NIO&Search=Search>
>


I like this article.  It's old, but since NIO was new when the article 
was written, it explains the basics without trying to do anything fancy. 
  It seem pretty close to the information I have in my book.

<https://www.ibm.com/developerworks/java/tutorials/j-nio/section9.html>

[toc] | [prev] | [next] | [standalone]


#8941

FromJan Burse <janburse@fastmail.fm>
Date2011-10-18 09:16 +0200
Message-ID<j7j950$bmk$1@news.albasani.net>
In reply to#8937
markspace schrieb:
> I like this article. It's old, but since NIO was new when the article
> was written, it explains the basics without trying to do anything fancy.
> It seem pretty close to the information I have in my book.
>
> <https://www.ibm.com/developerworks/java/tutorials/j-nio/section9.html>
>
>

Thanks for the reference, very helpful.

P.S.:

Just out of habit I would code:

   if ((key.readyOps() & SelectionKey.OP_ACCEPT)
      == SelectionKey.OP_ACCEPT) {

      // Accept the new connection
      // ...
   }

With a different check:

   if ((key.readyOps() & SelectionKey.OP_ACCEPT)
      != 0) {

      // Accept the new connection
      // ...
   }

The same check is also used in the definition
of the method isAcceptable(), so it could be
also coded as:

   if (key.isAcceptable()) {

      // Accept the new connection
      // ...
   }

[toc] | [prev] | [next] | [standalone]


#8942

FromJan Burse <janburse@fastmail.fm>
Date2011-10-18 09:20 +0200
Message-ID<j7j9cg$bmk$2@news.albasani.net>
In reply to#8937
markspace schrieb:
> I like this article. It's old, but since NIO was new when the article
> was written, it explains the basics without trying to do anything fancy.
> It seem pretty close to the information I have in my book.
>
> <https://www.ibm.com/developerworks/java/tutorials/j-nio/section9.html>
>
>

Something else: Some info around whether this NIO feature
is widely adopted? Anything known about the OS or hardware
support to implement this NIO feature in a JVM?

Further some info around about the origins of this construct,
I browsed over JSR-51 yesterday shortly, but the construct
was not clearly mentioned in the first proposal. Is this
some -ism from ADA or so?

Bye

[toc] | [prev] | [next] | [standalone]


#8952

Frommarkspace <-@.>
Date2011-10-18 07:49 -0700
Message-ID<j7k3lc$b13$1@dont-email.me>
In reply to#8942
On 10/18/2011 12:20 AM, Jan Burse wrote:
> markspace schrieb:
>> I like this article. It's old, but since NIO was new when the article
>> was written, it explains the basics without trying to do anything fancy.
>> It seem pretty close to the information I have in my book.
>>
>> <https://www.ibm.com/developerworks/java/tutorials/j-nio/section9.html>
>>
>>
>
> Something else: Some info around whether this NIO feature
> is widely adopted? Anything known about the OS or hardware
> support to implement this NIO feature in a JVM?


<http://www.cl.cam.ac.uk/cgi-bin/manpage?2+select>

My understanding is that it's critical to using Java in scalable 
applications like Tomcat.  OS support precedes the adoption of Java's 
Select by a decade or more.

[toc] | [prev] | [next] | [standalone]


#8997

FromJan Burse <janburse@fastmail.fm>
Date2011-10-19 16:17 +0200
Message-ID<j7mm5r$2lv$1@news.albasani.net>
In reply to#8952
markspace schrieb:

> <http://www.cl.cam.ac.uk/cgi-bin/manpage?2+select>
>
> My understanding is that it's critical to using Java in scalable
> applications like Tomcat. OS support precedes the adoption of Java's
> Select by a decade or more.

So this select was basically a unix port. Oki, Doki.

[toc] | [prev] | [next] | [standalone]


#9681

FromArne Vajhøj <arne@vajhoej.dk>
Date2011-11-06 16:32 -0500
Message-ID<4eb6fd02$0$293$14726298@news.sunsite.dk>
In reply to#8952
On 10/18/2011 10:49 AM, markspace wrote:
> On 10/18/2011 12:20 AM, Jan Burse wrote:
>> markspace schrieb:
>>> I like this article. It's old, but since NIO was new when the article
>>> was written, it explains the basics without trying to do anything fancy.
>>> It seem pretty close to the information I have in my book.
>>>
>>> <https://www.ibm.com/developerworks/java/tutorials/j-nio/section9.html>
>>
>> Something else: Some info around whether this NIO feature
>> is widely adopted? Anything known about the OS or hardware
>> support to implement this NIO feature in a JVM?
>
>
> <http://www.cl.cam.ac.uk/cgi-bin/manpage?2+select>
>
> My understanding is that it's critical to using Java in scalable
> applications like Tomcat. OS support precedes the adoption of Java's
> Select by a decade or more.

I believe Tomcat started supporting NIO in version 6 and
I am not even sure it is default today.

I consider earlier versions to be scaling OK.

Arne


[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web