Try OpenEdge Now
skip to main content
Web Services
Creating OpenEdge REST Web Services : Data Object Services : Coding Business Entities to implement Data Objects : Singleton classes and procedures as Data Object resources
Singleton classes and procedures as Data Object resources
The ABL to implement the interface to a single Data Object resource must be coded in a single class or external procedure that can be executed as a singleton object. A singleton object is a class or external procedure that once initially instantiated, the same instance is shared by all consumers of the class or procedure no matter how many times it is instantiated in a given application server session.
When, on behalf of a mobile or web app, a Web application executes any Data Object operation in the resource running in an application server session, if the ABL class or external procedure has not yet been instantiated as a singleton object, the session instantiates it and executes the ABL routine that implements the operation. When the operation completes, the object remains instantiated for access by other client requests. When the Web application executes another operation on the same resource running in the same ABL session, the same singleton object is then used to execute the ABL routine for that operation, and so on. If another application server session executes the operation for the same Data Object resource, the same process repeats itself, instantiating the singleton if it does not exist and remaining instantiated for all additional calls to the same resource on that or another session where the same object is instantiated. Once all running application server sessions have executed an operation for that same Data Object resource, they all maintain their singleton objects as long as they continue to run. Again, the process repeats for any additional session that runs on the application server and responds to a Data Object operation request.
ABL classes are inherently coded to be instantiated as singletons. However, external procedures must meet a basic requirement to be instantiated as singletons, and that is, they cannot contain any DEFINE PARAMETER statements in the main block. They can contain internal procedures and user-defined functions with their own parameters, each of which can implement a Data Object operation exactly like a method of a class.
Note that the singleton coding requirement for external procedures applies only to an external procedure that implements the resource for a Data Object and its operations. Any additional procedures or classes that a singleton class or procedure accesses can be implemented like any other class or procedure that runs on an OpenEdge application server.
For more information on singleton procedures instantiated in the context of an ABL client, see the RUN statement in OpenEdge Development: ABL Reference. Although this information is for ABL clients, singleton procedure behavior and coding requirements apply for OpenEdge procedures running on an application server as well.