Exemplo n.º 1
0
  /**
   * Helper用のQueue領域を生成する.<br>
   *
   * @param
   * @return
   * @throws
   */
  private void initHelperTaskQueue() {
    long queueIndex = 0L;
    try {

      for (int i = 0; i < this.maxConnectParallelQueue; i++) {
        super.createUniqueHelperParamQueue("KeyManagerConnectHelper" + this.myPrefix + i, 7000);
        this.maxConnectParallelQueueNames[i] = "KeyManagerConnectHelper" + this.myPrefix + i;
      }

      for (int i = 0; i < this.maxAcceptParallelQueue; i++) {
        super.createUniqueHelperParamQueue("KeyManagerAcceptHelper" + this.myPrefix + i, 5000);
        this.maxAcceptParallelQueueNames[i] = "KeyManagerAcceptHelper" + this.myPrefix + i;
      }

      for (int i = 0; i < this.maxWorkerParallelQueue; i++) {
        super.createUniqueHelperParamQueue("KeyManagerHelper" + this.myPrefix + i, 5000);
        this.maxWorkerParallelQueueNames[i] = "KeyManagerHelper" + this.myPrefix + i;
      }

      // 監視スレッド起動
      for (int i = 0; i < maxConnectParallelExecution; i++) {
        queueIndex = (i + 1) % this.maxConnectParallelQueue;

        Object[] queueParam = new Object[2];
        queueParam[0] = "KeyManagerConnectHelper" + this.myPrefix + queueIndex;
        queueParam[1] = this.maxAcceptParallelQueueNames;
        super.executeHelper("KeyManagerConnectHelper", queueParam, true);
      }

      for (int i = 0; i < maxAcceptParallelExecution; i++) {
        queueIndex = (i + 1) % this.maxAcceptParallelQueue;

        Object[] queueParam = new Object[2];
        queueParam[0] = "KeyManagerAcceptHelper" + this.myPrefix + queueIndex;
        queueParam[1] = this.maxWorkerParallelQueueNames;
        super.executeHelper("KeyManagerAcceptHelper", queueParam, true);
      }

      // KeyManagerHelper設定
      Object[] helperShareParams = new Object[(this.maxWorkerParallelQueue * 2)];

      queueIndex = 0;
      for (int i = 0; i < (this.maxWorkerParallelQueue * 2); i = i + 2) {
        helperShareParams[i] = "Bind-KeyManagerHelper" + this.myPrefix + queueIndex;
        helperShareParams[i + 1] = new AtomicInteger(0);
        queueIndex++;
      }

      queueIndex = 0;
      for (int i = 0; i < this.maxWorkerParallelExecution; i++) {
        queueIndex = (i + 1) % this.maxWorkerParallelQueue;
        AtomicInteger queueBindHelperCount =
            (AtomicInteger) helperShareParams[(new Long(queueIndex).intValue() * 2) + 1];
        queueBindHelperCount.getAndIncrement();
        helperShareParams[(new Long(queueIndex).intValue() * 2) + 1] = queueBindHelperCount;
      }

      for (int i = 0; i < maxWorkerParallelExecution; i++) {
        queueIndex = (i + 1) % this.maxWorkerParallelQueue;

        Object[] queueParam = new Object[4];
        queueParam[0] = this.keyMapManager;
        queueParam[1] = "KeyManagerHelper" + this.myPrefix + queueIndex;
        queueParam[2] = this.maxAcceptParallelQueueNames;
        queueParam[3] = "Bind-KeyManagerHelper" + this.myPrefix + queueIndex;

        if (i == 0) {

          super.executeHelper("KeyManagerHelper", queueParam, true, helperShareParams);
        } else {
          super.executeHelper("KeyManagerHelper", queueParam, true);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  /**
   * Jobメイン処理定義.<br>
   *
   * @param
   * @return
   * @throws
   */
  public String executeJob(String optionParam) throws BatchException {
    logger.debug("KeyManagerJob - executeJob - start");

    String ret = SUCCESS;

    Socket socket = null;

    String keyManagerConnectHelperQueuePrefix = "KeyManagerConnectHelper" + this.myPrefix;

    long accessCount = 0L;

    try {

      // KeyMapManagerの設定値を初期化
      this.initDataPersistentConfig(optionParam);

      // オリジナルのキュー領域を作成
      this.initHelperTaskQueue();

      // サーバソケットの生成
      InetSocketAddress bindAddress = null;
      if (this.bindIpAddress == null) {
        bindAddress = new InetSocketAddress(this.portNo);
      } else {
        bindAddress = new InetSocketAddress(this.bindIpAddress, this.portNo);
      }

      this.serverSocket = new ServerSocket();
      this.serverSocket.bind(bindAddress, this.backLog);

      // 共有領域にServerソケットのポインタを格納
      super.setJobShareParam(super.getJobName() + "_ServeSocket", this.serverSocket);

      // 処理開始
      logger.info("okuyama DataNode Initialization End ...");
      System.out.println("okuyama DataNode Initialization End ...");

      logger.info("okuyama DataNode start ...");
      logger.info("listening on " + bindAddress);
      System.out.println("okuyama DataNode start");
      System.out.println("listening on " + bindAddress);

      while (true) {
        if (StatusUtil.getStatus() == 1 || StatusUtil.getStatus() == 2) break;
        try {

          // クライアントからの接続待ち
          accessCount++;
          socket = serverSocket.accept();

          Object[] helperParam = new Object[1];
          helperParam[0] = socket;

          // アクセス済みのソケットをキューに貯める
          super.addSpecificationParameterQueue(
              keyManagerConnectHelperQueuePrefix + (accessCount % this.maxConnectParallelQueue),
              helperParam);

        } catch (Exception e) {
          if (StatusUtil.getStatus() == 2) {
            logger.info("KeyManagerJob - executeJob - ServerEnd");
            break;
          }
          logger.error("", e);
        }
      }
    } catch (Exception e) {
      logger.error("KeyManagerJob - executeJob - Error", e);
      throw new BatchException(e);
    }

    // logger.debug("KeyManagerJob - executeJob - end");
    return ret;
  }