Esempio 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();
        }
      }
    }
Esempio n. 2
0
 private void loadMappings() {
   PersistenceManager pm = JdoUtil.currentPm();
   Extent<Mapping> extent = pm.getExtent(Mapping.class);
   Iterator<Mapping> itr = extent.iterator();
   while (itr.hasNext()) {
     Mapping mapping = itr.next();
     pm.makeTransient(mapping);
     //			System.out.println("json:"+mapping.toJson());
     if (mapping.setup() == false) { // TODO mapping.setupがfalseで復帰したらすべてrollbackすべき?
       logger.error("fail to mapping setup.id:" + mapping.getId() + ":note:" + mapping.getNotes());
       continue;
     }
     loadMapping(mapping);
   }
 }
Esempio n. 3
0
 private void doJobs() {
   PersistenceManager pm = JdoUtil.getPersistenceManager();
   while (true) {
     Object req = null;
     synchronized (requestQueue) {
       if (requestQueue.size() == 0) {
         break;
       }
       req = requestQueue.remove(0);
     }
     try {
       pm = doJob(pm, req);
     } finally {
       if (pm != null && pm.currentTransaction().isActive()) {
         pm.currentTransaction().rollback();
       }
     }
   }
 }
Esempio n. 4
0
  void doCommand(String command, ParameterParser parameter) {
    if ("listCategory".equals(command)) {
      Collection<FilterCategory> categorys = FilterCategory.query(null, -1, 0, null);
      JSON categorysJson = FilterCategory.collectionToJson(categorys);
      responseJson(categorysJson);
      return;
    } else if ("addEntry".equals(command)) {
      String categoryId = parameter.getParameter("categoryId");
      PersistenceManager pm = JdoUtil.getPersistenceManager();
      try {
        pm.currentTransaction().begin();
        FilterCategory filterCategory = FilterCategory.getById(Long.parseLong(categoryId));
        String filter = parameter.getParameter("filter");
        FilterEntry f = new FilterEntry(filterCategory, filter);
        f.save();
        pm.currentTransaction().commit();
      } finally {
        if (pm.currentTransaction().isActive()) {
          pm.currentTransaction().rollback();
        }
      }
      responseJson(categoryId);
      return;
    } else if ("getRoleList".equals(command)) { // roleに対するblackList,whilteListを取得する
      String role = parameter.getParameter("role");
      boolean isBlack = "true".equalsIgnoreCase(parameter.getParameter("isBlacklist"));
      Collection<FilterRole> roles = FilterRole.getByKey(role, isBlack);

      JSONArray catagoryIds = new JSONArray();
      for (FilterRole filterRole : roles) {
        catagoryIds.add(filterRole.getCategory().getId());
      }
      responseJson(catagoryIds);
      return;
    } else if ("setRoleList".equals(command)) { // roleに対するblackList,whilteListを設定する
      String role = parameter.getParameter("role");
      boolean isBlack = "true".equalsIgnoreCase(parameter.getParameter("isBlacklist"));
      Collection<FilterRole> roles = FilterRole.getByKey(role, isBlack);

      String[] categoryIds = parameter.getParameter("categoryIds").split(",");
      Set<Long> idsSet = new HashSet<Long>();
      for (String categoryId : categoryIds) {
        idsSet.add(Long.parseLong(categoryId));
      }
      Iterator<FilterRole> itr = roles.iterator();
      while (itr.hasNext()) {
        FilterRole filterRole = itr.next();
        if (idsSet.remove(filterRole.getId())) {
          itr.remove();
        }
      }
      PersistenceManager pm = JdoUtil.getPersistenceManager();
      try {
        pm.currentTransaction().begin();
        itr = roles.iterator();
        while (itr.hasNext()) {
          FilterRole filterRole = itr.next();
          filterRole.delete();
        }
        for (Long id : idsSet) {
          FilterCategory filterCategory = FilterCategory.getById(id);
          if (filterCategory == null) {
            logger.error("not found id." + id);
            continue;
          }
          FilterRole filterRole = new FilterRole(role, isBlack, filterCategory);
          filterRole.save();
        }
        pm.currentTransaction().commit();
      } finally {
        if (pm.currentTransaction().isActive()) {
          pm.currentTransaction().rollback();
        }
      }
      responseJson(categoryIds);
      return;
    } else if ("listUpdate".equals(command)) { // categoryListをnetから取得する
      //			String chId=queueManger.createQueue();
      String chId = null;
      String source = parameter.getParameter("source");
      try {
        ListGetter listGetter = new ListGetter();
        listGetter.start(source, chId);
        responseJson(chId);
        return;
      } catch (MalformedURLException e) {
        logger.error("source error.source:" + source, e);
      } catch (IOException e) {
        logger.error("fail to listGetter.source:" + source, e);
      }
      //			queueManger.complete(chId, "fail to listGetter");
      return;
    }
    completeResponse("404");
  }