Exemplo n.º 1
0
    private void endBuffer(ZipEntry ze) {
      if (ze == null) {
        return;
      }
      if (store != null) {
        store.close(); // 終了処理は別スレッドで実行中
        String digest = store.getDigest();
        logPersister.addDigest(addDigests, digest);
        store = null;
      } else if (charsetDecoder != null) {
        charBuffer.flip();
        charBuffer.array();
        String accessLogJson =
            new String(charBuffer.array(), charBuffer.position(), charBuffer.limit());
        charsetDecoder = null;
        charBuffer = null;
        AccessLog accessLog = AccessLog.fromJson(accessLogJson);
        if (accessLog == null) {
          return;
        }
        logPersister.addDigest(refDigests, accessLog.getRequestHeaderDigest());
        logPersister.addDigest(refDigests, accessLog.getRequestBodyDigest());
        logPersister.addDigest(refDigests, accessLog.getResponseHeaderDigest());
        logPersister.addDigest(refDigests, accessLog.getResponseBodyDigest());
        accessLog.setId(null);
        accessLog.setPersist(true);

        PersistenceManager pm = JdoUtil.getPersistenceManager();
        logPersister.executeInsert(pm, accessLog);
        if (pm.currentTransaction().isActive()) {
          pm.currentTransaction().rollback();
        }
      }
    }
Exemplo n.º 2
0
 @Override
 public void onBufferFailure(Object userContext, Throwable failure) {
   if (store != null) {
     store.close(false);
     store = null;
   }
 }
Exemplo n.º 3
0
 private void startBuffer(ZipEntry ze) {
   String name = ze.getName();
   if (name.startsWith("/store")) {
     store = Store.open(true);
   } else if (name.startsWith("/accessLog")) {
     Charset c = Charset.forName("utf-8");
     charsetDecoder = c.newDecoder();
     // accessLogをjson化したものなので無制限に大きくならない
     charBuffer = CharBuffer.allocate(4096);
   }
 }
Exemplo n.º 4
0
 @Override
 public boolean onBuffer(Object userContext, ByteBuffer[] buffers) {
   if (currentZe != userContext) {
     endBuffer(currentZe);
     currentZe = (ZipEntry) userContext;
     startBuffer(currentZe);
   }
   if (store != null) {
     store.putBuffer(buffers);
   } else if (charsetDecoder != null) {
     for (ByteBuffer buffer : buffers) {
       charsetDecoder.decode(buffer, charBuffer, false);
     }
     PoolManager.poolBufferInstance(buffers);
   }
   return true;
 }