Amigo ANS tutorial - v2.0
23 pages
English
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Amigo ANS tutorial - v2.0

-

Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
23 pages
English

Description

IST Amigo Project Amigo Training Document: ANS Version 2.0 IST-2004-004182 Public June 2007 Confidential Project Number : IST-004182 Project Title : Amigo Deliverable Type : Tutorial Deliverable Number : Title of Deliverable : Amigo Training Document: ANS Nature of Deliverable : Public Internal Document Number : Contractual Delivery Date : Actual Delivery Date : Contributing WPs : Author(s) : Todor Dimitrov, Edwin Naroska, Jörg Schmalenstroer, Volker Leutnant Abstract This document is a tutorial about using the Awareness and Notification System (ANS) of Amigo. ANS is part of the intelligent user services and provides an easy way to get access to changes in the context of the home environment. ANS provides functionality to allow people/applications to stay aware of context changes. This tutorial briefly introduces how to use ANS, i.e. how to write and ANS client. Keyword list Awareness and Notification System, ANS, ANS client, context Amigo IST-2004-004182 1/22 June 2007 Confidential Table of Contents Table of Contents................................................................................................... 2 1 Introduction..................................................................................................... 3 1.1 Prerequisites..............................................................................................................................3 1.2 How to use this document. ...

Sujets

Informations

Publié par
Nombre de lectures 71
Langue English

Exrait

