Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

refactor: simplify api using encapsulating parameters and results #124

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

foreverneverer
Copy link
Contributor

@foreverneverer foreverneverer commented Aug 24, 2020

Note

The latest design has been updated in #122, the current some implement is outdated and need be refactored

Summary

#122 has described the design, this PR implement it and contain follow point:

  • every request content is wrapper one class, for example, Set(hashKey, sortKey, value)-> Set(set)
  • discard batchMultiXXX API
  • discard multiGetSortKeys API
  • maintain checkAndSet/checkAndMutate/compareAndChange/Scanner
  • batch future task was encapsulated into class futureGroup and usage:
  @Override
  public int batchSet(BatchSet batchSet, List<Pair<PException, Void>> results, int timeout)
      throws PException {
    if (results == null) {
      throw new PException("Invalid parameter: results should not be null");
    }
    results.clear();
    FutureGroup<Void> futureGroup =
        new FutureGroup<>(batchSet.setList.size(), batchSet.forceComplete);

    for (Set set : batchSet.setList) {
      futureGroup.add(asyncSet(set, timeout));
    }
    return futureGroup.waitAllComplete(results, timeout);
  }

New API list

async

  public Future<Boolean> asyncExist(Get get, int timeout /*ms*/);
  public Future<Integer> asyncTTL(Get get, int timeout /*ms*/);
  public Future<Long> asyncIncr(Increment increment, int timeout /*ms*/);

  public Future<byte[]> asyncGet(Get get, int timeout /*ms*/);
  public Future<MultiGetResult> asyncRangeGet(RangeGet rangeGet, int timeout /*ms*/)
      throws PException;
  public Future<MultiGetResult> asyncMultiGet(MultiGet multiGet, int timeout /*ms*/);

  public Future<Void> asyncSet(Set set, int timeout /*ms*/);
  public Future<Void> asyncMultiSet(MultiSet multiSet, int timeout /*ms*/);

  public Future<Void> asyncDel(Delete delete, int timeout /*ms*/);
  public Future<Void> asyncMultiDel(MultiDelete multiDelete, int timeout /*ms*/);

sync

  public byte[] get(Get get, int timeout) throws PException;
  public void batchGet(BatchGet batchGet, List<Pair<PException, byte[]>> results, int timeout)
      throws PException;
  public MultiGetResult multiGet(MultiGet multiGet, int timeout) throws PException;
  public MultiGetResult rangeGet(RangeGet rangeGet, int timeout) throws PException;

  public void set(Set set, int timeout) throws PException;
  public int batchSet(BatchSet batchSet, List<Pair<PException, Void>> results, int timeout)
      throws PException;
  public void multiSet(MultiSet multiSet, int timeout) throws PException;

  public void del(Delete delete, int timeout) throws PException;
  public int batchDel(BatchDelete batchDelete, List<Pair<PException, Void>> results, int timeout)
      throws PException;
  public void multiDel(MultiDelete multiDelete, int timeout) throws PException;
  public void rangeDel(RangeDelete rangeDelete, int timeout) throws PException;

  public int ttl(Get get, int timeout) throws PException;
  public long incr(Increment increment, int timeout) throws PException;
  public boolean exist(Get get, int timeout) throws PException;

@foreverneverer foreverneverer changed the title refactor: simply api refactor: simplify the API Aug 25, 2020
@foreverneverer foreverneverer changed the title refactor: simplify the API refactor: simplify the client api Aug 26, 2020
@foreverneverer foreverneverer changed the title refactor: simplify the client api refactor: simplify the client api using encapsulating parameters and results Sep 1, 2020
@foreverneverer foreverneverer changed the title refactor: simplify the client api using encapsulating parameters and results refactor: simplify api using encapsulating parameters and results Sep 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant