|Version 17 (modified by nliampotis, 4 years ago)|
- Context Management
- 3P API
- Context Admin GUI
This section provides guidelines regarding the use of the PSS Context Management facilities by 3rd party or platform context-aware service developers. The Context Management (CM) component block acts as an intermediate layer between context-aware services and the sources of context information.
An outline of the CM components follows:
- Context Broker: Provides context consumers with the ICtxBroker interface which provides methods for retrieving, adding, removing, and updating context data.
- Context Reasoning: Uses probabilistic methods in order to derive high-level context information based on raw sensor data and/or context history.
- Context History Management: Collects, maintains and processes historic context data.
- Context DB Management: Translates context queries into standard SQL queries which are then executed in the underlying databases.
- Context Source Management: Manages context sources and collects their information.
# Is this the MASTER Context DB? - valid only for the PSS-extended distribution org.personalsmartspace.cm.broker.id.master=false # The type of the PSS operator, e.g. 'person' or 'organisation' org.personalsmartspace.cm.db.operator.type=person # The DBMS for Context DB, i.e. 'derby' or 'mysql' org.personalsmartspace.cm.db.connection.dbms=derby # The Context DB name org.personalsmartspace.cm.db.connection.dbname=ContextDB # The Context DB user org.personalsmartspace.cm.db.connection.username=myuser # The Context DB user password org.personalsmartspace.cm.db.connection.password=mypasswd # Show SQL on stdout? org.personalsmartspace.cm.db.show_sql=false # Show DDL on stdout? org.personalsmartspace.cm.db.show_ddl=false # Reset Context DB? org.personalsmartspace.cm.db.reset=true
The CM supports the following DBMS systems for maintaining current and historic context data:
Apache Derby (embedded)
The jar providing the embedded Apache Derby driver is included in the ContextDBMgmt OSGi bundle so no special configuration or installation of non-PSS software is required.
MySQL server v5.1 with InnoDB support
Installation of MySQL server v5.1 is required. After connecting to the MySQL server as root, you can add the account for the Context DB as follows:
mysql> GRANT ALL PRIVILEGES ON ContextDB.* TO 'myuser'@'localhost' -> IDENTIFIED BY 'mypasswd';
- The MySQL server must be configured to listen on the standard MySQL port (i.e. 3306) on localhost.
- Debian-based systems might be affected by #560044 (use the bug report instructions as a possible workaround).
The context modelling requirements of PSSs are fullfiled be the Context Model, which includes all the interfaces and classes that model the context information to be retrieved, exchanged, maintained and managed in general. The core concept upon which the context model is built is the ICtxEntity. An ICtxEntity represents an object of the physical or conceptual world. For example an ICtxEntity could be a person, a device, or a service.
An ICtxEntity’s properties are described by the ICtxAttribute interface. Consequently many ICtxAttribute objects might be assigned to an ICtxEntity. Concepts such as the name, the age, and the location of a person are described by different ICtxAttributes. Similarly, ICtxAttributes describing a device’s properties might be the identity, the voltage, and the operational status of the device. Furthermore, an ICtxAttribute incorporates Quality of Context properties which are accessible through the ICtxQuality interface.
Relations that may exist among different entities are described by the ICtxAssociation interface. ICtxEntities might be associated by two possible ways: “peer relations” and “non-peer relations”. A “peer relation” among ICtxEntities is described by the concept of the undirected ICtxAssociation, while a “non-peer relation” among ICtxEntities is described by the concept of the directed ICtxAssociation. In the latter, only one of the associated ICtxEntities can be the originating point and is then called parent entity, while many entities could be the target points and are then called child entities. On the other hand, the undirected ICtxAssociation represents relations among peer entities, where there is no owner or parent entity. Example types of directed associations are: “owns”, “uses”, “locatedIn”, while types of non-directed associations are: “friends”, “schoolmates”, “fellow passengers”, “colleagues”, etc.
A developer can create, update, retrieve and remove context model objects by using methods provided by the ICtxBroker interface.
Creating context model objects
//Create an ICtxEntity ICtxEntity ctxEntity = ctxBroker.createEntity(“PERSON”); //Create an ICtxAssociation ICtxAssociation ctxAssociation = ctxBroker.createAssociation(“AssociationType”); //Create an ICtxAttribute – necessary to be assigned to an ICtxEntity ICtxAttribute ctxAttribute = ctxBroker.createAttribute(ctxEntity.getCtxIdentifier(), “NAME”, “Tom”); ICtxAttribute ctxAttribute = ctxBroker.createAttribute(ctxEntity.getCtxIdentifier(), “AGE”, new Integer(37)); ICtxAttribute ctxAttribute = ctxBroker.createAttribute(ctxEntity.getCtxIdentifier(), “HEIGHT”, new Double(179.5)); ICtxAttribute ctxAttribute = ctxBroker.createAttribute(ctxEntity.getCtxIdentifier(), ”Preferences”, prefs); //prefs is a java object that implements the serializable interface
Updating context attributes
Looking-up and retrieving context information
//Generic context object Look up List<ICtxIdentifier> ctxIdentifiers = ctxBroker.lookup(CtxModelType.ENTITY,“PERSON”,); //or List<ICtxIdentifier> ctxIdentifiers = ctxBroker.lookup(CtxModelType.ATTRIBUTE,“Name”); //or List<ICtxIdentifier> ctxIdentifiers = ctxBroker.lookup(CtxModelType.ASSOCIATION,“areFriends”); //Generic context object retrieval, it is used if the identifier of a context model object is known ICtxModelObject modelObj = ctxBroker.retrieve(ctxIdentifier); //or ICtxEntity ent = (ICtxEntity) ctxBroker.retrieve(entityIdentifier); //or List<ICtxModelObject> modelOjects = ctxBroker.retrieve(ctxIdentifiers);
Removing context model objects
Subscribing for context attribute update notifications
Additionally the ICtxBroker interface provides methods for registering for context update events. Upon registration a developer denotes the ICtxEntity identifier that holds the ICtxAttribute and the attribute type that wishes to receive events for. Alternatively the developer can register for update events by using only the ICtxAttribute identifier.
//An event is fired when an update occurs on ICtxAttribute(s) of type “symLoc” that is(are) assigned to the specified ICtxEntity ctxBroker.registerUpdateNotification(myEventListener, ctxEntity.getCtxIdentifier(), "symLoc"); //An event is fired when an update occurs on the specified attribute ctxBroker.registerUpdateNotification(myEventListener, ctxAttribute.getCtxIdentifier());
Maintaining history of context attributes
Context Attributes can be registered for recording each time an update on the attribute value is performed. Old values are recorded along with timestamps and stored in order to form a Context History log. Context History data can be retrieved or removed by methods provided by the ICtxBroker. Additionally a developer can register for recording a group of context attributes. The recording of grouped context attributes will be performed when a primary attribute is updated
//ICtxAttribute’s updates will be recorded in Context History ctxAttribute.setHistoryRecorded(true); //Retrieval of Context history data for a specified time period Map<Date,Serializable> hocData = ctxBroker.retrieveHistory(attributeIdentifier, startDate, endDate); //Recording the value of a CtxAttribute along with the values of a predefined set of other CtxAttributes ctxBroker.setHoCTuples(primaryAttrIdentifier, listOfEscortingAttributeIds); //Retrieval of historic data tuples for a specified time period (to be user for user intent purposes) Map<Serializable,List<Serializable>> hocData = ctxBroker.retrieveHoCTuples (attrId, attributeIds,startDate,endDate);
Context Admin GUI
A Context Management GUI is provided for managing context model objects. This Graphical Interface provides access to most of the described functions above and is provided through the PSS Admin GUI Framework. A screenshot of the GUI follows.
Introduction - Installation - Architecture Overview - Architecture Structural View - Running the example service - Writing your own service - Networking And Service Communication - Using Context management - Using Security and Privacy management features - Determining user intent - Accessing the service recommender - Accessing proactivity features