Archived

This forum has been archived. Please start a new discussion on GitHub.

Java2slice?

Hi,

I am using Spring/Faces/Hibernate/Seam. Seam will introspect my database and create the beans for me. I want to use Ice to expose those beans to client apps.

Here's the newbie question: how do I generate a Slice definition file from an existing Java class programatically? Because we're talking hundreds of beans, I can't create/modify them manually.

Thanks.
Jerry.

Comments

  • bernard
    bernard Jupiter, FL
    Hi Jerry,

    Welcome to our forums!

    Unfortunately, there is no tool to automatically "export" Java (or C++/C# etc) objects as Slice. You have to write your Slice definitions yourself.

    Such a java2slice tool is not really doable since many Java types or constructs can't be mapped directly to Slice.

    You should also be careful about the granularity of your Java methods and Ice operations. For example, making lots of calls to get/set various fields in a Java object is fine when everything is local; with remote invocations, you'd typically want to group several gets and sets within the same Ice operation (since remote invocations are much slower than local calls).

    Best regards,
    Bernard
  • java2slice and ports questions

    Bernard,

    Thanks for your quick reply!

    Two follow-up questions:

    1) Other languages (or whatever they are called) (JSON, for example), convert any kind of user-defined data structures by introspecting classes, etc.
    Now, Slice is not a superset language of Java ('many Java types or constructs can't be mapped directly to Slice'), but it could transmit all possible Java types, right?
    If so, it is theoretically possible to write a java2slice application, applying the same mappings from slice2java (plus some arbitrary rules). Am I missing something here?

    2) The hello world example binds an object to a port. I'm considering using Ice to replace hundreds of web services that serve as a gatekeeper for our databases. I suppose IceStorm can provide UDDI-like operations from what I've read. My questions: a) can more than 1 server be bound to a port? b) can more than 1 object be bound with a server to 1 port? I don't want to have to open and maintain 12000 ports!!! :D


    Thanks.
    Jerry.
  • bernard
    bernard Jupiter, FL
    Hi Jerry,

    For 1), let's take a few examples:

    // Java
    package Test;
    public class Simple
    {
    public int data;
    }

    The "equivalent" Slice is:
    module Test
    {
    struct Simple
    {
    int data;
    };
    };

    In this case we were lucky, there is a reverse-mapping!

    Now if the Java class was not public, or its data member wasn't public, there would be no mapping.

    Now take a little more complicated Java class:
    // Java
    package Test;
    public class LessSimple
    {
    public LessSimple next;
    }

    There the equivalent Slice would look like:

    // Slice
    module Test
    {
    class LessSimple
    {
    LessSimple next;
    };
    };

    However the mapping is far from perfect, since the LessSimple Java class generated from slice2java extends Ice.Object.

    Add methods to the mix, and you'll get quickly a far from perfect reverse mapping!

    For 2), you typically host several (or even many) objects in the same object adapter. In particular if you have a very large number of objects in database, the "default servant" pattern often makes a lot of sense; with this pattern, a single servant "incarnates" any number of Ice objects.

    Several object adapters listening on a given interface (on a given machine) can't share the same port; if you have just a few object adapters, assigning different ports is not a big deal. If you have a larger deployment, I'd strongly recommend to use IceGrid: IceGrid introduces an indirection between your clients and servers (only when establishing the connection, not for every call), and allows you to use OS-assigned ports for your object adapters.

    All the best,
    Bernard
  • My CTO always tell to me: "Nothing is impossible."

    I think it's a good idea to export POJO as ice servant, we could start up a adapter (or server ) to listen on a fix-port, using AOP to intercept the invocation from out site, and auto direct to the servant. And the java2slice is designed to as simple as possible.
  • You may also want to read this FAQ on the topic.

    Cheers,

    Michi.