Java Code Examples for org.redisson.api.RFuture#getNow()
The following examples show how to use
org.redisson.api.RFuture#getNow() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LiveObjectInterceptor.java From redisson with Apache License 2.0 | 4 votes |
@RuntimeType public Object intercept( @Origin Method method, @AllArguments Object[] args, @This Object me, @FieldValue("liveObjectId") Object id, @FieldProxy("liveObjectId") Setter idSetter, @FieldProxy("liveObjectId") Getter idGetter, @FieldValue("liveObjectLiveMap") RMap<String, ?> map, @FieldProxy("liveObjectLiveMap") Setter mapSetter, @FieldProxy("liveObjectLiveMap") Getter mapGetter ) throws Exception { if ("setLiveObjectId".equals(method.getName())) { if (args[0].getClass().isArray()) { throw new UnsupportedOperationException("RId value cannot be an array."); } //TODO: distributed locking maybe required. String idKey = getMapKey(args[0]); if (map != null) { if (map.getName().equals(idKey)) { return null; } try { map.rename(getMapKey(args[0])); } catch (RedisException e) { if (e.getMessage() == null || !e.getMessage().startsWith("ERR no such key")) { throw e; } //key may already renamed by others. } } RMap<Object, Object> liveMap = new RedissonMap<Object, Object>(namingScheme.getCodec(), commandExecutor, idKey, null, null, null); mapSetter.setValue(liveMap); return null; } if ("getLiveObjectId".equals(method.getName())) { if (map == null) { return null; } return namingScheme.resolveId(map.getName()); } if ("delete".equals(method.getName())) { CommandBatchService ce; if (commandExecutor instanceof CommandBatchService) { ce = (CommandBatchService) commandExecutor; } else { ce = new CommandBatchService(connectionManager); } RFuture<Long> deleteFuture = service.delete(me, map, ce); ce.execute(); return deleteFuture.getNow() > 0; } return method.invoke(map, args); }
Example 2
Source File: ReplicatedConnectionManager.java From redisson with Apache License 2.0 | 4 votes |
public ReplicatedConnectionManager(ReplicatedServersConfig cfg, Config config, UUID id) { super(config, id); this.config = create(cfg); initTimer(this.config); for (String address : cfg.getNodeAddresses()) { RedisURI addr = new RedisURI(address); RFuture<RedisConnection> connectionFuture = connectToNode(cfg, addr, null, addr.getHost()); connectionFuture.awaitUninterruptibly(); RedisConnection connection = connectionFuture.getNow(); if (connection == null) { continue; } Role role = Role.valueOf(connection.sync(RedisCommands.INFO_REPLICATION).get(ROLE_KEY)); if (Role.master.equals(role)) { if (currentMaster.get() != null) { stopThreads(); throw new RedisException("Multiple masters detected"); } currentMaster.set(addr); log.info("{} is the master", addr); this.config.setMasterAddress(addr.toString()); } else { log.info("{} is a slave", addr); this.config.addSlaveAddress(addr.toString()); } } if (currentMaster.get() == null) { stopThreads(); throw new RedisConnectionException("Can't connect to servers!"); } if (this.config.getReadMode() != ReadMode.MASTER && this.config.getSlaveAddresses().isEmpty()) { log.warn("ReadMode = " + this.config.getReadMode() + ", but slave nodes are not found! Please specify all nodes in replicated mode."); } initSingleEntry(); scheduleMasterChangeCheck(cfg); }
Example 3
Source File: RedisExecutor.java From redisson with Apache License 2.0 | 4 votes |
private void scheduleRetryTimeout(RFuture<RedisConnection> connectionFuture, RPromise<R> attemptPromise) { TimerTask retryTimerTask = new TimerTask() { @Override public void run(Timeout t) throws Exception { if (attemptPromise.isDone()) { return; } if (connectionFuture.cancel(false)) { if (exception == null) { exception = new RedisTimeoutException("Unable to acquire connection! Increase connection pool size and/or retryInterval settings " + "Node source: " + source + ", command: " + LogHelper.toString(command, params) + " after " + attempt + " retry attempts"); } } else { if (connectionFuture.isSuccess()) { if (writeFuture == null || !writeFuture.isDone()) { if (attempt == attempts) { if (writeFuture != null && writeFuture.cancel(false)) { if (exception == null) { long totalSize = 0; if (params != null) { for (Object param : params) { if (param instanceof ByteBuf) { totalSize += ((ByteBuf) param).readableBytes(); } } } exception = new RedisTimeoutException("Command still hasn't been written into connection! Increase nettyThreads and/or retryInterval settings. Payload size in bytes: " + totalSize + ". Node source: " + source + ", connection: " + connectionFuture.getNow() + ", command: " + LogHelper.toString(command, params) + " after " + attempt + " retry attempts"); } attemptPromise.tryFailure(exception); } return; } attempt++; scheduleRetryTimeout(connectionFuture, attemptPromise); return; } if (writeFuture.isSuccess()) { return; } } } if (mainPromise.isCancelled()) { if (attemptPromise.cancel(false)) { free(); } return; } if (attempt == attempts) { // filled out in connectionFuture or writeFuture handler attemptPromise.tryFailure(exception); return; } if (!attemptPromise.cancel(false)) { return; } attempt++; if (log.isDebugEnabled()) { log.debug("attempt {} for command {} and params {}", attempt, command, LogHelper.toString(params)); } mainPromiseListener = null; execute(); } }; timeout = connectionManager.newTimeout(retryTimerTask, retryInterval, TimeUnit.MILLISECONDS); }