예제 #1
0
  public Importer(NetworkParameters params, Jelectrum jelly, BlockStore block_store)
      throws com.google.bitcoin.store.BlockStoreException {
    this.jelly = jelly;
    this.params = params;
    this.file_db = jelly.getDB();
    this.block_store = (MapBlockStore) block_store;

    Config config = jelly.getConfig();
    config.require("block_save_threads");
    config.require("transaction_save_threads");

    block_queue = new LinkedBlockingQueue<Block>(32);
    tx_queue = new LinkedBlockingQueue<TransactionWork>(4096);
    transaction_cache = new LRUCache<Sha256Hash, Transaction>(100000);

    in_progress = new LRUCache<Sha256Hash, Semaphore>(1024);

    save_thread_list = new LinkedList<StatusContext>();
    for (int i = 0; i < config.getInt("block_save_threads"); i++) {
      BlockSaveThread t = new BlockSaveThread();
      save_thread_list.add(t);
      t.start();
    }

    for (int i = 0; i < config.getInt("transaction_save_threads"); i++) {
      TransactionSaveThread t = new TransactionSaveThread();
      save_thread_list.add(t);
      t.start();
    }

    putInternal(params.getGenesisBlock());

    // checkConsistency();

  }
예제 #2
0
  private void initialize() {
    VERSION = config.getString("jpf.version", VERSION);
    memoryReserve = new byte[config.getInt("jpf.memory_reserve", 64 * 1024)]; // in bytes

    try {

      Class<?>[] vmArgTypes = {JPF.class, Config.class};
      Object[] vmArgs = {this, config};
      vm = config.getEssentialInstance("vm.class", JVM.class, vmArgTypes, vmArgs);

      Class<?>[] searchArgTypes = {Config.class, JVM.class};
      Object[] searchArgs = {config, vm};
      search =
          config.getEssentialInstance("search.class", Search.class, searchArgTypes, searchArgs);

      // although the Reporter will always be notified last, this has to be set
      // first so that it can register utility listeners like Statistics that
      // can be used by configured listeners
      Class<?>[] reporterArgTypes = {Config.class, JPF.class};
      Object[] reporterArgs = {config, this};
      reporter = config.getInstance("report.class", Reporter.class, reporterArgTypes, reporterArgs);
      if (reporter != null) {
        search.setReporter(reporter);
      }

      addListeners();

      config.addChangeListener(new ConfigListener());

    } catch (JPFConfigException cx) {
      logger.severe(cx.toString());
      // cx.getCause().printStackTrace();
      throw new ExitException(false, cx);
    }
  }
예제 #3
0
파일: Effect.java 프로젝트: linhua55/trime
  public void reset() {
    Config config = Config.get();
    vibrateOn = config.getBoolean("key_vibrate");
    duration = config.getInt("key_vibrate_duration");
    if (vibrateOn && (vibrator == null)) {
      vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    }

    soundOn = config.getBoolean("key_sound");
    volume = config.getFloat("key_sound_volume");
    if (soundOn && (audioManager == null)) {
      audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    }

    isSpeakCommit = config.getBoolean("speak_commit");
    isSpeakKey = config.getBoolean("speak_key");
    if (mTTS == null && (isSpeakCommit || isSpeakKey)) {
      mTTS =
          new TextToSpeech(
              context,
              new TextToSpeech.OnInitListener() {
                public void onInit(int status) {
                  // 初始化結果
                }
              });
    }
  }
예제 #4
0
 /** Test default value. */
 public void testDefaultGet() {
   final String defaultString = "default value";
   assertEquals(defaultString, config.get("unknown", defaultString));
   final String missingPropertyName = "missing.property.name";
   assertEquals(defaultString, config.get(getClass(), missingPropertyName, defaultString));
   final int defaultInt = 42;
   assertEquals(defaultInt, config.getInt(getClass(), missingPropertyName, defaultInt));
 }
