当前位置: 首页>>代码示例>>Java>>正文


Java ImmutableMap类代码示例

本文整理汇总了Java中com.google.appengine.repackaged.com.google.common.collect.ImmutableMap的典型用法代码示例。如果您正苦于以下问题:Java ImmutableMap类的具体用法?Java ImmutableMap怎么用?Java ImmutableMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ImmutableMap类属于com.google.appengine.repackaged.com.google.common.collect包,在下文中一共展示了ImmutableMap类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getUploadUrl

import com.google.appengine.repackaged.com.google.common.collect.ImmutableMap; //导入依赖的package包/类
/**
 * Get an upload URL
 * @param req
 * @param resp
 * @throws ServletException
 * @throws IOException
 */
private void getUploadUrl(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  LOGGER.debug("Get blobstore upload url");

  String callback = req.getParameter(CALLBACK_PARAM);
  if (null == callback) {
    callback = req.getRequestURI();
  }

  String keepQueryParam = req.getParameter(KEEP_QUERY_PARAM);
  // Forward any existing query parameters, e.g. access_token
  if (null != keepQueryParam) {
    final String queryString = req.getQueryString();
    callback = String.format("%s?%s", callback, null != queryString ? queryString : "");
  }

  Map<String, String> response = ImmutableMap.of("uploadUrl", blobstoreService.createUploadUrl(callback));

  PrintWriter out = resp.getWriter();
  resp.setContentType(JsonCharacterEncodingResponseFilter.APPLICATION_JSON_UTF8);

  ObjectMapper mapper = new ObjectMapper();
  mapper.writeValue(out, response);

  out.close();
}
 
开发者ID:Wadpam,项目名称:guja,代码行数:33,代码来源:GAEBlobServlet.java

示例2: createErrorToExceptionMap

import com.google.appengine.repackaged.com.google.common.collect.ImmutableMap; //导入依赖的package包/类
public static Map<RemoteApiPb.RpcError.ErrorCode, ApiProxyException> createErrorToExceptionMap() {
  return new ImmutableMap.Builder<RemoteApiPb.RpcError.ErrorCode, ApiProxyException>()
      .put(RemoteApiPb.RpcError.ErrorCode.UNKNOWN,
          new ApiProxy.UnknownException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.CALL_NOT_FOUND,
          new ApiProxy.CallNotFoundException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.PARSE_ERROR,
          new ApiProxy.ArgumentException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.SECURITY_VIOLATION,
          new ApiProxy.UnknownException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.OVER_QUOTA,
          new ApiProxy.OverQuotaException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.REQUEST_TOO_LARGE,
          new ApiProxy.RequestTooLargeException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(
          RemoteApiPb.RpcError.ErrorCode.CAPABILITY_DISABLED,
          new ApiProxy.CapabilityDisabledException(TEST_ERROR_MESSAGE, TEST_PACKAGE_NAME,
              TEST_METHOD_NAME))
      .put(
          RemoteApiPb.RpcError.ErrorCode.FEATURE_DISABLED,
          new ApiProxy.FeatureNotEnabledException(TEST_ERROR_MESSAGE, TEST_PACKAGE_NAME,
              TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.BAD_REQUEST,
          new ApiProxy.ArgumentException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.RESPONSE_TOO_LARGE,
          new ApiProxy.ResponseTooLargeException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.CANCELLED,
          new ApiProxy.CancelledException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.REPLAY_ERROR,
          new ApiProxy.UnknownException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .put(RemoteApiPb.RpcError.ErrorCode.DEADLINE_EXCEEDED,
          new ApiProxy.ApiDeadlineExceededException(TEST_PACKAGE_NAME, TEST_METHOD_NAME))
      .build();
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:35,代码来源:VmApiProxyDelegateTest.java

示例3: sendMessage

import com.google.appengine.repackaged.com.google.common.collect.ImmutableMap; //导入依赖的package包/类
/**
 * Send to the first NUMBER_OF_DEVICE devices (you can modify this to send
 * to any number of devices or a specific device).
 * @param payload The message to send
 * @throws java.io.IOException if unable to send the message.
 */
@ApiMethod(httpMethod = "POST")
public final void sendMessage(final ImmutableMap<String, String> payload)
        throws IOException {
    if (payload == null || payload.size() == 0) {
        LOG.warning("Not sending message because payload is empty");
        return;
    }

    Sender sender = new Sender(Constants.GCM_API_KEY);
    Message msg = new Message.Builder()
            .setData(payload)
            .build();
    List<Registration> records = ofy().load()
            .type(Registration.class).limit(NUMBER_OF_DEVICES)
            .list();
    for (Registration record : records) {
        Result result = sender.send(msg, record.getRegId(),
                MAXIMUM_RETRIES);
        if (result.getMessageId() != null) {
            LOG.info("Message sent to " + record.getRegId());
            String canonicalRegId = result.getCanonicalRegistrationId();
            if (canonicalRegId != null) {
                // if the regId changed, we have to update the datastore
                LOG.info("Registration Id changed for " + record.getRegId()
                        + " updating to "
                        + canonicalRegId);
                record.setRegId(canonicalRegId);
                ofy().save().entity(record).now();
            }
        } else {
            String error = result.getErrorCodeName();
            if (error.equals(com.google.android.gcm.server.
                    Constants.ERROR_NOT_REGISTERED)) {
                LOG.warning("Registration Id " + record.getRegId()
                        + " no longer registered with GCM, "
                        + "removing from datastore");
                // if the device is no longer registered with Gcm, remove it
                // from the datastore
                ofy().delete().entity(record).now();
            } else {
                LOG.warning("Error when sending message : " + error);
            }
        }
    }
}
 
开发者ID:googlearchive,项目名称:MobileShoppingAssistant-sample,代码行数:52,代码来源:MessagingEndpoint.java


注:本文中的com.google.appengine.repackaged.com.google.common.collect.ImmutableMap类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。