Search in sources :

Example 1 with CounterListenerOp

use of org.infinispan.server.hotrod.counter.op.CounterListenerOp 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 CounterListenerOp

use of org.infinispan.server.hotrod.counter.op.CounterListenerOp 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)

Aggregations

CounterException (org.infinispan.counter.exception.CounterException)2 CounterListenerOp (org.infinispan.server.hotrod.counter.op.CounterListenerOp)2 TestResponse (org.infinispan.server.hotrod.test.TestResponse)2