Exemplo n.º 1
0
  public CTplugin(String rootFolder) {

    try {
      CTreader ctreader = new CTreader(rootFolder);
      ctreader.setDebug(debug);

      ArrayList<String> sourceList = ctreader.listSources();

      if (sourceList.size() == 0) {
        if (debug) System.err.println("No Sources in rootFolder: " + rootFolder);
        new PIrun(rootFolder, null, ctreader).start();
      } else {
        if (debug) System.err.println("Multiple Sources found: " + sourceList.size());
        for (String source : sourceList) {
          new PIrun(rootFolder, source, ctreader).start();
        }
      }
    } catch (Exception e) {
      System.err.println("Oops, error on startup: " + e);
      System.exit(0);
    }
  }
Exemplo n.º 2
0
    private PlugInChannelMap handleRegistration(PlugInChannelMap picm) throws Exception {
      // 	picm.PutTime( (System.currentTimeMillis()/1000.0), 0.0);

      try {
        if (((picm.GetName(0).equals("...")) || (picm.GetName(0).equals("*")))) {

          double otime = ctreader.oldTime(sourceFolder);
          double ntime = ctreader.newTime(sourceFolder);
          if (debug)
            System.err.println(
                "handleRegistration picm[0]: "
                    + picm.GetName(0)
                    + ", oldtime: "
                    + otime
                    + ", newtime: "
                    + ntime);

          picm.PutTime(otime, ntime - otime);
          if (regPicm
              != null) { // round about way to cache registration. actual RBNB pre-register does not
            // provide time limits
            if (debug) System.err.println("returning pre-fetched registration...");
            picm.Clear();
            for (int i = 0; i < regPicm.NumberOfChannels(); i++) {
              picm.Add(regPicm.GetName(i));
              picm.PutDataAsString(i, regString(regPicm.GetName(i)));
              picm.PutMime(i, "text/xml");
            }
            return picm; // return pre-fetched registration
          }

          ArrayList<String> chanlist = ctreader.listChans(sourceFolder);
          if (chanlist == null) {
            throw (new Exception("Oops, no channels for sourceFolder: " + sourceFolder));
          }
          picm.Clear();
          for (int i = 0; i < chanlist.size(); i++) {
            int j = picm.Add(chanlist.get(i));
            if (debug) System.err.println("register[" + j + "]: " + picm.GetName(j));
            picm.PutDataAsString(i, regString(chanlist.get(i)));
            picm.PutMime(i, "text/xml");
          }
        } else {
          CTmap ctmap = PI2CTmap(picm); // ignore time limits registration request
          double otime = ctreader.oldTime(sourceFolder, ctmap);
          double ntime = ctreader.newTime(sourceFolder, ctmap);
          picm.PutTime(otime, ntime - otime);
          if (debug)
            System.err.println(
                "handleRegistration picm[0]: "
                    + picm.GetName(0)
                    + ", oldtime: "
                    + otime
                    + ", newtime: "
                    + ntime);

          int nchan = picm.NumberOfChannels();
          if (debug)
            System.err.println("reg-request channel: " + picm.GetName(0) + ", num: " + nchan);
          for (int i = 0; i < nchan; i++) { // put start/end time for each channel individually?
            picm.PutDataAsString(i, regString(picm.GetName(i)));
            picm.PutMime(i, "text/xml");
          }
        }
      } catch (Exception e) {
        System.err.println("handleRegistration exception: " + e);
        e.printStackTrace();
      }
      //	 plugin.Flush(picm);
      return (picm);
    }
Exemplo n.º 3
0
    public void run() {
      if (debug) System.err.println("PIrun, sourceFolder: " + sourceFolder + ", sName: " + sName);

      PlugInChannelMap picm = new PlugInChannelMap();
      plugin = new PlugIn();

      try {
        plugin.OpenRBNBConnection(rbnbServer, sName);
        sink = new Sink();
        sink.OpenRBNBConnection(rbnbServer, sinkName);
      } catch (Exception e) {
        System.err.println("Error on connect: " + e);
        System.exit(0);
        //		    RBNBProcess.exit(0);
      }

      if (preRegister) {
        try {
          System.err.println("pre-registering channels for source: " + sName);
          picm.Add("...");
          regPicm = handleRegistration(picm);
          //					plugin.Register(picm);			// pre-register
          System.err.println("pre-register done: " + sName);
        } catch (Exception se) {
          System.err.println("Oops, exception on preRegister: " + se);
        }
      }

      // process is to wait for request, get data from sink, convert data, send response, repeat
      while (true) {
        try {
          if (debug) System.err.println("waiting on fetch...");
          picm = plugin.Fetch(-1); // block until request arrives
          if (debug) System.err.println("request picm: " + picm);

          if (picm.NumberOfChannels() == 0) {
            System.err.println("oops, no channels in request");
            continue;
          }

          if (picm.GetRequestReference().equals("registration")) {
            if (debug) System.err.println("registration request!");
            plugin.Flush(handleRegistration(picm));
            continue;
          } else {
            double tget = picm.GetRequestStart();
            double tdur = picm.GetRequestDuration();
            String tmode = picm.GetRequestReference();
            CTmap ctmap = PI2CTmap(picm);
            ctmap = ctreader.getDataMap(ctmap, sourceFolder, tget, tdur, tmode);
            picm = CT2PImap(picm, ctmap, tget, tdur, tmode);
            if (debug) System.err.println("Flush picm: " + picm + ", nframe: " + ctmap.size());
            if (picm == null) System.err.println("no channels!");
            else plugin.Flush(picm);
          }
        } catch (Exception e) {
          System.err.println("oops, exception: " + e + ", picm: " + picm);
          e.printStackTrace();
          try {
            Thread.sleep(1000);
            picm.PutDataAsString(0, "error: " + e);
            plugin.Flush(picm);
          } catch (Exception ee) {
          }
          ; // no busy loop
          //				System.exit(0);		// no infinite loops
        }
      }
    }