Is it possible to use RMI bidirectional between two classes?

后端 未结 8 2006
慢半拍i
慢半拍i 2020-12-15 08:16

I want to share some information between two classes (A and B), which are running in different java programs. Instead of writing a whole communication protocol I want to use

8条回答
  •  醉酒成梦
    2020-12-15 09:02

    If you pass B as an argument to a method in A and then use that reference to call a method on B I am fairly certain that a reverse connection is established, and I am fairly certain that RMI Registry is created for the JVM where B resides. At some point this got us into a bit of trouble with particularly strict firewall rules. Our code looked a little something like

    Web Server

    public int uploadFile(FileItem fileItem){
        return ApplicationClassLoader
            .get(DocumentManager.class)
            .attachFile(new RemoteInputStreamImpl(fileItem.getInputStream());
        )
    }
    

    Application Server

    public int attachFile(RemoteInputStream in){
        ...
    
        byte[] buffer;
        while((buffer = in.read(1024)) != null) // Would return null to indicate EOF
          // Do some stuff
    
        return documentId;       
    }
    

提交回复
热议问题