示例#1
0
  protected void prepare(
      Map stormConf, final TopologyContext context, final IOutputCollector collector) {

    _rand = new Random();
    _collector = collector;

    _context = context;

    heartbeatTimeoutMills = getHeartbeatTimeoutMillis(stormConf);

    _process = new NuShellProcess(_command, this, this);

    // subprocesses must send their pid first thing
    Number subpid = _process.launch(stormConf, context);
    LOG.info("Launched subprocess with pid " + subpid);
    this.pid = subpid.longValue();

    /**
     * randomizing the initial delay would prevent all shell bolts from heartbeating at the same
     * time frame
     */
    int initialDelayMillis = random.nextInt(4000) + 1000;
    BoltHeartbeatTimerTask task = new BoltHeartbeatTimerTask(this);
    heartBeatExecutorService.scheduleAtFixedRate(
        task, initialDelayMillis, getHeartbeatPeriodMillis(stormConf), TimeUnit.MILLISECONDS);
  }
示例#2
0
 private void onStartExecution() {
   log.debug("Starting canvas {}", getLabel());
   setRunning(true);
   setTime(0);
   synchronized (datesLock) {
     startTime = new Date();
     endTime = null;
   }
   timerFuture =
       scheduler.scheduleAtFixedRate(new TimeUpdateTask(), 250, 250, TimeUnit.MILLISECONDS);
   fixTimeLimit();
   hasStarted = true;
   setCompleted(false);
 }
示例#3
0
  /**
   * The dependent service is available and the bundle will start.
   *
   * @param dependentService the UIService this activator is waiting.
   */
  @Override
  public void start(Object dependentService) {
    if (logger.isDebugEnabled()) logger.debug("Update checker [STARTED]");

    ConfigurationService cfg = getConfiguration();

    if (OSUtils.IS_WINDOWS) {
      updateService = new Update();

      bundleContext.registerService(UpdateService.class.getName(), updateService, null);

      // Register the "Check for Updates" menu item if
      // the "Check for Updates" property isn't disabled.
      if (!cfg.getBoolean(CHECK_FOR_UPDATES_MENU_DISABLED_PROP, false)) {
        // Register the "Check for Updates" menu item.
        CheckForUpdatesMenuItemComponent checkForUpdatesMenuItemComponent =
            new CheckForUpdatesMenuItemComponent(Container.CONTAINER_HELP_MENU);

        Hashtable<String, String> toolsMenuFilter = new Hashtable<String, String>();
        toolsMenuFilter.put(Container.CONTAINER_ID, Container.CONTAINER_HELP_MENU.getID());

        bundleContext.registerService(
            PluginComponent.class.getName(), checkForUpdatesMenuItemComponent, toolsMenuFilter);
      }

      // Check for software update upon startup if enabled.
      if (cfg.getBoolean(UPDATE_ENABLED, true)) updateService.checkForUpdates(false);
    }

    if (cfg.getBoolean(CHECK_FOR_UPDATES_DAILY_ENABLED_PROP, false)) {
      logger.info("Scheduled update checking enabled");

      // Schedule a "check for updates" task that will run once a day
      int hoursToWait = calcHoursToWait();
      Runnable updateRunnable =
          new Runnable() {
            public void run() {
              logger.debug("Performing scheduled update check");
              getUpdateService().checkForUpdates(false);
            }
          };

      mUpdateExecutor = Executors.newSingleThreadScheduledExecutor();
      mUpdateExecutor.scheduleAtFixedRate(
          updateRunnable, hoursToWait, 24 * 60 * 60, TimeUnit.SECONDS);
    }

    if (logger.isDebugEnabled()) logger.debug("Update checker [REGISTERED]");
  }
示例#4
0
  public void receiveData(
      String ip,
      String paramName,
      String paramNo,
      int paramBote,
      int paramLength,
      int parmParity,
      int parmStopBit,
      int parmDelay) {
    try {
      try {
        m = new Mongo(ip, 27017);
        db = m.getDB(paramName);
        // db.authenticate("test", "123".toCharArray());
      } catch (UnknownHostException ex) {
        ex.printStackTrace();
      } catch (MongoException e) {
        e.printStackTrace();
      }
      final DBCollection coll = db.getCollection("DATAIN");
      final DBCollection collout = db.getCollection("DATAOUT");
      DBCollection meta = db.getCollection("META");

      // 记录数据字段
      final Map map1 = new HashMap();
      final Map map2 = new HashMap();
      Map map00 = new HashMap();
      Map map01 = new HashMap();
      Map map02 = new HashMap();
      Map map03 = new HashMap();

      final Map m_ai_max = new HashMap();
      final Map m_ai_min = new HashMap();
      final Map m_ao_max = new HashMap();
      final Map m_ao_min = new HashMap();

      DBCursor cursor = meta.find();
      while (cursor.hasNext()) {
        // 记录数据类型
        DBObject dbo = cursor.next();
        String name = dbo.get("_id").toString();
        String type = dbo.get("type").toString();
        String addr = dbo.get("addr").toString();
        Double max = (Double) dbo.get("max");
        Double min = (Double) dbo.get("min");
        if (type.equals("AI")) {
          map00.put(name, addr);
          m_ai_max.put(name, max);
          m_ai_min.put(name, min);
        }
        if (type.equals("DI")) {
          map01.put(name, addr);
        }
        if (type.equals("AO")) {
          map02.put(name, addr);
        }
        if (type.equals("DO")) {
          map03.put(name, addr);
        }
      }
      map1.put("AI", map00);
      map1.put("DI", map01);

      map2.put("AO", map02);
      map2.put("DO", map03);

      SerialParameters params = new SerialParameters();
      params.setCommPortId(paramNo);
      params.setBaudRate(paramBote);
      params.setDataBits(paramLength);
      params.setParity(parmParity);
      params.setStopBits(parmStopBit);
      ModbusFactory modbusFactory = new ModbusFactory();
      slave = modbusFactory.createRtuSlave(params);

      slave.addProcessImage(getModscanProcessImage(1, map00, coll));
      slave.addProcessImage(getModscanProcessImage(2, map01, coll));
      slave.addProcessImage(getModscanProcessImage(3, map02, collout));
      slave.addProcessImage(getModscanProcessImage(4, map03, collout));
      new Thread(
              new Runnable() {
                public void run() {
                  try {
                    slave.start();
                    // JOptionPane.showMessageDialog(f, "通讯连接成功!");
                  } catch (ModbusInitException e) {
                    e.printStackTrace();
                  }
                }
              })
          .start();
      ScheduledExecutorService timerRead = Executors.newScheduledThreadPool(1);
      timerRead.scheduleAtFixedRate(
          new Runnable() {
            public void run() {
              new TaskRead(map1, m_ai_max, m_ai_min, coll, slave);
            }
          },
          500,
          parmDelay,
          TimeUnit.MILLISECONDS);
      ScheduledExecutorService timerWrite = Executors.newScheduledThreadPool(2);
      timerWrite.scheduleAtFixedRate(
          new Runnable() {
            public void run() {
              new TaskWrite(map2, m_ao_max, m_ao_min, collout, slave);
            }
          },
          500,
          parmDelay,
          TimeUnit.MILLISECONDS);
    } catch (Exception ex) {
    }
  }
示例#5
0
 public ScheduledFuture<?> scheduleAtFixedRate(
     Runnable command, long initialDelay, long period, TimeUnit unit) {
   return e.scheduleAtFixedRate(command, initialDelay, period, unit);
 }
 public void startDaemon() {
   scheduledTask = scheduler.scheduleAtFixedRate(this, 1, 1, TimeUnit.SECONDS);
 }