TROSynchronizedSingletonClassFactory
Overview
This class provides a class factory that implements the Singleton pattern: only one instance of the Service class will ever be created, and this same class will be used to service all requests.
In contrast to its base class, TROSingletonClassFactory, this factory will not allow simultaneous access by several clients. Instead, access will by synchronized using a critical section, to make sure only one request executes at the same time.
Use Case
Use this class factory if you intend for data stored in the Service class to be shared by all callers and you do not want to handle synchronization and thread-safe access to this data yourself in code.
Location
- Unit: uROClassFactories.pas
- Ancestry: TInterfacedObject | TROClassFactory | TROSingletonClassFactory | TROSynchronizedSingletonClassFactory
constructor Create
Creates a new instance of the class factory.
constructor Create(const anInterfaceName: string; aCreatorFunc: TRORemotableCreatorFunc; anInvokerClass: TROInvokerClass)
Parameters:
- anInterfaceName: Specifies the interface name (service name) of the service to be registered. This must be the same name that clients will use to access the service.
- aCreatorFunc: Specifies the function that will be used to create new instances of the service class, when needed. When and how often instances are created will depend on the type of the used class factory.Usually, the creator function will be auto-generated as part of the _Impl unit for your service.
- anInvokerClass: The Invoker class to be used to invoke methods on your service.Usually, this will be the auto-generated invoker class from the _Invk unit.
CreateInstance protected override
This method of the class factory is created whenever a new request from a client needs to be served, in order to return the service instance to serve the request. Whether the returned instance is actually created anew or obtained otherwise will depend on the type of class factory.
procedure CreateInstance(const aClientID: TGUID; out anInstance: IInterface)
Parameters:
- aClientID: ClientID
- anInstance: Instance
CreatorFunc (declared in TROClassFactory)
property CreatorFunc: TRORemotableCreatorFunc read
delegate: procedure CreatorFunc(out anInstance: IInterface)
GetAliasNames protected (declared in TROClassFactory)
Holds a list of supported alias names.
function GetAliasNames: TStringList
GetInvoker protected (declared in TROClassFactory)
Returns the pointer to IROInvoker.
function GetInvoker: IROInvoker
IsInterfaceNameSupported protected (declared in TROClassFactory)
Verifies that the interface with the given name is supported by this class factory.
function IsInterfaceNameSupported(const anInterfaceName: string): Boolean
Parameters:
- anInterfaceName: Interface name
RegisterInterfaceName protected (declared in TROClassFactory)
procedure RegisterInterfaceName(const anInterfaceName: string)
Parameters:
- anInterfaceName:
ReleaseInstance protected override
Called whenever a Service instance previously acquired via CreateInstance has finished processing a request. Whether the service instance is actually destroyed or saved for future use will depend on the type of class factory.
procedure ReleaseInstance(const aClientID: TGUID; var anInstance: IInterface)
Parameters:
- aClientID: ClientID
- anInstance: Service instance
ResetCache protected virtual (declared in TROClassFactory)
procedure ResetCache
UnregisterInterfaceName protected (declared in TROClassFactory)
procedure UnregisterInterfaceName(const anInterfaceName: string)
Parameters:
- anInterfaceName:
constructor Create
Creates a new instance of the class factory.
constructor Create(const anInterfaceName: string; aCreatorFunc: TRORemotableCreatorFunc; anInvokerClass: TROInvokerClass)
Parameters:
- anInterfaceName: Specifies the interface name (service name) of the service to be registered. This must be the same name that clients will use to access the service.
- aCreatorFunc: Specifies the function that will be used to create new instances of the service class, when needed. When and how often instances are created will depend on the type of the used class factory.Usually, the creator function will be auto-generated as part of the _Impl unit for your service.
- anInvokerClass: The Invoker class to be used to invoke methods on your service.Usually, this will be the auto-generated invoker class from the _Invk unit.
CreateInstance protected override
This method of the class factory is created whenever a new request from a client needs to be served, in order to return the service instance to serve the request. Whether the returned instance is actually created anew or obtained otherwise will depend on the type of class factory.
procedure CreateInstance(const aClientID: TGUID; out anInstance: IInterface)
Parameters:
- aClientID: ClientID
- anInstance: Instance
GetAliasNames protected (declared in TROClassFactory)
Holds a list of supported alias names.
function GetAliasNames: TStringList
GetInvoker protected (declared in TROClassFactory)
Returns the pointer to IROInvoker.
function GetInvoker: IROInvoker
IsInterfaceNameSupported protected (declared in TROClassFactory)
Verifies that the interface with the given name is supported by this class factory.
function IsInterfaceNameSupported(const anInterfaceName: string): Boolean
Parameters:
- anInterfaceName: Interface name
RegisterInterfaceName protected (declared in TROClassFactory)
procedure RegisterInterfaceName(const anInterfaceName: string)
Parameters:
- anInterfaceName:
ReleaseInstance protected override
Called whenever a Service instance previously acquired via CreateInstance has finished processing a request. Whether the service instance is actually destroyed or saved for future use will depend on the type of class factory.
procedure ReleaseInstance(const aClientID: TGUID; var anInstance: IInterface)
Parameters:
- aClientID: ClientID
- anInstance: Service instance
ResetCache protected virtual (declared in TROClassFactory)
procedure ResetCache
UnregisterInterfaceName protected (declared in TROClassFactory)
procedure UnregisterInterfaceName(const anInterfaceName: string)
Parameters:
- anInterfaceName:
CreatorFunc (declared in TROClassFactory)
property CreatorFunc: TRORemotableCreatorFunc read
delegate: procedure CreatorFunc(out anInstance: IInterface)