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

The following examples show how to use com.google.ipc.invalidation.external.client.SystemResources.Scheduler. 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: MemoryStorageImpl.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void writeKey(final String key, final byte[] value, final Callback<Status> callback) {
  // Need to schedule immediately because C++ locks aren't reentrant, and
  // C++ locking code assumes that this call will not return directly.

  // Schedule the write even if the resources are started since the
  // scheduler will prevent it from running in case the resources have been
  // stopped.
  scheduler.schedule(Scheduler.NO_DELAY,
      new NamedRunnable("MemoryStorage.writeKey") {
    @Override
    public void run() {
      ticlPersistentState.put(key, value);
      callback.accept(Status.newInstance(Status.Code.SUCCESS, ""));
    }
  });
}
 
Example #2
Source File: RecurringTask.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a recurring task with the given parameters. The specs of the parameters are given in
 * the instance variables.
 * <p>
 * The created task is first scheduled with a smeared delay of {@code initialDelayMs}. If the
 * {@code this.run()} returns true on its execution, the task is rescheduled after a
 * {@code timeoutDelayMs} + smeared delay of {@code initialDelayMs} or {@code timeoutDelayMs} +
 * {@code delayGenerator.getNextDelay()} depending on whether the {@code delayGenerator} is null
 * or not.
 */

public RecurringTask(String name, Scheduler scheduler, Logger logger, Smearer smearer,
    TiclExponentialBackoffDelayGenerator delayGenerator,
    final int initialDelayMs, final int timeoutDelayMs) {
  this.delayGenerator = delayGenerator;
  this.name = Preconditions.checkNotNull(name);
  this.logger = Preconditions.checkNotNull(logger);
  this.scheduler = Preconditions.checkNotNull(scheduler);
  this.smearer = Preconditions.checkNotNull(smearer);
  this.initialDelayMs = initialDelayMs;
  this.isScheduled = false;
  this.timeoutDelayMs = timeoutDelayMs;

  // Create a runnable that runs the task. If the task asks for a retry, reschedule it after
  // at a timeout delay. Otherwise, resets the delayGenerator.
  this.runnable = createRunnable();
}
 
Example #3
Source File: RecurringTask.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Creates a recurring task with the given parameters. The specs of the parameters are given in
 * the instance variables.
 * <p>
 * The created task is first scheduled with a smeared delay of {@code initialDelayMs}. If the
 * {@code this.run()} returns true on its execution, the task is rescheduled after a
 * {@code timeoutDelayMs} + smeared delay of {@code initialDelayMs} or {@code timeoutDelayMs} +
 * {@code delayGenerator.getNextDelay()} depending on whether the {@code delayGenerator} is null
 * or not.
 */

public RecurringTask(String name, Scheduler scheduler, Logger logger, Smearer smearer,
    TiclExponentialBackoffDelayGenerator delayGenerator,
    final int initialDelayMs, final int timeoutDelayMs) {
  this.delayGenerator = delayGenerator;
  this.name = Preconditions.checkNotNull(name);
  this.logger = Preconditions.checkNotNull(logger);
  this.scheduler = Preconditions.checkNotNull(scheduler);
  this.smearer = Preconditions.checkNotNull(smearer);
  this.initialDelayMs = initialDelayMs;
  this.isScheduled = false;
  this.timeoutDelayMs = timeoutDelayMs;

  // Create a runnable that runs the task. If the task asks for a retry, reschedule it after
  // at a timeout delay. Otherwise, resets the delayGenerator.
  this.runnable = createRunnable();
}
 
Example #4
Source File: MemoryStorageImpl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void writeKey(final String key, final byte[] value, final Callback<Status> callback) {
  // Need to schedule immediately because C++ locks aren't reentrant, and
  // C++ locking code assumes that this call will not return directly.

  // Schedule the write even if the resources are started since the
  // scheduler will prevent it from running in case the resources have been
  // stopped.
  scheduler.schedule(Scheduler.NO_DELAY,
      new NamedRunnable("MemoryStorage.writeKey") {
    @Override
    public void run() {
      ticlPersistentState.put(key, value);
      callback.accept(Status.newInstance(Status.Code.SUCCESS, ""));
    }
  });
}
 
