diff options
-rw-r--r-- | Makefile | 39 | ||||
-rwxr-xr-x | debian/rules | 89 | ||||
-rw-r--r-- | doc/ivy-java.sgml | 294 | ||||
-rw-r--r-- | java.mk | 1 | ||||
-rwxr-xr-x | tools/jafter | 2 | ||||
-rwxr-xr-x | tools/jdaemon | 17 |
6 files changed, 317 insertions, 125 deletions
@@ -1,9 +1,9 @@ +include java.mk + # Be sure to set this before compiling ... - VER = 1.2.10 - DIST = lib/ivy-java-$(VER).jar + VERSION = 1.2.10 + DIST = ivy-$(VERSION).jar DOCS = doc/html/api - #JAR = fastjar # jar fails with kaffe on woody - JAR = jar #dist = woody/ dist = @@ -25,20 +25,31 @@ tests: #dist: class docs dist: class - ln -sf src/fr . - ln -sf bundle/${dist}gnu . - ln -sf bundle/${dist}org . - $(JAR) cvfm $(DIST) manifest fr/dgac/ivy/*.class fr/dgac/ivy/tools/*.class gnu org src/Makefile src/*.java examples/*txt examples/*xml examples/*java examples/Makefile tests/*java tests/Makefile doc/html/api/fr/dgac/ivy/*html doc/html/api/*html doc/html/api/*css README COPYING.LIB doc/ivy-java.pdf doc/ivy-java - rm -f fr gnu org + (cd src && $(JAR) cvfm ../$(DIST) ../manifest fr/dgac/ivy/*.class fr/dgac/ivy/tools/*.class ) jar: class - ln -sf src/fr . - ln -sf bundle/${dist}gnu . - ln -sf bundle/${dist}org . - $(JAR) cfm lib/ivy-java.jar manifest fr/dgac/ivy/*.class fr/dgac/ivy/tools/*.class src/Makefile src/*.java README COPYING.LIB Changelog BUGS gnu org examples/*.java - rm -f fr gnu org + #ln -sf src/fr . + #ln -sf bundle/${dist}gnu . + #ln -sf bundle/${dist}org . + #mkdir lib + #$(JAR) cfm lib/ivy-java.jar manifest fr/dgac/ivy/*.class fr/dgac/ivy/tools/*.class src/Makefile src/*.java README COPYING.LIB Changelog BUGS gnu org examples/*.java + #rm -f fr gnu org clean: ( cd src; make clean ;) ( cd tests; make clean ; ) ( cd examples; make clean; ) + +install: + install -m 0755 tools/jprobe $(DESTDIR)/usr/bin/ + install -m 0755 tools/jafter $(DESTDIR)/usr/bin/ + install -m 0755 tools/jdaemon $(DESTDIR)/usr/bin/ + install -m 0644 doc/ivy-java.1 $(DESTDIR)/usr/man/man1/ + gzip -9 $(DESTDIR)/usr/man/man1/ivy-java.1 + install -m 0644 doc/jprobe.1 $(DESTDIR)/usr/man/man1/ + gzip -9 $(DESTDIR)/usr/man/man1/jprobe.1 + install -m 0644 $(DIST) $(DESTDIR)/usr/share/java/ + ln -sf $(DESTDIR)/usr/share/java/$(DIST) $(DESTDIR)/usr/share/java/ivy.jar + (cd src; $(MAKE) docs DOCS=$(DESTDIR)/usr/share/doc/libivy-java/html/api) + cp -R doc/ivy-java $(DESTDIR)/usr/share/doc/libivy-java/programmersguide + install -m 0644 doc/ivy-java.pdf $(DESTDIR)/usr/share/doc/libivy-java/ diff --git a/debian/rules b/debian/rules index 4a585e2..d1282b7 100755 --- a/debian/rules +++ b/debian/rules @@ -1,54 +1,49 @@ #!/usr/bin/make -f -# Written by Yannick Jestin -# From an example by Antti-Juhani Kaijanaho -# You may treat this file as if it were in the public domain. +# Re Written by Yannick Jestin +# Made with the aid of debmake, by Christoph Lameter, +# based on the sample debian/rules file for GNU hello by Ian Jackson. -librules_interface = 1 -include debian/librules.mk +include java.mk -debian/stamp/binary/arch : debian/stamp/binary/libivy-java +clean: + dh_testdir + dh_testroot + rm -f build-stamp + $(MAKE) clean + dh_clean -debian/stamp/build : - $(MAKE) -C src - touch $@ +build: build-stamp +build-stamp: + dh_testdir + $(MAKE) + touch build-stamp -debian/stamp/clean-build: - -$(MAKE) -C src clean +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + $(MAKE) dist + $(MAKE) docs + $(MAKE) install DESTDIR=$(CURDIR)/debian/tmp -javarep=$(rootdir)/usr/share/java -mandir=$(rootdir)/usr/share/man/man1 +# Build architecture-independent files here. +binary-indep: build install + dh_testdir + dh_testroot + dh_installdocs README + dh_installexamples examples/*.java examples/*.xml examples/*txt + dh_installchangelogs Changelog + dh_compress + dh_link + dh_installdeb + dh_gencontrol + dh_fixperms + dh_md5sums + dh_builddeb -debian/stamp/binary/libivy-java : package=libivy-java -debian/stamp/binary/libivy-java : debian/stamp/build - $(prebinary) - $(install_dir) $(bindir) - $(install_dir) $(javarep) - $(install_dir) $(javarep)/repository - $(install_dir) $(exampledir) - $(install_dir) $(testsdir) - $(install_dir) $(docdir) - $(install_dir) $(docbasedir) - $(install_dir) $(mandir) - ( cd src; jar cvfm $(javarep)/ivy.jar ../manifest fr ) - #cp -r src/fr $(javarep)/repository/ - cp tools/jprobe $(bindir)/jprobe - cp -r Changelog $(docdir) - gzip -9 $(docdir)/Changelog - (cd doc; make) - cp doc/ivy-java.1 $(mandir) - mkdirhier $(docdir)/doc/html/api - ( cd src; make docs DOCS=$(docdir)/doc/html/api ) - cp -R doc/ivy-java $(docdir)/doc/programmersguide - cp -R doc/ivy-java.pdf $(docdir)/programmersguide.pdf - gzip -9 $(mandir)/ivy-java.1 - $(install_nonex) debian/README.Debian $(docdir) - $(install_nonex) BUGS README $(docdir) - $(install_nonex) examples/*.java $(exampledir) - $(install_nonex) examples/*.txt $(exampledir) - $(install_nonex) examples/*.xml $(exampledir) - $(install_nonex) tests/*.java $(testsdir) - $(install_nonex) debian/ivy-java $(docbasedir) - $(install_nonex) debian/changelog $(docdir)/Changelog.debian - $(gzip) $(docdir)/Changelog.debian - $(postbinary) - touch $@ +# Build architecture-dependent files here. +binary-arch: build install + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install diff --git a/doc/ivy-java.sgml b/doc/ivy-java.sgml index 4470c6e..92fe115 100644 --- a/doc/ivy-java.sgml +++ b/doc/ivy-java.sgml @@ -1,12 +1,12 @@ <!-- The Ivy Java guide - Copyright (c) 1999-2004 - Centre d'Etudes de la Navigation Aerienne + Copyright (c) 1999-2006 + DSNA/DTI Centre d'Etudes de la Navigation Aerienne SGML source file - Author: Yannick Jestin <jestin@cena.fr> + Author: Yannick Jestin <yannick.jestin@enac.fr> --> @@ -17,11 +17,6 @@ <artheader> -<copyright> -<year>2005</year> -<holder>DGAC/DSNA/DTI</holder> -</copyright> - <title>The Ivy Java library guide</title> <subtitle>CENA NT02-819</subtitle> <titleabbrev>NT02-819 © CENA</titleabbrev> @@ -29,13 +24,13 @@ <authorgroup> <author> <firstname>Yannick</firstname><surname>Jestin</surname> -<affiliation><address><email>jestin@cena.fr</email></address></affiliation> +<affiliation><address><email>yannick.jestin@enac.fr</email></address></affiliation> </author> </authorgroup> -<date>November 22, 2005</date> +<date>July 20, 2006</date> <copyright> -<year>2005</year> +<year>2006</year> <holder>DGAC/DSNA/DTI</holder> </copyright> @@ -43,7 +38,7 @@ <para> This document is a programmer's guide that describes how to use the Ivy Java library to connect applications to an Ivy bus. This guide describes -version 1.2.8 of the library. This document itself is part of the Java +version 1.2.10 of the library. This document itself is part of the Java package, available on the <ulink url="http://www.tls.cena.fr/products/ivy/">Ivy web site</ulink>. </para> @@ -65,7 +60,7 @@ incomplete, is quite ugly. We'll try and improve it. <sect1><title>What is Ivy?</title> <para> -Ivy is a software bus designed at <ulink +Ivy is a software bus initially designed at <ulink url="http://www.cena.fr/">CENA</ulink>. A software bus is a system that allows software applications to exchange information with the illusion of broadcasting that information, selection being performed by the receiving @@ -98,16 +93,18 @@ available from <ulink url="http://www.tls.cena.fr/products/ivy/">the Ivy Web sit <para> The Ivy Java library (aka libivy-java or fr.dgac.ivy) is a Java package that allows you to connect applications to an Ivy bus. You can use it to write -applications in Java. You can also use it to integrate any thread-safe Java -application on an Ivy bus. So far, this library has been tested and used on a variety of -Java virtual machines (from 1.1.7 to 1.4.2), and on a variety of architectures -(GNU/Linux, Solaris, Windows NT,XP,2000, MacOSX). +applications in Java. You can also use it to connect any thread-safe Java +application to an Ivy bus. So far, this library has been tested and used on a variety of +Java virtual machines (from 1.1.7 to 1.5.0), a variety of vendors (kaffe+gcj, +sun jdk, blackdown) and on a variety of architectures (GNU/Linux, Solaris, +Windows NT,XP,2000, MacOSX). It is developped and maintain on a Debian +GNU/Linux unstable distribution. </para> <para> -The Ivy Java library was originally developed by François-Régis Colin and is -now maintained by Yannick Jestin at CENA within a group at CENA (Toulouse, -France). +The Ivy Java library was originally developed by François-Régis Colin and +Yannick Jestin within a group at CENA (Toulouse, France). It is now maintained +by Yannick. </para> </sect2> @@ -130,12 +127,7 @@ mistakes is to put it in the command line each time you want to use ivy </para> <para> -The package contains the documentation, the sources and the class files for the fr.dgac.ivy package, -alongside with examples and a couple of useful tools, IvyDaemon and Probe. You -will need the <ulink url="http://jakarta.apache.org/regexp/">Apache Jakarta -project regexp library</ulink> -and the <ulink url="http://www.urbanophile.com/arenn/coding/download.html">gnu getopt library</ulink>. -Those could be included in the jar file, but not in the debian package. +The package contains the documentation, the sources and the class files for the fr.dgac.ivy package, alongside with examples and a small set of tools ( IvyDaemon, jrobe, jafter). You will need the <ulink url="http://jakarta.apache.org/regexp/">Apache Jakarta project regexp library</ulink> and the <ulink url="http://www.urbanophile.com/arenn/coding/download.html">gnu getopt library</ulink>. Those could be included in the jar file, but not in the debian package. </para> <para> @@ -146,10 +138,12 @@ $ <userinput>java fr.dgac.ivy.tools.Probe</userinput> If should display a line about broadcasting on a strange address, this is OK and means it is ready and working. If it complains about a missing class ( java.lang.NoClassDefFoundError ), then you have not pointed your virtual -machine to the jar file or your installation is incomplete. - -Alternatively, you can use the jprobe shell script. +machine to the jar file or your installation is incomplete. Alternatively, you can use the jprobe shell script. +<screen> +$ <userinput>jprobe</userinput> +</screen> </para> + </sect2> </sect1> @@ -207,10 +201,9 @@ class ivyTranslater implements IvyMessageListener { <sect2><title>Compiling it</title> <para> You should be able to compile the application with the -following command (if the ivy-java jar is in your development classpath): +following command (the classpath may vary): <screen> -$ <userinput>javac ivyTranslater.java</userinput> -$ +$ <userinput>javac -cp /usr/share/java/ivy.jar ivyTranslater.java</userinput> </screen> </para></sect2> @@ -219,7 +212,7 @@ $ We are going to test our application with <command>fr.dgac.ivy.tools.Probe</command>. In a shell, launch ivyTranslater: <screen> -$ <userinput>java ivyTranslater</userinput> +$ <userinput>java cp .:/usr/share/java/regexp.jar:/usr/share/java/ivy.jar ivyTranslater</userinput> </screen> In another shell, launch <command>java fr.dgac.ivy.tools.Probe '(.*)'</command>. You can see that the IvyTranslater has joined the bus, published its @@ -257,28 +250,29 @@ $ <sect1><title>Basic functions</title> <para> -The javadoc generated files are available on line on the ivy web site, and -should be included in your ivy java package (or in -/usr/share/doc/libivy-java, alongside with this very manual). Here are more details -on those functions. +The javadoc generated files are available on line on the ivy web site, and should be included in your ivy java package (or in /usr/share/doc/libivy-java, alongside with this very manual). Here are more details on those functions. </para> -<sect2><title>Initialisation an Ivy object and joining the bus</title> +<sect2><title>Initialization an Ivy object and joining the bus</title> <para> -Initialising a Java Ivy agent is a two step process. First of all, you must +Initializing a Java Ivy agent is a two step process. First of all, you must create an <function>fr.dgac.ivy.Ivy</function> object. It will be the repository of your agent name, network state, subscriptions, etc. Once this object is created, you can subscribe to the various Ivy events: text messages through Perl compatible regular expressions, other agents' arrival, departure, subscription or unsubscription to regexps, direct messages or die command -issued by other agents. At this point, your ivy application is still not connected. In +issued by other agents. +</para> + +<para> +At this point, your application is still not connected. In order to join the bus, call the <function>start(string domain)</function> method on your Ivy object. This will spawn two threads that will remain active until you call the <function>stop()</function> method on your Ivy object or until some other agent sends you a die message. Once this <function>start()</function> method has been called, -the network machinery is set up according to the ivy protocol, and your agent is ready to -handle messages on the bus ! +the network machinery is set up according to the ivy protocol, and your agent +is eventually ready to handle messages on the bus. <programlisting> fr.dgac.ivy.Ivy(String name,String message, IvyApplicationListener appcb) </programlisting> @@ -368,8 +362,9 @@ Use the <function>bindMsg()</function> method to bind a callback to a pattern, a public int bindMsg(String regexp, IvyMessageListener callback); public void unBindMsg(int id); </programlisting> -The <parameter>regexp</parameter> follows the PCRE syntax (see man -pcrepattern(3)), grouping is done with brackets. The <parameter>callback</parameter> +The <parameter>regexp</parameter> follows the PCRE syntax (see the <ulink +url="http://www.pcre.org/"> pcre web site</ulink> or the pcrepattern(3) man +page), grouping is done with brackets. The <parameter>callback</parameter> is an object implementing the IvyMessageListener interface, with the <function>receive</function> method. The thread listening on the connexion with the sending agent will execute the callback. </para> @@ -379,7 +374,7 @@ There are two ways of defining the callback: the first one is to make an object an implementation of the IvyMessageListener interface, and to implement the <function>public void receive(Ivyclient ic, String[] args)</function> method. But this is limited to one method per class, so the second method used -is the one of inner classes, introduced since Java 1.1 and widely used in +is the one of anonymous inner classes, introduced since Java 1.1 and widely used in swing programs, for instance: <programlisting> bindMsg("^a*(.*)c*$", new IvyMessageListener() { @@ -397,7 +392,18 @@ see in the advanced functions. <sect2><title>Subscribing to application events</title> <para> -TODO +Either at the creation time of your <function>Ivy</function> object or later +on with <function>Ivy.addApplicationListener()</function>, you can add add +some behaviour to perform callbacks upon different events: +<itemizedlist> +<listitem><para>when an agent joins the bus</para> </listitem> +<listitem><para>when an agent leaves the bus</para> </listitem> +<listitem><para>when an agent sends you a direct message</para> </listitem> +<listitem><para>when an agent forces you to leave the bus</para> </listitem> +</itemizedlist> +This can be handy if you design an agent requiring somme coordination with +other dedicated agents to run properly. To do so, the easiest way is to use +the ready messages. You can find later a description of the <function>Ivy.waitForClient()</function> method to implement a correct synchronization. </para> </sect2> @@ -409,7 +415,7 @@ TODO <para> By default, an application doesn't send the messages to itself. Usually, there are more efficient and convenient ways to communicate withing a program. -However, if you want to take benefit of the ease of ivy or to be as +However, if you want to take benefit of the ease of Ivy or to be as transparent as possible, you can set the Ivy object so that the pattern matching and message sending will be done for the sender too. <programlisting> @@ -431,9 +437,10 @@ provides the programmer with two useful function: public static String getDomain(String arg); public static String getDomainArgs(String progname,String[] args); </programlisting> -The getDomain() function, if arg is non null, will return arg, otherwise it +The <function>Ivy.getDomain()</function> function, if arg is non null, will return arg, otherwise it will return the IVYBUS property, otherwise the DEFAULT_DOMAIN. A very simple -way to start an Ivy agent is with ivy.start(getDomain(null)). The +way to start an Ivy agent is with +<function>Ivy.start(getDomain(null))</function>. The getDomainArgs(name,args) will add very simple processing of the args given to the main() function, and give higher priority to the command line argument. </para> @@ -466,6 +473,15 @@ won't be much documented, in order to make it harder to use. </para> </sect2> +<sect2><title>Ivy and swing GUI</title> +<para> +Swing requires the code to run in the main swing thread. In order to avoid +problems, be sure tu use the SwingUtilities.invokeLater() or +SwingUtilities.invokeAndWait() methods if you Ivy callbacks impact swing +components. +</para> +</sect2> + <sect2><title>Asynchronous Subscription to messages</title> <para> For each and every remote agent on the bus, a thread is in charge of handling the encoding @@ -542,15 +558,57 @@ chance to match the message you're sending, use the </para> </sect2> +<sect2><title>Message classes</title> +<para> +When your Ivy bus is populated with many agents, the cost of pattern matching +becomes painful. For instance, a bus with 20+ agents, with 2000+ +subscriptions, with hundreds of messages per second might cause a high CPU +load, thus leading to slow responsiveness in GUI animations. To limit this +phenomenon, use bounded regexp as much as possible like <function>^NAME +VALUE=(.*)</function> ( see the programmer's style guide later on ). However, +2000+ subscription are still 2000+ tests of bounded regexp, even if is less +costful. It is possible not to do the tests provided some requirements are +met: +<itemizedlist> +<listitem><para>your agent knows exhaustively and exactly the prefixes of all +the messages it will send</para></listitem> +<listitem><para>your use the <function>Ivy.setFilter()</function> before +starting the bus, with the list of prefixes ( e.g.: { "TOTO1" "PREFIX", "ETC" +} ) </para></listitem> +</itemizedlist> +</para> + +<para> +If you use the message classes, your Ivy agent will ignore the bounded subscriptions +of other agents that will never match any of your prefixes ( e.g: ^COUCOU +neither matches TOTO1, PREFIX, nor ETC ). The check is made this way: +<itemizedlist> +<listitem><para>if the regexp is bounded, the filter extracts the first word +according to this regexp: <function>^\\^([a-zA-Z0-9_-]+).*</function></para></listitem> +<listitem><para>the word is compared character to character to all the +prefixes in the message class; if it is not present, the subscription is +discarded</para></listitem> +</itemizedlist> +</para> + +<para> +When your agent sends a message, many pattern matching won't be made, and it +might save some time. Be sure to activate the <function>setFilter()</function> +when you are sure that you know perfectly the message classes. You can play +with the message classes with jprobe and see the problems that can arise. +</para> +</sect2> + </sect1><sect1><title>Utilities</title> -<sect2><title>Probe</title> +<sect2><title>jprobe</title> <para> -Probe is your swiss army knife as an Ivy Java developer. Use it +jprobe is your swiss army knife as an Ivy Java developer. Use it to try your regular expressions, to check the installation of the system, to -log the messages, etc. To use it, either run fr.dgac.ivy.tools.Probe, or run the jar -file directly with <command>$ java -jar ivy.jar</command> +log the messages, etc. To use it, either run <command>java +fr.dgac.ivy.tools.Probe</command>, run the jar file directly with <command>$ +java -jar ivy.jar</command>, or use the jprobe shell script. </para> <para> @@ -585,13 +643,16 @@ VY_DEBUG property ( java -DIVY_DEBUG fr.dgac.ivy.tools.Probe is the same as java fr.dgac.ivy.tools.Probe -d ) </para></listitem> <listitem><para> --c MESSAGECLASS uses a message filter (see Ivy.setFilter()), for example +-c MESSAGECLASS uses a message filter (see <function>Ivy.setFilter()</function>), for example 'Word1,Word2,Word3' </para></listitem> <listitem><para> -h dumps the command line options help. </para></listitem> </itemizedlist> +</para> + +<para> The run time commands are preceded by a single dot (.) at the beginning of the line. Issue ".help" at the prompt ( without the double quotes ) to have the list of available commands. If the lines does not begin with a dot, jprobe tries @@ -642,24 +703,131 @@ The "hello world" message will be sent on the default Ivy Bus to anyone having subscribe to a matching pattern</para> </sect2> -<sect2><title>After</title> +<sect2><title>jafter</title> <para> -TODO +jafter ( or fr.dgac.ivy.tools.JAfter ) is a simple utility that can be used +within shell script. The rationale is to block the processing until a specific +message is received, then continue. This can be used to wait for a ready +message before lauching another agent. The jafter program can wait forever or +timeout. It the timeout is triggered, a negative value is returned to the +shell. </sect2> </sect1><sect1><title>programmer's style guide</title> <para> -TODO +There are many specific programming patterns in Ivy. Some of them are Ivy +related, some are java related. See the jprobe source code to get an example +of some programming patterns. Here are some of them, to be completed later... </para> + +<sect2><title>join the right bus</title> +<para> +To join the right bus, you have to honor the IVYBUS property. It is a good way +to let the system get it, and an ever better way to override it with command +line options (e.g.: -b :3110). Here is a snippet to perform this task: +<programlisting> +import fr.dgac.ivy.* ; +import gnu.getopt.Getopt; + +public static void main(String[] args) throws IvyException { + Getopt opt = new Getopt("After",args,"b:"); // add more options ... + String domain=Ivy.getDomain(null); // gets IVYDOMAIN from property + // or, if none is set, defaults to Ivy.DEFAULT_DOMAIN + while ((c = opt.getopt()) != -1) switch (c) { + case 'b': domain=opt.getOptarg(); break; // overrides + // and more options + default: System.out.println(helpmsg); System.exit(0); + } + Ivy bus=new Ivy(name,name+" ready",null); + bus.start(domain); // sets the properties for children processes ... +} +</programlisting> + +</para> +</sect2> + +<sect2><title>nice regular expressions</title> +<para> +To avoid CPU consuming pattern matching operation, be sure to use bounded +regexps as much as possible. For instance, if we consider the regexp1 "^coord +x=(\d+)", the regexp2 "x=(\d+)" and the message msg "coord x=12 y=15". When +another agent sends the message msg, both regexp will match and trigger the +callback with on argument, the string "12". However, when another message is +sent, the regexp1 will fail as soon as possible, probably the very first +character, but the regexp2 will do some processing before failing. +</para> +</sect2> + +<sect2><title>Something's not working</title> +<para> +To trace the behaviour of an heavily multithread application is quite tedious, +especially when it's connected to others. The easiest path is to use the +built-in basic tracing mechanism provided by Ivy : run your jvm with the +-DIVY_DEBUG property set. Use jprobe to monitor what's going on with the +greedy regexp '(.*)' in a separate terminal. If in doubt, just join the Ivy mailing +list. +</para> +</sect2> + +<sect2><title>time consuming callbacks</title> +<para> +For each remote agent, the Ivy object has an IvyClient with a dedicated +working thread. This thread deals with the Ivy protocol coding and decoding, +and performs the callbacks. If your agent has time consuming callbacks, +involving CPU, or long IO, or so, then it might be better to run each callback +in a dedicated thread. You can write this yourself, or just use the +<function>Ivy.bindAsyncMsg()</function> function. The problem is that there is +a slight overhead in thread management. +</para> +</sect2> + +<sect2><title>how to perform requests</title> +<para> +When agent A needs to make a request to another agent B, you +can use the following pattern: +<itemizedlist> +<listitem><para>B has subscribed to ^MyRequest ID=([^ ]+) QUERY=(.*)<para></listitem> +<listitem><para>A subscribes to ^MyResult ID=someSpecificId RESULT=(.*)<para></listitem> +<listitem><para>A send to MyRequest ID=someSpecificId QUERY=2+2<para></listitem> +<listitem><para>B receives, computes the results, then sends MyResult ID=someSpecificId RESULT=4<para></listitem> +<listitem><para>A receives, and unsubscribes to his subscription<para></listitem> +</itemizedlist> +</para> + +<para>To program this, you have to get a gentle way of choosing the +specificId, associate this to the subscription number returned by +Ivy.bindMsg(), and add code within the callback to perform the unsubscription. +Moreover, you have to be sure that there are not two "B type" agents on the +bus, otherwise you'll eventually perform your callback twice if the results +are sent during the short lapse of time before unsubscription. +</para> + +<para>The preferred way is to to let the API provide this singleton mechanism +with <function>Ivy.getWBUID()</function> function returning an unique ID, and +the <function>Ivy.bindMsgOnce()</function> that handles all the mechanisms +ensuring that the callback will be run on time only, and that the +unsubscription will take place. +<programlisting> + String id = bus.getWBUID(); // a more or less unique ID + bus.bindMsgOnce("MyResult ID="+id+" RESULT=(.*)",{ + public void receive(IvyClient ic,String[] args) { + System.out.println("2+2="+args[0]); + // the unsubscription is done for me + } + }); + bus.sendMsg("MyRequest ID="+id+" QUER=2+2"); +</programlisting> +</para> + +</sect2> + </sect1> -<sect1><title>Contacting the author</title> +<sect1><title>Contacting the authors</title> <para> -The Ivy Java library is now maintained by Yannick Jestin. For bug reports or -comments on the library itself or about this document, please send him an -email at <email>jestin@cena.fr</email>. For comments and ideas about Ivy itself -(protocol, applications, etc), please join and use the Ivy mailing list -<email>ivy@cena.fr</email>. +For bug reports or comments on the library itself or about this document, +please me an email at <email>yannick.jestin@enac.fr</email>. For comments and ideas about Ivy itself (protocol, applications, etc), please join and use the +<ulink url="http://www.tls.cena.fr/products/ivy/contact.html">Ivy mailing list</ulink> </para> <para> @@ -15,3 +15,4 @@ JAVA = java JAVAC = javac #JAVAC = /usr/local/j2sdk1.4.2/bin/javac #JAVACOPTS = --encoding=8859_1 -Wall -g +JAR = jar diff --git a/tools/jafter b/tools/jafter index 57c5e28..113a8a9 100755 --- a/tools/jafter +++ b/tools/jafter @@ -6,7 +6,7 @@ jar=/usr/share/java/ivy.jar re=/usr/share/java/regexp.jar -go=/usr/share/java/gnu.getopt.jar +go=/usr/share/java/gnu-getopt.jar bus= if [ "$IVYBUS" ]; then diff --git a/tools/jdaemon b/tools/jdaemon new file mode 100755 index 0000000..6635857 --- /dev/null +++ b/tools/jdaemon @@ -0,0 +1,17 @@ +#!/bin/sh +# +# (c) CENA 2004 +# +# + +jar=/usr/share/java/ivy.jar +re=/usr/share/java/regexp.jar +go=/usr/share/java/gnu-getopt.jar +#jar=../lib/ivy-java-1.2.6.jar +bus= + +if [ "$IVYBUS" ]; then + bus="-DIVYBUS=${IVYBUS}" +fi + +java -classpath ${jar}:${re}:${go} $bus fr.dgac.ivy.tools.IvyDaemon "$@" |