Java Code Examples for org.apache.ratis.util.JavaUtils#cast()

The following examples show how to use org.apache.ratis.util.JavaUtils#cast() . 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: CounterStateMachine.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
/**
 * Load the state of the state machine from the storage.
 *
 * @param snapshot to load
 * @return the index of the snapshot or -1 if snapshot is invalid
 * @throws IOException if any error happens during read from storage
 */
private long load(SingleFileSnapshotInfo snapshot) throws IOException {
  //check the snapshot nullity
  if (snapshot == null) {
    LOG.warn("The snapshot info is null.");
    return RaftLog.INVALID_LOG_INDEX;
  }

  //check the existance of the snapshot file
  final File snapshotFile = snapshot.getFile().getPath().toFile();
  if (!snapshotFile.exists()) {
    LOG.warn("The snapshot file {} does not exist for snapshot {}",
        snapshotFile, snapshot);
    return RaftLog.INVALID_LOG_INDEX;
  }

  //load the TermIndex object for the snapshot using the file name pattern of
  // the snapshot
  final TermIndex last =
      SimpleStateMachineStorage.getTermIndexFromSnapshotFile(snapshotFile);

  //read the file and cast it to the AtomicInteger and set the counter
  try (ObjectInputStream in = new ObjectInputStream(
      new BufferedInputStream(new FileInputStream(snapshotFile)))) {
    //set the last applied termIndex to the termIndex of the snapshot
    setLastAppliedTermIndex(last);

    //read, cast and set the counter
    counter = JavaUtils.cast(in.readObject());
  } catch (ClassNotFoundException e) {
    throw new IllegalStateException(e);
  }

  return last.getIndex();
}
 
Example 2
Source File: RaftClientReply.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
/** If this reply has {@link AlreadyClosedException}, return it; otherwise return null. */
public AlreadyClosedException getAlreadyClosedException() {
  return JavaUtils.cast(exception, AlreadyClosedException.class);
}
 
Example 3
Source File: RaftClientReply.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
/** If this reply has {@link NotLeaderException}, return it; otherwise return null. */
public NotLeaderException getNotLeaderException() {
  return JavaUtils.cast(exception, NotLeaderException.class);
}
 
Example 4
Source File: RaftClientReply.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
/** If this reply has {@link NotReplicatedException}, return it; otherwise return null. */
public NotReplicatedException getNotReplicatedException() {
  return JavaUtils.cast(exception, NotReplicatedException.class);
}
 
Example 5
Source File: RaftClientReply.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
/** If this reply has {@link StateMachineException}, return it; otherwise return null. */
public StateMachineException getStateMachineException() {
  return JavaUtils.cast(exception, StateMachineException.class);
}
 
Example 6
Source File: RaftClientReply.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
public LeaderNotReadyException getLeaderNotReadyException() {
  return JavaUtils.cast(exception, LeaderNotReadyException.class);
}
 
Example 7
Source File: SimulatedRpc.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
Factory(Parameters parameters) {
  serverRequestReply = JavaUtils.cast(parameters.getNonNull(SERVER_REQUEST_REPLY_KEY, SimulatedRequestReply.class));
  client2serverRequestReply = parameters.getNonNull(
      CLIENT_TO_SERVER_REQUEST_REPLY_KEY, SimulatedClientRpc.class);
}
 
Example 8
Source File: RaftClientReply.java    From ratis with Apache License 2.0 4 votes vote down vote up
/** If this reply has {@link NotLeaderException}, return it; otherwise return null. */
public NotLeaderException getNotLeaderException() {
  return JavaUtils.cast(exception, NotLeaderException.class);
}
 
Example 9
Source File: RaftClientReply.java    From ratis with Apache License 2.0 4 votes vote down vote up
/** If this reply has {@link NotReplicatedException}, return it; otherwise return null. */
public NotReplicatedException getNotReplicatedException() {
  return JavaUtils.cast(exception, NotReplicatedException.class);
}
 
Example 10
Source File: RaftClientReply.java    From ratis with Apache License 2.0 4 votes vote down vote up
/** If this reply has {@link StateMachineException}, return it; otherwise return null. */
public StateMachineException getStateMachineException() {
  return JavaUtils.cast(exception, StateMachineException.class);
}
 
Example 11
Source File: RaftClientReply.java    From ratis with Apache License 2.0 4 votes vote down vote up
/** If this reply has {@link RaftRetryFailureException}, return it; otherwise return null. */
public RaftRetryFailureException getRetryFailureException() {
  return JavaUtils.cast(exception, RaftRetryFailureException.class);
}
 
Example 12
Source File: SimulatedRpc.java    From ratis with Apache License 2.0 4 votes vote down vote up
Factory(Parameters parameters) {
  serverRequestReply = JavaUtils.cast(parameters.getNonNull(SERVER_REQUEST_REPLY_KEY, SimulatedRequestReply.class));
  client2serverRequestReply = parameters.getNonNull(
      CLIENT_TO_SERVER_REQUEST_REPLY_KEY, SimulatedClientRpc.class);
}