Difference between revisions of "Service Consumers"
m (Removed attachment marks from code examples, because this is not correct.) |
(Removed attachment marks) |
||
Line 12: | Line 12: | ||
store_state | store_state | ||
local | local | ||
− | consumer: | + | consumer: SERVICE_CONSUMER [SESSION_MANAGER_S] |
service: !SESSION_MANAGER_S | service: !SESSION_MANAGER_S | ||
do | do | ||
Line 18: | Line 18: | ||
if consumer.is_service_available then | if consumer.is_service_available then | ||
-- Service is available and can be used | -- Service is available and can be used | ||
− | if { | + | if attached {SESSION_I} consumer.service.retrieve (False) as session then |
session.set_value (is_sorted, "com.eiffel.my_tool.sorted") | session.set_value (is_sorted, "com.eiffel.my_tool.sorted") | ||
end | end | ||
Line 28: | Line 28: | ||
<eiffel> | <eiffel> | ||
− | service_provider: | + | service_provider: SERVICE_PROVIDER |
-- Local service provider | -- Local service provider | ||
store_state | store_state | ||
local | local | ||
− | consumer: | + | consumer: SERVICE_CONSUMER [SESSION_MANAGER_S] |
do | do | ||
-- Create service consumer with the local service provider of Current | -- Create service consumer with the local service provider of Current |
Revision as of 14:48, 3 April 2009
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 guaranteed 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 if attached {SESSION_I} consumer.service.retrieve (False) as session then session.set_value (is_sorted, "com.eiffel.my_tool.sorted") end 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