當前位置: 首頁>>代碼示例>>Java>>正文


Java MemcacheService.setErrorHandler方法代碼示例

本文整理匯總了Java中com.google.appengine.api.memcache.MemcacheService.setErrorHandler方法的典型用法代碼示例。如果您正苦於以下問題:Java MemcacheService.setErrorHandler方法的具體用法?Java MemcacheService.setErrorHandler怎麽用?Java MemcacheService.setErrorHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.appengine.api.memcache.MemcacheService的用法示例。


在下文中一共展示了MemcacheService.setErrorHandler方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doGet

import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException,
    ServletException {
  String path = req.getRequestURI();
  if (path.startsWith("/favicon.ico")) {
    return; // ignore the request for favicon.ico
  }

  MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
  syncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));

  byte[] whoKey = "who".getBytes();
  byte[] countKey = "count".getBytes();

  byte[] who = (byte[]) syncCache.get(whoKey);
  String whoString = who == null ? "nobody" : new String(who);
  resp.getWriter().print("Previously incremented by " + whoString + "\n");
  syncCache.put(whoKey, "Java".getBytes());
  Long count = syncCache.increment(countKey, 1L, 0L);
  resp.getWriter().print("Count incremented by Java = " + count + "\n");
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:22,代碼來源:MemcacheBestPracticeServlet.java

示例2: countPackages

import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
/**
 * @return the number of packages
 */
public static int countPackages() {
    final String key =
            NWUtils.class.getName() + "[email protected]" +
            NWUtils.getDataVersion();
    MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
    syncCache.setErrorHandler(ErrorHandlers
            .getConsistentLogAndContinue(Level.INFO));
    Integer value = (Integer) syncCache.get(key); // read from cache
    if (value == null) {
        ShardedCounter sc =
                ShardedCounter.getOrCreateCounter("NumberOfPackages", 2);
        value = sc.getCount();
        if (sc.getCount() == 0) {
            Objectify ofy = DefaultServlet.getObjectify();
            sc.increment(ofy.query(Package.class).count());
            value = sc.getCount();
        }
        syncCache.put(key, value); // populate cache
    }
    return value;
}
 
開發者ID:tim-lebedkov,項目名稱:npackd-gae-web,代碼行數:25,代碼來源:NWUtils.java

示例3: doGet

import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
    final String uuid = request.getParameter(UpdatePositionServletImpl.PARAMETER_UUID);
    if (uuid == null || uuid.trim().equals("")) {
        response.sendError(HttpStatus.SC_BAD_REQUEST, "?uuid= mandatory");
    }
    
    final MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
    syncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));
    final Object inMemory = syncCache.get(uuid);
    
    if (inMemory == null) {
        response.sendError(HttpStatus.SC_NOT_FOUND, "element not found");
    }
    
    final Cache cache = Cache.from(inMemory);
    response.getWriter().write(cache.toString());
}
 
開發者ID:sylvek,項目名稱:sharemyposition,代碼行數:20,代碼來源:RetrievePositionServletImpl.java

示例4: doGet

import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException,
    ServletException {
  String path = req.getRequestURI();
  if (path.startsWith("/favicon.ico")) {
    return; // ignore the request for favicon.ico
  }

  MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
  syncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));
  String key = "count-sync";
  byte[] value;
  long count = 1;
  value = (byte[]) syncCache.get(key);
  if (value == null) {
    value = BigInteger.valueOf(count).toByteArray();
    syncCache.put(key, value);
  } else {
    // Increment value
    count = new BigInteger(value).longValue();
    count++;
    value = BigInteger.valueOf(count).toByteArray();
    // Put back in cache
    syncCache.put(key, value);
  }

  // Output content
  resp.setContentType("text/plain");
  resp.getWriter().print("Value is " + count + "\n");
}
 
開發者ID:GoogleCloudPlatform,項目名稱:java-docs-samples,代碼行數:31,代碼來源:MemcacheSyncCacheServlet.java

示例5: getKeys

import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
/**
 * Returns possible cached result of a query.
 * 
 * @param <T>
 *            datastore object class
 * @param ofy
 *            Objectify
 * @param q
 *            a query
 * @param cacheSuffix
 *            suffix for the cache key
 * @return possible cached result of the query
 */
public static <T> List<Key<T>> getKeys(Objectify ofy,
        com.googlecode.objectify.Query<T> q, String cacheSuffix) {
	String key = q.toString() + cacheSuffix;

	MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
	syncCache.setErrorHandler(ErrorHandlers
	        .getConsistentLogAndContinue(Level.INFO));
	String value = (String) syncCache.get(key); // read from cache
	List<Key<T>> result;
	if (value == null) {
		result = q.listKeys();

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < result.size(); i++) {
			if (i != 0)
				sb.append(' ');
			sb.append(result.get(i).getString());
		}
		value = sb.toString();

		syncCache.put(key, value); // populate cache
	} else {
		List<String> keys = NWUtils.split(value, ' ');
		result = new ArrayList<Key<T>>();
		for (String k : keys) {
			result.add(new Key<T>(k));
		}
	}
	return result;
}
 
開發者ID:tim-lebedkov,項目名稱:npackd-gae-web,代碼行數:44,代碼來源:QueryCache.java

示例6: incDataVersion

import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
/**
 * Increments the version of the data.
 *
 * @return new version number
 */
