com.google.ipc.invalidation.external.client.types.Status Java Examples

The following examples show how to use com.google.ipc.invalidation.external.client.types.Status. 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 android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Reads the Ticl state from persistent storage (if any) and calls {@code startInternal}. */
private void scheduleStartAfterReadingStateBlob() {
  storage.readKey(CLIENT_TOKEN_KEY, new Callback<SimplePair<Status, byte[]>>() {
    @Override
    public void accept(final SimplePair<Status, byte[]> readResult) {
      Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
      final byte[] serializedState = readResult.getFirst().isSuccess() ?
          readResult.getSecond() : null;
      // Call start now.
      if (!readResult.getFirst().isSuccess()) {
        statistics.recordError(ClientErrorType.PERSISTENT_READ_FAILURE);
        logger.warning("Could not read state blob: %s", readResult.getFirst().getMessage());
      }
      startInternal(serializedState);
    }
  });
}
 
Example #2
Source File: InvalidationClientCore.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/** Reads the Ticl state from persistent storage (if any) and calls {@code startInternal}. */
private void scheduleStartAfterReadingStateBlob() {
  storage.readKey(CLIENT_TOKEN_KEY, new Callback<SimplePair<Status, byte[]>>() {
    @Override
    public void accept(final SimplePair<Status, byte[]> readResult) {
      Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
      final byte[] serializedState = readResult.getFirst().isSuccess() ?
          readResult.getSecond() : null;
      // Call start now.
      if (!readResult.getFirst().isSuccess()) {
        statistics.recordError(ClientErrorType.PERSISTENT_READ_FAILURE);
        logger.warning("Could not read state blob: %s", readResult.getFirst().getMessage());
      }
      startInternal(serializedState);
    }
  });
}
 
Example #3
Source File: AndroidStorage.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.execute(new NamedRunnable("AndroidStorage.readKey") {
    @Override
    public void run() {
        byte [] value = properties.get(key);
        if (value != null) {
          done.accept(SimplePair.of(SUCCESS, value));
        } else {
          Status status =
              Status.newInstance(Status.Code.PERMANENT_FAILURE, "No value in map for " + key);
          done.accept(SimplePair.of(status, (byte []) null));
        }
    }
  });
}
 
Example #4
Source File: InvalidationClientCore.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Reads the Ticl state from persistent storage (if any) and calls {@code startInternal}. */
private void scheduleStartAfterReadingStateBlob() {
  storage.readKey(CLIENT_TOKEN_KEY, new Callback<SimplePair<Status, byte[]>>() {
    @Override
    public void accept(final SimplePair<Status, byte[]> readResult) {
      Preconditions.checkState(internalScheduler.isRunningOnThread(), "Not on internal thread");
      final byte[] serializedState = readResult.getFirst().isSuccess() ?
          readResult.getSecond() : null;
      // Call start now.
      if (!readResult.getFirst().isSuccess()) {
        statistics.recordError(ClientErrorType.PERSISTENT_READ_FAILURE);
        logger.warning("Could not read state blob: %s", readResult.getFirst().getMessage());
      }
      startInternal(serializedState);
    }
  });
}
 
Example #5
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 #6
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 #7
Source File: AndroidStorage.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.execute(new NamedRunnable("AndroidStorage.readKey") {
    @Override
    public void run() {
        byte [] value = properties.get(key);
        if (value != null) {
          done.accept(SimplePair.of(SUCCESS, value));
        } else {
          Status status =
              Status.newInstance(Status.Code.PERMANENT_FAILURE, "No value in map for " + key);
          done.accept(SimplePair.of(status, (byte []) null));
        }
    }
  });
}
 
Example #8
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 #9
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 #10
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 #11
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 #12
Source File: AndroidStorage.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>> keyCallback) {
  scheduler.execute(new NamedRunnable("AndroidStorage.readAllKeys") {
    @Override
    public void run() {
      for (String key : properties.keySet()) {
        keyCallback.accept(SimplePair.of(SUCCESS, key));
      }
    }
  });
}
 
Example #13
Source File: AndroidStorage.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>> keyCallback) {
  scheduler.execute(new NamedRunnable("AndroidStorage.readAllKeys") {
    @Override
    public void run() {
      for (String key : properties.keySet()) {
        keyCallback.accept(SimplePair.of(SUCCESS, key));
      }
    }
  });
}
 
Example #14
Source File: AndroidStorage.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void writeKey(final String key, final byte[] value, final Callback<Status> done) {
  scheduler.execute(new NamedRunnable("AndroidStorage.writeKey") {
    @Override
    public void run() {
      properties.put(key, value);
      store();
      done.accept(SUCCESS);
    }
  });
}
 
