| fscom.rmi: | Modinfo | Source |
RMI stands for Remote Method Invocation. This module provides you with the possibility to call methods of objects that are not in your runtime (i.e. in another process or another machine).
Why would I want to do this?
You don't need to care about networking any more. Your methods will be called with correct parameters and can return a value. Only condition: The arguments of the method you call and the return value must be transferable over the network (being serializable e.g. Int, String, Arrays of Strings...)
To use RMI you must connect the two runtimes via stream, register a service object where the method should be called and link it to an object from where the method call should originate. Both sides must implement the same methods so it is a good idea to use a shared abstract type.
RMI uses proxies, so run buildproxies with the shared type (see fscom.proxy)
There are more features like type services. See fscom.rmiclient and fscom.rmiserver for client/server specific information, see fscom.rmishared for general rmi information.
Example:
'shared.bmx
Type TService {proxy}
Method GetInfo:String(id:Int) Abstract
End Type
'server.bmx
Framework fscom.rmi
Import "shared.bmx"
Type TServiceImpl Extends TService
Field info:String[]
Method GetInfo:String(id:Int)
Return info[id]
End Method
End Type
Local server:TServiceImpl = New TServiceImpl
server.info=["ABC","123","!§$"]
RMIStartServer
RMIRegisterObjectService server, "InfoService"
Repeat
RMIPollNetwork
PollSystem
Forever
'client.bmx
Framework fscom.rmi
Import BRL.StandardIO
Import "shared.bmx"
RMIConnect "localhost"
Local client:TService=TService(RMIGetServiceObject("InfoService","TService"))
Print client.GetInfo(0)
Print client.GetInfo(1)
Print client.GetInfo(2)
Input
| Version | 0.3 |
|---|---|
| Author | Francesco Silvani |
| License | zlib/libpng |
| History | 0.2 |
| History | Added clientside invocations. |
| History | Removed rmiclientex. To manage RMI yourself without proxies and buffered streams, import fscom.rmishared. |