-
Notifications
You must be signed in to change notification settings - Fork 44
Wrapper's life cycle
##Wrapper's Life Cycle
An instance of a wrapper is created whenever a Wrapper Connection Request (WCR) is received by the Wrappers Repository (WR). The WCRs are generated whenever GSN wants to activate a new virtual sensor. A WCR is generated for each stream source in the virtual sensor.
A Wrapper Connection Request is an object which contains a wrapper name and its initialization parameters as defined in the Virtual Sensor. Therefore, two WCRs are identical if their wrapper name and initialization parameters are the same. The Wrappers Repository in a GSN instance is a repository of the active wrapper instances indexed by their WCRs.
Whenever a WCR is generated at the virtual sensor loader, it will be sent to the wrapper repository which does the following steps.
- Look for a wrapper instance in the repository which has the identical WCR. If found, WR registers the stream-source query with the wrapper and returns true.
- If there is no such WCR in the repository, the WR instantiates the appropriate wrapper object and calls its initialize method. If the initialize method returns true, WR will add the wrapper instance to the WR. Back to Step 1.
- If there is no WCR in the repository and the WR can not initialize the new wrapper using the specified initialization parameters and GSN context (e.g., the initialize method returns false), WR returns false to the virtual sensor loader. When the virtual sensor loader receives false, it tries the next wrapper (if there is any). The virtual sensor loader fails to load a virtual sensor if at least one of the stream sources required by an input stream fails.
The two main reasons behind using the wrappers repository are:
- Sharing the processing power by performing query merging.
- Reducing the storage when several stream sources use the same wrappers.
- The Wrapper Disconnect Request (WDR) is generated at the virtual-sensor-loader whenever GSN wants to release resources used by a virtual sensor. Typically, when the user removes a virtual sensor configuration while GSN is running, the virtual-sensor-loader generates a WDR for each stream source that was previously used by this virtual sensor.
When WR receives a WDR request, it de-registers the stream-source query from the wrapper. If after removing the stream source query from the wrapper, there are no queries registered with this wrapper (e.g., no other stream source is using the considered wrapper), WR calls the finalize method of the wrapper instance so that all its allocated resources will be released.