Web Services Integration Patterns, Part 2
by Massimiliano Bigatti
|
Pages: 1, 2, 3, 4, 5
Flow Logger
Input and output from the services involved in the process is logged in a database table

The flow logger works at the coordination level, storing the status of a process that uses several services.
When it comes to coordination of network resources, even the simpler process could raise execution failures. The following simple process is modeled after a real-world services coordination case (in original, of about a dozen services call):
| State | Operation/Service |
|---|---|
| 1 | CREATE |
| 2 | INIT |
| 3 | ADD A |
| 4 | ADD B |
| 5 | ADD C |
| 6 | MODIFY B |
| 7 | MODIFY C |
| 8 | CLOSE |
The CREATE service create a new account, which is therefore INITialized; the program then ADD some elements, editing some others, and close the process with the CLOSE method. The correlation between calls is obtained by the application, passing a token from one call to another.
When an exception is thrown during a service call, the coordination could call a ROLLBACK service which clean the intermediate state of the account being created; the flow logger stores the calling sequence and the point where the problem occourred.
Note that transactional behavior is not comprised in base technologies used for Web Services like SOAP, WSDL, UDDI, XML-RPC or REST (but standards are emerging, like WS-Transaction), so commit/rollback features has to be developed at the application level.
The Flow Logger manages the access to the table used to track the operation flow, maybe using a DAO. The Service Coordinator organize the services in a process. Every time a service returns correctly, with a complete response or a Fault, the Flow Logger writes a record in the log table.
Sample code
Below you can see an exampleFlowLogger interface. It
specifies a track() method that is used to store the
current state in the database. The implementation will create a row
for each call to this method. The integer key distinguishes
different calls to the same process, when executed concurrently by
different users on different data.
public interface FlowLogger {
public int track( int key, String currentState );
}
The AccountCreateCoordinator class models the process
shown in the table afterwards. Each single call is wrapped inside a
method, that logs the specific call. Each method could raise a
ServiceException, breaking the process in the middle
and returing the control to the caller.
public class AccountCreateCoordinator {
FlowLogger flowLogger;
int accountId;
...
public void createAccount( AccountData data ) throws ServiceException {
this.data = data;
create();
init();
addA();
...
close();
}
public void create() throws ServiceException {
CreateService createService = new CreateService();
createService.setKey( data.key );
createService.setType( data.type );
createService.setName( data.name );
createService.setSurname( data.surname );
create.call();
accountId = createService.getAccountId();
flowLogger.track( data.key, "CREATE" );
}
...
}