Example #5
Source File: MemoryStorageImpl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void readKey(final String key, final Callback<SimplePair<Status, byte[]>> done) {
  scheduler.schedule(Scheduler.NO_DELAY,
      new NamedRunnable("MemoryStorage.readKey") {
    @Override
    public void run() {
      byte[] value = TypedUtil.mapGet(ticlPersistentState, key);
      final SimplePair<Status, byte[]> result;
      if (value != null) {
        result = SimplePair.of(Status.newInstance(Status.Code.SUCCESS, ""), value);
      } else {
        String error = "No value present in map for " + key;
        result = SimplePair.of(Status.newInstance(Status.Code.PERMANENT_FAILURE, error), null);
      }
      done.accept(result);
    }
  });
}
 
Example #6
Source File: MemoryStorageImpl.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void readKey(final String key, final Callback<SimplePair<Status, byte[]>> done) {
  scheduler.schedule(Scheduler.NO_DELAY,
      new NamedRunnable("MemoryStorage.readKey") {
    @Override
    public void run() {
      byte[] value = TypedUtil.mapGet(ticlPersistentState, key);
      final SimplePair<Status, byte[]> result;
      if (value != null) {
        result = SimplePair.of(Status.newInstance(Status.Code.SUCCESS, ""), value);
      } else {
        String error = "No value present in map for " + key;
        result = SimplePair.of(Status.newInstance(Status.Code.PERMANENT_FAILURE, error), null);
      }
      done.accept(result);
    }
  });
}
 
Example #7
Source File: MemoryStorageImpl.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void readKey(final String key, final Callback<SimplePair<Status, byte[]>> done) {
  scheduler.schedule(Scheduler.NO_DELAY,
      new NamedRunnable("MemoryStorage.readKey") {
    @Override
    public void run() {
      byte[] value = TypedUtil.mapGet(ticlPersistentState, key);
      final SimplePair<Status, byte[]> result;
      if (value != null) {
        result = SimplePair.of(Status.newInstance(Status.Code.SUCCESS, ""), value);
      } else {
        String error = "No value present in map for " + key;
        result = SimplePair.of(Status.newInstance(Status.Code.PERMANENT_FAILURE, error), null);
      }
      done.accept(result);
    }
  });
}
 
Example #8
Source File: MemoryStorageImpl.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void writeKey(final String key, final byte[] value, final Callback<Status> callback) {
  // Need to schedule immediately because C++ locks aren't reentrant, and
  // C++ locking code assumes that this call will not return directly.

  // Schedule the write even if the resources are started since the
  // scheduler will prevent it from running in case the resources have been
  // stopped.
  scheduler.schedule(Scheduler.NO_DELAY,
      new NamedRunnable("MemoryStorage.writeKey") {
    @Override
    public void run() {
      ticlPersistentState.put(key, value);
      callback.accept(Status.newInstance(Status.Code.SUCCESS, ""));
    }
  });
}
 
Example #9
Source File: RecurringTask.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Creates a recurring task with the given parameters. The specs of the parameters are given in
 * the instance variables.
 * <p>
 * The created task is first scheduled with a smeared delay of {@code initialDelayMs}. If the
 * {@code this.run()} returns true on its execution, the task is rescheduled after a
 * {@code timeoutDelayMs} + smeared delay of {@code initialDelayMs} or {@code timeoutDelayMs} +
 * {@code delayGenerator.getNextDelay()} depending on whether the {@code delayGenerator} is null
 * or not.
 */

public RecurringTask(String name, Scheduler scheduler, Logger logger, Smearer smearer,
    TiclExponentialBackoffDelayGenerator delayGenerator,
    final int initialDelayMs, final int timeoutDelayMs) {
  this.delayGenerator = delayGenerator;
  this.name = Preconditions.checkNotNull(name);
  this.logger = Preconditions.checkNotNull(logger);
  this.scheduler = Preconditions.checkNotNull(scheduler);
  this.smearer = Preconditions.checkNotNull(smearer);
  this.initialDelayMs = initialDelayMs;
  this.isScheduled = false;
  this.timeoutDelayMs = timeoutDelayMs;

  // Create a runnable that runs the task. If the task asks for a retry, reschedule it after
  // at a timeout delay. Otherwise, resets the delayGenerator.
  this.runnable = createRunnable();
}
 
