Difference between revisions of "Service Consumers"

m (Corrected example code)
m (Using Consumers: Removed unused local in code snippet.)
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
[[Category:EiffelStudio Services]]
 
[[Category:EiffelStudio Services]]
Services consumers are a simplest and safest means to use [[Griffin]]-based services from within [[EiffelStudio]].
+
Services consumers are a simplest and safest means to use [[Griffin]]-based services from within [[:Category:EiffelStudio|EiffelStudio]].
  
 
== Services Are Tentative ==
 
== 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.
+
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 [[:Category:EiffelStudio|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 ==
 
== Using Consumers ==
Line 12: Line 12:
 
store_state
 
store_state
 
   local
 
   local
     consumer: !SERVICE_CONSUMER [!SESSION_MANAGER_S]
+
     consumer: SERVICE_CONSUMER [SESSION_MANAGER_S]
    service: !SESSION_MANAGER_S
+
 
   do
 
   do
 
     create consumer
 
     create consumer
 
     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 {session: !SESSION_I} consumer.service.retrieve (False) then
+
       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 27:
  
 
<eiffel>
 
<eiffel>
service_provider: !SERVICE_PROVIDER
+
service_provider: SERVICE_PROVIDER
 
   -- Local service provider
 
   -- Local service provider
  
 
store_state
 
store_state
 
   local
 
   local
     consumer: !SERVICE_CONSUMER [!SESSION_MANAGER_S]
+
     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

Latest revision as of 02:44, 27 September 2012

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]
  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