| 1 |
package org.astrogrid.samp.xmlrpc.apache; |
| 2 |
|
| 3 |
import java.io.IOException; |
| 4 |
import java.util.List; |
| 5 |
import java.util.Vector; |
| 6 |
import org.apache.xmlrpc.XmlRpcClient; |
| 7 |
import org.apache.xmlrpc.XmlRpcException; |
| 8 |
import org.astrogrid.samp.xmlrpc.SampXmlRpcClient; |
| 9 |
|
| 10 |
/** |
| 11 |
* SampXmlRpcClient implementation based on Apache XMLRPC classes. |
| 12 |
* |
| 13 |
* @author Mark Taylor |
| 14 |
* @since 16 Sep 2008 |
| 15 |
*/ |
| 16 |
public class ApacheClient implements SampXmlRpcClient { |
| 17 |
|
| 18 |
private final XmlRpcClient xmlrpcClient_; |
| 19 |
|
| 20 |
/** |
| 21 |
* Constructor. |
| 22 |
* |
| 23 |
* @param xmlrpcClient Apache XML-RPC client instance |
| 24 |
*/ |
| 25 |
public ApacheClient( XmlRpcClient xmlrpcClient ) { |
| 26 |
xmlrpcClient_ = xmlrpcClient; |
| 27 |
} |
| 28 |
|
| 29 |
public Object callAndWait( String method, List params ) |
| 30 |
throws IOException { |
| 31 |
try { |
| 32 |
return xmlrpcClient_ |
| 33 |
.execute( method, (Vector) ApacheUtils.toApache( params ) ); |
| 34 |
} |
| 35 |
catch ( XmlRpcException e ) { |
| 36 |
throw (IOException) new IOException( e.getMessage() ) |
| 37 |
.initCause( e ); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
public void callAndForget( String method, List params ) |
| 42 |
throws IOException { |
| 43 |
|
| 44 |
// I'm not sure that the Apache implementation is *sufficiently* |
| 45 |
// asynchronous. It does leave a thread hanging around waiting |
| 46 |
// for a response, though the result of this response is |
| 47 |
// discarded. May cause problems under heavy load. |
| 48 |
xmlrpcClient_ |
| 49 |
.executeAsync( method, (Vector) ApacheUtils.toApache( params ), |
| 50 |
null ); |
| 51 |
} |
| 52 |
} |