public EVCacheFutures(OperationFuture<Boolean>[] futures, String key, String app, ServerGroup serverGroup, EVCacheLatch latch) { this.futures = futures; this.app = app; this.serverGroup = serverGroup; this.key = key; this.latch = latch; this.completionCounter = new AtomicInteger(futures.length); if (latch != null && latch instanceof EVCacheLatchImpl) ((EVCacheLatchImpl) latch).addFuture(this); for (int i = 0; i < futures.length; i++) { final OperationFuture<Boolean> of = futures[i]; if (of.isDone()) { try { onComplete(of); } catch (Exception e) { } } else { of.addListener(this); } } }
private <T> Cancellable operation(final OperationFuture<T> operationFuture, final FutureCallback<T> callback) { operationFuture.addListener(new OperationCompletionListener() { @Override public void onComplete(final OperationFuture<?> future) throws Exception { try { callback.completed(operationFuture.get()); } catch (final ExecutionException ex) { if (ex.getCause() instanceof Exception) { callback.failed((Exception) ex.getCause()); } else { callback.failed(ex); } } } }); return Operations.cancellable(operationFuture); }
private <T> Cancellable operation(final OperationFuture<T> operationFuture, final FutureCallback<T> callback) { operationFuture.addListener(new OperationCompletionListener() { @Override public void onComplete(final OperationFuture<?> future) throws Exception { try { callback.completed(operationFuture.get()); } catch (final ExecutionException ex) { if (ex.getCause() instanceof Exception) { callback.failed((Exception) ex.getCause()); } else { callback.failed(ex); } } } }); return Operations.cancellable(operationFuture); }
public void setKeyValueInCouchBase(T tuple) { id++; String key = getKey(tuple); Object value = getValue(tuple); if (!(value instanceof Boolean) && !(value instanceof Integer) && !(value instanceof String) && !(value instanceof Float) && !(value instanceof Double) && !(value instanceof Character) && !(value instanceof Long) && !(value instanceof Short) && !(value instanceof Byte)) { if (serializer != null) { value = serializer.serialize(value); } } OperationFuture<Boolean> future = processKeyValue(key, value); synchronized (syncObj) { future.addListener(listener); mapFuture.put(future, id); if (!mapTuples.containsKey(id)) { mapTuples.put(id, tuple); } numTuples++; } }
public void setKeyValueInCouchBase(T tuple) { id++; String key = getKey(tuple); Object value = getValue(tuple); if(!(value instanceof Boolean) && !(value instanceof Integer) && !(value instanceof String) && !(value instanceof Float) && !(value instanceof Double) && !(value instanceof Character) && !(value instanceof Long) && !(value instanceof Short) && !(value instanceof Byte)){ if (serializer != null) { value = serializer.serialize(value); } } OperationFuture<Boolean> future = processKeyValue(key, value); synchronized (syncObj) { future.addListener(listener); mapFuture.put(future, id); if (!mapTuples.containsKey(id)) { mapTuples.put(id, tuple); } numTuples++; } }
key, latch, cbConnFactory.getObsTimeout(), executorService); original.addListener(new OperationCompletionListener() { @Override public void onComplete(final OperationFuture<?> future) throws Exception {
executorService); casOp.addListener(new OperationCompletionListener() { @Override public void onComplete(OperationFuture<?> future) throws Exception {
public static ComposableFuture<CASResponse> fromCASResponse(final CASFutureProducer source) { return ComposableFutures.build(consumer -> { final OperationFuture<CASResponse> realFuture = (OperationFuture<CASResponse>) source.createFuture(); realFuture.addListener(future -> { try { final CASResponse casResponse = realFuture.get(); consumer.consume(Try.fromValue(casResponse)); } catch (final InterruptedException e) { consumer.consume(Try.fromError(e)); } catch (final ExecutionException e) { consumer.consume(Try.fromError(e.getCause() == null ? e : e.getCause())); } catch (final Exception e) { consumer.consume(Try.fromError(e)); } }); }); }
public static <T> ComposableFuture<CASValue<T>> fromCASValue(final CASValueFutureProducer<T> source) { return ComposableFutures.build(consumer -> { final OperationFuture<CASValue<T>> realFuture = (OperationFuture<CASValue<T>>) source.createFuture(); realFuture.addListener(future -> { try { @SuppressWarnings("unchecked") final CASValue<T> value = realFuture.get(); consumer.consume(Try.fromValue(value)); } catch (final InterruptedException e) { consumer.consume(Try.fromError(e)); } catch (final ExecutionException e) { consumer.consume(Try.fromError(e.getCause() == null ? e : e.getCause())); } catch (final Exception e) { consumer.consume(Try.fromError(e)); } }); }); }
@Test public void test() { URI uri = null; ArrayList<URI> nodes = new ArrayList<URI>(); // Add one or more nodes of your cluster (exchange the IP with yours) nodes.add(URI.create("http://localhost:8091/pools")); // Try to connect to the client try { client = new CouchbaseClient(nodes, "default", ""); } catch (Exception e) { throw new RuntimeException(e); } TestPojo obj = new TestPojo(); obj.setName("test"); obj.setPhone(123344555); HashMap<String, Integer> map = new HashMap<String, Integer>(); map.put("test", 12345); obj.setMap(map); future = processKeyValue("key", obj); future.addListener(listener); }
public static ComposableFuture<Boolean> fromOperation(final OperationFutureProducer source) { return ComposableFutures.build(consumer -> { try { final OperationFuture<Boolean> realFuture = (OperationFuture<Boolean>) source.createFuture(); realFuture.addListener(future -> { try { final Boolean value = realFuture.get(); consumer.consume(Try.fromValue(value)); } catch (final InterruptedException e) { consumer.consume(Try.fromError(e)); } catch (final ExecutionException e) { consumer.consume(Try.fromError(e.getCause() == null ? e : e.getCause())); } catch (final Exception e) { consumer.consume(Try.fromError(e)); } }); } catch (final Exception e) { consumer.consume(Try.fromError(e)); } }); }