In this case study, the scenario is a composition of services to manipulate a text docu-ment. Firstly, the contents of the text document contents are translated to a specified language by a document translation service. Then, the document is given to another service in order to be converted to a format suitable for the available printers. Finally, the resulting document is sent to the available printer services to be printed.
The goal of this scenario is to demonstrate the use of service abstraction (uses), par-allel composition (|), service allocation (all), exception handling (catch), and service re-execution (retry).
We now present the settings for this case study, also the SAL and SUL components used, and the main class file with the composition for this demonstration.
5.2.1 Scenario Settings
The execution environment setting for this scenario is as follows. One jUDDI registry that contains three available printer services, one document translation service, and two document converter services. At runtime, after invoking all services, the bindings for the translation service and the printers are broken. The application is expected to recover and create new bindings to other equivalent services registered in jUDDI.
In this subsection, we present the SAL and SUL components for this scenario, and the main file coordinating the services. Listing 5.1 illustrates a possible SAL definition for a document translation service. The SAL definition implements the Translation interface, presented in Listing 5.2.
Listing 5.1: SAL - TextTranslation
s e r v i c e T e x t T r a n s l a t i o n implements T r a n s l a t i o n { t y p e = " doc " ,
i n p u t i n { " e n g l i s h " , " f r e n c h " , " german " } , o u t p u t i n { " portuguese " }
}
Listing 5.2: Translation interface
p ub li c i n t e r f a c e T r a n s l a t i o n {
byte[ ] t r a n s l a t e (byte[ ] doc , S t r i n g i n _ l a n g , S t r i n g o u t _ l a n g ) ; }
The SUL file to use the document translation service is presented on Listing 5.3, and the correspondent generated code for this component is illustrated on Appendix A.6.
Listing 5.3: SUL - TestTranslator
Listing 5.4 illustrates a SAL definition for a possible document converter service, it implements theConverter interface shown in Listing 5.5.
Listing 5.4: SAL - DocumentConverter
Listing 5.6 illustrates the SUL file for a document converter application. The gener-ated code for this SUL component is listed on Appendix A.7.
Listing 5.6: SUL - TestConverter
Listing 5.7 illustrates a SAL definition for a possible document printer service. The SAL definition implements thePrinter interface presented in Listing 5.8.
Listing 5.7: SAL - ColorPrinter
Listing 5.9 illustrates the SUL file for a printer application. The correspondent gen-erated code for this component is illustrated on Appendix A.8.
Listing 5.9: SUL - TestPrinter
17 / / re-execute service, waits 4 seconds then re-executes once
18 r e t r y 1 i n 4 ;
19 }
5.2.2 Execution
Listing 5.10 illustrates the main file containing the composition of services and se-quence of actions that are used in this scenario.
Listing 5.10: DocumentManipulationScenario class
1 import j a v a . i o . F i l e ;
2
3 p ub li c class DocumentManipulationScenario {
4
5 p ub li c void run ( S t r i n g f i l e n a m e ) {
6 F i l e f = new F i l e ( f i l e n a m e ) ;
7
8 T e s t T r a n s l a t o r t r a n s l a t o r = n u l l;
9 T e s t C o n v e r t e r c o n v e r t e r = n u l l;
10 T e s t P r i n t e r p r i n t e r = n u l l;
11
12 / / get text from document
13 byte[ ] doc = U t i l s . g e t B y t e s F r o m F i l e ( f ) ;
27 / / breaking the binding for translate and printer
28 / / calling the services again
29
TheDocumentScenarioManipulation class defines a possible configuration for us-ing the three generated classes of services. First, the translation service is executed, it translates the given document, in byte array, from English to Portuguese language, returning also a byte array. In line 16 thenewconstruct creates a new instance of Test-Translator class and obtains service bindings from the middleware. Then in line 17 the translation service is executed, returning the document in the desired language.
Secondly, the document is sent to a document converter service, lines 20-21, in or-der to convert the document fromdoctopdfformat. Finally, the document is sent to a printing service. TheTestPrinter class demonstrates the use of parallel composition (|), the document is sent to print in two different printers at the same time.
Service Discovery at Runtime
In this case, the TestPrinter did not perform a service search during the compila-tion phase. So, when a new instance of this class is created thegetServiceBindings() operation in line 18 of Appendix A.8 involves a service discovery process to retrieve
available service instances. Two different printers are found that match given proper-ties.
Handling Broken Bindings
After executing all three services the bindings for the translation and printer ser-vices are broken, the Web Serser-vices currently executing translation and printing oper-ations are terminated. Invoking these services again will result in failure, lines 21-26 on Appendix A.6 ofTestTranslator class show that when a service invocation failure occurs, the index of service instances list is stored and a boolean variable is set totrue.
The former is used in the middleware during service replacement to replace the fail-ing instance, in theServiceAppProperties class, with the new replacement. The latter is used in line 27 to check if a failure occurred, in order to trigger the service bind-ing replacement process (lines 30-31). A new bindbind-ing is established for the translation service and the service is executed as if no error occurred for the user.
The same process is realized in the TestPrinter class, lines 40-41 on Appendix A.8 show the service replacement. Regarding the printer service, the registry returns only one service different from the services that failed. This new instance is used in both invocations of the parallel composition. The document is sent twice for printing in the same printer. Only during document printing we became aware that just one printer service is available.
The case study demonstrated the use of service abstraction, parallel composition, service allocation, exception handling and service re-execution.