org.redisson.connection.SingleEntry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of redisson Show documentation
Show all versions of redisson Show documentation
Redis Java client with features of In-Memory Data Grid
/**
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.redisson.connection;
import java.net.InetSocketAddress;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import org.redisson.MasterSlaveServersConfig;
import org.redisson.client.RedisClient;
import org.redisson.client.RedisConnection;
import org.redisson.client.RedisPubSubConnection;
import org.redisson.cluster.ClusterSlotRange;
import org.redisson.connection.ClientConnectionsEntry.NodeType;
import org.redisson.misc.ConnectionPool;
import org.redisson.misc.PubSubConnectionPoll;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.Promise;
public class SingleEntry extends MasterSlaveEntry {
final ConnectionPool pubSubConnectionHolder;
public SingleEntry(Set slotRanges, ConnectionManager connectionManager, MasterSlaveServersConfig config) {
super(slotRanges, connectionManager, config);
pubSubConnectionHolder = new PubSubConnectionPoll(config, connectionManager, this) {
protected ClientConnectionsEntry getEntry() {
return entries.get(0);
}
};
}
@Override
public Future setupMasterEntry(String host, int port) {
RedisClient masterClient = connectionManager.createClient(host, port);
masterEntry = new ClientConnectionsEntry(masterClient,
config.getMasterConnectionMinimumIdleSize(),
config.getMasterConnectionPoolSize(),
config.getSlaveConnectionMinimumIdleSize(),
config.getSlaveSubscriptionConnectionPoolSize(), connectionManager, NodeType.MASTER, config);
final Promise res = connectionManager.newPromise();
Future f = writeConnectionHolder.add(masterEntry);
Future s = pubSubConnectionHolder.add(masterEntry);
FutureListener listener = new FutureListener() {
AtomicInteger counter = new AtomicInteger(2);
@Override
public void operationComplete(Future future) throws Exception {
if (!future.isSuccess()) {
res.setFailure(future.cause());
return;
}
if (counter.decrementAndGet() == 0) {
res.setSuccess(null);
}
}
};
f.addListener(listener);
s.addListener(listener);
return res;
}
@Override
Future nextPubSubConnection() {
return pubSubConnectionHolder.get();
}
@Override
public void returnPubSubConnection(PubSubConnectionEntry entry) {
pubSubConnectionHolder.returnConnection(masterEntry, entry.getConnection());
}
@Override
public Future connectionReadOp(InetSocketAddress addr) {
return super.connectionWriteOp();
}
@Override
public Future connectionReadOp() {
return super.connectionWriteOp();
}
@Override
public void releaseRead(RedisConnection сonnection) {
super.releaseWrite(сonnection);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy