This page shows how to control the order in which activities are processed by a service.
A request component is either an activity, a flow or a sequence.
Flow components contain one or more subcomponents that are processed in parallel. A subcomponent is usually an activity (or more precisely, a string of connected activities) but it can also be another flow or sequence component, i.e. flows can be nested.
Sequence components contain one or more subcomponents that are processed in sequence. A subcomponent can either be a string of connected activities or another flow or sequence component.
A flow contains a number of request components which are processed in parallel by the server.
SQLUpdate update1 = new SQLUpdate("insert into littleblackbook (id, name) values ('99998', 'Alice')"); SQLUpdate update2 = new SQLUpdate("insert into littleblackbook (id, name) values ('99999', 'Bob')");
Flow flow = new Flow();
flow.addChild(update1); flow.addChild(update2);Since the activities will be processed at the same time it doesn't matter in which order they are added to the flow.
service.perform(flow);
A sequence contains a number of request components which are processed sequentially by the server.
Say you'd like to do the following: Create a new table in a data resource, bulk load some data into the table and then query the data. Obviously, the bulk load cannot start before the table has been created. Likewise, the query should not commence before the data has been loaded into the new table.
You could solve the problem by sending three requests to a service:
This however means that you are sending three requests to the service - three requests go over the network which the associated communications overheads this incurs. It would be nicer if we could specify these activities in a single request:
while being reassured that the query will not run until the bulk load has finished and that the bulk load won't start until the table has been created. This is where the sequence component comes in - we make our three activities components of a single request and have a guarantee that they will be executed strictly in sequence.
Sequence components are used as follows.
Sequence sequence = new Sequence();
SQLUpdate create = new SQLUpdate("create table mytable (id integer, number integer)); SQLQuery query1 = new SQLQuery("select id, phone from littleblackbook where name like '%Krause'"); WebRowSet rowset1 = new WebRowSet(query1.getOutput()); SQLBulkLoad bulkload = new SQLBulkLoad( rowset1.getOutput(), "mytable" ); SQLQuery query2 = new SQLQuery(select count(*) from mytable); WebRowSet rowset2 = new WebRowSet(query2.getOutput());
sequence.addChild(create); sequence.addChild(query1); sequence.addChild(rowset1); sequence.addChild(bulkload); sequence.addChild(query2); sequence.addChild(rowset2);
SQLQuery query3 = new SQLQuery("select * from mytable"); sequence.insertChild(2, query3);
sequence.removeChild(query3);
sequence.removeChild(2);
Back: Updates and Bulk Load | Up: Using the Client Toolkit | Next: Obtaining Meta Data |
© International Business Machines Corporation, 2002-2006 | © The University of Edinburgh, 2002-2006 |