• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java InvalidationClientCore类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: tryHandleStartIntent

import com.google.ipc.invalidation.ticl.InvalidationClientCore; //导入依赖的package包/类
/** Tries to handle a start intent. Returns {@code true} iff the intent is a start intent. */
private boolean tryHandleStartIntent(Intent intent) {
  StartCommand command = AndroidListenerIntents.findStartCommand(intent);
  if ((command == null) || !AndroidListenerProtos.isValidStartCommand(command)) {
    return false;
  }
  // Reset the state so that we make no assumptions about desired registrations and can ignore
  // messages directed at the wrong instance.
  state = new AndroidListenerState(initialMaxDelayMs, maxDelayFactor);
  boolean skipStartForTest = false;
  ClientConfigP clientConfig = InvalidationClientCore.createConfig();
  if (command.getAllowSuppression() != clientConfig.getAllowSuppression()) {
    ClientConfigP.Builder clientConfigBuilder = clientConfig.toBuilder();
    clientConfigBuilder.allowSuppression = command.getAllowSuppression();
    clientConfig = clientConfigBuilder.build();
  }
  Intent startIntent = ProtocolIntents.InternalDowncalls.newCreateClientIntent(
      command.getClientType(), command.getClientName(), clientConfig, skipStartForTest);
  AndroidListenerIntents.issueTiclIntent(getApplicationContext(), startIntent);
  return true;
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:22,代码来源:AndroidListener.java


示例2: decodeTiclState

import com.google.ipc.invalidation.ticl.InvalidationClientCore; //导入依赖的package包/类
/**
 * Returns the persisted state for the client with key {@code clientKey} in
 * {@code storageForClient}, or {@code null} if no valid state could be found.
 * <p>
 * REQUIRES: {@code storageForClient}.load() has been called successfully.
 */


PersistentTiclState decodeTiclState(final String clientKey, AndroidStorage storageForClient) {
  synchronized (lock) {
    // Retrieve the serialized state.
    final Map<String, byte[]> properties = storageForClient.getPropertiesUnsafe();
    byte[] clientStateBytes = TypedUtil.mapGet(properties,
        InvalidationClientCore.CLIENT_TOKEN_KEY);
    if (clientStateBytes == null) {
      logger.warning("No client state found in storage for %s: %s", clientKey,
          properties.keySet());
      return null;
    }

    // Deserialize it.
    PersistentTiclState clientState =
        PersistenceUtils.deserializeState(logger, clientStateBytes, digestFn);
    if (clientState == null) {
      logger.warning("Invalid client state found in storage for %s", clientKey);
      return null;
    }
    return clientState;
  }
}
 
开发者ID:morristech,项目名称:android-chromium,代码行数:31,代码来源:AndroidInvalidationService.java


示例3: createClient

import com.google.ipc.invalidation.ticl.InvalidationClientCore; //导入依赖的package包/类
/**
 * Creates a new InvalidationClient instance that the proxy will delegate requests to and listen
 * for events from.
 */
// Overridden by tests to inject mock clients or for listener interception

InvalidationClient createClient(SystemResources resources, int clientType, byte[] clientName,
    String applicationName, InvalidationListener listener, ClientConfigP config) {
  // We always use C2DM, so set the channel-supports-offline-delivery bit on our config.
  final ClientConfigP.Builder configBuilder;
  if (config == null) {
    configBuilder = InvalidationClientCore.createConfig();
  } else {
    configBuilder = ClientConfigP.newBuilder(config);
  }
  configBuilder.setChannelSupportsOfflineDelivery(true);
  config = configBuilder.build();
  Random random = new Random(resources.getInternalScheduler().getCurrentTimeMs());
  return new InvalidationClientImpl(resources, random, clientType, clientName, config,
      applicationName, listener);
}
 
开发者ID:morristech,项目名称:android-chromium,代码行数:22,代码来源:AndroidClientProxy.java


示例4: deleteKey

import com.google.ipc.invalidation.ticl.InvalidationClientCore; //导入依赖的package包/类
@Override
public void deleteKey(String key, Callback<Boolean> done) {
  // We only support the CLIENT_TOKEN_KEY.
  if (!key.equals(InvalidationClientCore.CLIENT_TOKEN_KEY)) {
    done.accept(false);
    return;
  }
  if (!context.getFileStreamPath(STATE_FILENAME).exists()) {
    // Deletion "succeeds" if the key didn't exist.
    done.accept(true);
  } else {
    // Otherwise it succeeds based on whether the IO operation succeeded.
    done.accept(context.deleteFile(STATE_FILENAME));
  }
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:16,代码来源:AndroidStorage.java


示例5: readAllKeys

import com.google.ipc.invalidation.ticl.InvalidationClientCore; //导入依赖的package包/类
@Override
public void readAllKeys(Callback<SimplePair<Status, String>> keyCallback) {
  // If the state file exists, supply the CLIENT_TOKEN_KEY as a present key.
  if (context.getFileStreamPath(STATE_FILENAME).exists()) {
    Status status = Status.newInstance(Status.Code.SUCCESS, "");
    keyCallback.accept(SimplePair.of(status, InvalidationClientCore.CLIENT_TOKEN_KEY));
  }
  keyCallback.accept(null);
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:10,代码来源:AndroidStorage.java


示例6: createClient

import com.google.ipc.invalidation.ticl.InvalidationClientCore; //导入依赖的package包/类
/**
 * Constructs an invalidation client library instance.
 *
 * @param resources {@link SystemResources} to use for logging, scheduling, persistence, and
 *     network connectivity
 * @param clientConfig application provided configuration for the client.
 * @param listener callback object for invalidation events
 */
public static InvalidationClient createClient(SystemResources resources,
    InvalidationClientConfig clientConfig, InvalidationListener listener) {
  ClientConfigP.Builder internalConfigBuilder = InvalidationClientCore.createConfig().toBuilder();
  internalConfigBuilder.allowSuppression = clientConfig.allowSuppression;
  ClientConfigP internalConfig = internalConfigBuilder.build();
  Random random = new Random(resources.getInternalScheduler().getCurrentTimeMs());
  return new InvalidationClientImpl(resources, random, clientConfig.clientType,
      clientConfig.clientName, internalConfig, clientConfig.applicationName, listener);
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:18,代码来源:InvalidationClientFactory.java


示例7: handleGcmMessageForUnstartedClient

import com.google.ipc.invalidation.ticl.InvalidationClientCore; //导入依赖的package包/类
/**
 * Handles receipt of a GCM message for a client that was unknown or not started. If the client
 * was unknown, drops the message. If the client was not started, rewrites the client's
 * persistent state to have a last-message-sent-time of 0, ensuring that the client will
 * send a heartbeat to the server when restarted. Since we drop the received GCM message,
 * the client will be disconnected by the invalidation pusher; this heartbeat ensures a
 * timely reconnection.
 */
private void handleGcmMessageForUnstartedClient(AndroidClientProxy proxy) {
  if (proxy == null) {
    // Unknown client; nothing to do.
    return;
  }

  // Client is not started. Open its storage. We are going to use unsafe calls here that
  // bypass the normal storage API. This is safe in this context because we hold a lock
  // that prevents anyone else from starting this client or accessing its storage. We
  // really should not be holding a lock across I/O, but at least this is only local
  // file I/O, and we're only writing a few bytes. Additionally, since we currently only
  // have one Ticl, we should only ever enter this function if we're not being used for
  // anything else.
  final String clientKey = proxy.getClientKey();
  logger.info("Received message for unloaded client; rewriting state file: %s", clientKey);

  // This storage must have been loaded, because we got this proxy from the client manager,
  // which always ensures that its entries have that property.
  AndroidStorage storageForClient = proxy.getStorage();
  PersistentTiclState clientState = decodeTiclState(clientKey, storageForClient);
  if (clientState == null) {
    // Logging done in decodeTiclState.
    return;
  }

  // Rewrite the last message sent time.
  PersistentTiclState newState = PersistentTiclState.newBuilder(clientState)
      .setLastMessageSendTimeMs(0).build();

  // Serialize the new state.
  byte[] newClientState = PersistenceUtils.serializeState(newState, digestFn);

  // Write it out.
  storageForClient.getPropertiesUnsafe().put(InvalidationClientCore.CLIENT_TOKEN_KEY,
      newClientState);
  storageForClient.storeUnsafe();
}
 
开发者ID:morristech,项目名称:android-chromium,代码行数:46,代码来源:AndroidInvalidationService.java


示例8: createClient

import com.google.ipc.invalidation.ticl.InvalidationClientCore; //导入依赖的package包/类
/**
 * Constructs an invalidation client library instance.
 *
 * @param resources {@link SystemResources} to use for logging, scheduling, persistence, and
 *     network connectivity
 * @param clientConfig application provided configuration for the client.
 * @param listener callback object for invalidation events
 */
public static InvalidationClient createClient(SystemResources resources,
    InvalidationClientConfig clientConfig, InvalidationListener listener) {
  ClientConfigP internalConfig = InvalidationClientCore.createConfig()
      .setAllowSuppression(clientConfig.allowSuppression)
      .build();
  Random random = new Random(resources.getInternalScheduler().getCurrentTimeMs());
  return new InvalidationClientImpl(resources, random, clientConfig.clientType,
      clientConfig.clientName, internalConfig, clientConfig.applicationName, listener);
}
 
开发者ID:morristech,项目名称:android-chromium,代码行数:18,代码来源:InvalidationClientFactory.java


示例9: handleServerMessage

import com.google.ipc.invalidation.ticl.InvalidationClientCore; //导入依赖的package包/类
/**
 * Handles a {@code message} for a {@code ticl}. If the {@code ticl} is started, delivers the
 * message. If the {@code ticl} is not started, drops the message and clears the last message send
 * time in the Ticl persistent storage so that the Ticl will send a heartbeat the next time it
 * starts.
 */
private void handleServerMessage(boolean isTiclStarted, byte[] message) {
  if (isTiclStarted) {
    // Normal case -- message for a started Ticl. Deliver the message.
    resources.getNetworkListener().onMessageReceived(message);
    return;
  }

  // Even if the client is stopped, attempt to send invalidations if the client is configured to
  // receive them.
  maybeSendBackgroundInvalidationIntent(message);

  // The Ticl isn't started. Rewrite persistent storage so that the last-send-time is a long
  // time ago. The next time the Ticl starts, it will send a message to the data center, which
  // ensures that it will be marked online and that the dropped message (or an equivalent) will
  // be delivered.
  // Android storage implementations are required to execute callbacks inline, so this code
  // all executes synchronously.
  resources.getLogger().fine("Message for unstarted Ticl; rewrite state");
  resources.getStorage().readKey(InvalidationClientCore.CLIENT_TOKEN_KEY,
      new Callback<SimplePair<Status, byte[]>>() {
    @Override
    public void accept(SimplePair<Status, byte[]> result) {
      byte[] stateBytes = result.second;
      if (stateBytes == null) {
        resources.getLogger().info("No persistent state found for client; not rewriting");
        return;
      }
      // Create new state identical to the old state except with a cleared
      // lastMessageSendTimeMs.
      PersistentTiclState state = PersistenceUtils.deserializeState(
          resources.getLogger(), stateBytes, digestFn);
      if (state == null) {
        resources.getLogger().warning("Ignoring invalid Ticl state: %s",
            Bytes.toLazyCompactString(stateBytes));
        return;
      }
      PersistentTiclState.Builder stateBuilder = state.toBuilder();
      stateBuilder.lastMessageSendTimeMs = 0L;
      state = stateBuilder.build();

      // Serialize the new state and write it to storage.
      byte[] newClientState = PersistenceUtils.serializeState(state, digestFn);
      resources.getStorage().writeKey(InvalidationClientCore.CLIENT_TOKEN_KEY, newClientState,
          new Callback<Status>() {
            @Override
            public void accept(Status status) {
              if (status.getCode() != Status.Code.SUCCESS) {
                resources.getLogger().warning(
                    "Failed saving rewritten persistent state to storage");
              }
            }
      });
    }
  });
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:62,代码来源:TiclService.java


示例10: handleServerMessage

import com.google.ipc.invalidation.ticl.InvalidationClientCore; //导入依赖的package包/类
/**
 * Handles a {@code message} for a {@code ticl}. If the {@code ticl} is started, delivers the
 * message. If the {@code ticl} is not started, drops the message and clears the last message send
 * time in the Ticl persistent storage so that the Ticl will send a heartbeat the next time it
 * starts.
 */
private void handleServerMessage(boolean isTiclStarted, byte[] message) {
  if (isTiclStarted) {
    // Normal case -- message for a started Ticl. Deliver the message.
    resources.getNetworkListener().onMessageReceived(message);
    return;
  }
  // The Ticl isn't started. Rewrite persistent storage so that the last-send-time is a long
  // time ago. The next time the Ticl starts, it will send a message to the data center, which
  // ensures that it will be marked online and that the dropped message (or an equivalent) will
  // be delivered.
  // Android storage implementations are required to execute callbacks inline, so this code
  // all executes synchronously.
  resources.getLogger().fine("Message for unstarted Ticl; rewrite state");
  resources.getStorage().readKey(InvalidationClientCore.CLIENT_TOKEN_KEY,
      new Callback<SimplePair<Status, byte[]>>() {
    @Override
    public void accept(SimplePair<Status, byte[]> result) {
      byte[] stateBytes = result.second;
      if (stateBytes == null) {
        resources.getLogger().info("No persistent state found for client; not rewriting");
        return;
      }
      // Create new state identical to the old state except with a cleared
      // lastMessageSendTimeMs.
      PersistentTiclState state = PersistenceUtils.deserializeState(
          resources.getLogger(), stateBytes, digestFn);
      if (state == null) {
        resources.getLogger().warning("Ignoring invalid Ticl state: %s", stateBytes);
        return;
      }
      PersistentTiclState newState = PersistentTiclState.newBuilder(state)
          .setLastMessageSendTimeMs(0)
          .build();

      // Serialize the new state and write it to storage.
      byte[] newClientState = PersistenceUtils.serializeState(newState, digestFn);
      resources.getStorage().writeKey(InvalidationClientCore.CLIENT_TOKEN_KEY, newClientState,
          new Callback<Status>() {
            @Override
            public void accept(Status status) {
              if (status.getCode() != Status.Code.SUCCESS) {
                resources.getLogger().warning(
                    "Failed saving rewritten persistent state to storage");
              }
            }
      });
    }
  });
}
 
开发者ID:morristech,项目名称:android-chromium,代码行数:56,代码来源:TiclService.java


示例11: createClient

import com.google.ipc.invalidation.ticl.InvalidationClientCore; //导入依赖的package包/类
/**
 * Creates a new client.
 * <p>
 * REQUIRES: no client exist, or a client exists with the same type and name as provided. In
 * the latter case, this call is a no-op.
 *
 * @param context Android system context
 * @param clientType type of the client to create
 * @param clientName name of the client to create
 */
public static void createClient(Context context, int clientType, byte[] clientName) {
  ClientConfigP config = InvalidationClientCore.createConfig();
  Intent intent = ProtocolIntents.InternalDowncalls.newCreateClientIntent(
      clientType, Bytes.fromByteArray(clientName), config, false);
  intent.setClassName(context, new AndroidTiclManifest(context).getTiclServiceClass());
  context.startService(intent);
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:18,代码来源:AndroidClientFactory.java


示例12: createClient

import com.google.ipc.invalidation.ticl.InvalidationClientCore; //导入依赖的package包/类
/**
 * Creates a new client.
 * <p>
 * REQUIRES: no client exist, or a client exists with the same type and name as provided. In
 * the latter case, this call is a no-op.
 *
 * @param context Android system context
 * @param clientType type of the client to create
 * @param clientName name of the client to create
 */
public static void createClient(Context context, ClientType.Type clientType, byte[] clientName) {
  ClientConfigP config = InvalidationClientCore.createConfig().build();
  Intent intent = ProtocolIntents.InternalDowncalls.newCreateClientIntent(
      clientType.getNumber(), clientName, config, false);
  intent.setClassName(context, new AndroidTiclManifest(context).getTiclServiceClass());
  context.startService(intent);
}
 
开发者ID:morristech,项目名称:android-chromium,代码行数:18,代码来源:AndroidClientFactory.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SkipStrategy类代码示例发布时间:2022-05-23
下一篇:
Java UnauthorizedInstantiationException类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap