XmlRpcClientWorker.java
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one
00003  * or more contributor license agreements.  See the NOTICE file
00004  * distributed with this work for additional information
00005  * regarding copyright ownership.  The ASF licenses this file
00006  * to you under the Apache License, Version 2.0 (the
00007  * "License"); you may not use this file except in compliance
00008  * with the License.  You may obtain a copy of the License at
00009  *
00010  *   http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing,
00013  * software distributed under the License is distributed on an
00014  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00015  * KIND, either express or implied.  See the License for the
00016  * specific language governing permissions and limitations
00017  * under the License.    
00018  */
00019 package org.apache.xmlrpc.client;
00020 
00021 import org.apache.xmlrpc.XmlRpcException;
00022 import org.apache.xmlrpc.XmlRpcRequest;
00023 import org.apache.xmlrpc.common.XmlRpcController;
00024 import org.apache.xmlrpc.common.XmlRpcWorker;
00025 
00026 
00032 public class XmlRpcClientWorker implements XmlRpcWorker {
00033         private final XmlRpcClientWorkerFactory factory;
00034 
00039         public XmlRpcClientWorker(XmlRpcClientWorkerFactory pFactory) {
00040                 factory = pFactory;
00041         }
00042 
00043         public XmlRpcController getController() {
00044                 return factory.getController();
00045         }
00046 
00052         public Object execute(XmlRpcRequest pRequest)
00053                         throws XmlRpcException {
00054                 try {
00055                         XmlRpcClient client = (XmlRpcClient) getController();
00056                         return client.getTransportFactory().getTransport().sendRequest(pRequest);
00057                 } finally {
00058                         factory.releaseWorker(this);
00059                 }
00060         }
00061 
00062         protected Thread newThread(Runnable pRunnable) {
00063                 Thread result = new Thread(pRunnable);
00064                 result.setDaemon(true);
00065                 return result;
00066         }
00067 
00072         public void execute(final XmlRpcRequest pRequest,
00073                                                 final AsyncCallback pCallback) {
00074                 Runnable runnable = new Runnable(){
00075                         public void run(){
00076                                 Object result = null;
00077                                 Throwable th = null;
00078                                 try {
00079                                         XmlRpcClient client = (XmlRpcClient) getController();
00080                                         result = client.getTransportFactory().getTransport().sendRequest(pRequest);
00081                                 } catch (Throwable t) {
00082                                         th = t;
00083                                 }
00084                                 factory.releaseWorker(XmlRpcClientWorker.this);
00085                                 if (th == null) {
00086                                         pCallback.handleResult(pRequest, result);
00087                                 } else {
00088                                         pCallback.handleError(pRequest, th);
00089                                 }
00090                         }
00091                 };
00092                 newThread(runnable).start();
00093         }
00094 }


rosjava_core
Author(s):
autogenerated on Wed Aug 26 2015 16:06:49