Version 44

    How to port JGroups J2SE to work on J2ME (with bluetooth consideration)


    Much of JGroups can be used on CLDC devices.  You'll need to obtain Sun

    Microsystems WTK (wireless toolkit) from here.  Maybe you know this already, maybe

    not... I'm just trying to be complete so you can get started without

    problems.  To be honest you don't even need real devices to test everything since you can run multiple instances of the WTK emulator and test your

    code like that.  You may even be testing with the emulator more often

    than on real devices.  It is (of course) nice to have real

    devices available since the rubber needs to meet the road at some



    I've played with version 2.5.1 of the wireless toolkit a little and it's important to note that if you

    are going to use the Linux version you should have a Linux that uses

    GLIBC 2.4.  Otherwise, you better get the Windows version.  I've

    learned this from experience (the Debian

    Etch system I use doesn't have GLIBC 2.4 on it yet).  Well, I mostly use WTK 2.2 on FreeBSD and to be honest 2.2 should suffice -

    after all... there are bluetooth samples provided with WTK 2.2.


    Also, you should be aware that JGroups-ME is distributed as a patch to

    JGroups, no matter which platform you'll be using (Windows or Linux)

    you should have the 'patch' program available.  Most Linux

    distributions include 'patch'; on Windows you can install

    'patch' by way of cygwin.  If you prefer, you can use a unix machine to

    patch the sources and then copy the patched code onto your Windows

    computer.  In addition you'll need to have a 'cvs' client program and apache 'ant' too.


    Now, after you've got your WTK installed you can start playing with

    JGroups-ME.  Let me give you some background...  there is no

    JGroups-ME code per se.  Wait, that doesn't make sense!!!  Yes, there

    is JGroups-ME code... but it may not be what you think it is.  The

    JGroups-ME code can be thought of as a 'portability' or 'compatibility' layer that

    enables JGroups code to work with J2ME.


    I'm not sure if you are aware of this, but J2ME is somewhat different

    from J2SE.  That is, J2ME does not provide all the goodies that

    regular Java (i.e. J2SE) does... after all it's meant to run on rather

    limited systems (e.g. cell-phones, set-top boxes, microwave ovens and

    toasters) not on full blown general purpose computers.  As such,

    most of Bela's JGroups code won't work on your cell-phone

    without a little help, that's where JGroups-ME steps in.


    In a nutshell, all that JGroups-ME does is provide an infrastructure of the objects and interfaces of J2SE that are not available or differ in J2ME.  For

    example, the 'vector' class in J2ME is more limited than that of

    J2SE.  So, JGroups-ME provides its own vector class...

    '' that more closely resembles the Vector

    provided by J2SE.  The JGroups code is then patched to import

    '' rather than 'java.util.Vector' and viola, all

    of a sudden the JGroups code works on J2ME.  The vast majority of

    JGroups-ME consists of these kinds of infrastructure wrappers.


    Now, back to getting you started...  okay, you've got the WTK and you

    have SUN's JDK installed as well as having 'cvs', 'patch' and

    finally apache 'ant'.


    We're basically ready to roll.  You should start by reading the JGroups-ME readme.txt located here.  As the readme.txt file indicates, the first thing you want to do is get a version of JGroups from cvs.  JGroups-ME is known to work with a number of JGroups versions, but you should probably stick with the version recommended by the readme.txt file.


    Grab the JGroups code from cvs, e.g. to get version 2.3 you can use the following command:


    cvs -z3 co -rJGroups_2_3 -P JGroups


    Yes, you'll need the 'cvs' program available.  You could download

    JGroups from the sourceforge download area but JGroups-ME is only

    available via cvs... sorry.  Again, cvs can be installed via cygwin.  Or, you can use a unix machine that has cvs installed to obtain the

    code and then copy the code to your Windows computer.


    Now grab the latest JGroups-ME/CLCD11 code, e.g.:


    cvs -z3 co -P JGroups-ME/CLDC11


    Since you just grabbed the code, you can skip the

    first two steps listed in the readme.txt and continue by removing the

    class mappings.  JGroups-ME doesn't use class mappings so you should

    build both the J2SE and J2ME binaries with an empty jg-magic-map.xml

    file, i.e. delete everything in between "<magic-number-class-mapping>"

    and "</magic-number-class-mapping>" from the jg-magic-map.xml file

    before building your programs.  Proceed by performing the remaining steps outlined in the readme.txt.


    Since bluetooth is not yet supported by JGroups, the next step is to figure out how to incorporate it.  As I understand it, getting JGroups-ME working with

    bluetooth will consist of at least two things....


    First off, you'll need to make sure that the J2ME device can act as a

    'GossipRouter' (I don't think this is the case right now since

    JGroups-ME devices always act as a 'client' and the GossipRouter always

    resides on a 'central' J2SE enabled server).


    Then, you'll need to provide a mechanism to initialize JGroups-ME in

    a bluetooth context.  My best guess is that the protocol string which

    initializes a JChannel will need some specifier to indicate bluetooth

    parameters.  The underlying code will need to handle that

    specifier so that the connection is created using JSR-82.  It seems to

    me that in order to use JGroups-ME over bluetooth there will be more

    code written to prepare the protocol string and just a bit of code

    that will reside in JGroups to handle that protocol string.


    Of course this is were the real work begins and I'm sure you'll

    discover more as you work towards your goal.  Once you're comfortable

    with the overall process you can begin to think about adding bluetooth support.


    If you are feeling overwhelmed, concentrate on familiarizing yourself with how JGroups and JGroups-ME work together.  It's really not as daunting as it may seem.  Then, when you've tried the chat sample and you are comfortable with JGroups-ME, you can consider how bluetooth will fit into the picture.


    In summary, the requirements to get started are:


    • Sun's JDK

    • Sun's WTK

    • cvs

    • patch

    • apache ant




    • grab JGroups from cvs

    • grab JGroups-ME/CLDC11 from cvs

    • remove class mappings from jg-magic-map.xml

    • build J2SE version (i.e. 'ant jar' from command prompt)

    • link/copy J2SE files into JGroups-ME using JGroups-ME/CLDC11/src/org/jgroups/ as a guide

    • patch J2SE code using 'patch' with one of the patches available from JGroups-ME/CLDC11/src/org/jgroups

    • change the initProt method in to match your network setup (that is, you may need to change the sample code to use IP address(es) from your network, rather than 'localhost' which is hardcoded in the chat demo)

    • build the J2ME version of JGroups from the newly patched code (using the wireless toolkit)

    • start the J2SE GossipRouter

    • increase the heap size in the WTK emulator

    • try out the JGroups-ME chat demo (i.e. using the wireless emulator


    Now real work begins:


    • get a J2ME GossipRouter working

    • crow-bar bluetooth in somehow


    If you have questions or need help, let me know.