Пример #1
0
 public static boolean addVSensorInstance(VirtualSensor sensorPool) {
   try {
     if (logger.isInfoEnabled())
       logger.info(
           (new StringBuilder("Testing the pool for :"))
               .append(sensorPool.getConfig().getName())
               .toString());
     sensorPool.returnVS(sensorPool.borrowVS());
   } catch (Exception e) {
     logger.error(e.getMessage(), e);
     sensorPool.closePool();
     logger.error(
         "GSN can't load the virtual sensor specified at "
             + sensorPool.getConfig().getFileName()
             + " because the initialization of the virtual sensor failed (see above exception).");
     logger.error("Please fix the following error");
     return false;
   }
   TreeMap<String, Boolean> vsNameToOutputStructureFields = new TreeMap<String, Boolean>();
   vsNamesToOutputStructureFields.put(
       sensorPool.getConfig().getName(), vsNameToOutputStructureFields);
   for (DataField fields : sensorPool.getConfig().getOutputStructure())
     vsNameToOutputStructureFields.put(fields.getName(), Boolean.TRUE);
   vsNameToOutputStructureFields.put("timed", Boolean.TRUE);
   vsNameTOVSConfig.put(sensorPool.getConfig().getName(), sensorPool.getConfig());
   fileNameToVSInstance.put(sensorPool.getConfig().getFileName(), sensorPool);
   return true;
 }
Пример #2
0
 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("\">\n");
   for (DataField df : sensorConfig.getOutputStructure())
     sb.append("<field name=\"")
         .append(df.getName())
         .append("\" ")
         .append("type=\"")
         .append(df.getType())
         .append("\" ")
         .append("description=\"")
         .append(StringEscapeUtils.escapeXml(df.getDescription()))
         .append("\" />\n");
   sb.append(
       "<field name=\"timed\" type=\"string\" description=\"The timestamp associated with the stream element\" />\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());
 }