GNDMS 0.6.0
RESTful verison of GNDMS
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes

de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient Class Reference

Performs all requests necessary for taskflow execution. More...

Inheritance diagram for de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient:
de.zib.gndms.gndmc.gorfx.ExampleTaskFlowExecClient

List of all members.

Public Member Functions

void execTF (Order order, String dn)
 Executes a complete task flow.
void execTF (Order order, String dn, boolean withQuote, final Quote desiredQuote)
 Executes a complete task flow.
GORFXClient getGorfxClient ()
 Delivers the value of ::gorfxClient.
void setGorfxClient (GORFXClient gorfxClient)
 Sets the value of ::gorfxClient to gorfxClient.
TaskFlowClient getTfClient ()
 Delivers the value of ::tfClient.
void setTfClient (TaskFlowClient tfClient)
 Sets the value of ::tfClient to tfClient.
TaskClient getTaskClient ()
 Delivers the value of ::taskClient.
void setTaskClient (TaskClient taskClient)
 Sets the value of ::taskClient to taskClient.
long getPollingDelay ()
 Delivers the value of ::pollingDelay.
void setPollingDelay (long pollingDelay)
 Sets the value of ::pollingDelay to pollingDelay.

Protected Member Functions

GNDMSResponseHeader setupContext (final GNDMSResponseHeader context)
 Offers implementing clients the possibility to add values to the request context.
abstract void handleStatus (TaskStatus stat)
 Handler method for the current task status.
abstract Integer selectQuote (List< Specifier< Quote >> quotes)
 Allows the caller to select a quote.
abstract void handleTaskSpecifier (Specifier< Facets > ts)
 Allows additional handling for the task specifier.
abstract void handleResult (TaskResult res)
 Handler for the task result.
abstract void handleFailure (TaskFailure fail)
 Handler for task failures.

Private Member Functions

boolean finished (TaskStatus ts)
 Checks if ts is FINISHED.
boolean failed (TaskStatus ts)
 Checks if ts is FINISHED.

Private Attributes

GORFXClient gorfxClient
 A ready to uses instance of the gorfx client.
TaskFlowClient tfClient
 A ready to uses instance of the taskflow client.
TaskClient taskClient
 A ready to uses instance of the task client.
long pollingDelay = 1000
 delay in ms to poll the task status, once the task is running.

Detailed Description

Performs all requests necessary for taskflow execution.

Author:
try ma ik jo rr a zib
Date:
14.03.11 11:38 To put the caller in control over the taskflow this class provides handler methods for the result of imported calls.
Note:
The handler methods are only called if the preceding server response was positive.

Member Function Documentation

void de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient.execTF ( Order  order,
String  dn 
)

Executes a complete task flow.

Parameters:
orderThe order of the taskflow.
dnThe DN of the user calling the task flow.
Note:
for now the workflow id is generated on the fly.
void de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient.execTF ( Order  order,
String  dn,
boolean  withQuote,
final Quote  desiredQuote 
)

Executes a complete task flow.

This method is imported when you want to understand the Taskflow protocoll.

