A very simple rel client.

This forum is for discussing the development of Rel examples and sample applications.
Post Reply
Blake
Posts: 9
Joined: Tue Jun 07, 2011 9:08 pm

A very simple rel client.

Post by Blake »

I am starting to write some client code for Rel.
Here is code to call a predefined function:

Code: Select all

package brc;

import java.io.IOException;

import ca.mb.armchair.rel3.client.Connection;
import ca.mb.armchair.rel3.client.Response;
import ca.mb.armchair.rel3.client.Value;
import ca.mb.armchair.rel3.client.stream.CrashHandler;

public class RelAccess
{
    public static void main (String[] args)
    {
        Connection connection = new Connection("localhost:5514");
        try
        {
            Response response = connection.evaluate("max(scenarios,sid)", new CrashHandler(){
                @Override
                public void process (Throwable t)
                {
                    System.out.println("Ouch!" + t.getMessage());
                    
                }});
            Value value = response.awaitResult(10000);
            System.out.println(value.toInt());
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
The program needs the relclient and relshared jar files.
To use the database directly the connection string "local:C:\\PROGRAMS\\Rel" can be used, but more jars are required.

There may be better ways to do this. I don't know what the CrashHandler should be doing.
Dave
Site Admin
Posts: 372
Joined: Sun Nov 27, 2005 7:19 pm

Re: A very simple rel client.

Post by Dave »

Nice!

Your CrashHandler is fine. It's intended to allow you to provide user-defined failure notification mechanisms, along the lines of "this application has crashed, would you like to notify the developers?" It's used in Rel's DBrowser to catch crashes and construct an error log and optionally send it to me. In a future update, I'll provide a built-in CrashHandler with some sensible defaults, so you won't need to specify it on every call to Connection's evaluate() and execute() methods.
Post Reply