public static long incDataVersion() {
    MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
    syncCache.setErrorHandler(ErrorHandlers
            .getConsistentLogAndContinue(Level.INFO));
    Long v = syncCache.increment("DataVersion", 1L);
    if (v == null) {
        syncCache.put("DataVersion", 1L);
        v = 1L;
    }
    return v;
}
 
開發者ID:tim-lebedkov,項目名稱:npackd-gae-web,代碼行數:17,代碼來源:NWUtils.java

示例7: getDataVersion

import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
/**
 * @return current data version
 */
public static long getDataVersion() {
    MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
    syncCache.setErrorHandler(ErrorHandlers
            .getConsistentLogAndContinue(Level.INFO));
    Long v = (Long) syncCache.get("DataVersion");
    if (v == null) {
        syncCache.put("DataVersion", 1L);
        v = 1L;
    }
    return v;
}
 
開發者ID:tim-lebedkov,項目名稱:npackd-gae-web,代碼行數:15,代碼來源:NWUtils.java

示例8: doPost

import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
    final String position = request.getParameter(PARAMETER_POSITION);
    final String uuid = request.getParameter(PARAMETER_UUID);
    final MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
    syncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));
    syncCache.put(uuid, Cache.to(position));
}
 
開發者ID:sylvek,項目名稱:sharemyposition,代碼行數:10,代碼來源:UpdatePositionServletImpl.java

示例9: getBoards

import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
/**
 * Gets a list of all game board entities.
 *
 * @return non null map of board entities indexed by entity keys.
 */
private Map<Key, BoardEntity> getBoards() {
  // Gets a list of all game boards from memcache.
  MemcacheService cache = MemcacheServiceFactory.getMemcacheService();
  cache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));

  @SuppressWarnings("unchecked")
  Map<Key, BoardEntity> boards = (Map<Key, BoardEntity>) cache.get(ALL_BOARDS_CACHE_KEY);

  // If the list wasn't in the cache then retrieve it from Datastore
  // and cache it (unless the list is empty).
  if (boards == null) {
    boards = new HashMap<Key, BoardEntity>();

    Query query = new Query(BoardEntity.KIND);
    PreparedQuery preparedQuery = dataStore.prepare(query);

    for (Entity board : preparedQuery.asIterable()) {
      boards.put(board.getKey(), new BoardEntity(board));
    }

    if (boards.size() > 0) {
      cache.put(ALL_BOARDS_CACHE_KEY, boards);
    }
  }

  return boards;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:solutions-griddler-sample-backend-java,代碼行數:33,代碼來源:GameService.java

示例10: create

import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
@Override
public void create(HttpServletRequest request, HttpServletResponse resp)
        throws IOException {
    resp.setContentType("application/xml");

    final String key =
            this.getClass().getName() + "@" + NWUtils.getDataVersion() +
            "@" + user + "@" + tag;
    MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
    syncCache.setErrorHandler(ErrorHandlers
            .getConsistentLogAndContinue(Level.INFO));
    byte[] value = (byte[]) syncCache.get(key); // read from cache
    if (value == null) {
        NWUtils.LOG.warning("Found no value in cache");
        try {
            Objectify ofy = DefaultServlet.getObjectify();
            ArrayList<PackageVersion> pvs = new ArrayList<PackageVersion>();
            Query<PackageVersion> q =
                    ofy.query(PackageVersion.class).limit(20)
                            .order("-lastModifiedAt");
            if (user != null) {
                q =
                        q.filter(
                                "lastModifiedBy =",
                                new User(user, user.substring(user
                                        .indexOf('@'))));
            }
            if (tag != null) {
                q = q.filter("tags =", tag);
            }
            pvs.addAll(q.list());
            Document d = RepXMLPage.toXML(ofy, pvs, false, null);

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            NWUtils.serializeXML(d, baos);
            value = baos.toByteArray();
            syncCache.put(key, value); // populate cache
        } catch (Exception e) {
            throw new IOException(e);
        }
    } else {
        NWUtils.LOG.log(Level.WARNING, "Found value in cache {0} bytes",
                value.length);
    }

    ServletOutputStream ros = resp.getOutputStream();
    ros.write(value);
    ros.close();
}
 
開發者ID:tim-lebedkov,項目名稱:npackd-gae-web,代碼行數:50,代碼來源:RecentRepXMLPage.java

示例11: initMemcacheService

import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
private MemcacheService initMemcacheService() {
  MemcacheService memcacheService = getMemcacheService();
  memcacheService.setErrorHandler(getConsistentLogAndContinue(Level.INFO));
  return memcacheService;
}
 
開發者ID:google,項目名稱:domaintest,代碼行數:6,代碼來源:Memcache.java

示例12: initMemcache

import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
private static MemcacheService initMemcache() {
  MemcacheService m = MemcacheServiceFactory.getMemcacheService();
  m.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));
  return m;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:solutions-cloud-adventure-sample-backend-java,代碼行數:6,代碼來源:StorageUtils.java

示例13: getService

import com.google.appengine.api.memcache.MemcacheService; //導入方法依賴的package包/類
/**
 * Get a Memcache service for specific namespace
 *
 * @param namespace namespace of memcache
 * @return the Memcache
 */
private MemcacheService getService(String namespace) {
    MemcacheService cache = MemcacheServiceFactory.getMemcacheService("alarmClock");
    cache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.WARNING));
    return cache;
}
 
開發者ID:masters-info-nantes,項目名稱:myLazyClock,代碼行數:12,代碼來源:MyLazyClockMemcacheService.java


注:本文中的com.google.appengine.api.memcache.MemcacheService.setErrorHandler方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。