com.google.ipc.invalidation.external.client.SystemResources.NetworkChannel Java Examples

The following examples show how to use com.google.ipc.invalidation.external.client.SystemResources.NetworkChannel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InvalidationClientCore.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Registers handlers for received messages and network status changes with the network of
 * {@code resources}.
 */
private void registerWithNetwork(final SystemResources resources) {
  resources.getNetwork().setListener(new NetworkChannel.NetworkListener() {
    @Override
    public void onMessageReceived(byte[] incomingMessage) {
      InvalidationClientCore.this.handleIncomingMessage(incomingMessage);
    }
    @Override
    public void onOnlineStatusChange(boolean isOnline) {
      InvalidationClientCore.this.handleNetworkStatusChange(isOnline);
    }
    @Override
    public void onAddressChange() {
      // Send a message to the server. The header will include the new network address.
      Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
      sendInfoMessageToServer(false, false);
    }
  });
}
 
Example #2
Source File: InvalidationClientCore.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Registers handlers for received messages and network status changes with the network of
 * {@code resources}.
 */
private void registerWithNetwork(final SystemResources resources) {
  resources.getNetwork().setListener(new NetworkChannel.NetworkListener() {
    @Override
    public void onMessageReceived(byte[] incomingMessage) {
      final String name = "handleIncomingMessage";
      InvalidationClientCore.this.handleIncomingMessage(incomingMessage);
    }
    @Override
    public void onOnlineStatusChange(boolean isOnline) {
      InvalidationClientCore.this.handleNetworkStatusChange(isOnline);
    }
    @Override
    public void onAddressChange() {
      // Send a message to the server. The header will include the new network address.
      Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
      sendInfoMessageToServer(false, false);
    }
  });
}
 
Example #3
Source File: InvalidationClientCore.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Registers handlers for received messages and network status changes with the network of
 * {@code resources}.
 */
private void registerWithNetwork(final SystemResources resources) {
  resources.getNetwork().setListener(new NetworkChannel.NetworkListener() {
    @Override
    public void onMessageReceived(byte[] incomingMessage) {
      final String name = "handleIncomingMessage";
      InvalidationClientCore.this.handleIncomingMessage(incomingMessage);
    }
    @Override
    public void onOnlineStatusChange(boolean isOnline) {
      InvalidationClientCore.this.handleNetworkStatusChange(isOnline);
    }
    @Override
    public void onAddressChange() {
      // Send a message to the server. The header will include the new network address.
      Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
      sendInfoMessageToServer(false, false);
    }
  });
}
 
Example #4
Source File: InvalidationClientCore.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public NetworkEndpointId getNetworkIdForTest() {
  NetworkChannel network = resources.getNetwork();
  if (!(network instanceof TestableNetworkChannel)) {
    throw new UnsupportedOperationException(
        "getNetworkIdForTest requires a TestableNetworkChannel, not: " + network.getClass());
  }
  return ((TestableNetworkChannel) network).getNetworkIdForTest();
}
 
Example #5
Source File: SystemResourcesBuilder.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** See specs at {@code DefaultResourcesFactory.createDefaultResourcesBuilder}. */
public SystemResourcesBuilder(Logger logger, Scheduler internalScheduler,
    Scheduler listenerScheduler, NetworkChannel network, Storage storage) {
  this.logger = logger;
  this.internalScheduler = internalScheduler;
  this.listenerScheduler = listenerScheduler;
  this.network = network;
  this.storage = storage;
}
 
Example #6
Source File: AndroidResourcesFactory.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Constructs a {@link SystemResourcesBuilder} instance using default scheduling, Android-style
 * logging, and storage, and using {@code network} to send and receive messages.
 */
public static SystemResourcesBuilder createResourcesBuilder(String logPrefix,
    NetworkChannel network, Storage storage) {
  SystemResourcesBuilder builder = new SystemResourcesBuilder(AndroidLogger.forPrefix(logPrefix),
        new ExecutorBasedScheduler("ticl" + logPrefix),
        new ExecutorBasedScheduler("ticl-listener" + logPrefix),
        network, storage);
  builder.setPlatform("Android-" + android.os.Build.VERSION.RELEASE);
  return builder;
}
 
Example #7
Source File: InvalidationClientCore.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public NetworkEndpointId getNetworkIdForTest() {
  NetworkChannel network = resources.getNetwork();
  if (!(network instanceof TestableNetworkChannel)) {
    throw new UnsupportedOperationException(
        "getNetworkIdForTest requires a TestableNetworkChannel, not: " + network.getClass());
  }
  return ((TestableNetworkChannel) network).getNetworkIdForTest();
}
 
Example #8
Source File: ResourcesFactory.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Creates an instance for test from the provided resources and context. */

AndroidResources(Logger logger, AndroidInternalScheduler internalScheduler,
    NetworkChannel network, Storage storage, Context context) {
  super(logger, internalScheduler, new InvalidScheduler(), network, storage,
      getPlatformString());
  this.context = Preconditions.checkNotNull(context);
}
 
Example #9
Source File: SystemResourcesBuilder.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** See specs at {@code DefaultResourcesFactory.createDefaultResourcesBuilder}. */
public SystemResourcesBuilder(Logger logger, Scheduler internalScheduler,
    Scheduler listenerScheduler, NetworkChannel network, Storage storage) {
  this.logger = logger;
  this.internalScheduler = internalScheduler;
  this.listenerScheduler = listenerScheduler;
  this.network = network;
  this.storage = storage;
}
 
