Math.min(message.length(), MAX_DEBUG_LENGTH))));
/*
* get the JSON formatter, because we know, subgraphs are serialized in
* JSON
*/
final Formatter formatter = new JSONFormatter();
/*
* try to parse the message
*/
P2PMessage msg = null;
try {
msg = P2PMessage.parse(message);
} catch (RuntimeException e) {
l.error(String.format(
"Error unmarshalling received message from %s: %s", from,
message), e);
}
/*
* if this message is a response of subgraph requests, store this result
* and inform waiting instance, that result is received.
*/
if (msg.type != null && msg.type.equals(P2PMessage.SUBGRAPH_RESPONSE)) {
l.debug(String.format(
"Got result from message %s: %s",
msg.id,
msg.message.substring(0,
Math.min(msg.message.length(), MAX_DEBUG_LENGTH))));
/*
* add the result and inform the waiting thread
*/
addMessageResult(msg.id, msg.message);
return;
} else if (msg.type != null
&& msg.type.equals(P2PMessage.SUBGRAPH_REQUEST)) {
/*
* so here, the message is a request, so evaluate the request with
* local evaluator and sent the result back
*/
// Get the subgraph and data for unmarshalling the subgraph into
// operator graph.
final String subgraphSerializedAsJSONString = msg.message;
if (!hasEvaluator())
throw new RuntimeException(
"No local executer found for evaluation subgraph.");
final String _answerId = msg.id;
final Runnable task = new Runnable() {
public void run() {
// get the local evaluator and things for unmarshalling data
QueryEvaluator<?> eval = getEvaluator();
Dataset dataset = null;
// get the creator
IOperatorCreator creater = new QueryClientOperatorCreator();
// get the dataset
if (eval instanceof BasicIndexQueryEvaluator) {
dataset = ((BasicIndexQueryEvaluator) eval)
.getDataset();
}
try {
/*
* now evaluate the subgraph and get the result back as
* Tuple, where the first component is the serialized
* result, and the second is the MIME-type (would be
* here: JSON)
*/
l.debug(String.format(
"Local executing subgraph: %s on %s",
subgraphSerializedAsJSONString, this));
LiteralFactory.setType(MapType.NOCODEMAP);
/*
* this message request is sent via streaming, because
* P2P network does support
*/
if (getP2PNetwork().supportsStreaming()) {
/*
* for streaming we use XML als formatter
*/
final Formatter _formatter = new XMLFormatter();
/*
* create header and evaluate the subgraph
*/
byte[] head = P2PInputStreamMessage.createHeader(
_answerId, true);