[MOBY-guts] biomoby commit
Paul Gordon
gordonp at pub.open-bio.org
Sun Aug 7 23:46:12 UTC 2005
gordonp
Sun Aug 7 19:46:11 EDT 2005
Update of /home/repository/moby/moby-live/Java/docs
In directory pub.open-bio.org:/tmp/cvs-serv28953/docs
Modified Files:
ChangeLog SimpleClient.html
Log Message:
Update of code and documentation for asynchronous calls to MobyRequest
moby-live/Java/docs ChangeLog,1.33,1.34 SimpleClient.html,1.8,1.9
===================================================================
RCS file: /home/repository/moby/moby-live/Java/docs/ChangeLog,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- /home/repository/moby/moby-live/Java/docs/ChangeLog 2005/08/07 06:36:33 1.33
+++ /home/repository/moby/moby-live/Java/docs/ChangeLog 2005/08/07 23:46:11 1.34
@@ -1,3 +1,11 @@
+2005-08-07 Paul Gordon <gordonp at ucalgary.ca>
+
+ * Added asynchronous mode to MobyRequest, so clients get callbacks when
+ results are ready (not to be confused with asynchronous calls at the
+ MOBY protocol level).
+
+ * Web site documentation update for client/server quickstart.
+
2005-08-07 Martin Senger <martin.senger at gmail.com>
* Added methods to Central.java for getting URLs of the RDF
===================================================================
RCS file: /home/repository/moby/moby-live/Java/docs/SimpleClient.html,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- /home/repository/moby/moby-live/Java/docs/SimpleClient.html 2005/08/04 16:27:57 1.8
+++ /home/repository/moby/moby-live/Java/docs/SimpleClient.html 2005/08/07 23:46:11 1.9
@@ -14,11 +14,13 @@
This document is intended to get you up and running using the client-server service communication
code (i.e. calling or providing remote Web Services) in the Java implementation
(<a href="http://www.biomoby.org/moby-live/Java/docs/index.html">jMOBY</a>) of
- <a href="http://www.biomoby.org">MOBY</a>-S "Web Services for Molecular Biology". If you are looking
+ <a href="http://www.biomoby.org">MOBY</a>-S "Web Services for Molecular Biology".
+ This document assumes that you are familiar with <a href="http://java.sun.com">Java</a> and
+ <a href="http://www.w3.org/TR/2004/REC-xml-20040204/"><acronym title="eXtensible Markup Language">XML</acronym></a>.
+ If you are looking
for more detailed information on how to query MOBY Central's yellow pages about what services are
available, please see <a href="http://www.biomoby.org/moby-live/Java/docs/CmdLineClients.html">this
- document</a>. This document assumes that you are familiar with <a href="http://java.sun.com">Java</a> and
- <a href="http://www.w3.org/TR/2004/REC-xml-20040204/"><acronym title="eXtensible Markup Language">XML</acronym></a>.
+ document</a>.
</p>
<h2>Syntax Notes</h2>
@@ -87,7 +89,8 @@
The following code has two parts. First, a service called "MOBYSHoundGetGenBankff" is found via MOBY Central.
This service fetches sequences based on keys such as GenBank gi identifiers. Second, the service
is called using <code>MobyRequest</code> with a sample input <code>MobyDataObject</code>. The result of the
- service invocation (a DNA sequence in XML) is printed.
+ service invocation (a DNA sequence record in
+ <a href="http://www.ncbi.nlm.nih.gov/Sitemap/samplerecord.html">Genbank flat file format</a>) is printed.
<blockquote><code>
<pre>
@@ -143,7 +146,7 @@
which is then visualized or submitted to other services. All MOBY objects have
<a href="http://www.biomoby.org/twiki/bin//view/Moby/MobySAPI#The_root_Object_Class_Minimal_St">a namespace and an ID</a>,
therefore a database identifier is the simplest form of a object. A <code>MobyDataObject</code> constructor is available
-to easily build database identifiers (<code>MobyDataObject(String namespace, String id)</code>):
+to easily build database identifiers, <code>MobyDataObject(String namespace, String id)</code>:
<blockquote><code>MobyDataObject dbid = new MobyDataObject("NCBI_gi", "111076");</code></blockquote>
@@ -155,15 +158,15 @@
<a name="primitives"></a>
<table border="1">
<thead>
-<tr><th><a href="http://www.biomoby.org/twiki/bin//view/Moby/MobySAPI#The_MOBY_Data_Class_Ontology">MOBY Specification</a></th><th>jMOBY class in <code>org.biomoby.shared.data</code></th><th>underlying Java implementation</th><th>Can be instantiated using any one of</th></tr>
+<tr><th><a href="http://www.biomoby.org/twiki/bin//view/Moby/MobySAPI#The_MOBY_Data_Class_Ontology">MOBY Specification</a></th><th>jMOBY class in <code><a href="http://www.biomoby.org/moby-live/Java/docs/API/org/biomoby/shared/data/package-summary.html">org.biomoby.shared.data</a></code></th><th>underlying Java implementation</th><th>Can be instantiated using any one of</th></tr>
</thead>
<tbody>
- <tr><td><em>Object</em></td><td><code>MobyDataObject</code></td><td><code>Object</code></td><td><ul><li>"namespace", "id"</li><li>MOBYDataObject (cloning)</li></ul></tr>
- <tr><td><em>String</em></td><td><code>MobyDataString</code></td><td><code><a href="http://www.javadocs.org/StringBuffer">java.lang.StringBuffer</a></code></td><td><ul><li><a href="http://www.javadocs.org/CharSequence/">java.lang.CharSequence</a> (i.e. CharBuffer, String, StringBuffer, StringBuilder)</li></ul></td></tr>
- <tr><td><em>Integer</em></td><td><code>MobyDataInt</code></td><td><code><a href="http://www.javadocs.org/BigInteger">java.math.BigInteger</a></code></td><td><ul><li>int</li><li><a href="http://www.javadocs.org/Number">java.lang.Number</a> (i.e. Byte, Double, Float, Integer, Long, Short, BigInteger, BigDecimal)</li><li>Strings like "2005"</li></ul></tr>
- <tr><td><em>Float</em></td><td><code>MobyDataFloat</code></td><td><code><a href="http://www.javadocs.org/BigDecimal">java.math.BigDecimal</a></code></td><td><ul><li>double</li><li>java.lang.Number</li><li>Strings like "2.0-e4" or "0.0002"</li></ul></tr>
- <tr><td><em>Boolean</em></td><td><code>MobyDataBoolean</code></td><td><code><a href="http://www.javadocs.org/Boolean">java.lang.Boolean</a></code></td><td><ul><li>Boolean</li><li>boolean</li><li>Strings "true" or "false"</li></ul></tr>
- <tr><td><em>DateTime</em></td><td><code>MobyDataDateTime</code></td><td><code><a href="http://www.javadocs.org/GregorianCalendar">java.util.GregorianCalendar</a></code></td><td><ul><li>java.util.GregorianCalendar</li><li>Strings like "2005-07-21" (a <a href="http://www.w3.org/TR/NOTE-datetime">W3C profile version of an ISO 8601 date-time string</a>)</a></ul></tr>
+ <tr><td><em>Object</em></td><td><code><a href="http://www.biomoby.org/moby-live/Java/docs/API/org/biomoby/shared/data/MobyDataObject.html">MobyDataObject</a></code></td><td><code><a href="http://www.javadocs.org/Object">Object</a></code></td><td><ul><li>"namespace", "id"</li><li>MOBYDataObject (cloning)</li></ul></tr>
+ <tr><td><em>String</em></td><td><code><a href="http://www.biomoby.org/moby-live/Java/docs/API/org/biomoby/shared/data/MobyDataString.html">MobyDataString</a></code></td><td><code><a href="http://www.javadocs.org/StringBuffer">java.lang.StringBuffer</a></code></td><td><ul><li><a href="http://www.javadocs.org/CharSequence/">java.lang.CharSequence</a> (i.e. CharBuffer, String, StringBuffer, StringBuilder)</li></ul></td></tr>
+ <tr><td><em>Integer</em></td><td><code><a href="http://www.biomoby.org/moby-live/Java/docs/API/org/biomoby/shared/data/MobyDataInt.html">MobyDataInt</a></code></td><td><code><a href="http://www.javadocs.org/BigInteger">java.math.BigInteger</a></code></td><td><ul><li>int</li><li><a href="http://www.javadocs.org/Number">java.lang.Number</a> (i.e. Byte, Double, Float, Integer, Long, Short, BigInteger, BigDecimal)</li><li>Strings like "2005"</li></ul></tr>
+ <tr><td><em>Float</em></td><td><code><a href="http://www.biomoby.org/moby-live/Java/docs/API/org/biomoby/shared/data/MobyDataFloat.html">MobyDataFloat</a></code></td><td><code><a href="http://www.javadocs.org/BigDecimal">java.math.BigDecimal</a></code></td><td><ul><li>double</li><li>java.lang.Number</li><li>Strings like "2.0-e4" or "0.0002"</li></ul></tr>
+ <tr><td><em>Boolean</em></td><td><code><a href="http://www.biomoby.org/moby-live/Java/docs/API/org/biomoby/shared/data/MobyDataBoolean.html">MobyDataBoolean</a></code></td><td><code><a href="http://www.javadocs.org/Boolean">java.lang.Boolean</a></code></td><td><ul><li>Boolean</li><li>boolean</li><li>Strings "true" or "false"</li></ul></tr>
+ <tr><td><em>DateTime</em></td><td><code><a href="http://www.biomoby.org/moby-live/Java/docs/API/org/biomoby/shared/data/MobyDataDateTime.html">MobyDataDateTime</a></code></td><td><code><a href="http://www.javadocs.org/GregorianCalendar">java.util.GregorianCalendar</a></code></td><td><ul><li>java.util.GregorianCalendar</li><li>Strings like "2005-07-21" (a <a href="http://www.w3.org/TR/NOTE-datetime">W3C profile version of an ISO 8601 date-time string</a>)</a></ul></tr>
</tbody>
</table>
Any object can also be instantiated using the corresponding XML data as an <code><a href="http://www.javadocs.org/Element">org.w3c.dom.Element</a></code>.
@@ -172,9 +175,10 @@
<blockquote><code>MobyDataString sequenceString = new MobyDataString("MPGGFILAIDEGTTSARAIIYNQDLEVLGIGQYDFPQHYPSPGYVEHNPDEIWNAQMLAI");</code></blockquote>
<blockquote><code>MobyDataInt sequenceLength = new MobyDataInt(60);</code></blockquote>
<blockquote><code>MobyDataFloat sequence<a href="http://www.expasy.org/tools/pi_tool-doc.html">PI</a> = new MobyDataFloat(3.67);</code></blockquote>
-<blockquote><code>MobyDataFloat sequence<a href="http://www.ncbi.nlm.nih.gov/Education/BLASTinfo/information3.html"><acronym title="Blasic Local Alignment Search Tool">Blast</acronym></a><a href="http://www.ncbi.nlm.nih.gov/BLAST/tutorial/Altschul-1.html#head2">EValue</a> = new MobyDataFloat("1e-29");</code></blockquote>
+<blockquote><code>MobyDataFloat sequence<a href="http://www.ncbi.nlm.nih.gov/Education/BLASTinfo/information3.html"><acronym title="Basic Local Alignment Search Tool">Blast</acronym></a><a href="http://www.ncbi.nlm.nih.gov/BLAST/tutorial/Altschul-1.html#head2">EValue</a> = new MobyDataFloat("1e-29");</code></blockquote>
+<blockquote><code>MobyDataBoolean <a href="http://www.embl-heidelberg.de/~andrade/papers/rep/search.html">isRepetitive</a> = new MobyDataBoolean(false);</code></blockquote>
<blockquote><code>MobyDataDateTime <a href="ftp://ftp.ncbi.nih.gov/blast/db/blastdb.txt">blastDB</a>Updated = new MobyDataDateTime("2005-03-24");</code></blockquote>
-<blockquote><code></code></blockquote>
+<blockquote><code>MobyDataDateTime now = new MobyDataDateTime(Calendar.getInstance());</code></blockquote>
</p>
<h3>Creating composite objects</h3>
@@ -195,7 +199,7 @@
<h3>Dealing with binary data</h3>
<p>Because there is no byte array equivalent in MOBY, all binary data must be encoded as a text string. The
most used text encoding is <a href="http://en.wikipedia.org/wiki/Base64">Base64</a>, and jMOBY contains a convenience
-class (<code>MobyDataBytes</code>) that will encode and decode for you. For example, to create a
+class (<code><a href="http://www.biomoby.org/moby-live/Java/docs/API/org/biomoby/shared/data/MobyDataBytes.html">MobyDataBytes</a></code>) that will encode and decode for you. For example, to create a
<em>b64_encoded_gif</em> using the URL based constructor:
<blockquote><code><pre>
@@ -230,9 +234,57 @@
<h2>Client/Server Communication (<code>MobyRequest</code>)</h2>
<p>
-We have seen the <code>MobyRequest</code> class in the <a href="#helloWorld">Hello World</a> example -- it
-invokes and sends data to a remote Web service. It can also be used by a service provider to parse an incoming
-request and return the results. <font color="red">More info to come shortly...</font>
+We have seen the <code>MobyRequest</code> class in the <a href="#helloWorld">HelloMOBY</a> example -- it
+synchronously sent data to a remote Web service and waited for a response. This class can also work
+<a href="http://searchnetworking.techtarget.com/sDefinition/0,,sid7_gci211605,00.html">asynchronously</a>,
+performing a callback to a <code>MobyRequestEventHandler</code> when the response is available.
+Let's recode (<a href="http://www.biomoby.org/GettingTheCode.html">available in the CVS</a> Client directory)
+the HelloMOBY example to work asynchronously:
+
+<blockquote><code><pre>
+import org.biomoby.client.*;
+import org.biomoby.shared.*;
+import org.biomoby.shared.data.*;
+
+public class HelloMOBY2 implements MobyRequestEventHandler{
+ public static void main(String[] args) throws Exception{
+
+ Central worker = new CentralImpl();
+ MobyService templateService = new MobyService("MOBYSHoundGetGenBankff");
+ MobyService[] validServices = worker.findService(templateService);
+
+ MobyRequest mr = new MobyRequest(worker);
+ mr.setService(validServices[0]);
+ mr.setInput(new MobyDataObject("NCBI_gi", "111076"));
+
+ // HelloMOBY2 (ourselves) is a valid listener, must use "new" to
+ // have a non-static reference for callback
+ mr.invokeService(new HelloMOBY2());
+
+ // Infinite loop broken only by exit in callback function
+ while(true){
+ System.err.print("."); // Print a dot every second (poor man's text hourglass)
+ try{Thread.sleep(100);}catch(InterruptedException ie){}
+ }
+ }
+
+ // Called by MobyRequest when the response is available
+ public void processEvent(MobyRequestEvent mre){
+ System.out.println(""); // Blank line to seperate response from hourglass dots
+ System.out.println(mre.getContent().toString());
+ System.exit(0);
+ }
+}
+</pre></code></blockquote>
+
+</p>
+
+<p>
+
+It can also be used by a service
+provider to parse an incoming request and return the results.
+
+<font color="red">More info to come shortly...</font>
</p>
<a name="manipulatingjMOBYData"></a>
@@ -262,8 +314,9 @@
<p>The <code>getObject</code> method allows the user to retrieve the underlying internal
representation of the MOBY data in any <code>MobyDataInstance</code>. The returned <code>Object</code> can be safely
cast as listed <a href="#primitives">in the primitives table above</a>, <code>MobyDataComposite</code>
-uses a <code>HashMap</code>, <code>MobyDataObjectSet</code> uses a <code>Vector</code>. Modifying mutable returned
-object modifies the MobyDataObject from which it came. For example, building on the previous example:
+uses a <code>HashMap</code>, <code>MobyDataObjectSet</code> uses a <code>Vector</code>. Modifying a mutable returned
+object (from <code>MobyString</code>, <code>MobyDateTime</code>, or <code>MobyDataBytes</code>) modifies the
+MobyDataObject from which it came. For example, building on the previous example:
<blockquote><code><pre>
StringBuffer mutableSequence = (StringBuffer) ((MobyDataString) data.get("SequenceString")).getObject();
@@ -274,7 +327,17 @@
</pre></code></blockquote>
This would print the sequence XML, with the first three letters of the sequence string being "XXX". Note that you do have to do some casting to get all of these data right. When jMOBY requires Java 1.5, we can get rid of several of these cast annoyances by using the Generics construct.
+</p>
+
+<p>For classes with unmutable underlying objects (<code>MobyDataInt</code>, <code>MobyDataFloat</code>, and <code>MobyDataBoolean</code>), <a href="http://www.biomoby.org/moby-live/Java/docs/API/org/biomoby/shared/data/MobyDataInt.html#method_summary">methods</a> have been added to modify the object values rather than having to build new ones. For example:
+
+<blockquote><code><pre>
+mobyBooleanObject.setValue(true);
+mobyFloatObject.divide(Math.PI);
+mobyIntObject.add(new Integer(2));
+</pre></code></blockquote>
+The math functions have been written to maintain as much numerical precision as possible.
</p>
<hr/>
@@ -346,7 +409,7 @@
<address><a href="mailto:gordonp at ucalgary.ca">Paul Gordon</a></address>
<!-- Created: Wed Jul 20 11:44:30 MDT 2005 -->
<!-- hhmts start -->
-Last modified: Thu Aug 4 11:22:27 MDT 2005
+Last modified: Sun Aug 7 18:34:57 MDT 2005
<!-- hhmts end -->
</body>
</html>
More information about the MOBY-guts
mailing list