Example #15
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 #16
Source File: SafeStorage.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>> keyCallback) {
  delegate.readAllKeys(new Callback<SimplePair<Status, String>>() {
    @Override
    public void accept(final SimplePair<Status, String> keyResult) {
      scheduler.schedule(NO_DELAY, new NamedRunnable("SafeStorage.readAllKeys") {
        @Override
        public void run() {
          keyCallback.accept(keyResult);
        }
      });
    }
  });
}
 
Example #17
Source File: SafeStorage.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void readKey(String key, final Callback<SimplePair<Status, byte[]>> done) {
  delegate.readKey(key, new Callback<SimplePair<Status, byte[]>>() {
    @Override
    public void accept(final SimplePair<Status, byte[]> result) {
      scheduler.schedule(NO_DELAY, new NamedRunnable("SafeStorage.readKey") {
        @Override
        public void run() {
          done.accept(result);
        }
      });
    }
  });
}
 
Example #18
Source File: SafeStorage.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void writeKey(String key, byte[] value, final Callback<Status> done) {
  delegate.writeKey(key, value, new Callback<Status>() {
    @Override
    public void accept(final Status status) {
      scheduler.schedule(NO_DELAY, new NamedRunnable("SafeStorage.writeKey") {
        @Override
        public void run() {
          done.accept(status);
        }
      });
    }
  });
}
 
Example #19
Source File: AndroidStorage.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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);
}
 
Example #20
Source File: SafeStorage.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>> keyCallback) {
  delegate.readAllKeys(new Callback<SimplePair<Status, String>>() {
    @Override
    public void accept(final SimplePair<Status, String> keyResult) {
      scheduler.schedule(NO_DELAY, new NamedRunnable("SafeStorage.readAllKeys") {
        @Override
        public void run() {
          keyCallback.accept(keyResult);
        }
      });
    }
  });
}
 
Example #21
Source File: SafeStorage.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void readKey(String key, final Callback<SimplePair<Status, byte[]>> done) {
  delegate.readKey(key, new Callback<SimplePair<Status, byte[]>>() {
    @Override
    public void accept(final SimplePair<Status, byte[]> result) {
      scheduler.schedule(NO_DELAY, new NamedRunnable("SafeStorage.readKey") {
        @Override
        public void run() {
          done.accept(result);
        }
      });
    }
  });
}
 
Example #22
Source File: SafeStorage.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void writeKey(String key, byte[] value, final Callback<Status> done) {
  delegate.writeKey(key, value, new Callback<Status>() {
    @Override
    public void accept(final Status status) {
      scheduler.schedule(NO_DELAY, new NamedRunnable("SafeStorage.writeKey") {
        @Override
        public void run() {
          done.accept(status);
        }
      });
    }
  });
}
 
Example #23
Source File: AndroidStorage.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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);
}
 
Example #24
Source File: AndroidStorage.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void writeKey(final String key, final byte[] value, final Callback<Status> done) {
  scheduler.execute(new NamedRunnable("AndroidStorage.writeKey") {
    @Override
    public void run() {
      properties.put(key, value);
      store();
      done.accept(SUCCESS);
    }
  });
}
 
Example #25
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 #26
Source File: SafeStorage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void readAllKeys(final Callback<SimplePair<Status, String>> keyCallback) {
  delegate.readAllKeys(new Callback<SimplePair<Status, String>>() {
    @Override
    public void accept(final SimplePair<Status, String> keyResult) {
      scheduler.schedule(NO_DELAY, new NamedRunnable("SafeStorage.readAllKeys") {
        @Override
        public void run() {
          keyCallback.accept(keyResult);
        }
      });
    }
  });
}
 
Example #27
Source File: SafeStorage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void readKey(String key, final Callback<SimplePair<Status, byte[]>> done) {
  delegate.readKey(key, new Callback<SimplePair<Status, byte[]>>() {
    @Override
    public void accept(final SimplePair<Status, byte[]> result) {
      scheduler.schedule(NO_DELAY, new NamedRunnable("SafeStorage.readKey") {
        @Override
        public void run() {
          done.accept(result);
        }
      });
    }
  });
}
 
Example #28
Source File: SafeStorage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void writeKey(String key, byte[] value, final Callback<Status> done) {
  delegate.writeKey(key, value, new Callback<Status>() {
    @Override
    public void accept(final Status status) {
      scheduler.schedule(NO_DELAY, new NamedRunnable("SafeStorage.writeKey") {
        @Override
        public void run() {
          done.accept(status);
        }
      });
    }
  });
}
 
Example #29
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 #30
Source File: AndroidStorage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@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);
}