Пример #1
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;
  }