Monday, May 24, 2010

Exercise 14 - Topic 10

1) What is a spider? What does it do?

A spider, also known as crawler, robot, traverses the World Wide Web in an orderly manner. Search engines line Google uses this technology to provide up-to-date search results. The spider downloads the pages from the web, keeps a copy of the pages that is later indexed to provide quicker search.

Spiders can also perform automated maintenance tasks like link validating. It can also retrieve specific information from web pages, like the email addresses.

Using some search engine technology like the FAST search engine, we can specify the web sites to crawl. This allows for creating custom search engines that filters results by the particular web sites, typically a certain type of websites (for example, all Australian news websites).

2) Differentiate the various types of software agents:

The following are the different types of software agents:
a) Collaborative Agents: Collaborative Agents can act rationally and autonomously in open and time-constrained multi-agent environments.

b) Interface Agents: Interface agents support and provide assistance, typically to a user learning to use a particular software. The agent tracks the user using the software and suggests better ways to perform the task as needed.

c) Mobile Agents: Mobile agents are software processes capable of roaming the WWW, interacting with foreign hosts, gathering information on behalf of its owner and retrieve data and complete tasks set by the user.

d) Information/Internet Agents: Information agents have come about because of the sheer demand for tools to help us manage the explosive growth of information and it can traverse the WWW.

e) Reactive Software Agents: Reactive agents is a special category of agents which do not possess internal, symbolic models of their environments. Instead they respond in a stimulus-response manner depending on the state of the system where they are embedded.

f) Hybrid Agents: Hybrid Agents are created based to combat the disadvantages of the five other software agents.

g) Heterogeneous Agent Systems: Heterogeneous agent systems refers to an integrated set-up of at least two or more agents which belong to two or more different agent classes. A heterogeneous agent system may also contain one or more hybrid agents.

http://agents.umbc.edu/introduction/ao/5.shtml

3) Identify various activities in e-commerce where software agents are currently in use:

Examples include:
  • News sites that collect news from various websites and displays it as one.
  • Credit card comparison sites that compares various credit cards and give results with best rates, personal loans, etc.
