Announcement Announcement Module
Collapse
No announcement yet.
Stream oriented remoting. Possible? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Stream oriented remoting. Possible?

    Hi,
    so far I've been using the Spring remoting capabilities to make transparent the location of the services I'm using. Basically, I'm developing a swing based client that, in production, should talk so a Tomcat server, but to ease development and debugging, for the moment I'm mostly testing it against local services (that is, the Swing client connects directly to the database).

    This has proven to work fine so far, but now I'm facing a problem. The client should exchange files with the server, both upload and download. I know I can do this by using the HTTPClient library, but this would make the code location dependent (I would need one implementation for a local filesystem, and another for HTTP streaming)
    I'm wondering, if I have an interface like this:

    interface FileService {
    InputStream getFile(Long fileId);
    void putFile(Long fileId, InputStream stream);
    }

    would it be possibile to remote it with Spring and HTTPInvoker, and have it properly deal with the streaming part transparently? Am I asking too much? ;-)

  • #2
    As HttpInvoker relies on Java serialization there's no way that your going to be able to remote that interface as streams are not serializable. However, what you could do is adapt the interface to a statefull file transfer service that send the file across the wire in chunks using multiple remote invocations:

    Code:
    interface ChunkedFileTransferService {
        int beginSend(Long fileId);
        void sendChunk(int transferKey, byte[] cunk); 
        void endSend(int transferKey);
    }
    
    class FileServiceAdapter implements FileService {
         private ChunkedFileTransferService cfts;
    
         void putFile(Long fileId, InputStream stream) {
              int transferKey = cfts.beginSend(fileId);
    
              byte[] buffer = new byte[1024];
              while (data left to read) {
                   stream.read(buffer);
                   cfts.sendChunk(transferKey, buffer);
              }
              
              cfts.endSend(transferKey);
         }
         
         ...
    
    }
    This is also nice as it makes it easy to implement things like a progess bar.

    HTH

    Ollie

    Comment


    • #3
      Originally posted by oliverhutchison
      As HttpInvoker relies on Java serialization there's no way that your going to be able to remote that interface as streams are not serializable. However, what you could do is adapt the interface to a statefull file transfer service that send the file across the wire in chunks using multiple remote invocations
      Thank you for the suggestion, but I don't think it would work out very well for transferring data over a high latency network, since every call is a isolated network rountrip... of course I could use a bigger buffer to reduce this problem... Yet the idea of the progress bar is really good indeed, especially if the network is slow...

      Comment

      Working...
      X