• No results found

Business Operation Methods

In document Developing Ensemble Productions (Page 159-162)

A business operation class must provide one or more operation methods, each of which correspond to a specific action to be carried out within an external application. The business operation class determines which method to invoke by means of a message map.

Additionally, a business operation class provides the operation methods OnInit, OnTearDown,

OnProductionStart, and OnProductionStop, each of which has a common signature, as seen in the

following example. The first argument is the incoming request object received by the message queue. The second is used to return an instance of a response object by reference. The operation method returns a %Status value indicating success or failure:

Method MyMethod(pRequest As MyProduction.MyRequest,

Output pResponse As MyProduction.MyResponse) As %Status

{

// invoke a method of our Adapter object Set tSC = ..Adapter.Send(pRequest.Value) // create a response object

Set pResponse = ##class(MyProduction.MyResponse).%New() Set pResponse.Value = 10

Quit tSC }

A business operation class also provides methods to send messages to other business processes or to business operations, as follows: SendRequestSync sends a message synchronously (wait for a response),

SendRequestAsync sends a message asynchronously (do not wait for a response), and

SendDeferredResponse sends a response that was previously deferred by another business operation. Business Operation Methods

7.2.1 The OnInit Method

A business operation class may override the OnInit method. This method is called after the business operation object has been created and its configurable property values have been set. The OnInit method provides a way for a business operation to perform any special setup actions.

Method OnInit() As %Status {

Quit $$$OK }

7.2.2 The OnTearDown Method

A business operation class may override the OnTearDown method. This method is called during shutdown before the business operation object is destroyed. The OnTearDown method provides a way for a business operation to perform any special cleanup actions.

Method OnTearDown() As %Status {

Quit $$$OK }

7.2.3 The OnProductionStart Method

A business operation class may override the OnProductionStart method. This class method is called once for each configured business operation when a production is started. The OnProductionStart method provides a way for a business operation to perform any special business operation-wide setup actions.

ClassMethod OnProductionStart() As %Status {

Quit $$$OK }

7.2.4 The OnProductionStop Method

A business operation class may override the OnProductionStop method. This class method is called once for each configured business operation when a production is stopped. The OnProductionStop method provides a way for a business operation to perform any special business operation-wide cleanup actions.

ClassMethod OnProductionStart() As %Status {

Quit $$$OK }

7.2.5 The SendRequestSync Method

A request is synchronous when the business operation invokes its SendRequestSync method to make the request. A call to SendRequestSync requires the business operation to wait, and do nothing else, until it receives a response from the call. To send a synchronous request from a business operation, use the SendRequestSync method as follows:

Set tSC = ..SendRequestSync(pTargetDispatchName, tRequest, .tResponse)

This method takes the following arguments:

pTargetDispatchName — The configuration name of the business process or business operation

to which the request is sent.

pRequest — Any persistent object, but typically a subclass of Ens.Request. This object contains the data to send with the request.

pResponse — (By reference) Any persistent object, but typically a subclass of Ens.Response. This object receives the data returned by the response.

pTimeout — (Optional) The number of seconds to wait for a response. The default is –1 (wait

forever).

If no response is expected, you can use SendRequestAsync instead of SendRequestSync.

7.2.6 The SendRequestAsync Method

A request is asynchronous when the business operation invokes itsSendRequestAsync method to make the request. A call to SendRequestAsync requires the business operation to “fire and forget” — that is, the request is sent and the business operation continues its next activity without waiting for a response from the call.

To send an asynchronous request from a business operation, use the SendRequestAsync method as follows:

Set tSC = ..SendRequestAsync(pTargetDispatchName, tRequest)

This method takes the following arguments:

pTargetDispatchName — The configuration name of the business process or business operation

to which the request is sent.

pRequest — Any persistent object, but typically a subclass of Ens.Request. This object contains the data to send with the request.

7.2.7 Deferred Response Methods

This topic describes the methods that business operations provide to support deferred response: For an overview of the feature that explains the role of a business operation, see the Deferred Response

section in the “Ensemble Messages” chapter.

7.2.7.1 The DeferResponse Method

This method returns a %Status value indicating success or failure. It provides one by-reference argument,

token, which returns the deferred response delivery token required for a later call to SendDeferredResponse. For example:

Set sc=..DeferResponse(.token) // Send the token out somewhere... Quit $$$OK

7.2.7.2 The SendDeferredResponse Method

A business operation can request information from an external system and then use this information to construct a deferred response. In this case, upon receiving the external data the business operation would call SendDeferredResponse to construct a response message and direct it to the caller that originated the request. The SendDeferredResponse call would look like this:

Set sc = ..SendDeferredResponse(token, pResponseBody)

SendDeferredResponse takes the following arguments:

token — A string that identifies the deferred response so that the caller can match it to the original

request. The business operation obtains the token string through some mechanism unique to the production.

pResponseBody — Any persistent object, but typically a subclass of Ens.Response. This object contains the actual response message.

In document Developing Ensemble Productions (Page 159-162)