@Override public Boolean get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { for (OperationFuture<Boolean> future : futures) { if (future.get(timeout, unit) == false) return false; } return true; }
@Override public Boolean get() throws InterruptedException, ExecutionException { for (OperationFuture<Boolean> future : futures) { if (future.get() == false) return false; } return true; }
@Override public boolean add(final String key, int exp, final Object value) { log.trace("Memcached add operation on key '{}', with value:{}", key, value); boolean success = false; int tryCount = 0; do { try { if (tryCount > 0) { Thread.sleep(retryAfterSec * 1000); log.warn("retrying operation #{}", tryCount); } tryCount++; success = memcachedClient.add(key, exp, value) .get(); } catch (final Exception e) { log.warn("memcache set: {}", e.getMessage()); } } while (!success && tryCount < maxTry); if (!success) { log.error("Failed to add key to Elasticache {}", key); } if (success && tryCount > 1) { log.info("Connection restored OK to Elasticache cluster"); } available = success; return success; }
private boolean putInternal(final CouchbaseClient client, final String key, final V value) { try { return client.set(key, value) .get(); } catch (InterruptedException | ExecutionException e) { throw ExceptionSoftener.throwSoftenedException(e); } }
@Override public boolean evictBlock(BlockCacheKey cacheKey) { try { cacheStats.evict(); return client.delete(cacheKey.toString()).get(); } catch (InterruptedException e) { LOG.warn("Error deleting " + cacheKey.toString(), e); Thread.currentThread().interrupt(); } catch (ExecutionException e) { if (LOG.isDebugEnabled()) { LOG.debug("Error deleting " + cacheKey.toString(), e); } } return false; }
if (log.isDebugEnabled()) log.debug(";App : " + evcacheEvent.getAppName() + "; Call : " + evcacheEvent.getCall() + "; Keys : " + evcacheEvent.getCanonicalKeys() + "; completeCount : " + completeCount + "; totalFutureCount : " + totalFutureCount +"; failureCount : " + failureCount); try { if(future.isDone() && future.get().equals(Boolean.FALSE)) { failureCount++;
@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); } } }
@SuppressWarnings("unchecked") @BeforeMethod public void setup() throws Exception { final StandardContext context = createContext(); context.setBackgroundProcessorDelay( 1 ); // needed for test of updateExpiration final SessionManager manager = createSessionManager(context); _service = manager.getMemcachedSessionService(); _service.setMemcachedNodes( "n1:127.0.0.1:11211" ); _service.setSessionBackupAsync( false ); _service.setSticky( true ); _memcachedMock = mock( MemcachedClient.class ); final OperationFuture<Boolean> setResultMock = mock( OperationFuture.class ); when( setResultMock.get( ) ).thenReturn( Boolean.TRUE ); when( setResultMock.get( anyInt(), any( TimeUnit.class ) ) ).thenReturn( Boolean.TRUE ); when( _memcachedMock.set( any( String.class ), anyInt(), any(), any( Transcoder.class ) ) ).thenReturn( setResultMock ); final OperationFuture<Boolean> deleteResultMock = mock( OperationFuture.class ); when( deleteResultMock.get() ).thenReturn( Boolean.TRUE ); when( _memcachedMock.delete( anyString() ) ).thenReturn( deleteResultMock ); startInternal( manager, _memcachedMock ); _executor = Executors.newCachedThreadPool(); }
/** * Test for issue #105: Make memcached node optional for single-node setup * http://code.google.com/p/memcached-session-manager/issues/detail?id=105 */ @Test public void testBackupSessionFailureWithoutMemcachedNodeIdConfigured105() throws Exception { _service.setMemcachedNodes( "127.0.0.1:11211" ); _service.setSessionBackupAsync(false); _service.startInternal(new MemcachedStorageClient(_memcachedMock)); final MemcachedBackupSession session = createSession( _service ); session.access(); session.endAccess(); session.setAttribute( "foo", "bar" ); @SuppressWarnings( "unchecked" ) final OperationFuture<Boolean> futureMock = mock( OperationFuture.class ); when( futureMock.get( ) ).thenThrow(new ExecutionException(new RuntimeException("Simulated exception."))); when( futureMock.get( anyInt(), any( TimeUnit.class ) ) ).thenThrow(new ExecutionException(new RuntimeException("Simulated exception."))); when( _memcachedMock.set( eq( session.getId() ), anyInt(), any(), any( Transcoder.class ) ) ).thenReturn( futureMock ); final BackupResult backupResult = _service.backupSession( session.getIdInternal(), false, null ).get(); assertEquals(backupResult.getStatus(), BackupResultStatus.FAILURE); verify( _memcachedMock, times( 1 ) ).set( eq( session.getId() ), anyInt(), any(), any( Transcoder.class ) ); }
public T get(long duration, TimeUnit units) throws InterruptedException, TimeoutException, ExecutionException { Future<T> v = rv.get(duration, units); return v == null ? null : v.get(); }
public T get(long duration, TimeUnit units) throws InterruptedException, TimeoutException, ExecutionException { Future<T> v = rv.get(duration, units); return v == null ? null : v.get(); }
public T get(long duration, TimeUnit units) throws InterruptedException, TimeoutException, ExecutionException { Future<T> v = rv.get(duration, units); return v == null ? null : v.get(); }
public T get(long duration, TimeUnit units) throws InterruptedException, TimeoutException, ExecutionException { Future<T> v = rv.get(duration, units); return v == null ? null : v.get(); }
@Override public Boolean get(long duration, TimeUnit units) throws InterruptedException, TimeoutException, ExecutionException { status = new OperationStatus(true, "OK", StatusCode.SUCCESS); return super.get(duration, units); }
@Override public Boolean get(long duration, TimeUnit units) throws InterruptedException, TimeoutException, ExecutionException { status = new OperationStatus(true, "OK"); return super.get(duration, units); }
@SuppressWarnings("unchecked") @Override public void put(Object key, Object value) { try { memcacheClient.set(key.toString(), keyExpiryTime, value).get(); } catch (Exception ex) { throw new RuntimeException(ex); } }
@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); } } }
public void testGets() throws Exception { MemcachedClient client = bootstrapClient(); client.add("getskey", 10, "casValue").get(); CASValue<Object> val = client.gets("getskey"); long oldCas = val.getCas(); assertEquals("casValue", val.getValue()); client.replace("getskey", 10, "myNewVal").get(); val = client.gets("getskey"); assertEquals(oldCas + 1, val.getCas()); assertEquals("myNewVal", val.getValue()); }