Example #10
Source File: AndroidResourcesFactory.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Constructs a {@link SystemResourcesBuilder} instance using default scheduling, Android-style
 * logging, and storage, and using {@code network} to send and receive messages.
 */
public static SystemResourcesBuilder createResourcesBuilder(String logPrefix,
    NetworkChannel network, Storage storage) {
  SystemResourcesBuilder builder = new SystemResourcesBuilder(AndroidLogger.forPrefix(logPrefix),
        new ExecutorBasedScheduler("ticl" + logPrefix),
        new ExecutorBasedScheduler("ticl-listener" + logPrefix),
        network, storage);
  builder.setPlatform("Android-" + android.os.Build.VERSION.RELEASE);
  return builder;
}
 
Example #11
Source File: InvalidationClientCore.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public NetworkEndpointId getNetworkIdForTest() {
  NetworkChannel network = resources.getNetwork();
  if (!(network instanceof TestableNetworkChannel)) {
    throw new UnsupportedOperationException(
        "getNetworkIdForTest requires a TestableNetworkChannel, not: " + network.getClass());
  }
  return ((TestableNetworkChannel) network).getNetworkIdForTest();
}
 
Example #12
Source File: ResourcesFactory.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Creates an instance for test from the provided resources and context. */

AndroidResources(Logger logger, AndroidInternalScheduler internalScheduler,
    NetworkChannel network, Storage storage, Context context) {
  super(logger, internalScheduler, new InvalidScheduler(), network, storage,
      getPlatformString());
  this.context = Preconditions.checkNotNull(context);
}
 
Example #13
Source File: SystemResourcesBuilder.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** See specs at {@code DefaultResourcesFactory.createDefaultResourcesBuilder}. */
public SystemResourcesBuilder(Logger logger, Scheduler internalScheduler,
    Scheduler listenerScheduler, NetworkChannel network, Storage storage) {
  this.logger = logger;
  this.internalScheduler = internalScheduler;
  this.listenerScheduler = listenerScheduler;
  this.network = network;
  this.storage = storage;
}
 
Example #14
Source File: AndroidChannel.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void setListener(NetworkChannel.NetworkListener listener) {
  this.listener = Preconditions.checkNotNull(listener);
}
 
Example #15
Source File: ResourcesFactory.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns the network listener provided by the Ticl. */
NetworkChannel.NetworkListener getNetworkListener() {
  return Preconditions.checkNotNull(networkListener, "network listener not yet set");
}
 
Example #16
Source File: SystemResourcesBuilder.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns the network channel. */
public NetworkChannel getNetwork() {
  return network;
}
 
Example #17
Source File: SystemResourcesBuilder.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Sets the network channel for communicating with the server to be {@code network}.
 * <p>
 * REQUIRES: {@link #build} has not been called.
 */
public SystemResourcesBuilder setNetwork(NetworkChannel network) {
  Preconditions.checkState(!sealed, "Builder's build method has already been called");
  this.network = network;
  return this;
}
 
Example #18
Source File: ResourcesFactory.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Sets the network message listener provided by the Ticl. The network calls this method when
 * the Ticl provides it with a listener; the Ticl service later retrieves the listener when
 * it has a network event to communicate to the Ticl.
 */
public void setNetworkListener(NetworkChannel.NetworkListener networkListener) {
  Preconditions.checkState(this.networkListener == null, "Listener already set: %s",
      networkListener);
  this.networkListener = Preconditions.checkNotNull(networkListener);
}
 
Example #19
Source File: ResourcesFactory.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Sets the network message listener provided by the Ticl. The network calls this method when
 * the Ticl provides it with a listener; the Ticl service later retrieves the listener when
 * it has a network event to communicate to the Ticl.
 */
public void setNetworkListener(NetworkChannel.NetworkListener networkListener) {
  Preconditions.checkState(this.networkListener == null, "Listener already set: %s",
      networkListener);
  this.networkListener = Preconditions.checkNotNull(networkListener);
}
 
Example #20
Source File: ResourcesFactory.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns the network listener provided by the Ticl. */
NetworkChannel.NetworkListener getNetworkListener() {
  return Preconditions.checkNotNull(networkListener, "network listener not yet set");
}
 
Example #21
Source File: SystemResourcesBuilder.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the network channel for communicating with the server to be {@code network}.
 * <p>
 * REQUIRES: {@link #build} has not been called.
 */
public SystemResourcesBuilder setNetwork(NetworkChannel network) {
  Preconditions.checkState(!sealed, "Builder's build method has already been called");
  this.network = network;
  return this;
}
 
Example #22
Source File: SystemResourcesBuilder.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/** Returns the network channel. */
public NetworkChannel getNetwork() {
  return network;
}
 
Example #23
Source File: AndroidChannel.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void setListener(NetworkChannel.NetworkListener listener) {
  this.listener = Preconditions.checkNotNull(listener);
}
 
Example #24
Source File: SystemResourcesBuilder.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns the network channel. */
public NetworkChannel getNetwork() {
  return network;
}
 
Example #25
Source File: SystemResourcesBuilder.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Sets the network channel for communicating with the server to be {@code network}.
 * <p>
 * REQUIRES: {@link #build} has not been called.
 */
public SystemResourcesBuilder setNetwork(NetworkChannel network) {
  Preconditions.checkState(!sealed, "Builder's build method has already been called");
  this.network = network;
  return this;
}