| Developing with the SDK > Using and Writing Data Models > Content on Demand |
Content on Demand |
INDEX
PREVIOUS
NEXT
|
The content on demand feature allows an SDM model to delay the loading of its objects content in order to save resources. Unlike a tiling system, content on demand requires that all the objects be present in the model. The objects can be empty. Content on demand sends a notification when the content of a set of objects needs to be loaded, and, optionally, when it can be unloaded. Assuming that empty model objects have low memory and time footprints, content on demand allows you to fill them on demand and empty them when they are no more needed.
Content on demand addresses two main use cases:
The classes of the content on demand feature are located in the package ilog.views.sdm.modeltools. The entry point is the class ilog.views.sdm.modeltools.IlvContentController.
A content on demand sample is available in <installdir>jviews-diagrammer81/samples/diagrammer/content-on-demand/index.html.
The content on demand feature operates at the granularity of SDM model objects. The content controller maintains a state for each model object. A model object can be in one of three states:
The state changes after events, such as a user request, a zoom or a pan change (in fact visible area changes), have taken place. The controller then sends a notification to explicitly load or unload a set of objects.
Usually, the lifecycle of an object content is: unloaded, then locked, then loaded, then potentially back to unloaded.
The cache is virtual. The object content is held in the SDM model. When the state changes to loaded, this simply means that the content remains in the model. As a matter of fact, the SDM model implements the cache for the object content, and the controller manages this cache.
The controller contains the states of the objects as well as a handler that processes the load and unload commands.
Extreme values for the cache size have a radical impact on the content on demand behavior.
For other cache size values, the objects are loaded when locked and remain in the cache until they are flushed (FIFO way) to keep the average memory size close to constant. Note that when objects are requested to be locked, they are loaded before the cache is purged to avoid unloading an object that is going to be locked again. This means that the cache can temporarely be larger that the expected size.
A locking request is an event sent to the controller to lock, load or unload objects. There are two types of event:
Both types of event are non exclusive: An area event may be followed by a set event, and conversely.
The controller does not know by itself how to load the content of SDM model objects. On request, it calls a handler, ilog.views.sdm.modeltools.IlvContentHandler, that performs the load and unload actions by upgrading the SDM model. Then, the usual SDM model notifications take over to customize and refresh the graphic representations.
A load event is sent when the object state changes from unloaded to locked or loaded. An unload event is sent when the object state changes from locked or loaded to unloaded. No notification is sent when the state changes from loaded to locked.
The handler is able to work asynchronously, that is, if the controller asks to load an object, the handler marks the object as locked while the object may be loaded in a separate thread. In any case, the handler must notify the SDM model when the action is complete. The locking requests are synchronized, so that the handler holds the controller synchronization lock until completion of the event.
The controller is aware of SDM model structural changes when:
IlvSDMEngine.setModel() sets a new model: All the objects are unloaded without notification to the handler.
To summarize, the controller forgets about the obselete objects of the model.
Using the content on demand feature involves the following steps:
setCacheSize(int size) method to change the cache value.
lockArea(IlvRect area, int mode) Locks the objects that intersect with the given rectangle. The class ilog.views.sdm.modeltools.IlvVisibleAreaListener provides a view listener that locks automatically the visible area of an SDM view (see below). The mode indicates the treatment to apply to previously locked objects. The allowed values are:
IlvContentHandler.OVERRIDE Previously locked objects are unlocked.
IlvContentHandler.AUGMENT Previously locked objects remain locked.
processObjects(Object[] objects, int action) Locks, loads, or unloads the given objects, according to the action value, which can be one of:
IlvContentHandler.LOCK Lock action.
IlvContentHandler.UNLOCK Unlock action (once unlocked, objects can be unloaded at any time).
IlvContentHandler.UNLOAD Unload action.
processObjects(Enumeration objects, int action) Similar to the previous method but objects are defined in an Enumeration.
processObjects(Iterator objects, int action) Similar to the previous method but objects are defined in an Iterator.
processAllObjects(int action) Similar to the previous method but operates on all objects.
All these methods are synchronized and return an integer which represents the number of objects that have switched to the requested state.
The following method retrieves the current state (LOCK/UNLOCK/UNLOAD) of an object in the controller. Depending on the handler implementation (typically, if actions are performed in a different thread), the state may differ from reality, for example, a content is not available although the state is LOCK.
Other methods of the IlvContentController class:
IlvSDMEngine getSDMEngine() Returns the SDM engine.
IlvContentHandler getContentHandler() Returns the content handler.
void setNotificationEnabled(boolean on) If on is false, the handler is not notified.
boolean isNotificationEnabled() Returns whether notifications are enabled.
int getLockedCount() Returns the number of locked objects.
int getLoadedCount() Returns the number of objects in the cache.
The IlvContentHandler interface defines the following methods:
loadContent(IlvContentControler source, Object[] objs) Loads the content of the given objects into the SDM model.
unloadContent(IlvContentControler source, Object[] objs) Unloads the content of the given objects into the SDM model.
The source argument indicates the controller that sends the request.
The IlvVisibleAreaListener class computes the visible area of a view as it changes and sends it as a request to the controller. The constructor takes the controller as parameter. To start listening to the visible area changes on a view, call the method:
Example of use:
IlvVisibleAreaListener l = new IlvVisibleAreaListener(contentControler); l.installListener(contentControler.getSDMEngine().getReferenceView());
The method requestAreaToLock can be subclassed to control the area to lock, as follows:
int requestAreaToLock(IlvRect area) Called when the view transformer has changed. The default implementation simply calls the controller method lockArea(area, OVERRIDE) and returns the number of objects that have been loaded.
The content on demand feature is similar to a tiling system, such as ilog.views.tiling, with the following major differences:
| Copyright © 1987-2007 ILOG S.A. All rights reserved. Documentation homepage. Legal terms. | PREVIOUS NEXT |