franz inc logo  
  download learning center franz inc search franz inc resources franz inc          

allegrograph
racer
tbc
services
support
  Learning Center
  Documentation
  Updates
     Info
  FAQ
about

RSS Feeds

AllegroServe at opensource.franz.com

AGEvalInServer.java

package com.franz.ag.examples;

import com.franz.ag.*;

public class AGEvalInServer {
    /**
     * Demonstrates some basics of evaluating lisp in the server.
     * 
     * To run this and other examples that use evalInServer, you will need
     * to start the server using the --eval-in-server-file option, as in:
     * 
     * $ ./AllegroGraphServer --eval-in-server-file evalinserver.cfg
     * 
     * Refer also to the Learning Center under Starting a Server Manually
     * for more information.
     * 
     * Note that this is an advanced feature for users that understand the
     * internals of the AllegroGraph server.  The purpose of this example
     * is simply to convey that one can indeed command the server in Lisp 
     * through the Java API.
     *   
     * @param args unused
     * @throws AllegroGraphException 
     */
    public static void main(String[] args) throws AllegroGraphException {
        // Connect to server, which must already be running.
        AllegroGraphConnection ags = new AllegroGraphConnection();
        try {
            ags.enable();
        } catch (Exception e) {
            throw new AllegroGraphException("Server connection problem", e);
        }
        
        // Add two numbers in the server and show the result
        evalInServer("(+ 2 3)",ags);
        
        // Define and call a function to add two numbers
        evalInServer("(defun foo (x y) (+ x y))",ags);
        evalInServer("(foo 4 5)",ags);
        
        // You can send a sequence of commands in a single call
        evalInServer("(progn (defun bar (x y) (+ x y)) (bar 6 7))",ags);
        
        // Symbols do not come back from the server
        evalInServer("'a",ags);

        // Disconnect from the server
        ags.disable();
    }

    public static void evalInServer(String lispexpr, AllegroGraphConnection ags) throws AllegroGraphException {
        Object[] result;
        try {
            result = ags.evalInServer(lispexpr);
            AGUtils.printObjectArray("Server> "+ lispexpr, result);
        } catch (IllegalArgumentException e) {
            if (e.getMessage().contains("eval not permitted")) {
                throw new AllegroGraphException("evalInServer not permitted: Please ensure you have started the server with the --eval-in-server-file option.");
            } else {
                throw new AllegroGraphException(e.getMessage());
            }
        }
    }
    
}

Up | Next

 

© 2008 Franz Inc - Privacy Statement
[ Consulting Services | Franz | TopQuadrant | Racer Systems ]