ipc in java

T

tom fredriksen

Does there exists any ipc mechanisms in java similar to what is
available in os's, such as pipes, shared memory etc. or is the only ipc
in java sockets and files?

/tom
 
T

Thomas Weidenfeller

tom said:
Does there exists any ipc mechanisms in java
J2SE?

similar to what is
available in os's, such as pipes, shared memory etc.

No, although using named pipes via the Files class often works.
or is the only ipc
in java sockets and files?

Plus things on top of it, like CORBA and RMI. In J2EE you have things
like SOAP support (SAAJ, JAX-RPC).

But it is likely that you can find a JNI-based third party
implementation for almost every OS-specific IPC mechanism.


/Thomas
 
T

tom fredriksen

Thomas said:
tom fredriksen wrote:

But it is likely that you can find a JNI-based third party
implementation for almost every OS-specific IPC mechanism.

I found one package which implemented posix ipc, "posix for java"

http://www.bmsi.com/java/posix/package.html


In any case it was more a question of curiosity as I had never heard of
it. I was thinking that some simple and common version of a couple
mechanisms could perhaps have been implemented java, if it could be an
abstracted implementation of what exists in current OS's. But I realise
that a hindrance is that java is not process oriented but rather thread
oriented. Which makes it a bit awkward to use.

/tom
 
N

Nigel Wade

EJP said:
and to this extensive list should be added java.nio.channels.Pipe. These
are not named pipes, they are more like Unix inter-process pipes (i.e. a
read pipe and a write pipe), but they are implemented under the hood
with sockets (as I believe Unix pipes are too actually).

IIRC a pipe is equivalent to a socket in the UNIX domain rather than the INET
domain, and yes they use sockets. Because the sockets are in the UNIX (local)
domain a pipe is only available for IPC on the same host, there is no network
involvement. It's really only of use in communicating between parent/child
processes as the pipe has no ability to listen for connections. Both ends of
the socket are established when the pipe is created, within a single process.

Also, a pipe is uni-directional. To have 2-way communication requires two pipes.
 
T

Thomas Weidenfeller

Nigel said:
IIRC a pipe is equivalent to a socket in the UNIX domain rather than the INET
domain, and yes they use sockets.

This all depends on the type of Unix pipe you are talking about, and on
the heritage of the particular Unix version.

Classic Unix pipes need not use sockets at all. In SVR4 these ones are
implemented on top of the streams io framework. In older AT&T Unix
version it was just some particular code in the kernel.

So called stream pipes are socked-based in BSD Unix systems, and simply
pipes-based in SVR4.

Regarding SVR4,
Also, a pipe is uni-directional. To have 2-way communication requires two pipes.

here the normal pipe is already bi-directional (due to the
implementation on top of the streams io framework). When you ask for a
pipe, you always get a bi-directional one in SVR4. While on BSD systems
you have to ask for a socket pair to get a bi-directional one (or use
two normal pipes).

Of course, there are for sure Unix dialects where this is done differently.

And you of course also have named pipes (FIFOs) and you can associate a
name with a stream pipe.

/Thomas
 
N

Nigel Wade

Thomas said:
This all depends on the type of Unix pipe you are talking about, and on
the heritage of the particular Unix version.

Classic Unix pipes need not use sockets at all. In SVR4 these ones are
implemented on top of the streams io framework. In older AT&T Unix
version it was just some particular code in the kernel.

So called stream pipes are socked-based in BSD Unix systems, and simply
pipes-based in SVR4.

It's been a while since I did any programming requiring pipes. In those days the
pipe system call returned a pair of file descriptors, one for read and one for
write. It was the responsibility of the programmer to ensure that the correct
end of each was closed in the parent/child to allow correct communications.

As in all fields, progress has been made (but not necessarily in the
documentation). According to the man pages for Linux/IRIX/Solaris the pipe
system call still returns a classic, uni-directional pipe. To further confuse
matters IRIX implements 2 versions of pipe, one with the conventional SVR3.2
uni-directional semantics and another with the bi-directional SVR4 semantics,
controlled either by a kernel tunable parameter, or the library linked at
runtime.

Which type of pipe is really returned remains a mystery...
Regarding SVR4,
pipes.

here the normal pipe is already bi-directional (due to the
implementation on top of the streams io framework). When you ask for a
pipe, you always get a bi-directional one in SVR4. While on BSD systems
you have to ask for a socket pair to get a bi-directional one (or use
two normal pipes).


Sorry, what I meant to say was that Pipe is uni-directional. According to the
API Javadocs it implements a uni-directional pipe.
 
T

Thomas Weidenfeller

Nigel said:
As in all fields, progress has been made (but not necessarily in the
documentation). According to the man pages for Linux/IRIX/Solaris the pipe
system call still returns a classic, uni-directional pipe.

Solaris has bi-directional pipes. From the Solaris 8 pipe(2) man page
(Solaris has its roots in SVR4):

| The files associated with fildes[0] and fildes[1] are streams
| and are both opened for reading and writing.
| ...
| Since a pipe is bi-directional,

/Thomas
 
N

Nigel Wade

Thomas said:
Nigel said:
As in all fields, progress has been made (but not necessarily in the
documentation). According to the man pages for Linux/IRIX/Solaris the pipe
system call still returns a classic, uni-directional pipe.

Solaris has bi-directional pipes. From the Solaris 8 pipe(2) man page
(Solaris has its roots in SVR4):

| The files associated with fildes[0] and fildes[1] are streams
| and are both opened for reading and writing.
| ...
| Since a pipe is bi-directional,

/Thomas

Ah, there's obviously been a change. The Solaris version I have (for
compatibility reasons) is 2.7. I can't remember whether pipe() does actually
return bi-directional pipes or not. It might be that in 2.7 you have to
specifically request them, as in IRIX where you need to link with -lnsl, or
just that the man page hadn't been updated (I have a vague recollection it
might be the latter, but it's some time since I used pipes on Solaris).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top