Piped stream help.  
Author Message
Andrew Tucker





PostPosted: 2003-10-5 17:15:00 Top

java-programmer, Piped stream help. Hi Everyone,
I have two servlets that both need access to a data file. I would like to
have a 'driver' program that takes care of writing / reading objects to the
data file and i would like the driver program to be able to communicate
objects to each servlet. Can i do this w/ pipedinput / output streams? I do
not understand how i can reference a piped output stream in one object from
another!

TIA, Andrew.


 
Knute Johnson





PostPosted: 2003-10-6 12:02:00 Top

java-programmer >> Piped stream help. Andrew Tucker wrote:
> Hi Everyone,
> I have two servlets that both need access to a data file. I would like to
> have a 'driver' program that takes care of writing / reading objects to the
> data file and i would like the driver program to be able to communicate
> objects to each servlet. Can i do this w/ pipedinput / output streams? I do
> not understand how i can reference a piped output stream in one object from
> another!
>
> TIA, Andrew.
>
>

Piped streams are used to communicate between threads, not between VMs.
Reference them with global variables.

--

Knute Johnson
email s/nospam/knute/
Molon labe...

 
Harald Hein





PostPosted: 2003-10-7 3:40:00 Top

java-programmer >> Piped stream help. "Andrew Tucker" wrote:

> I have two servlets that both need access to a data file. I would
> like to have a 'driver' program that takes care of writing /
> reading objects to the data file and i would like the driver
> program to be able to communicate objects to each servlet. Can i
> do this w/ pipedinput / output streams?

Yes, if you are in the same VM. But in this case you could also use a
simpler architecture. Since you claim that your "driver" already
converts file data from/to objects, a simple mechanism to pass the
object references around would do.

If you use a piped stream, you would have to serialize the objects
from/to the driver which is unnecessary overhead. Piped streams are
nice to send raw data between two threads, but are otherwise not
extremely useful.

You could e.g. use some queue data structure for passing the object
references around, or you could provide your "driver" with a simple api
like:

public synchronized YourDataClass read(String key);
public synchronized void write(String key, YourDataClass data);

Both of your servelets get a reference to the driver object and use
this API.