TimingOutCallback.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 
00024 
00043 public class TimingOutCallback implements AsyncCallback {
00046     public static class TimeoutException extends XmlRpcException {
00047         private static final long serialVersionUID = 4875266372372105081L;
00048 
00052         public TimeoutException(int pCode, String message) {
00053             super(pCode, message);
00054         }
00055     }
00056 
00057     private final long timeout;
00058     private Object result;
00059     private Throwable error;
00060     private boolean responseSeen;
00061 
00064     public TimingOutCallback(long pTimeout) {
00065         timeout = pTimeout;
00066     }
00067 
00073     public synchronized Object waitForResponse() throws Throwable {
00074         if (!responseSeen) {
00075             wait(timeout);
00076             if (!responseSeen) {
00077                 throw new TimeoutException(0, "No response after waiting for " + timeout + " milliseconds.");
00078             }
00079         }
00080         if (error != null) {
00081             throw error;
00082         }
00083         return result;
00084     }
00085 
00086     public synchronized void handleError(XmlRpcRequest pRequest, Throwable pError) {
00087         responseSeen = true;
00088         error = pError;
00089         notify();
00090     }
00091 
00092     public synchronized void handleResult(XmlRpcRequest pRequest, Object pResult) {
00093         responseSeen = true;
00094         result = pResult;
00095         notify();
00096     }
00097 }


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