Search in sources :

Example 1 with CounterException

use of org.infinispan.counter.exception.CounterException in project infinispan by infinispan.

the class TestCounterNotificationManager method add.

private List<UserListener<?>> add(String counterName, List<UserListener<?>> list, UserListener<?> listener) {
    if (list == null) {
        CounterListenerOp op = createListener(client.protocolVersion(), counterName, listenerId.getBytes());
        TestResponse response = client.execute(op);
        switch(response.getStatus()) {
            case Success:
                break;
            case OperationNotExecuted:
                break;
            case KeyDoesNotExist:
                throw new CounterException("Counter " + counterName + " doesn't exist");
            default:
                throw new IllegalStateException("Unknown status " + response.getStatus());
        }
        list = new CopyOnWriteArrayList<>();
    }
    list.add(listener);
    return list;
}
Also used : CounterListenerOp(org.infinispan.server.hotrod.counter.op.CounterListenerOp) TestResponse(org.infinispan.server.hotrod.test.TestResponse) CounterException(org.infinispan.counter.exception.CounterException)

Example 2 with CounterException

use of org.infinispan.counter.exception.CounterException in project infinispan by infinispan.

the class TestCounterNotificationManager method remove.

private void remove(String counterName, UserListener<?> listener) {
    userListenerList.computeIfPresent(counterName, (name, list) -> {
        list.remove(listener);
        if (list.isEmpty()) {
            CounterListenerOp op = removeListener(client.protocolVersion(), counterName, listenerId.getBytes());
            TestResponse response = client.execute(op);
            switch(response.getStatus()) {
                case Success:
                    break;
                case OperationNotExecuted:
                    break;
                case KeyDoesNotExist:
                    throw new CounterException("Counter " + counterName + " doesn't exist");
                default:
                    throw new IllegalStateException("Unknown status " + response.getStatus());
            }
            return null;
        }
        return list;
    });
}
Also used : CounterListenerOp(org.infinispan.server.hotrod.counter.op.CounterListenerOp) TestResponse(org.infinispan.server.hotrod.test.TestResponse) CounterException(org.infinispan.counter.exception.CounterException)

Example 3 with CounterException

use of org.infinispan.counter.exception.CounterException in project infinispan by infinispan.

the class TestWeakCounter method executeOp.

private CompletableFuture<Void> executeOp(CounterOp op) {
    TestResponse response = client.execute(op);
    CompletableFuture<Void> future = new CompletableFuture<>();
    switch(response.getStatus()) {
        case Success:
            future.complete(null);
            break;
        case OperationNotExecuted:
            future.complete(null);
            break;
        case KeyDoesNotExist:
            future.completeExceptionally(new IllegalStateException("Counter Not Found!"));
            break;
        case ServerError:
            future.completeExceptionally(new CounterException(((TestErrorResponse) response).msg));
            break;
        default:
            future.completeExceptionally(new Exception("unknown response " + response));
    }
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) CounterValueTestResponse(org.infinispan.server.hotrod.counter.response.CounterValueTestResponse) TestResponse(org.infinispan.server.hotrod.test.TestResponse) TestErrorResponse(org.infinispan.server.hotrod.test.TestErrorResponse) CounterException(org.infinispan.counter.exception.CounterException) CounterException(org.infinispan.counter.exception.CounterException)

Example 4 with CounterException

use of org.infinispan.counter.exception.CounterException in project infinispan by infinispan.

the class TestStrongCounter method executeOp.

private <T> CompletableFuture<T> executeOp(CounterOp op, BiConsumer<CompletableFuture<T>, TestResponse> responseHandler, BooleanSupplier canReachUpperBound) {
    TestResponse response = client.execute(op);
    CompletableFuture<T> future = new CompletableFuture<>();
    switch(response.getStatus()) {
        case Success:
            responseHandler.accept(future, response);
            break;
        case OperationNotExecuted:
            responseHandler.accept(future, response);
            break;
        case KeyDoesNotExist:
            future.completeExceptionally(new IllegalStateException("Counter Not Found!"));
            break;
        case ServerError:
            future.completeExceptionally(new CounterException(((TestErrorResponse) response).msg));
            break;
        case NotExecutedWithPrevious:
            future.completeExceptionally(canReachUpperBound.getAsBoolean() ? new CounterOutOfBoundsException(format(FORMAT_MESSAGE, UPPER_BOUND)) : new CounterOutOfBoundsException(format(FORMAT_MESSAGE, LOWER_BOUND)));
            break;
        default:
            future.completeExceptionally(new Exception("unknown response " + response));
    }
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) COUNTER_RESET(org.infinispan.server.hotrod.HotRodOperation.COUNTER_RESET) COUNTER_GET(org.infinispan.server.hotrod.HotRodOperation.COUNTER_GET) TestResponse(org.infinispan.server.hotrod.test.TestResponse) CounterValueTestResponse(org.infinispan.server.hotrod.counter.response.CounterValueTestResponse) CounterOutOfBoundsException(org.infinispan.counter.exception.CounterOutOfBoundsException) TestErrorResponse(org.infinispan.server.hotrod.test.TestErrorResponse) CounterException(org.infinispan.counter.exception.CounterException) CounterException(org.infinispan.counter.exception.CounterException) CounterOutOfBoundsException(org.infinispan.counter.exception.CounterOutOfBoundsException)

Example 5 with CounterException

use of org.infinispan.counter.exception.CounterException in project infinispan by infinispan.

the class TestWeakCounter method getValue.

@Override
public long getValue() {
    CounterOp op = new CounterOp(client.protocolVersion(), COUNTER_GET, name);
    TestResponse response = client.execute(op);
    switch(response.getStatus()) {
        case Success:
            return ((CounterValueTestResponse) response).getValue();
        case ServerError:
            throw new CounterException(((TestErrorResponse) response).msg);
        default:
            throw new CounterException("unknown response " + response);
    }
}
Also used : CounterValueTestResponse(org.infinispan.server.hotrod.counter.response.CounterValueTestResponse) TestResponse(org.infinispan.server.hotrod.test.TestResponse) CounterOp(org.infinispan.server.hotrod.counter.op.CounterOp) CounterValueTestResponse(org.infinispan.server.hotrod.counter.response.CounterValueTestResponse) CounterException(org.infinispan.counter.exception.CounterException)

Aggregations

CounterException (org.infinispan.counter.exception.CounterException)5 TestResponse (org.infinispan.server.hotrod.test.TestResponse)5 CounterValueTestResponse (org.infinispan.server.hotrod.counter.response.CounterValueTestResponse)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 CounterListenerOp (org.infinispan.server.hotrod.counter.op.CounterListenerOp)2 TestErrorResponse (org.infinispan.server.hotrod.test.TestErrorResponse)2 CounterOutOfBoundsException (org.infinispan.counter.exception.CounterOutOfBoundsException)1 COUNTER_GET (org.infinispan.server.hotrod.HotRodOperation.COUNTER_GET)1 COUNTER_RESET (org.infinispan.server.hotrod.HotRodOperation.COUNTER_RESET)1 CounterOp (org.infinispan.server.hotrod.counter.op.CounterOp)1