Is there a way to send serialized classes over a pipe? I see PipedOutputStream and PipedInputStream but I cannot seem to use ObjectInputStream and ObjectOutputStream with them. I am using ObjectStreams with sockets just fine. JDK6. Or would there be a better way? The issue I have is I have a external driver/server that sends updates via a PropertyChangeListener, but the information comes in bursts and too fast to process. It causes information loss and the remote server disconnects. I was going to setup a pipe to buffer the information, one thread that has the PropertyChangeListener and send the information across the pipe as classes, and another thread that can process the information at other end of the pipe in order but buffered so it can catch up. Is there a better way to buffer this information (I will store the info in a serialized class). Using a ArrayList would cause data access issues, there is some way to buffer the information FIFO, or is there a good set of classes for queuing data in order? Would I be able to use a H2 database? Any suggestions? Thanks! -
I cannot seem to use ObjectInputStream and ObjectOutputStream with them.
That does work, but there are gotchas:
1. They block more readily than sockets because the internal buffer is only 4k instead of at least 8k at both ends of a socket, more like 90k in total if there are no Windows platforms involved.
2. You must create the pipes themselves first, connected together; then start the reading thread; then construct the ObjectOutputStream around the PipedOutputStream; the reading thread must construct the ObjectInputStream around the PipedInputStream in its run method. Otherwise things will jam or fail in various ways due to the object stream header, and the requirement to have the pipes connected to each other, and a read thread in existence when you write.
Thank you, BlockingQueue is exactly what I was looking for. I had found a example of using the Pipe and Objects but now I know why it was written that way. I could not get it to work because I shortened it and did not setup the pipe first. Thanks!! - Jeremy