示例#1
0
文件: CspBdbQueue.java 项目: kevx/csp
 public void doValue(byte[] vdata) {
   try {
     String[] v = (String[]) JavaCodec.decodeObject(vdata);
     if (v != null) {
       HbaseQueue.get().addData(v);
     }
   } catch (Exception e) {
     logger.warn("HbaseQueue bdb addData exception", e);
   }
 }
示例#2
0
文件: CspBdbQueue.java 项目: kevx/csp
  private static long readByCursor() {
    long count = 0;

    // 性能高,但是抛异常,未解
    // DiskOrderedCursor  cursor = database.openCursor(docc);
    Cursor cursor = database.openCursor(null, null);
    DatabaseEntry curkey = new DatabaseEntry();
    DatabaseEntry curval = new DatabaseEntry();

    boolean isGoingFull = false;
    try {
      while (cursor.getNext(curkey, curval, null) == OperationStatus.SUCCESS) {
        /*队列接近饱和,停止恢复*/
        if (HbaseQueue.get().getQueueSize() > HbaseQueue.BDB_QUEUE_SIZE) {
          isGoingFull = true;
          break;
        }
        byte[] vdata = curval.getData();
        if (null == vdata || vdata.length < 1) {
          continue;
        }
        doValue(vdata);
        OperationStatus ops = cursor.delete();
        // OperationStatus ops=database.delete(null, curkey);
        if (ops != OperationStatus.SUCCESS) {
          logger.warn("delete data faile," + ops);
        }
        count++;
      }
    } catch (Exception e) {
      logger.warn("read data from bdb Exception,", e);
    } finally {
      if (null != cursor) cursor.close();
    }
    if (isGoingFull) {
      try {
        logger.warn("queue going full sleep 5min," + totalRecovery);
        Thread.sleep(1000 * 60 * 3);
      } catch (InterruptedException e) {
        // TODO INGORE
      }
    }
    totalRecovery = totalRecovery + count;
    return count;
  }