To allow you to work with persistent, shared data in a distributed application, PowerBuilder provides support for shared objects. Shared objects are user objects that can be shared by multiple client connections.
Shared objects provide significant benefits to both distributed PowerBuilder applications and Internet applications that use Web.PB. Shared objects allow you to:
- Provide convenient access to common data that would otherwise need to be retrieved separately by each client connection
- Reduce the number of database accesses, freeing the database server for other processing
- Maintain state information in Web.PB applications
To allow multiple client applications to share a single object, the server application performs these operations:
- Invokes the SharedObjectRegister function to register a named instance of the object.
- Invokes the SharedObjectGet function to get an object instance that is a reference to the shared object.
The server can perform these operations in its main thread or inside of a client session. The server application does not need to issue a CREATE statement for the shared object. When the server calls the SharedObjectRegister function, PowerBuilder automatically creates the shared object instance.
Shared objects are accessible only from the server's main session and from the client sessions created for each client connection on the server. Client applications cannot access a shared object directly. To access a shared object, a client needs to communicate with a remote object that delegates work to the shared object. Often the remote object has an instance variable that provides a reference to the shared object.
Once the server has registered the shared object instance and retrieved a reference to the object, client applications can call the methods defined for the shared object by interfacing with the remote object, which in turn passes requests on to the shared object. The remote object has methods that provide indirect access to the methods of the shared object. Typically, these methods have the same names as the methods defined for the shared object.
The data types that are permitted for the arguments and the return value of a shared object method are the same as for a remote object method.
The following functions have been added for shared objects:
For more information
For more information about shared objects, see the following topics:
What happens at execution time
Example of using a shared object