Handling Requests and Their Results

Services A number of services are available, each distinguished by a String. The most important are: icc.net.DataRequest.MEDIATOR
    provides information on connected users and available agents icc.db.Project.QUERY
    retrieves project information, including project partners and access rights icc.db.Project.ENTRY
    alters project information (project administrator only) icc.db.Partner.QUERY
    retrieves team partner and team information icc.db.Partner.ENTRY
    alters team and partner information (with restrictions) icc.db.File.QUERY
    retrieves document information icc.db.File.ENTRY
    alters document information (with restrictions) icc.db.File.SEARCH
    retrieves document information with respect to selected search criteria

1. Registering a data handler By registering itself to a Speaker, a data handler can process all results from service requests, as well as other packages and exceptions destined to this speaker. For this purpose, the data handler class needs to implement icc.net.DataHandling by containing the methods public void process (Package pkg) and public void handleException (Exception e). For example:

public void process(Package pkg) {
    IDCard source = pkg.from();
    Object content = pkg.content;
    System.out.println("Received package from " +
        source.name() + " with content of class " +
        pkg.content.getClass().getName());
}

public void handleException(Exception e) {
    System.out.println("Caught "+ e);
}
The data handler class can register itself to the speaker as follows:
    speaker.setDataHandler(this);

2. Creating requests All service methods for creating data requests are listed with specification of the icc.db class files they can be found in: Document requests:   File, WorkFile Partner requests:   Partner, Team Project requests:   Project, Access, Cube, Phase Document search requests:   Folder, Select, Cube Mediator service requests:   icc.net.DataRequest Attention: Requests cannot be modified after creation. Read access to requests is limited as well. See below for more information on how to deal with these restrictions.

3. Altering the arguments of a requests Once created, requests cannot be modified. However, sometimes it may be necessary to alter the arguments of a request after creation, e.g., when created in a different process. One of the following two methods can be used to achieve this.

a. Delaying the creation If the request can be created from an object (non-static service method), this object (or objects) can be passed on by the first process, in order to create the request just before sending it off.

b. Providing separate access to the arguments Otherwise, the arguments can additionally be provided as separate objects to the request, though within a single package when passed on over the network. When the argument objects are manipulated, so are the arguments in the request.

4. Sending requests

a. Chaining requests Multiple requests can be sent as one, by attaching them to one another:
    request1.attach(request2);
attaches request2 to request1, or at the end of the chain of requests represented by request1.

b. Packaging a request (chain) In order to be serviced, a request must be sent to IDCard.SERVICE. The result will be returned to the sender, unless otherwise specified in the package.
    new Package(IDCard.SERVICE, request)
prepares a request to be sent off.

5. Processing the results It is assumed that the result arrives as a package pkg to the process method and that the content of this package is an instance of the DataRequest class:
    DataRequest request = (DataRequest) pkg.content;

a. Was the request successful?     if (!request.successful())
        System.out.println("unsuccessful " + request.toString());
A request is unsuccessful if the service threw an exception when processing the request, or if the service in question was not available, resulting in a nonServicedRequest exception. In both cases, the thrown Exception object is provided as the result of the request:
    Exception result = (Exception) request.result();

b. Interpreting the result To aid in the processing, the following information can be extracted from the result: The name of the service
    String name = request.service(); The resulting object
    Object result = request.result(); The number of arguments to the request
    int number = request.arguments(); Each argument to the request
    Object arg1 = request.argument(0);

c. Chained results If multiple requests were attached into a chain, their results may arrive attached as well (though they don't need to).     if ((request = request.detach()) != null)
retrieves the next attached result, and checks if it is non-null.

6. Handling respective results Examples are provided on how to deal with the results from each type of data requests:     Document results     Partner results     Project results     Document search results     Mediator service results

Putting it all together: Processing the results This java source file shows a data handler class handling the results from data requests, as compiled from the information provided higher.

Last updated: 12 June 1999
Please send suggestions, comments and bug reports to tuncer@arch.ethz.ch

This website has been archived and is no longer maintained.