Skip to main content

Very simple example?

  5 posts   Feedicon  
Replies: 4 - Last Post: June 07, 2013 21:12
by: jrounceville
showing 1 - 5 of 5
Posted: February 20, 2011 22:25 by Obsfucation

Hi there.

I'm very very new to distributed systems, but have reasonable experience in Java so thought it would be the right language to explore it in further. This is what led me to Cajo really- that and a few people who recommend it!

I'm trying to create the most simple example that I can. I am running both the client and the server on the same machine, and am attempting to remotely access an object exported by the server on the client. Unfortunately, my client is never able to find any objects.

I've tried repeatedly to learn from various bits of code on the site, but with the move to the new Java.net I keep hitting dead links, or content I believe may be out-of-date (e.g. using constructors that do not seem to exist).

The code I am trying to use is as follows:

Server code-

import gnu.cajo.Cajo;
import java.io.IOException;

public class CajoServer {
    public static void main(String[] args) throws IOException {
        Cajo cajo = new Cajo();
        CajoExportInterface object = new CajoObject();
        cajo.export(object);
        System.out.println("Server running");
    }
}

Client code-

import gnu.cajo.Cajo;

public class CajoClient {
    public static void main(String[] args) throws Exception {
        Cajo cajo = new Cajo();
        Object[] results = cajo.lookup(CajoExportInterface.class);
        System.out.println(results.length);
    }
}

Interface for object being shared-

package cajotest;

public interface CajoExportInterface {
    public String getMessage();
}

Object implementing interface-

public class CajoObject implements CajoExportInterface {

    public String getMessage() {
        return "Hello there!";
    }

}

Please could you give any advice on what I am doing wrong? I know it may be something relatively simple, or that I have misunderstood a concept, so please go easy on me!

If there are any resources you believe I should review, please also feel free to link those instead of replying directly- I am not adverse to reading material, I have just struggled at finding suitable material to help me!

Thanks in advance for any help

Posted: February 21, 2011 01:54 by John Catherino
You are almost there. The problem, though not common, is quite simple. Your test client is so small, it is executing a lookup faster than the server can propagate its service object references to it! Wink (that is why the returned count is always zero) Once you start to flesh-out your client a little more, the problem usually goes away.

Here is a slightly tweaked version of your test code that works:

CajoServer.java:
import gnu.cajo.Cajo;

class CajoObject {
    public String getMessage() { return "Hello there!"; }
}

public class CajoServer {
    public static void main(String[] args) throws Exception {
        Cajo cajo = new Cajo();
        cajo.export(new CajoObject());
        System.out.println("Server running");
    }
}

CajoClient.java:
import gnu.cajo.Cajo;

interface CajoExportInterface {
   String getMessage();
}

public class CajoClient {
    public static void main(String[] args) throws Exception {
        Cajo cajo = new Cajo();
        Thread.currentThread().sleep(100); // allow some discovery time
        Object[] results = cajo.lookup(CajoExportInterface.class);
        CajoExportInterface service = (CajoExportInterface)
            cajo.proxy(results[0], CajoExportInterface.class);
        System.out.println("Result = " + service.getMessage());
    }
}

This should help you get to the next level. If you have any further questions, feel free to ask.

John
Posted: February 21, 2011 10:52 by Obsfucation
I must admit, I have never had a problem like this before- where such a simple example is too quick for its own good... However, I definitely don't take that as any bad thing!

Thanks very much for your incredibly speedy help, I'll be sure to post again if I hit any other issues- rather than hitting my head against a wall for too long!
Posted: August 12, 2011 19:00 by dev_14525209189
Hi John,

I've been looking into trying out CAJO and was intrigued by this very simple example (I am looking for a very small, lightweight proof of concept). The server starts up fine, but then when I run the client code, I get an exception when accessing the results. It looks like cajo.lookup isn't finding anything. Do you have any ideas as to what could be causing this, or were there any setup steps I missed (I just copied and pasted the code you provided directly)?

Thanks.
Posted: June 07, 2013 21:12 by jrounceville
For future reference, another thing that can cause this problem, besides this time dependency issue, is the McAfee Host Intrution Prevention Service. It appears that it interferes with the multicast architecture of cajo.

Regarding cajo itself, I looked through the code while I was debugging this McAfee conflict, and I'm really surprised at how much code I see eating exceptions (empty catch blocks). Shouldn't you at least be logging those, and then letting us set the logging level on whether we want to see them or not? It took a long time to debug this McAfee problem because exceptions were being gobbled up in empty catch blocks.
Replies: 4 - Last Post: June 07, 2013 21:12
by: jrounceville
 
 
Close
loading
Please Confirm
Close