RemoteObjects
RemoteObjects is an HTTP based protocol allowing object-oriented access to remote Ruby classes. The implementation provides an OpenLaszlo client library and a Ruby on Rails plugin on the server. The current release uses Javascript Object Notation (JSON) as the HTTP serialization format (XML support is planned for a future release).
RemoteObjects Protocol for OpenLaszlo and Rails (0.0.2)
RemoteObjects supports the invocation of both Ruby class and instance methods. Use of class methods is a natural and easy way to provide RPC style stateless web services where every client would see the same service API.
RemoteObjects also supports the remote instantiation of class objects whose lifetime may be either the duration of a single request or the lifetime of the session. Use of instance methods is useful for creating objects where each client may have a separate object with its own state or where a single client may have several instances of the same object.
If an object is designated as a session object, its state is stored in the client’s session between requests using whichever session store is configured in Rails. Object reference handles are returned to the OpenLaszlo client which then can invoke methods on these statefull objects.
Regular Ruby Classes can be used with RemoteObjects without necessarily deriving from a special class. An object is treated as a Session Object by the controller if it’s Class is listed in a RemoteSessionClasses array (or alternatively it may derive from the SessionObject Class to get this treatment). The Rails RemoteObject controller automatically restores and saves the attribute state of Objects around HTTP requests if it is identified as a Session Object.
Programmatic use of Remote Objects is straightforward. On the server, Ruby Classes simply need to be made available, e.g. by putting them in the “lib” directory or by including a reference to them. They also must be enabled for remote access by listing them in a RemoteClasses array. Class names may have Module name prefixes which is helpful for avoiding name collisions, e.g. “MyModule::MyClass”.
On the client, the required OpenLaszlo Classes are:- remote_server to define the (host, port, format) to use and handle remote communication.
- remote_class to define the class name and invoke class methods.
- remote_instance to hold a reference to the remote object once it has been instantiated and invoke instance methods. A Client Library User Guide is available for more details.
Automatic data-binding to all standard OpenLaszlo components is provided as part of the product. If the OpenLaszlo object which owns the request has an attribute named “dataobject” then any data received is bound to the “dataobject” it refers to. In this case, JSON objects received from the backend are translated directly into the OpenLaszlo DOM tree during binding which eliminates the need to translate to XML first. A “dataoptions” literal object may also be defined to control specifics of the databinding operation.
One of the benefits of RemoteObjects is that it is able to operate in OpenLaszlo Solo mode rather than Proxy mode. This means that the client machine can communicate directly with a Rails web server without the need for the Lazlo Presentation Server (which runs in a Java servlet container) acting as an intermediary. This greatly simplifies server deployments and opens up many possibilities for deployment scenarios.
This Slide Presentation provides an overview of the functionality, info on the client APIs and some design details.
RemoteObjects is currently being used as the RPC mechanism in the FrontRails product. This Demo allows a user to interact with a set of backend Ruby Classes and Objects.