@Override
  public void doGet(final HttpServletRequest req, final HttpServletResponse resp)
      throws IOException {

    final MemcacheService cacheShared = MemcacheServiceFactory.getMemcacheService();
    if (cacheShared.contains(MemCacheKey.activePoints)) {
      try {
        final Map<String, Point> points =
            (Map<String, Point>) cacheShared.get(MemCacheKey.activePoints);
        cacheShared.delete(
            MemCacheKey.activePoints); // TODO possible race condition with record value service
        for (final Point point : points.values()) {
          TaskFactory.getInstance().startMoveCachedValuesToStoreTask(point);
        }
      } catch (InvalidValueException e) {
        cacheShared.clearAll();
      }
    }
  }
Esempio n. 2
0
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    int index;

    DatastoreService ds;
    MemcacheService ms;

    Cookie[] cookies;
    boolean insideFlag;

    String delpw;
    String paramOffset;
    String paramSize;
    int offset;
    int size;

    Key postObjGroupKey;
    Query q;
    List<Entity> postObjList;
    PostObj postObj;

    Gson gson;
    List<String> filelinkList;

    resp.setCharacterEncoding("UTF-8");
    resp.setContentType("text/plain");

    ds = DatastoreServiceFactory.getDatastoreService();
    ms = MemcacheServiceFactory.getMemcacheService();

    insideFlag = false;
    try {
      cookies = req.getCookies();
      if (cookies.length > 0) {
        if (ms.contains(cookies[0].getValue()) == true) {
          insideFlag = true;
        }
      }
    } catch (Exception e) {
      insideFlag = false;
    }

    delpw = req.getParameter("delpw");
    if (delpw != null) {
      if (delpw.equals("") == true) {
        delpw = null;
      }
    }

    paramOffset = req.getParameter("offset");
    if (paramOffset != null) {
      offset = Integer.valueOf(paramOffset);
    } else {
      offset = 0;
    }

    paramSize = req.getParameter("size");
    if (paramSize != null) {
      size = Integer.valueOf(paramSize);
    } else {
      size = 4096;
    }

    postObjGroupKey = KeyFactory.createKey("PostObjGroup", 1L);
    q = new Query("PostObj", postObjGroupKey);
    if (delpw != null) {
      q.addFilter("delpw", FilterOperator.EQUAL, delpw);
      q.addSort("delpw");
    }
    q.addSort("posttime", SortDirection.DESCENDING);
    postObjList = ds.prepare(q).asList(FetchOptions.Builder.withOffset(offset).limit(size));

    postObj = new PostObj();
    filelinkList = new ArrayList<String>();
    for (index = 0; index < postObjList.size(); index++) {
      postObj.getDB(postObjList.get(index));
      if ((postObj.flag.equals("showgallery") == false && insideFlag == true)
          || (postObj.flag.equals("showgallery") == true && insideFlag == false)
          || delpw != null) {
        filelinkList.add(postObj.filelink);
      }
    }

    gson = new Gson();
    resp.getWriter().print(gson.toJson(filelinkList));
  }