IST Amigo Project Amigo Training Document: ANS Version 2.0 IST-2004-004182 Public
June 2007
: IST-004182 : Amigo : Tutorial
Confidential
: : Amigo Training Document: ANS : Public : : : : : Todor Dimitrov, Edwin Naroska, Jörg Schmalenstroer, Volker Leutnant
Project Number Project Title Deliverable Type Deliverable Number Title of Deliverable Nature of Deliverable Internal Document Number Contractual Delivery Date Actual Delivery Date Contributing WPs Author(s) Abstract This document is a tutorial about using the Awareness and Notification System (ANS) of Amigo. ANS is part of the intelligent user services and provides an easy way to get access to changes in the context of the home environment. ANS provides functionality to allow people/applications to stay aware of context changes. This tutorial briefly introduces how to use ANS, i.e. how to write and ANS client. Keyword list Awareness and Notification System, ANS, ANS client, context
Amigo IST-2004-004182
1/22
June 2007
Confidential
Table of Contents TableofContents...................................................................................................2 1 Introduction ..................................................................................................... 3 1.1 Prerequisites..............................................................................................................................3 1.2 How to use this document ........................................................................................................ 3 2 System and software requirements ............................................................... 5 2.1 Installing and configuring Oscar ............................................................................................ 5 2.1.1 Installation .......................................................................................................................... 5 2.1.2 GUI.....................................................................................................................................5 2.1.3 Installing bundles ............................................................................................................... 6 2.1.4 Repositories ........................................................................................................................ 7 2.1.5 Stopping Oscar ................................................................................................................... 7 3 Using the Awareness and Notification System ............................................. 8 3.1 Writing an ANS client ........................................................................................................... 8 3.1.1 Looking up the ANS service .............................................................................................. 8 3.1.2 The main component ........................................................................................................ 10 3.1.3 Service activator ............................................................................................................... 14 3.1.4 Clientnotification.............................................................................................................14 3.1.5 Providing rules to ANS .................................................................................................... 15 3.1.6 Service bundle metadata................................................................................................... 16 3.1.7 Client bundle manifest...................................................................................................... 16 3.2 Writing a context source for testing ............................................................................... 17 4 Recommended next steps.............................................................................. 22
Amigo IST-2004-004182
2/22
June 2007
Confidential
1 Introduction This document is a tutorial about using the Awareness and Notification System (ANS) of Amigo. ANS is part of the intelligent user services and provides an easy way to get access to changes in the context of the home environment. ANS provides functionality to allow people/applications to stay aware of context changes. For example, it can inform applications about changes of the current location of a specific user. As a result, the application does not have to query all the various context sources that may provide appropriate location information. Instead, it subscribes to ANS and inject an appropriate rule that is automatically checked by ANS each time context information changes This tutorial briefly introduces how to use ANS, i.e. how to write and ANS client.
1.1 Prerequisites Amigo training blocks typically requires some Amigo related as well as non Amigo related skills or knowledge. These are given in the following:  Non Amigo related prerequisites: o  The reader should be familiar with either Java or C# to easily follow the explanations.o  The reader should be familiar with an integrated development environment (IDE) for the programming language that shall be used. It is suggested to use either Eclipse 3.2 (or higher) for Java or Visual Studio 2005 for C#.  Amigo related prerequisites: o  The reader should be familiar with the Amigo Deployment Framework. To learn about this framework the Using Web Services can be used. The Tutorial can be downloaded from https://gforge.inria.fr/frs/?group_id=160 . o  The reader should also be familiar with using and developing Context Sources. Please read with the CMS Tutorial available from https://gforge.inria.fr/frs/?group_id=160 . For some general information on the Amigo project please refer to the Amigo project web site at http://www.hitech-projects.com/euprojects/amigo/index.htm .
1.2 How to use this document This document aims at providing the reader with valuable information about how to use the Amigo middleware. To this end it gives a step by step introduction where explanations are accompanied with short programming assignments. Please proceed to the document section by section and step by step and try to do the assignments. In order to save some typing, an appropriate set of template files is given that can be used to fulfill the assignments. These template files already include a programming frame that must be extend by you in order to complete the assignment. For information on how where to obtain these template files please refer to Chapter 0. The example below shows how a piece of source code is printed. Note that code blocks are embedded in a box in order to easily separate them from normal text: using ( Service service = new AddService (securedService)) { WebServer .AddWebService(serviceLocation, service); Console .WriteLine( "Sample service 2 running. " + Environment .NewLine + "Press <return> to quit" ); Amigo IST-2004-004182 3/22
June 2007
Console .ReadLine();  } If code is printed in normal text, it is shown in italic .
A
migoIST-2004-004182
Confidential
4/22
June 2007
Confidential
2 System and software requirements For the Java parts of the tutorial you need an installed version of the Java Development Kit, including the javac compiler and the jar tools (Java Version 1.5.x). If your are using Java, then the following additional software is needed:  Java Software Development Kit. This is a general package needed for Java software development. The package is available from http://java.sun.com .  Oscar. Oscar is a open source OSGi framework. This software is also available from http://amigo.gforge.inria.fr/obr/tools/ . Please note that it may be required to de-activated the firewall on the computer that shall run the test server. A set of template files have been prepared in order to help you running the practical parts of this tutorial. It is recommended that you use this templates. A package that includes this template along with some other files an be downloaded from https://gforge.inria.fr/frs/?group_id=160 .
2.1 Installing and configuring Oscar Oscar is an open source implementation of the Open Services Gateway Initiative (OSGi) framework specification, which is used by many Amigo services. The main components of the CMS system are based on Oscar bundles, which are available through the Online Bundle Repository (OBR) of Amigo.
2.1.1 Installation Oscar does not have a special installation routine, so the full software package is available as a zip-file (e.g. http://amigo.gforge.inria.fr/obr/tools/oscar_j2se.zip ) and has to be extracted to a directory of your choice. If you are connected to the Internet through a proxy server, you’ll have to add the appropriate proxy settings to the “system.properties” file located in the “lib” sub-directory. You’ll find the start scripts “oscar.bat” (Windows) and “oscar.sh” (Linux 1 ) in the main directory. After calling the start script you are asked for a profile name (enter CMSTutorial, for example), which defines the name of the current Oscar profile. You can use profile names for separating different configurations.
2.1.2 GUI Below you see a screenshot of a running version of Oscar. On the left side you find the three items:  Bundle List: A list of all installed bundles, showing Id , State and Location;  additionally, local URLs can be entered for installing bundles (e.g.: file:///home/user/amigo_bundle.jar) Shell: Command shell  OBR: A list of all bundles available from the repositories, this can be online or  offline repositories as defined in /lib/bundle.properties.
1 If “oscar.sh” is not executable use “chmod u+x oscar.sh” to change the file attribute. Amigo IST-2004-004182
5/22
June 2007 Confidential Use the OBR item to install bundles from the repository and the Bundle List item for starting and stopping installed bundles.
2.1.3 Installing bundles Now start installing bundles to the Oscar platform: 1. Click on the item “OBR” 2. Select “amigo_core” and press “Start All” Installed dependencies:  log4j  Service Binder 3. Select “amigo_ksoap_binding” and press “Start All” 4. Select “amigo_ksoap_export” and press “Start All” Installed dependencies:  Servlet  HTTP Service (+ Amigo mods) 5. Select “amigo_wsdiscovery” and press “Start All” 6. Using the same procedure as describes above start the following bundles:  “context_broker”, “co _ _ ger” and “context_helper” ntext source man _ All bundles that start with “ANS ...” Now click on the “Bundle list” to check if all bundles are installed. You should get the following list:
Amigo IST-2004-004182
6/22
June 2007
Confidential
If during the bundle installation the above listed dependencies are not installed (an error will occur and pop up), please install the dependencies prior to the bundles by hand. In the “OBR” list you also find several other software bundles, which you can use for your services. Now we should start with compiling bundles and installing them. 2.1.4 Repositories The URL of the repositories is defined in “lib/bundle.properties”. The standard Amigo repositories are defined by the following copy of the “bundle.properties” file. You also find the address of the actual repositories on the item OBR. # all known repositories oscar.repository.url=\ http://amigo.gforge.inria.fr/obr/tools/oscar-repository.xml \ http://amigo.gforge.inria.fr/obr/v2/repository.xml # the port on which the http server will listen # if you have several OSGi platforms on the same machines change the port number org.osgi.service.http.port=8080
2.1.5 Stopping Oscar You can stop Oscar by typing “shutdown” in the Oscar shell. If nothing happens you can press “Ctrl+c” for killing Oscar, but try to shutdown Oscar gently through the “shutdown”-command beforehand.
Amigo IST-2004-004182
7/22
June 2007
Confidential
3 Using the Awareness and Notification System ANS is part of the intelligent user services and provides an easy way to get access to changes in the context of the home environment. ANS provides functionality to allow people/applications to stay aware of context changes. For example, it can inform applications about changes of the current location of a specific user. As a result, the application does not have to query all the various context sources that may provide appropriate location information. Instead, it subscribes to ANS and inject an appropriate rule that is automatically checked by ANS each time context information changes. Whenever the rule matches, an appropriate notification is send to the appropriate client. ANS has implemented in Java. However, it communicates with clients using SOAP which makes the client part independent of the actual server implementation. Communication between ANS and clients that make use of it happens in two directions: Client application searches for ANS and uses its interface to manage rules (subscribe, start, update etc.). Further, when a rule evaluates to true, ANS calls the client and uses its interface to notify it.
3.1 Writing an ANS client In the following, it is shown how to write an ANS client. The template files are located in Code\Java\tutorial_ansclient\src\de\ims\fraunhofer\amigo\tutorial\ans_client.Thecompletesolutions can be found in the subdirectories starti g _Solution”. n with “Code
3.1.1 Looking up the ANS service First, we write a class named ANSWrapper  that discovers the Amigo ANS service and encapsulates it. It provides the functionality of the IManageRules interface to an application that wants to use ANS. The unique instance of this class is provided by the getInstance . method. After retrieving an ANSWrapper object in this way, simply invoke the connect method and the wrapper will search automatically for available ANS services. Note that the class provides the same methods of the IManageRule  interface. Hence, invocations are simply delegated to ANS. First, import the packages that are needed by the wrapper. Further, define some members that are internally used by the wrapper: package de.ims.fraunhofer.amigo.tutorial.an _ ; s client import java.rmi.RemoteException; import amigo.ans.api.IManageRule; import amigo.ans.api.Rule; import amigo.ans.api.RuleFormatException; import com.francetelecom.amigo.core.AmigoException; import com.francetelecom.amigo.core.AmigoLdapLookup; import com.francetelecom.amigo.core.AmigoService; public class ANSWrapper { /** ANS web service object */ private IManageRule ans = null ; /** service objects */ private AmigoService[] services ; /* lookup service */ * private AmigoLdapLookup lookup = null ;  ... Amigo IST-2004-004182
8/22
June 2007 Confidential ANSWrapper is build according to the singleton pattern: /** singleton */ private static ANSWrapper instance = null ; /** * Return the ANSWrapper instance * @return The unique instance */ public static ANSWrapper getInstance() { if ( instance == null ) { instance = new ANSWrapper();  } return instance ;  } /** private constructor to match singleton pattern */ private ANSWrapper() {}  ... The connect  method now looks up the Amigo ANS service on the network. To this end a service with service type “Amigo_ANS” is searched. Moreover, the service URL must contain the string “IManageRule” in order to use it. Here, we just use the first service that matches this specific pattern. In case of an success, true  is returned. Otherwise, if no appropriate ANS service could be found the return value is false : /** * Searches for the ANS via service discovery and connects to it if a * service object is found. */ public boolean connect() { try { //reset connection... ans = null ; services = lookup .lookup( "(ServiceType=Amigo_ANS)" ); //no service discoveres --> no connection if ( services . length == 0) { return false ;  } else { // we use the first service with "IManageRule"  // in its name that is found for ( int i = 0; i < services . length ; i++) { if ( services [i].getReference().  getUrl().toLowerCase()  .contains( "imanagerule" )) { ans = (IManageRule) services [i]  .getSpecificStub(  IManageRule. class ); return true ;  }  }  }  } catch (AmigoException ex) {  ex.printStackTrace();  } Amigo IST-2004-004182 9/22
June 2007
Confidential
//something has gone wrong or no ANS found --> return false return false ;  }  ... The remainder of the class is dedicated to forwarding various method calls to the actual ANS service that has been found: /** * Return whether or not the application is connected to ANS. * * @return true if application is connected */ public boolean isConnected() { return ( ans != null );  } public int subscribe(Rule rule, String appID) throws  RuleFormatException, RemoteException { return ans .subscribe(rule, appID);  } public boolean unsubscribe( int ruleID) throws RemoteException { return ans .unsubscribe(ruleID);  } public boolean updateRule( int ruleID, Rule rule) throws  RemoteException { return ans .updateRule(ruleID, rule);  } public Rule queryRule( int ruleID) throws RemoteException { return ans .queryRule(ruleID);  } public boolean startRule( int ruleID) throws RemoteException { return ans .startRule(ruleID);  } public boolean stopRule( int ruleID) throws RemoteException { return ans .stopRule(ruleID);  } public void bindLookupService(AmigoLdapLookup lookup) { this . lookup = lookup;  } public void unbindLookupService(AmigoLdapLookup lookup) { if ( this . lookup == lookup) { this . lookup = null ;  }  } } 3.1.2 The main component The code below shows the main component of the client application. Note that this class implements the Lifeycle interface in order to provide the appropriate functionality to work as a Web service within OSGi. Note further, that the client works as an Web Service within OSGi.
Amigo IST-2004-004182
10/22
  • Accueil Accueil
  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • BD BD
  • Documents Documents