コード例 #1
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
        }
      }
    }