Java Code Examples for org.redisson.client.protocol.CommandData#isBlockingCommand()
The following examples show how to use
org.redisson.client.protocol.CommandData#isBlockingCommand() .
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: RedisConnection.java From redisson with Apache License 2.0 | 5 votes |
private void close() { CommandData<?, ?> command = getCurrentCommand(); if (!isActive() || (command != null && command.isBlockingCommand()) || !connectionPromise.isDone()) { channel.close(); } else { RFuture<Void> f = async(RedisCommands.QUIT); f.onComplete((res, e) -> { channel.close(); }); } }
Example 2
Source File: PingConnectionHandler.java From redisson with Apache License 2.0 | 5 votes |
private void sendPing(ChannelHandlerContext ctx) { RedisConnection connection = RedisConnection.getFrom(ctx.channel()); CommandData<?, ?> commandData = connection.getCurrentCommand(); RFuture<String> future; if (commandData == null || !commandData.isBlockingCommand()) { future = connection.async(StringCodec.INSTANCE, RedisCommands.PING); } else { future = null; } config.getTimer().newTimeout(new TimerTask() { @Override public void run(Timeout timeout) throws Exception { if (connection.isClosed()) { return; } if (future != null && (future.cancel(false) || !future.isSuccess())) { ctx.channel().close(); if (future.cause() != null) { log.error("Unable to send PING command over channel: " + ctx.channel(), future.cause()); } log.debug("channel: {} closed due to PING response timeout set in {} ms", ctx.channel(), config.getPingConnectionInterval()); } else { sendPing(ctx); } } }, config.getPingConnectionInterval(), TimeUnit.MILLISECONDS); }
Example 3
Source File: MasterSlaveEntry.java From redisson with Apache License 2.0 | 4 votes |
private void reattachBlockingQueue(CommandData<?, ?> commandData) { if (commandData == null || !commandData.isBlockingCommand() || commandData.getPromise().isDone()) { return; } String key = null; for (int i = 0; i < commandData.getParams().length; i++) { Object param = commandData.getParams()[i]; if ("STREAMS".equals(param)) { key = (String) commandData.getParams()[i+1]; break; } } if (key == null) { key = (String) commandData.getParams()[0]; } MasterSlaveEntry entry = connectionManager.getEntry(key); if (entry == null) { connectionManager.newTimeout(timeout -> reattachBlockingQueue(commandData), 1, TimeUnit.SECONDS); return; } RFuture<RedisConnection> newConnectionFuture = entry.connectionWriteOp(commandData.getCommand()); newConnectionFuture.onComplete((newConnection, e) -> { if (e != null) { connectionManager.newTimeout(timeout -> reattachBlockingQueue(commandData), 1, TimeUnit.SECONDS); return; } if (commandData.getPromise().isDone()) { entry.releaseWrite(newConnection); return; } ChannelFuture channelFuture = newConnection.send(commandData); channelFuture.addListener(future -> { if (!future.isSuccess()) { connectionManager.newTimeout(timeout -> reattachBlockingQueue(commandData), 1, TimeUnit.SECONDS); } }); commandData.getPromise().onComplete((r, ex) -> { entry.releaseWrite(newConnection); }); }); }