예제 #5
0
 /** Set the dataReader to point to the row where load has to be started */
 private void rowToStart(Config cfg, DataReader daoReader) throws DataAccessObjectException {
   // start at the correct row
   final int rowToStart;
   try {
     rowToStart = cfg.getInt(Config.LOAD_ROW_TO_START_AT);
   } catch (final ParameterLoadException e) {
     return;
   }
   if (rowToStart > 0) {
     // keep skipping over rows until we run into an invalid row or we have gotten
     // to the starting row
     while (daoReader.getCurrentRowNumber() < rowToStart) {
       if (!DAORowUtil.isValidRow(daoReader.readRow())) break;
     }
   }
 }
예제 #6
0
 @Test(expected = NumberFormatException.class)
 public void getIntNFE() throws Exception {
   final Config config = new Config();
   config.overrideConfig("asynchbase.int", "this can't be parsed to int");
   config.getInt("asynchbase.int");
 }
예제 #7
0
 @Test(expected = NumberFormatException.class)
 public void getIntDoesNotExist() throws Exception {
   final Config config = new Config();
   config.getInt("asynchbase.nosuchkey");
 }
예제 #8
0
 @Test(expected = NumberFormatException.class)
 public void getIntNull() throws Exception {
   final Config config = new Config();
   config.overrideConfig("asynchbase.null", null);
   config.getInt("asynchbase.null");
 }
예제 #9
0
 @Test
 public void getIntNegative() throws Exception {
   final Config config = new Config();
   config.overrideConfig("asynchbase.int", Integer.toString(Integer.MIN_VALUE));
   assertEquals(Integer.MIN_VALUE, config.getInt("asynchbase.int"));
 }
예제 #10
0
  /**
   * Runs a match; configures the controller and list of proxies, and starts running the game in a
   * separate thread.
   */
  private void runMatch(final Match match, final ProxyWriter proxyWriter) throws Exception {
    if (Mode.HEADLESS.equals(mode) || Mode.SCRIMMAGE.equals(mode) || Mode.TOURNAMENT.equals(mode)) {
      this.state = State.RUNNING;
      this.runUntil = Integer.MAX_VALUE;
    }

    // Poll for RUNNING, if mode == Mode.LOCAL
    while (!State.RUNNING.equals(state)) {
      try {
        Thread.sleep(250);
      } catch (InterruptedException e) {
      }
    }

    long startTime = System.currentTimeMillis();

    say("-------------------- Match Starting --------------------");
    say(match.toString());

    // Compute the header and send it to all listeners.
    MatchHeader header = match.getHeader();
    proxyWriter.enqueue(header);
    ExtensibleMetadata exHeader = match.getHeaderMetadata();
    proxyWriter.enqueue(exHeader);

    this.state = State.RUNNING;

    int count = 0;

    final String throttle = options.get("bc.server.throttle");
    final int throttleCount = options.getInt("bc.server.throttle-count");
    final boolean doYield = "yield".equals(throttle);
    final boolean doSleep = "sleep".equals(throttle);

    // If there are more rounds to be run, run them and
    // and send the round (and optionally stats) bytes to
    // recipients.
    while (match.hasMoreRounds()) {

      // If not paused/stopped:
      switch (this.state) {
        case RUNNING:
          if (match.getRoundNumber() == runUntil) {
            Thread.sleep(25);
            break;
          }

          final RoundDelta round = match.getRound();
          if (round == null) break;

          if (GameState.BREAKPOINT.equals(match.getGameState())) {
            this.state = State.PAUSED;
            proxyWriter.enqueue(new PauseEvent());
          } else if (GameState.DONE.equals(match.getGameState())) {
            this.state = State.FINISHED;
          }

          proxyWriter.enqueue(round);

          if (count++ == throttleCount) {
            if (doYield) Thread.yield();
            else if (doSleep) Thread.sleep(1);
            count = 0;
          }

          break;

        case PAUSED:
          Thread.sleep(250);
          break;
      }
    }

    // Compute footer data.
    GameStats gameStats = match.getGameStats();
    MatchFooter footer = match.getFooter();

    proxyWriter.enqueue(gameStats);
    proxyWriter.enqueue(footer);

    say(match.getWinnerString());
    say("-------------------- Match Finished --------------------");

    double timeDiff = (System.currentTimeMillis() - startTime) / 1000.0;
    debug(String.format("match completed in %.4g seconds", timeDiff));

    this.state = State.FINISHED;
  }