Service Consumers
Services consumers are a simplest and safest means to use Griffin-based services from within EiffelStudio.
Services Are Tentative
Given the nature of Griffin services it is paramount that a service be checked for existence before attempting to use a service interface. Querying for a service is not guarentee to return a service even if it was available at some point. A service may have been available at the time of writing but it may not be available when a version of the EiffelStudio product is released. Many reasons exist for the tentative nature of a service, ranging from research, insufficient stability to meet the release deadline or deprecation. Building functionality around services should always respect the tentative nature and work to the best abilities, or restrict functionality, without the service in place. Service consumers can help.
Using Consumers
The service consumer class (SERVICE_CONSUMER is generic and requires a generic parameter conforming SERVICE_I (base of all services). Once declared and instantiated the consumer may be used to query the service's existence and then access the service.
Below is a simple example of using the Session Manager Service:
store_state local consumer: !SERVICE_CONSUMER [!SESSION_MANAGER_S] service: !SESSION_MANAGER_S do create consumer if consumer.is_service_available then -- Service is available and can be used consumer.service.retrieve (False) then session.set_value (is_sorted, "com.eiffel.my_tool.sorted") end
Using Local Service Providers
Service consumers are used in place of using a service provider interface (SERVICE_PROVIDER) directly, encapsulating the service and providing safe access to the service through a status function. Creating a service consumer using default_create
as above will make use of the global service heap to fetch a service, based on SERVICE_CONSUMER's generic parameter SESSION_MANAGER_S. If a local service provider is available then creation of a service consumer should always use make_with_provider
creation routine, because the local service provider may restrict or proffer services not available in the global service heap.
service_provider: !SERVICE_PROVIDER -- Local service provider store_state local consumer: !SERVICE_CONSUMER [!SESSION_MANAGER_S] do -- Create service consumer with the local service provider of Current create consumer.make_with_provider (service_provider) if consumer.is_service_available then ... end end