Parameters:
orderThe order of the taskflow.
dnThe DN of the user calling the task flow.
Note:
for now the workflow id is generated on the fly.
Parameters:
withQuoteActivates co-scheduling
desiredQuoteA quote holding desired time values for the tasflow execution.

 this is imporant
         */              

        // sends the order and creates the task flow
        ResponseEntity<Specifier<Facets>> res = gorfxClient.createTaskFlow( order.getTaskFlowType(), order, dn, wid, context );

        if ( !HttpStatus.CREATED.equals( res.getStatusCode() ) )
            throw new RuntimeException( "createTaskFlow failed " + res.getStatusCode().name() );

        // the taskflow id is stored under "id" in the urlmap
        String tid = res.getBody().getUriMap().get( "id" );

        Integer q = null;
        if( withQuote ) {
            if( desiredQuote != null ) {
                tfClient.setQuote( order.getTaskFlowType(), tid, desiredQuote, dn, wid );
            }
            // queries the quotes for the task flow
            ResponseEntity<List<Specifier<Quote>>> res2 = tfClient.getQuotes( order.getTaskFlowType(), tid, dn, wid );

            if ( !HttpStatus.OK.equals( res2.getStatusCode() ) )
                throw new RuntimeException( "getQuotes failed " + res2.getStatusCode().name() );

            // lets the implementors of this class choose a quote
            q = selectQuote( res2.getBody() );
        }

        //
        // 'til here it is valid to change the order and request new quotes
        // 
        
        // accepts quote q and triggers task creation
        ResponseEntity<Specifier<Facets>> res3 = tfClient.createTask( order.getTaskFlowType(), tid, q, dn, wid );

        if(! HttpStatus.CREATED.equals( res3.getStatusCode() ) )
            throw new RuntimeException( "createTask failed " + res3.getStatusCode().name() );

        // let the implementor do smart things with the task specifier
        handleTaskSpecifier( res3.getBody() );
        
        // the task id is stored under "taskId" in the specifiers urlmap
        String taskId = res3.getBody().getUriMap().get( "taskId" );

        ResponseEntity<TaskStatus> stat;
        TaskStatus ts;
        do {
            // queries the status of the task execution
            stat = taskClient.getStatus( taskId, dn, wid );
            if(! HttpStatus.OK.equals( stat.getStatusCode() ) )
                throw new RuntimeException( "Task::getStatus failed " + stat.getStatusCode().name() );
            ts =  stat.getBody();

            // allows the implementor to do something with the task status
            handleStatus( ts );
            try {
                Thread.sleep( pollingDelay );
            } catch ( InterruptedException e ) {
                throw new RuntimeException( e );
            }
        } while( !(  finished( ts ) || failed( ts ) ) ); // run 'til the task hits a final state

        // finished without an error, good 
        if( finished( ts ) ) {
            // collect the result
            ResponseEntity<TaskResult> tr = taskClient.getResult( taskId, dn, wid );
            if(! HttpStatus.OK.equals( tr.getStatusCode() ) )
                throw new RuntimeException( "Failed to obtain task result " + tr.getStatusCode().name() );

            // do something with it
            handleResult(  tr.getBody() );

        } else  { // must be failed, not so good
            // find out way
            ResponseEntity<TaskFailure> tf = taskClient.getErrors( taskId, dn, wid );
            if(! HttpStatus.OK.equals( tf.getStatusCode() ) )
                throw new RuntimeException( "Failed to obtain task errors " + tf.getStatusCode().name() );

            // handle the failure
            handleFailure( tf.getBody() );
        }

        /**

boolean de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient.failed ( TaskStatus  ts) [private]

Checks if ts is FINISHED.

Parameters:
tsThe current task state.
Returns:
true if ts is FINISHED
boolean de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient.finished ( TaskStatus  ts) [private]

Checks if ts is FINISHED.

Parameters:
tsThe current task state.
Returns:
true if ts is FINISHED
GORFXClient de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient.getGorfxClient ( )

Delivers the value of ::gorfxClient.

Returns:
The value of ::gorfxClient.
long de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient.getPollingDelay ( )

Delivers the value of ::pollingDelay.

Returns:
The value of ::pollingDelay.
TaskClient de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient.getTaskClient ( )

Delivers the value of ::taskClient.

Returns:
The value of ::taskClient.
TaskFlowClient de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient.getTfClient ( )

Delivers the value of ::tfClient.

Returns:
The value of ::tfClient.
abstract void de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient.handleFailure ( TaskFailure  fail) [protected, pure virtual]

Handler for task failures.

Override this method to gain access to the task(flow) error object, e.g. to send an error-report to someone who cares.

Parameters:
failThe failure object.

Implemented in de.zib.gndms.gndmc.gorfx.ExampleTaskFlowExecClient.

abstract void de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient.handleResult ( TaskResult  res) [protected, pure virtual]

Handler for the task result.

Override this method to gain access to the task(flow) result an send it to the user, post process it or store it for later usage.

Parameters:
resThe result object.

Implemented in de.zib.gndms.gndmc.gorfx.ExampleTaskFlowExecClient.

abstract void de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient.handleStatus ( TaskStatus  stat) [protected, pure virtual]

Handler method for the current task status.

This method can be used to delegate the current task progress to the user.

Parameters:
statThe current task status.

Implemented in de.zib.gndms.gndmc.gorfx.ExampleTaskFlowExecClient.

abstract void de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient.handleTaskSpecifier ( Specifier< Facets ts) [protected, pure virtual]

Allows additional handling for the task specifier.

Parameters:
tsThe task specifier, including all task facets as payload.

Implemented in de.zib.gndms.gndmc.gorfx.ExampleTaskFlowExecClient.

abstract Integer de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient.selectQuote ( List< Specifier< Quote >>  quotes) [protected, pure virtual]

Allows the caller to select a quote.

Parameters:
quotesAll available quotes.
Returns:
The index of the accepted quote. null will disable quote usage.

Implemented in de.zib.gndms.gndmc.gorfx.ExampleTaskFlowExecClient.

void de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient.setGorfxClient ( GORFXClient  gorfxClient)

Sets the value of ::gorfxClient to gorfxClient.

Parameters:
gorfxClientThe new value of ::gorfxClient.
void de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient.setPollingDelay ( long  pollingDelay)

Sets the value of ::pollingDelay to pollingDelay.

Parameters:
pollingDelayThe new value of ::pollingDelay.
void de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient.setTaskClient ( TaskClient  taskClient)

Sets the value of ::taskClient to taskClient.

Parameters:
taskClientThe new value of ::taskClient.
void de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient.setTfClient ( TaskFlowClient  tfClient)

Sets the value of ::tfClient to tfClient.

Parameters:
tfClientThe new value of ::tfClient.
GNDMSResponseHeader de.zib.gndms.gndmc.gorfx.AbstractTaskFlowExecClient.setupContext ( final GNDMSResponseHeader  context) [protected]

Offers implementing clients the possibility to add values to the request context.

The request context is used to create taskflows and the right place to provide myProxyTokens.

Parameters:
contextThe create request context.
Returns:
The augmented context

The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables Enumerations