Package lupos.endpoint.server.format

Examples of lupos.endpoint.server.format.Formatter


            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);
View Full Code Here


    if(args.length<3 || args.length%2 == 0){
      System.err.println("Wrong number of arguments!");
    }
    final RDF3XQueryEvaluator evaluator = new RDF3XQueryEvaluator();
    evaluator.loadLargeScaleIndices(args[0]);
    final Formatter formatter = new XMLFormatter();
    ServiceApproaches.Semijoin_Approach.setup();
    for(int i=1; i<args.length; i+=2){
      final String query = FileHelper.readFile(args[i]);
      System.out.println("\nProcess SPARQL query:");
      System.out.println(query);
      final QueryResult queryResult = evaluator.getResult(query, true);
      System.out.println("\nSave result into file: "+args[i+1]);
      final OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(args[i+1]));
      formatter.writeResult(outputStream, evaluator.getVariablesOfQuery(), queryResult);
      outputStream.close();
      evaluator.writeOutIndexFileAndModifiedPages(args[0]);
      queryResult.release();
    }
    System.out.println("\nDone!");
View Full Code Here

      final String response = Endpoint.getResponse(t);
      final String[] responseParts = response.split("[&]");
      if(responseParts.length>0){
        // first check whether or not a format is given (default is XML as defined by W3C)
        final String formatParameter = Endpoint.getParameter(responseParts, format, "XML");
        final Formatter formatter = registeredFormatter.get(formatParameter.toLowerCase());
        if(formatter == null){
          t.getResponseHeaders().add("Content-type", "text/plain");
          final String answer = "Bad Request: format " + formatParameter + " not supported";
          System.out.println(answer);
          Endpoint.sendString(t, answer);
View Full Code Here

TOP

Related Classes of lupos.endpoint.server.format.Formatter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.