Example #10
Source File: RecurringTask.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Creates a recurring task from {@code marshalledState}. Other parameters are as in the
 * constructor above.
 */
RecurringTask(String name, Scheduler scheduler, Logger logger, Smearer smearer,
    TiclExponentialBackoffDelayGenerator delayGenerator,
    RecurringTaskState marshalledState) {
  this(name, scheduler, logger, smearer, delayGenerator, marshalledState.getInitialDelayMs(),
      marshalledState.getTimeoutDelayMs());
  this.isScheduled = marshalledState.getScheduled();
}
 
Example #11
Source File: MemoryStorageImpl.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void deleteKey(final String key, final Callback<Boolean> done) {
  scheduler.schedule(Scheduler.NO_DELAY,
      new NamedRunnable("MemoryStorage.deleteKey") {
    @Override
    public void run() {
      TypedUtil.remove(ticlPersistentState, key);
      done.accept(true);
    }
  });
}
 
Example #12
Source File: MemoryStorageImpl.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void readAllKeys(final Callback<SimplePair<Status, String>> done) {
  scheduler.schedule(Scheduler.NO_DELAY,
      new NamedRunnable("MemoryStorage.readAllKeys") {
    @Override
    public void run() {
      Status successStatus = Status.newInstance(Status.Code.SUCCESS, "");
      for (String key : ticlPersistentState.keySet()) {
        done.accept(SimplePair.of(successStatus, key));
      }
      done.accept(null);
    }
  });
}
 
Example #13
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 #14
Source File: CheckingInvalidationListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
CheckingInvalidationListener(InvalidationListener delegate, Scheduler internalScheduler,
    Scheduler listenerScheduler, Logger logger) {
  this.delegate = Preconditions.checkNotNull(delegate, "Delegate cannot be null");
  this.internalScheduler = Preconditions.checkNotNull(internalScheduler,
      "Internal scheduler cannot be null");
  this.listenerScheduler = Preconditions.checkNotNull(listenerScheduler,
      "Listener scheduler cannot be null");
  this.logger = Preconditions.checkNotNull(logger, "Logger cannot be null");
}
 
Example #15
Source File: CheckingInvalidationListener.java    From 365browser with Apache License 2.0 5 votes vote down vote up
CheckingInvalidationListener(InvalidationListener delegate, Scheduler internalScheduler,
    Scheduler listenerScheduler, Logger logger) {
  this.delegate = Preconditions.checkNotNull(delegate, "Delegate cannot be null");
  this.internalScheduler = Preconditions.checkNotNull(internalScheduler,
      "Internal scheduler cannot be null");
  this.listenerScheduler = Preconditions.checkNotNull(listenerScheduler,
      "Listener scheduler cannot be null");
  this.logger = Preconditions.checkNotNull(logger, "Logger cannot be null");
}
 
Example #16
Source File: MemoryStorageImpl.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void deleteKey(final String key, final Callback<Boolean> done) {
  scheduler.schedule(Scheduler.NO_DELAY,
      new NamedRunnable("MemoryStorage.deleteKey") {
    @Override
    public void run() {
      TypedUtil.remove(ticlPersistentState, key);
      done.accept(true);
    }
  });
}
 
Example #17
Source File: MemoryStorageImpl.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void readAllKeys(final Callback<SimplePair<Status, String>> done) {
  scheduler.schedule(Scheduler.NO_DELAY,
      new NamedRunnable("MemoryStorage.readAllKeys") {
    @Override
    public void run() {
      Status successStatus = Status.newInstance(Status.Code.SUCCESS, "");
      for (String key : ticlPersistentState.keySet()) {
        done.accept(SimplePair.of(successStatus, key));
      }
      done.accept(null);
    }
  });
}
 