4) Case Study: rocky

    Sunday, May 23, 2010

    WorkShop 6 - Playing Audio and Video

    In this tutorial, I will create a Blackberry application to play audio and video files using the Mobile Media API (MMAPI).

    Audio Playback
    Classes from the javax.microedition.media package will be used to play audio on Blackberry devices. This package is compatible with the MMAPI.

    Manager class

    The Manager class is part of the javax.microedition.media package and is responsible from media handling. This class is needed to get access to the system resources such as the Player for multimedia processing. The Manager class can create a Player object and it can also query the player for specific details like supported media contents.

    Content types

    Content types identify the type of the media type and are registered as the mime types. Common audio types are audio/mpeg (for files with .mp3 extension) and audio/midi (for files with .midi extension).
    We can use the method
    public static String[] getSupportedProtocols(String content_type)

    to find out which protocols specific content types support on the device we can use.


    Playing Single Tone
    To play a single tone, the following method can be used.
    public static void playTone(int note, int duration, int volume) throws MediaException

    where:
    • SEMITONE_CONST = 17.31234049066755 = 1/(ln(2^(1/12)))
    • note = ln(freq/8.176)*SEMITONE_CONST
    • The musical note A = MIDI note 69 (0x45) = 440 Hz
    • duration is note duration in milliseconds, and
    • volume is in range from 0 to 100.
    Creating a Player

    To create a player that plays audio files, the following method can be used.
    PlayerManager.createPlayer(String url);
    where the url is the location of the media file.

    Player class

    The Player class has a life-cycle consisting of 5 states – unrealized, realized, prefetched, started and closed. Once a Player is created, it is in the unrealized state. When it is created, it tries to connect to the audio file. When the system finds the source, the Player moves to the realized state. When the Player is ready to play the audio, it moves to the prefetched state. If the Player is started in this state, it enters the started state. From this state, the Player can either be moved to prefetched state or can be closed.

    Audio Sample Application

    In this example, I will create an application and play audio files from the Blackberry simulator. I will create a new project and call it AudioVideo, and add a new mp3 file as a resource. How the file is imported and the code to run the application is shown in the screen shots below.


    When the application is run, the audio file starts playing and the list of supported media types are displayed as shown below.

    Video Playback

    Video files can be played in the application using the Manager and Player classes. Videos are larger in size and should be played from the SD Card.
    Mobile devices have smaller screen and smaller files are sufficient to be played in mobile devices.

    I have added a new class called Video.java to play the video file. The code for the class is below.

    Note that, I am calling the video file from the SD Card. To set the SD Card, click on the Simulate menu, select change card and add the directory that contains the video file as shown below.



    When the application is run, the video starts playing in the simulator.

    Saturday, May 22, 2010

    Workshop 5 - Network Transport

    Overview
    Blackberry device offers a a wide range of choices for creating an application that connects with servers and other systems on the internet or in the corporate network. Blackberry hides the details of the wireless network characteristics and let the developer concentrate on the core system.

    Overview of Network Transports
    Blackberry provides a number of different ways to connect to the network including the Blackberry Enterprise Server / Blackberry Mobile Data System (BES/MDS), TCP/IP, Blackberry Internet Service (BIS), WiFi, WAP 1.0 and WAP 2.0. All these methods may or may not be available depending on how the device is configured.

    BES/MDS

    BES allows Blackberry devices to make connections to corporate network. MDS component proxies the connection and can even connect to server that are behind the corporate firewall. This makes Blackberry a good choice to be used in the corporate world. On the other hand, since all connections is proxied by the MDS, the device can only connect to websites or servers that are allowed by BES server.

    TCP/IP

    Blackberry device can make direct connection to TCP/IP if permitted by the BES administrator.

    BIS

    BIS provide users the same functionality as for BES users but has lower lever of security. Devices connected to the BES servers are already connected to the BIS. BIS also provides the proxy connection similar to the BES/MDS but it does not allow connections to the corporate network.

    WiFi

    Many Blackberry devices include WiFi networking that allows connecting to a network via a WiFi router. Once the connection is made, the device can connect to network over the WiFi.

    WAP 1.0, 1.1, 2.0

    WAP is the standard carrier network available to blackberry. Devices connect to the cell towers and then to WAP gateway typically hosted by the carrier. The carrier Internet Web Servers.

    MIDP Connection Framework

    Blackberry uses the same connection framework as defined in the MIDP framework.

    Connector

    All connections are initiated using the javax.microedition.io.Connector class. The same class is used for HTTP, HTTPS, socket and many other connection types. For example, a HttpConnection can be opened using the followuing code.
    
    HttpConnection connection = (HttpConnection)Connector.open("http://www.csu.edu.au/");
    or
    SocketConnection
    socket = (SocketConnection)Connector.open("socket://www.csu.edu.au:80");

    Connection Method:

    When making a network connection, a device automatically try to connect using BES server. If BES is not available, the device will try to connect using TCP/IP. We can also specify how a device going to connect to the network.

    To connect using TCP/IP, use the following code,

    HttpConnection connection = (HttpConnection)Connector.
    open(url + ";deviceside=true");

    To connect using WiFi, use the following code,
    HttpConnection connection = (HttpConnection)Connector.open(url +";interface=wifi");

    To connect using BIS, the application will need to be approved by Blackberry Alliance Program.

    Determining Network Availability
    Using CoverageInfo
    The net.rim.device.api.system.CoverageInfo class provides information on which connection methods are available to the blackberry device by checking the device's radio, current network coverage and service book. The main method providing the availability is the getCoverageStatus method. Different coverage values might be returned including the following:

    • COVERAGE_MDS means you can make connections using the BES/MDS connection method.

    • COVERAGE_DIRECT means you can make conections using direct TCP/IP or WAP.
    • COVERAGE_BIS_B means you can make connections using BIS.

    Thursday, April 15, 2010

    Workshop 4 - Storing persistent data

    Storing Persistent Data

    In a blackberry application, if an objects needs to be saved and then retrieved after the blackberry device is restarted, the object needs to implement the Persistable interface. In this workshop, I will create a blackberry project that saves data and then retrieve data from the application.

    Note: Sub-classes of the class implementing Persistable interface do not automatically implement the interface.


    Setting up a new project:

    In previous workshops, I have shown how to create a Blackberry project using Eclipse. I will create another project "Bookstore" similarly and add a class called "Bookstore.java". The class will extend UiApplication and contain some EditFields, a java.util.Vector variable and a PersistentObject variable. The class will like below.



    Menu Items:

    I will add menu items to Save and Get item. The Save menu will save the data that is entered and display a success message. The Get menu will retrieve the data from the saved object and populates the EditFields. The codes for the menu items are shown below.




    StoreInfo class:



    The StoreInfo class implements the Persistable interface. The class declares a Vector variable and some constants. Constants are used to make sure that the data is read from and saved at the same location. The class also contains methods to set and get data from the Vector variable. The code for this class is shown below.


    How persistence works:

    The code to how persistence works is shown below.



    As can be seen, persistence occurs by calling the getPersistentObject(long id) method. This method requires us to pass a unique id that is used to identify the persistent object. The setContents(Object obj) method is used to set the contents that will be saved in the device. The commit() method is called to save the object to the Blackberry device. Data can be retrieved from the device by calling the getContents() method (it returns an Object). In Eclipse, these methods are marked with a padlock. This means that the application has to be signed before it works - however, this will fine within the simulator.