org.dianahep.root4j.daemon.xrootd.Callback Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of root4j Show documentation
Show all versions of root4j Show documentation
Derived from FreeHEP ROOT IO (http://java.freehep.org/freehep-rootio); modernized and GUI dropped.
package org.dianahep.root4j.daemon.xrootd;
import java.io.IOException;
/**
*
* @author tonyj
*/
abstract class Callback {
/**
* Called by the system when a response is ready. This method must completely
* read the response before returning. Since xrootd supports partial responses
* this method may be called multiple times for a single message (in which case
* response.isComplete() == false
for all but the last call).
* @param response The response
* @return The final result of processing the response.
* @throws java.io.IOException If there is an error reading the response
*/
abstract V responseReady(Response response) throws IOException;
/**
* Called if the original message had to be resubmitted. In this case any
* partial responses previously received should be discarded. Default implementation
* does nothing.
*/
void clear() {
}
/**
* The default response callback reads any data available in the response,
* and returns null as the response.
*/
static class DefaultCallback extends Callback {
public Void responseReady(Response response) throws IOException {
response.readData();
return null;
}
}
static class StringCallback extends Callback {
String responseReady(Response response) throws IOException {
return response.getDataAsString();
}
}
}