Example #18
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 #19
Source File: CheckingInvalidationListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
CheckingInvalidationListener(InvalidationListener delegate, Scheduler internalScheduler,
    Scheduler listenerScheduler, Logger logger) {
  this.delegate = Preconditions.checkNotNull(delegate, "Delegate cannot be null");
  this.internalScheduler = Preconditions.checkNotNull(internalScheduler,
      "Internal scheduler cannot be null");
  this.listenerScheduler = Preconditions.checkNotNull(listenerScheduler,
      "Listener scheduler cannot be null");
  this.logger = Preconditions.checkNotNull(logger, "Logger cannot be null");
}
 
Example #20
Source File: RecurringTask.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Creates a recurring task from {@code marshalledState}. Other parameters are as in the
 * constructor above.
 */
RecurringTask(String name, Scheduler scheduler, Logger logger, Smearer smearer,
    TiclExponentialBackoffDelayGenerator delayGenerator,
    RecurringTaskState marshalledState) {
  this(name, scheduler, logger, smearer, delayGenerator, marshalledState.getInitialDelayMs(),
      marshalledState.getTimeoutDelayMs());
  this.isScheduled = marshalledState.getScheduled();
}
 
Example #21
Source File: RecurringTask.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a recurring task from {@code marshalledState}. Other parameters are as in the
 * constructor above.
 */
RecurringTask(String name, Scheduler scheduler, Logger logger, Smearer smearer,
    TiclExponentialBackoffDelayGenerator delayGenerator,
    RecurringTaskState marshalledState) {
  this(name, scheduler, logger, smearer, delayGenerator, marshalledState.getInitialDelayMs(),
      marshalledState.getTimeoutDelayMs());
  this.isScheduled = marshalledState.getScheduled();
}
 
Example #22
Source File: MemoryStorageImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteKey(final String key, final Callback<Boolean> done) {
  scheduler.schedule(Scheduler.NO_DELAY,
      new NamedRunnable("MemoryStorage.deleteKey") {
    @Override
    public void run() {
      TypedUtil.remove(ticlPersistentState, key);
      done.accept(true);
    }
  });
}
 
Example #23
Source File: MemoryStorageImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void readAllKeys(final Callback<SimplePair<Status, String>> done) {
  scheduler.schedule(Scheduler.NO_DELAY,
      new NamedRunnable("MemoryStorage.readAllKeys") {
    @Override
    public void run() {
      Status successStatus = Status.newInstance(Status.Code.SUCCESS, "");
      for (String key : ticlPersistentState.keySet()) {
        done.accept(SimplePair.of(successStatus, key));
      }
      done.accept(null);
    }
  });
}
 
Example #24
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 #25
Source File: SystemResourcesBuilder.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Sets the scheduler for scheduling listener events to be {@code listenerScheduler}.
 * <p>
 * REQUIRES: {@link #build} has not been called.
 */
public SystemResourcesBuilder setListenerScheduler(Scheduler listenerScheduler) {
  Preconditions.checkState(!sealed, "Builder's build method has already been called");
  this.listenerScheduler = listenerScheduler;
  return this;
}
 
Example #26
Source File: SystemResourcesBuilder.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Sets the scheduler for scheduling internal events to be {@code internalScheduler}.
 * <p>
 * REQUIRES: {@link #build} has not been called.
 */
public SystemResourcesBuilder setInternalScheduler(Scheduler internalScheduler) {
  Preconditions.checkState(!sealed, "Builder's build method has already been called");
  this.internalScheduler = internalScheduler;
  return this;
}
 
Example #27
Source File: SystemResourcesBuilder.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns the listener scheduler. */
public Scheduler getListenerScheduler() {
  return listenerScheduler;
}
 
Example #28
Source File: SystemResourcesBuilder.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns the internal scheduler. */
public Scheduler getInternalScheduler() {
  return internalScheduler;
}
 
Example #29
Source File: InvalidationClientCore.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public Scheduler getInternalSchedulerForTest() {
  return resources.getInternalScheduler();
}
 
Example #30
Source File: SystemResourcesBuilder.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/** Returns the internal scheduler. */
public Scheduler getInternalScheduler() {
  return internalScheduler;
}