public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
   response.setStatus(HttpServletResponse.SC_OK);
   String vsName = request.getParameter("name");
   VSensorConfig sensorConfig = Mappings.getVSensorConfig(vsName);
   if (logger.isInfoEnabled())
     logger.info(
         new StringBuilder()
             .append("Structure request for *")
             .append(vsName)
             .append("* received.")
             .toString());
   StringBuilder sb =
       new StringBuilder("<virtual-sensor name=\"")
           .append(vsName)
           .append("\" last-modified=\"")
           .append(new File(sensorConfig.getFileName()).lastModified())
           .append("\">\n");
   for (KeyValue df : sensorConfig.getAddressing())
     sb.append("<predicate key=\"")
         .append(StringEscapeUtils.escapeXml(df.getKey().toString()))
         .append("\">")
         .append(StringEscapeUtils.escapeXml(df.getValue().toString()))
         .append("</predicate>\n");
   sb.append("</virtual-sensor>");
   response.setHeader("Cache-Control", "no-store");
   response.setDateHeader("Expires", 0);
   response.setHeader("Pragma", "no-cache");
   response.getWriter().write(sb.toString());
 }
Beispiel #2
0
  public static void run(Configuration config, String file, String date) {

    initStationCode(file);

    List<KeyValue> lsttrain = getAllTrainInfo(config, date);
    for (KeyValue item : lsttrain) {
      System.out.println("from " + item.getKey() + " to " + item.getValue());
    }
  }
Beispiel #3
0
  public void evaluate(
      LoggedInInfo loggedInInfo,
      Denominator deno,
      Numerator numer,
      List<KeyValue> additionalFields) {
    denominator = deno;
    numerator = numer;
    List demoList = deno.getDenominatorList();
    denominatorCount = demoList.size();
    setReportResultList(new ArrayList<Hashtable<String, Object>>());
    for (int i = 0; i < demoList.size(); i++) {
      String demo = (String) demoList.get(i);
      boolean bool = numer.evaluate(loggedInInfo, demo);
      // Object obj = numer.getOutputValues();  // PROBLEM IS THAT THIS WILL ALWAYS HAVE A VALUE
      Hashtable<String, Object> h = new Hashtable<String, Object>();
      h.put("_demographic_no", demo);
      h.put("_report_result", new Boolean(bool));

      if (additionalFields != null) {
        for (KeyValue field : additionalFields) {
          String key = (String) field.getKey();
          String val = (String) field.getValue();

          EctMeasurementsDataBeanHandler ect =
              new EctMeasurementsDataBeanHandler(Integer.valueOf(demo), val);
          Collection<EctMeasurementsDataBean> v = ect.getMeasurementsDataVector();
          // Execute for the value and attach it to the key in the hashtable
          // Object obj =
          if (v.iterator().hasNext()) {
            h.put(key, v.iterator().next());
          }
        }
      }

      getReportResultList().add(h);
      //            if (obj != null){
      //                getReportResultList().add(obj);
      //            }
      if (bool) {
        numeratorCount++;
      }
    }
  }
 /**
  * Constructs a new entry from the specified KeyValue.
  *
  * @param pair the pair to copy, must not be null
  * @throws NullPointerException if the entry is null
  */
 public DefaultMapEntry(final KeyValue pair) {
   super(pair.getKey(), pair.getValue());
 }
Beispiel #5
0
  public static List<KeyValue> getAllTrainInfo(Configuration config, String date) {
    List<KeyValue> result = new ArrayList<>();
    String strJson = null;
    BufferedWriter writer = null;
    Table table = null;
    try (Connection connect = ConnectionFactory.createConnection(config);
        Admin admin = connect.getAdmin()) {
      TableName tablename = TableName.valueOf(TABLE_NAME);
      if (!admin.tableExists(tablename)) {
        System.out.println("Table does not exist.");
        return null;
      }

      table = connect.getTable(tablename);
      Put put = null;
      String start = null;
      String end = null;
      writer = new BufferedWriter(new FileWriter(new File(strConfig), true));
      for (KeyValue item : lstAllProcessStation) {
        start = (String) item.getKey();
        end = (String) item.getValue();
        try {
          try {
            Thread.sleep(200);
          } catch (InterruptedException e1) {
            e1.printStackTrace();
          }
          System.out.println("process : " + start + ":" + end);
          strJson = getFromAPIX(mapStationCode.get(start), mapStationCode.get(end), date);
          writer.write(start + ":" + end);
          writer.newLine();

        } catch (Exception e) {
          System.out.println(start + ":" + end + "error");
          e.printStackTrace();
          break;
        }
        JSONObject jo = new JSONObject(strJson);

        if (jo.has("httpstatus") && (jo.getInt("httpstatus") == 200)) {
          JSONObject joData = jo.getJSONObject("data");
          if (joData.has("flag") && joData.getBoolean("flag")) {
            result.add(new DefaultKeyValue(start, end));
            // 插入到hbase
            String rowkey = start + ":" + end;
            put = new Put(rowkey.getBytes());
            put.addColumn(
                CF_JSON.getBytes(), "json".getBytes(), joData.toString().getBytes("utf-8"));
            table.put(put);

            System.out.println("start " + start + "\t end " + end + "\t has ticket");
          }
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if (writer != null) {
        try {
          writer.flush();
          writer.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      if (table != null) {
        try {
          table.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }

    return result;
  }