Service Lifecycle Support

Service Lifecycle is a way to manage life cycle of a particular mashup you deploy in the WSO2 Mashup Server. For example, let's say a user wants a mashup to start execution as soon as a mashup gets deployed. Such situations may be a good example for the usage of service life cycle.The Service Lifecycle support in the WSO2 Mashup Server is powered by the "init" and "destroy" service level annotations. The function referred to by the "init" annotation will be executed when the particullar mashup is been deployed while the function referred to by the "destroy" annotation will be executed when the particullar mashup is been undeployed. You can have a look at the feedCache mashup that ships as a sample with the WSO2 Mashup Server for an illustration of the usage of these annotations.

In addition to the "init" and "destroy" annotation which control what happens when a mashup is deployed or undeployed the Mashup Server provides another usefull annotation called "undispatched". Under normal circumstances when the Mashup Server receives a request it first dispatches the request to the correct service and then to the corresponding operation depending on the information available in the request. There are cases where the Mashup Server would not be able to find the correct operation from the information available in the request. In such cases it would result in a fault been thrown. Users can overcome the above issue by using the " undispatched" annotation. What it basically does is route all undispatched operations that came into that service to this special operation. Please refer the example below for details.

Using the init or destroy annotation

The "init" or "destroy" function can be specified in three different ways. They are as follows

  1. Uisng this annotation in the following manner will make the function you reference reusable within your mashup. Using it in this manner will also make the referenced init function appear in the WSDL. For example if you deploy the following mashup, the corresponding WSDL will have a operation called myInitFunction.
                            //Because the function referenced by init is not a annonymous fucntion it can be reused in a mashup
                            this.init=myInitFunction;
                            function myInitFunction() {
                                // Do some stuff upon deployment
                                system.log("init");
                            }
                        
  2. Uisng this annotation in the following manner will mean that you cannot reuse the functionreferenced by the annotation. Still using it in this manner will make the referenced init function appear in the WSDL. For example if you deploy the following mashup, the corresponding WSDL will have a operation calledmyInitFunction.
                            //The function referenced by init cannot be reused in your mashup
                            this.init = function myInitFunction() {
                                // Do some stuff upon deployment
                                system.log("init");
                            }
                        
  3. Uisng this annotation in the following manner will mean that you cannot reuse the function referenced by the annotation. Furthermore the referenced init function will not appear in the WSDL.
                            //The function referenced by init cannot be reused in your mashup
                            this.init = function () {
                                // Do some stuff upon deployment
                                system.log("init");
                            }
                        

init annotation

The init annotation helps you specify the function that should be executed when a mashup is deployed. Please note that using the session host object from within a init function will not preserve your session. The reason is that the init function is called within the Masup Server and sessions are created when request enter the Mashup Server.

destroy annotation

The destroy annotation helps you specify the function that should be executed when a mashup is undeployed. Please note that using the session host object from within a destroy function will not give you the services session. The reason is that the destroy function is called within the Masup Server and sessions are created when request enter the Mashup Server.

undispatched annotation

All undispatched operations that came into a particullar service will be routed to the operation reffered to by the undispatched annotation. As the Mashup Server should be able to call this function from the requests it receives using this annotation in the third variant defined above is not allowed. The operation referred to be the undispatched annotation should be avaiable in the WSDL.
                this.undispatched = function undispatchedOperation() {
                    // Do something here
                    system.log("undispatched");
                }