fr.dgac.ivy
Class Ivy

java.lang.Object
  |
  +--fr.dgac.ivy.Ivy
All Implemented Interfaces:
java.lang.Runnable

public class Ivy
extends java.lang.Object
implements java.lang.Runnable


Field Summary
static java.lang.String DEFAULT_DOMAIN
          the domain for the UDP rendez vous
static int DEFAULT_PORT
          the port for the UDP rendez vous, if none is supplied
static java.lang.String libVersion
          the library version, useful for development purposes only, when java is invoked with -DIVY_DEBUG
static int PROCOCOLVERSION
          the protocol version number
static int TIMEOUTLENGTH
           
 
Constructor Summary
Ivy(java.lang.String name, java.lang.String message, fr.dgac.ivy.IvyApplicationListener appcb)
          Readies the structures for the software bus connexion.
 
Method Summary
 int addApplicationListener(fr.dgac.ivy.IvyApplicationListener callback)
          adds an application listener to a bus
 int bindMsg(java.lang.String regexp, fr.dgac.ivy.IvyMessageListener callback)
          Subscribes to a regular expression.
 void connect(fr.dgac.ivy.IvyClient client)
           
 void dieReceived(fr.dgac.ivy.IvyClient client, int id)
          invokes the application listeners when we are summoned to die then stops
 void directMessage(fr.dgac.ivy.IvyClient client, int id, java.lang.String msgarg)
           
 java.lang.String domains(java.lang.String toparse)
           
static java.lang.String getDomain(java.lang.String domainbus)
           
 java.util.Vector getIvyClients()
          gives the names of IvyClient(s)
 java.util.Vector getIvyClientsByName(java.lang.String name)
          gives a list of IvyClient(s) with the name given in parameter
static void main(java.lang.String[] args)
           
 fr.dgac.ivy.Ivy.Domain[] parseDomains(java.lang.String domainbus)
           
 void removeApplicationListener(int id)
          removes an application listener
 void run()
           
 int sendMsg(java.lang.String message)
          Performs a pattern matching according to everyone's regexps, and sends the results to the relevant ivy agents.
 void sendToSelf(boolean b)
          Toggles the sending of messages to oneself
 void start(java.lang.String domainbus)
          connects the Ivy bus to a domain or list of domains.
 void stop()
          disconnects from the Ivy bus
 void unBindMsg(int id)
          unsubscribes a regular expression
 boolean unBindMsg(java.lang.String re)
          unsubscribes a regular expression
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROCOCOLVERSION

public static final int PROCOCOLVERSION
the protocol version number

See Also:
Constant Field Values

DEFAULT_PORT

public static final int DEFAULT_PORT
the port for the UDP rendez vous, if none is supplied

See Also:
Constant Field Values

DEFAULT_DOMAIN

public static final java.lang.String DEFAULT_DOMAIN
the domain for the UDP rendez vous

See Also:
Constant Field Values

libVersion

public static final java.lang.String libVersion
the library version, useful for development purposes only, when java is invoked with -DIVY_DEBUG

See Also:
Constant Field Values

TIMEOUTLENGTH

public static final int TIMEOUTLENGTH
See Also:
Constant Field Values
Constructor Detail

Ivy

public Ivy(java.lang.String name,
           java.lang.String message,
           fr.dgac.ivy.IvyApplicationListener appcb)
Readies the structures for the software bus connexion. All the dirty work is done un the start() method

Parameters:
name - The name of your Ivy agent on the software bus
message - The hellow message you will send once ready
appcb - A callback handling the notification of connexions and disconnections, may be null
See Also:
start(java.lang.String)
Method Detail

start

public void start(java.lang.String domainbus)
           throws IvyException
connects the Ivy bus to a domain or list of domains.
  • One thread (IvyWatcher) for each traffic rendezvous (either UDP broadcast or TCPMulticast)
  • One thread (serverThread/Ivy) to accept incoming connexions on server socket
  • a thread for each IvyClient when the connexion has been done

    Parameters:
    domainbus - a domain of the form 10.0.0:1234, it is similar to the netmask without the trailing .255. This will determine the meeting point of the different applications. Right now, this is done with an UDP broadcast. Beware of routing problems ! You can also use a comma separated list of domains.
    IvyException

  • parseDomains

    public fr.dgac.ivy.Ivy.Domain[] parseDomains(java.lang.String domainbus)

    stop

    public void stop()
    disconnects from the Ivy bus


    sendToSelf

    public void sendToSelf(boolean b)
    Toggles the sending of messages to oneself


    sendMsg

    public int sendMsg(java.lang.String message)
    Performs a pattern matching according to everyone's regexps, and sends the results to the relevant ivy agents.

    There is one thread for each client connected, we could also create another thread each time we send a message.

    Parameters:
    message - A String which will be compared to the regular expressions of the different clients
    Returns:
    the number of messages actually sent

    bindMsg

    public int bindMsg(java.lang.String regexp,
                       fr.dgac.ivy.IvyMessageListener callback)
    Subscribes to a regular expression. The callback will be executed with the saved parameters of the regexp as arguments when a message will sent by another agent. A program doesn't receive its own messages.

    Example:
    the Ivy agent A performs

    b.bindMsg("^Hello (*)",cb);

    the Ivy agent B performs
    b2.sendMsg("Hello world");

    a thread in A will uun the callback cb with its second argument set to a array of String, with one single element, "world"

    Parameters:
    regexp - a perl regular expression, groups are done with parenthesis
    callback - any objects implementing the IvyMessageListener interface, on the AWT/Swing framework
    Returns:
    the id of the regular expression

    unBindMsg

    public void unBindMsg(int id)
                   throws IvyException
    unsubscribes a regular expression

    Parameters:
    id - the id of the regular expression, returned when it was bound
    IvyException

    unBindMsg

    public boolean unBindMsg(java.lang.String re)
    unsubscribes a regular expression

    Returns:
    a boolean, true if the regexp existed, false otherwise or whenever an exception occured during unbinding

    addApplicationListener

    public int addApplicationListener(fr.dgac.ivy.IvyApplicationListener callback)
    adds an application listener to a bus

    Parameters:
    callback - is an object implementing the IvyApplicationListener interface
    Returns:
    the id of the application listener, useful if you wish to remove it later

    removeApplicationListener

    public void removeApplicationListener(int id)
    removes an application listener

    Parameters:
    id - the id of the application listener to remove

    connect

    public void connect(fr.dgac.ivy.IvyClient client)

    dieReceived

    public void dieReceived(fr.dgac.ivy.IvyClient client,
                            int id)
    invokes the application listeners when we are summoned to die then stops


    directMessage

    public void directMessage(fr.dgac.ivy.IvyClient client,
                              int id,
                              java.lang.String msgarg)

    getIvyClients

    public java.util.Vector getIvyClients()
    gives the names of IvyClient(s)


    getIvyClientsByName

    public java.util.Vector getIvyClientsByName(java.lang.String name)
    gives a list of IvyClient(s) with the name given in parameter

    Parameters:
    name - The name of the Ivy agent you're looking for

    getDomain

    public static java.lang.String getDomain(java.lang.String domainbus)

    run

    public void run()
    Specified by:
    run in interface java.lang.Runnable

    domains

    public java.lang.String domains(java.lang.String toparse)

    main

    public static void main(java.lang.String[] args)