Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Channel Switch in GO, can I do this with java.nio

Reply
Thread Tools

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

 
 
Jan Burse
Guest
Posts: n/a
 
      10-17-2011
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
 
Reply With Quote
 
 
 
 
markspace
Guest
Posts: n/a
 
      10-17-2011
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>


 
Reply With Quote
 
 
 
 
Jan Burse
Guest
Posts: n/a
 
      10-17-2011
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
 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      10-17-2011
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.


 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      10-17-2011
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=Sear ch>

--
Lew
 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      10-18-2011
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=Sear ch>
>



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>


 
Reply With Quote
 
Jan Burse
Guest
Posts: n/a
 
      10-18-2011
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
// ...
}
 
Reply With Quote
 
Jan Burse
Guest
Posts: n/a
 
      10-18-2011
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
 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      10-18-2011
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.


 
Reply With Quote
 
Jan Burse
Guest
Posts: n/a
 
      10-19-2011
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Dual channel or triple channel? Zeke Computer Support 0 06-07-2010 03:40 PM
Re: Dual channel or triple channel? Tony Computer Support 0 06-06-2010 08:32 AM
Re: Dual channel or triple channel? VanguardLH Computer Support 1 06-06-2010 01:36 AM
Six channel or two channel sound on DVD? cydeweys@gmail.com DVD Video 1 10-10-2005 04:51 AM
Have two ATA100 Seagate drives in a vp6, one IDE channel comes up as mode 5 in winxp but the other channel is stuck in mode 4 Tim Computer Support 3 02-23-2004 03:35 AM



Advertisments