refactoring

pull/4879/head
Nikita Koksharov 2 years ago
parent 175d5dcfb5
commit c432023f27

@ -193,7 +193,7 @@ public class RedissonRegionFactory implements RegionFactory {
log.debug("Building entity cache region: " + regionName);
RMapCache<Object, Object> mapCache = getCache(regionName, properties, ENTITY_DEF);
return new RedissonEntityRegion(mapCache, ((Redisson)redisson).getConnectionManager(),this, metadata, settings, properties, ENTITY_DEF);
return new RedissonEntityRegion(mapCache, ((Redisson)redisson).getServiceManager(),this, metadata, settings, properties, ENTITY_DEF);
}
@Override
@ -202,7 +202,7 @@ public class RedissonRegionFactory implements RegionFactory {
log.debug("Building naturalId cache region: " + regionName);
RMapCache<Object, Object> mapCache = getCache(regionName, properties, NATURAL_ID_DEF);
return new RedissonNaturalIdRegion(mapCache, ((Redisson)redisson).getConnectionManager(),this, metadata, settings, properties, NATURAL_ID_DEF);
return new RedissonNaturalIdRegion(mapCache, ((Redisson)redisson).getServiceManager(),this, metadata, settings, properties, NATURAL_ID_DEF);
}
@Override
@ -211,7 +211,7 @@ public class RedissonRegionFactory implements RegionFactory {
log.debug("Building collection cache region: " + regionName);
RMapCache<Object, Object> mapCache = getCache(regionName, properties, COLLECTION_DEF);
return new RedissonCollectionRegion(mapCache, ((Redisson)redisson).getConnectionManager(),this, metadata, settings, properties, COLLECTION_DEF);
return new RedissonCollectionRegion(mapCache, ((Redisson)redisson).getServiceManager(),this, metadata, settings, properties, COLLECTION_DEF);
}
@Override
@ -219,7 +219,7 @@ public class RedissonRegionFactory implements RegionFactory {
log.debug("Building query cache region: " + regionName);
RMapCache<Object, Object> mapCache = getCache(regionName, properties, QUERY_DEF);
return new RedissonQueryRegion(mapCache, ((Redisson)redisson).getConnectionManager(),this, properties, QUERY_DEF);
return new RedissonQueryRegion(mapCache, ((Redisson)redisson).getServiceManager(),this, properties, QUERY_DEF);
}
@Override
@ -227,7 +227,7 @@ public class RedissonRegionFactory implements RegionFactory {
log.debug("Building timestamps cache region: " + regionName);
RMapCache<Object, Object> mapCache = getCache(regionName, properties, TIMESTAMPS_DEF);
return new RedissonTimestampsRegion(mapCache, ((Redisson)redisson).getConnectionManager(),this, properties, TIMESTAMPS_DEF);
return new RedissonTimestampsRegion(mapCache, ((Redisson)redisson).getServiceManager(),this, properties, TIMESTAMPS_DEF);
}
protected RMapCache<Object, Object> getCache(String regionName, Properties properties, String defaultKey) {

@ -22,7 +22,7 @@ import org.hibernate.cache.spi.RegionFactory;
import org.hibernate.cache.spi.TransactionalDataRegion;
import org.redisson.api.RFuture;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import org.redisson.hibernate.RedissonRegionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -44,7 +44,7 @@ public class BaseRegion implements TransactionalDataRegion, GeneralDataRegion {
final RMapCache<Object, Object> mapCache;
final RegionFactory regionFactory;
final CacheDataDescription metadata;
final ConnectionManager connectionManager;
final ServiceManager serviceManager;
int ttl;
int maxIdle;
@ -52,12 +52,12 @@ public class BaseRegion implements TransactionalDataRegion, GeneralDataRegion {
boolean fallback;
volatile boolean fallbackMode;
public BaseRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager, RegionFactory regionFactory, CacheDataDescription metadata, Properties properties, String defaultKey) {
public BaseRegion(RMapCache<Object, Object> mapCache, ServiceManager serviceManager, RegionFactory regionFactory, CacheDataDescription metadata, Properties properties, String defaultKey) {
super();
this.mapCache = mapCache;
this.regionFactory = regionFactory;
this.metadata = metadata;
this.connectionManager = connectionManager;
this.serviceManager = serviceManager;
String maxEntries = getProperty(properties, mapCache.getName(), defaultKey, RedissonRegionFactory.MAX_ENTRIES_SUFFIX);
if (maxEntries != null) {
@ -91,7 +91,7 @@ public class BaseRegion implements TransactionalDataRegion, GeneralDataRegion {
private void ping() {
fallbackMode = true;
connectionManager.newTimeout(t -> {
serviceManager.newTimeout(t -> {
RFuture<Boolean> future = mapCache.isExistsAsync();
future.whenComplete((r, ex) -> {
if (ex == null) {

@ -23,7 +23,7 @@ import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
import org.hibernate.cfg.Settings;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import org.redisson.hibernate.strategy.NonStrictReadWriteCollectionRegionAccessStrategy;
import org.redisson.hibernate.strategy.ReadOnlyCollectionRegionAccessStrategy;
import org.redisson.hibernate.strategy.ReadWriteCollectionRegionAccessStrategy;
@ -40,9 +40,9 @@ public class RedissonCollectionRegion extends BaseRegion implements CollectionRe
private final Settings settings;
public RedissonCollectionRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager, RegionFactory regionFactory,
public RedissonCollectionRegion(RMapCache<Object, Object> mapCache, ServiceManager serviceManager, RegionFactory regionFactory,
CacheDataDescription metadata, Settings settings, Properties properties, String defaultKey) {
super(mapCache, connectionManager, regionFactory, metadata, properties, defaultKey);
super(mapCache, serviceManager, regionFactory, metadata, properties, defaultKey);
this.settings = settings;
}

@ -23,7 +23,7 @@ import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
import org.hibernate.cfg.Settings;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import org.redisson.hibernate.strategy.NonStrictReadWriteEntityRegionAccessStrategy;
import org.redisson.hibernate.strategy.ReadOnlyEntityRegionAccessStrategy;
import org.redisson.hibernate.strategy.ReadWriteEntityRegionAccessStrategy;
@ -40,9 +40,9 @@ public class RedissonEntityRegion extends BaseRegion implements EntityRegion {
private final Settings settings;
public RedissonEntityRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager, RegionFactory regionFactory,
public RedissonEntityRegion(RMapCache<Object, Object> mapCache, ServiceManager serviceManager, RegionFactory regionFactory,
CacheDataDescription metadata, Settings settings, Properties properties, String defaultKey) {
super(mapCache, connectionManager, regionFactory, metadata, properties, defaultKey);
super(mapCache, serviceManager, regionFactory, metadata, properties, defaultKey);
this.settings = settings;
}

@ -23,7 +23,7 @@ import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy;
import org.hibernate.cfg.Settings;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import org.redisson.hibernate.strategy.NonStrictReadWriteNaturalIdRegionAccessStrategy;
import org.redisson.hibernate.strategy.ReadOnlyNaturalIdRegionAccessStrategy;
import org.redisson.hibernate.strategy.ReadWriteNaturalIdRegionAccessStrategy;
@ -40,9 +40,9 @@ public class RedissonNaturalIdRegion extends BaseRegion implements NaturalIdRegi
private final Settings settings;
public RedissonNaturalIdRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager, RegionFactory regionFactory,
public RedissonNaturalIdRegion(RMapCache<Object, Object> mapCache, ServiceManager serviceManager, RegionFactory regionFactory,
CacheDataDescription metadata, Settings settings, Properties properties, String defaultKey) {
super(mapCache, connectionManager, regionFactory, metadata, properties, defaultKey);
super(mapCache, serviceManager, regionFactory, metadata, properties, defaultKey);
this.settings = settings;
}

@ -15,12 +15,12 @@
*/
package org.redisson.hibernate.region;
import java.util.Properties;
import org.hibernate.cache.spi.QueryResultsRegion;
import org.hibernate.cache.spi.RegionFactory;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import java.util.Properties;
/**
*
@ -29,9 +29,9 @@ import org.redisson.connection.ConnectionManager;
*/
public class RedissonQueryRegion extends BaseRegion implements QueryResultsRegion {
public RedissonQueryRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager,
public RedissonQueryRegion(RMapCache<Object, Object> mapCache, ServiceManager serviceManager,
RegionFactory regionFactory, Properties properties, String defaultKey) {
super(mapCache, connectionManager, regionFactory, null, properties, defaultKey);
super(mapCache, serviceManager, regionFactory, null, properties, defaultKey);
}
}

@ -15,12 +15,12 @@
*/
package org.redisson.hibernate.region;
import java.util.Properties;
import org.hibernate.cache.spi.RegionFactory;
import org.hibernate.cache.spi.TimestampsRegion;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import java.util.Properties;
/**
*
@ -29,9 +29,9 @@ import org.redisson.connection.ConnectionManager;
*/
public class RedissonTimestampsRegion extends BaseRegion implements TimestampsRegion {
public RedissonTimestampsRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager,
public RedissonTimestampsRegion(RMapCache<Object, Object> mapCache, ServiceManager serviceManager,
RegionFactory regionFactory, Properties properties, String defaultKey) {
super(mapCache, connectionManager, regionFactory, null, properties, defaultKey);
super(mapCache, serviceManager, regionFactory, null, properties, defaultKey);
}
}

@ -200,7 +200,7 @@ import java.util.concurrent.atomic.AtomicLong;
log.debug("Building entity cache region: " + regionName);
RMapCache<Object, Object> mapCache = getCache(regionName, properties, ENTITY_DEF);
return new RedissonEntityRegion(mapCache, ((Redisson)redisson).getConnectionManager(),this, metadata, settings, properties, ENTITY_DEF, cacheKeysFactory);
return new RedissonEntityRegion(mapCache, ((Redisson)redisson).getServiceManager(),this, metadata, settings, properties, ENTITY_DEF, cacheKeysFactory);
}
@Override
@ -209,7 +209,7 @@ import java.util.concurrent.atomic.AtomicLong;
log.debug("Building naturalId cache region: " + regionName);
RMapCache<Object, Object> mapCache = getCache(regionName, properties, NATURAL_ID_DEF);
return new RedissonNaturalIdRegion(mapCache, ((Redisson)redisson).getConnectionManager(),this, metadata, settings, properties, NATURAL_ID_DEF, cacheKeysFactory);
return new RedissonNaturalIdRegion(mapCache, ((Redisson)redisson).getServiceManager(),this, metadata, settings, properties, NATURAL_ID_DEF, cacheKeysFactory);
}
@Override
@ -218,7 +218,7 @@ import java.util.concurrent.atomic.AtomicLong;
log.debug("Building collection cache region: " + regionName);
RMapCache<Object, Object> mapCache = getCache(regionName, properties, COLLECTION_DEF);
return new RedissonCollectionRegion(mapCache, ((Redisson)redisson).getConnectionManager(),this, metadata, settings, properties, COLLECTION_DEF, cacheKeysFactory);
return new RedissonCollectionRegion(mapCache, ((Redisson)redisson).getServiceManager(),this, metadata, settings, properties, COLLECTION_DEF, cacheKeysFactory);
}
@Override
@ -226,7 +226,7 @@ import java.util.concurrent.atomic.AtomicLong;
log.debug("Building query cache region: " + regionName);
RMapCache<Object, Object> mapCache = getCache(regionName, properties, QUERY_DEF);
return new RedissonQueryRegion(mapCache, ((Redisson)redisson).getConnectionManager(),this, properties, QUERY_DEF);
return new RedissonQueryRegion(mapCache, ((Redisson)redisson).getServiceManager(),this, properties, QUERY_DEF);
}
@Override
@ -234,7 +234,7 @@ import java.util.concurrent.atomic.AtomicLong;
log.debug("Building timestamps cache region: " + regionName);
RMapCache<Object, Object> mapCache = getCache(regionName, properties, TIMESTAMPS_DEF);
return new RedissonTimestampsRegion(mapCache, ((Redisson)redisson).getConnectionManager(),this, properties, TIMESTAMPS_DEF);
return new RedissonTimestampsRegion(mapCache, ((Redisson)redisson).getServiceManager(),this, properties, TIMESTAMPS_DEF);
}
protected RMapCache<Object, Object> getCache(String regionName, Properties properties, String defaultKey) {

@ -23,7 +23,7 @@ import org.hibernate.cache.spi.TransactionalDataRegion;
import org.hibernate.engine.spi.SessionImplementor;
import org.redisson.api.RFuture;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import org.redisson.hibernate.RedissonRegionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -45,7 +45,7 @@ public class BaseRegion implements TransactionalDataRegion, GeneralDataRegion {
final RMapCache<Object, Object> mapCache;
final RegionFactory regionFactory;
final CacheDataDescription metadata;
final ConnectionManager connectionManager;
final ServiceManager serviceManager;
int ttl;
int maxIdle;
@ -53,12 +53,12 @@ public class BaseRegion implements TransactionalDataRegion, GeneralDataRegion {
boolean fallback;
volatile boolean fallbackMode;
public BaseRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager, RegionFactory regionFactory, CacheDataDescription metadata, Properties properties, String defaultKey) {
public BaseRegion(RMapCache<Object, Object> mapCache, ServiceManager serviceManager, RegionFactory regionFactory, CacheDataDescription metadata, Properties properties, String defaultKey) {
super();
this.mapCache = mapCache;
this.regionFactory = regionFactory;
this.metadata = metadata;
this.connectionManager = connectionManager;
this.serviceManager = serviceManager;
String maxEntries = getProperty(properties, mapCache.getName(), defaultKey, RedissonRegionFactory.MAX_ENTRIES_SUFFIX);
if (maxEntries != null) {
@ -92,7 +92,7 @@ public class BaseRegion implements TransactionalDataRegion, GeneralDataRegion {
private void ping() {
fallbackMode = true;
connectionManager.newTimeout(t -> {
serviceManager.newTimeout(t -> {
RFuture<Boolean> future = mapCache.isExistsAsync();
future.whenComplete((r, ex) -> {
if (ex == null) {

@ -27,6 +27,7 @@ import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
import org.hibernate.cfg.Settings;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import org.redisson.hibernate.strategy.NonStrictReadWriteCollectionRegionAccessStrategy;
import org.redisson.hibernate.strategy.ReadOnlyCollectionRegionAccessStrategy;
import org.redisson.hibernate.strategy.ReadWriteCollectionRegionAccessStrategy;
@ -42,9 +43,9 @@ public class RedissonCollectionRegion extends BaseRegion implements CollectionRe
private final Settings settings;
private final CacheKeysFactory cacheKeysFactory;
public RedissonCollectionRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager, RegionFactory regionFactory,
public RedissonCollectionRegion(RMapCache<Object, Object> mapCache, ServiceManager serviceManager, RegionFactory regionFactory,
CacheDataDescription metadata, Settings settings, Properties properties, String defaultKey, CacheKeysFactory cacheKeysFactory) {
super(mapCache, connectionManager, regionFactory, metadata, properties, defaultKey);
super(mapCache, serviceManager, regionFactory, metadata, properties, defaultKey);
this.settings = settings;
this.cacheKeysFactory = cacheKeysFactory;
}

@ -15,8 +15,6 @@
*/
package org.redisson.hibernate.region;
import java.util.Properties;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.CacheKeysFactory;
@ -26,12 +24,14 @@ import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
import org.hibernate.cfg.Settings;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import org.redisson.hibernate.strategy.NonStrictReadWriteEntityRegionAccessStrategy;
import org.redisson.hibernate.strategy.ReadOnlyEntityRegionAccessStrategy;
import org.redisson.hibernate.strategy.ReadWriteEntityRegionAccessStrategy;
import org.redisson.hibernate.strategy.TransactionalEntityRegionAccessStrategy;
import java.util.Properties;
/**
*
* @author Nikita Koksharov
@ -42,9 +42,9 @@ public class RedissonEntityRegion extends BaseRegion implements EntityRegion {
private final Settings settings;
private final CacheKeysFactory cacheKeysFactory;
public RedissonEntityRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager, RegionFactory regionFactory,
public RedissonEntityRegion(RMapCache<Object, Object> mapCache, ServiceManager serviceManager, RegionFactory regionFactory,
CacheDataDescription metadata, Settings settings, Properties properties, String defaultKey, CacheKeysFactory cacheKeysFactory) {
super(mapCache, connectionManager, regionFactory, metadata, properties, defaultKey);
super(mapCache, serviceManager, regionFactory, metadata, properties, defaultKey);
this.settings = settings;
this.cacheKeysFactory = cacheKeysFactory;
}

@ -15,8 +15,6 @@
*/
package org.redisson.hibernate.region;
import java.util.Properties;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.CacheKeysFactory;
@ -26,12 +24,14 @@ import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy;
import org.hibernate.cfg.Settings;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import org.redisson.hibernate.strategy.NonStrictReadWriteNaturalIdRegionAccessStrategy;
import org.redisson.hibernate.strategy.ReadOnlyNaturalIdRegionAccessStrategy;
import org.redisson.hibernate.strategy.ReadWriteNaturalIdRegionAccessStrategy;
import org.redisson.hibernate.strategy.TransactionalNaturalIdRegionAccessStrategy;
import java.util.Properties;
/**
*
* @author Nikita Koksharov
@ -42,9 +42,9 @@ public class RedissonNaturalIdRegion extends BaseRegion implements NaturalIdRegi
private final Settings settings;
private final CacheKeysFactory cacheKeysFactory;
public RedissonNaturalIdRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager, RegionFactory regionFactory,
public RedissonNaturalIdRegion(RMapCache<Object, Object> mapCache, ServiceManager serviceManager, RegionFactory regionFactory,
CacheDataDescription metadata, Settings settings, Properties properties, String defaultKey, CacheKeysFactory cacheKeysFactory) {
super(mapCache, connectionManager, regionFactory, metadata, properties, defaultKey);
super(mapCache, serviceManager, regionFactory, metadata, properties, defaultKey);
this.settings = settings;
this.cacheKeysFactory = cacheKeysFactory;
}

@ -15,12 +15,12 @@
*/
package org.redisson.hibernate.region;
import java.util.Properties;
import org.hibernate.cache.spi.QueryResultsRegion;
import org.hibernate.cache.spi.RegionFactory;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import java.util.Properties;
/**
*
@ -29,9 +29,9 @@ import org.redisson.connection.ConnectionManager;
*/
public class RedissonQueryRegion extends BaseRegion implements QueryResultsRegion {
public RedissonQueryRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager,
public RedissonQueryRegion(RMapCache<Object, Object> mapCache, ServiceManager serviceManager,
RegionFactory regionFactory, Properties properties, String defaultKey) {
super(mapCache, connectionManager, regionFactory, null, properties, defaultKey);
super(mapCache, serviceManager, regionFactory, null, properties, defaultKey);
}
}

@ -15,12 +15,12 @@
*/
package org.redisson.hibernate.region;
import java.util.Properties;
import org.hibernate.cache.spi.RegionFactory;
import org.hibernate.cache.spi.TimestampsRegion;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import java.util.Properties;
/**
*
@ -29,9 +29,9 @@ import org.redisson.connection.ConnectionManager;
*/
public class RedissonTimestampsRegion extends BaseRegion implements TimestampsRegion {
public RedissonTimestampsRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager,
public RedissonTimestampsRegion(RMapCache<Object, Object> mapCache, ServiceManager serviceManager,
RegionFactory regionFactory, Properties properties, String defaultKey) {
super(mapCache, connectionManager, regionFactory, null, properties, defaultKey);
super(mapCache, serviceManager, regionFactory, null, properties, defaultKey);
}
}

@ -201,7 +201,7 @@ public class RedissonRegionFactory implements RegionFactory {
log.debug("Building entity cache region: " + regionName);
RMapCache<Object, Object> mapCache = getCache(regionName, properties, ENTITY_DEF);
return new RedissonEntityRegion(mapCache, ((Redisson)redisson).getConnectionManager(),this, metadata, settings, properties, ENTITY_DEF, cacheKeysFactory);
return new RedissonEntityRegion(mapCache, ((Redisson)redisson).getServiceManager(),this, metadata, settings, properties, ENTITY_DEF, cacheKeysFactory);
}
@Override
@ -210,7 +210,7 @@ public class RedissonRegionFactory implements RegionFactory {
log.debug("Building naturalId cache region: " + regionName);
RMapCache<Object, Object> mapCache = getCache(regionName, properties, NATURAL_ID_DEF);
return new RedissonNaturalIdRegion(mapCache, ((Redisson)redisson).getConnectionManager(),this, metadata, settings, properties, NATURAL_ID_DEF, cacheKeysFactory);
return new RedissonNaturalIdRegion(mapCache, ((Redisson)redisson).getServiceManager(),this, metadata, settings, properties, NATURAL_ID_DEF, cacheKeysFactory);
}
@Override
@ -219,7 +219,7 @@ public class RedissonRegionFactory implements RegionFactory {
log.debug("Building collection cache region: " + regionName);
RMapCache<Object, Object> mapCache = getCache(regionName, properties, COLLECTION_DEF);
return new RedissonCollectionRegion(mapCache, ((Redisson)redisson).getConnectionManager(),this, metadata, settings, properties, COLLECTION_DEF, cacheKeysFactory);
return new RedissonCollectionRegion(mapCache, ((Redisson)redisson).getServiceManager(),this, metadata, settings, properties, COLLECTION_DEF, cacheKeysFactory);
}
@Override
@ -227,7 +227,7 @@ public class RedissonRegionFactory implements RegionFactory {
log.debug("Building query cache region: " + regionName);
RMapCache<Object, Object> mapCache = getCache(regionName, properties, QUERY_DEF);
return new RedissonQueryRegion(mapCache, ((Redisson)redisson).getConnectionManager(),this, properties, QUERY_DEF);
return new RedissonQueryRegion(mapCache, ((Redisson)redisson).getServiceManager(),this, properties, QUERY_DEF);
}
@Override
@ -235,7 +235,7 @@ public class RedissonRegionFactory implements RegionFactory {
log.debug("Building timestamps cache region: " + regionName);
RMapCache<Object, Object> mapCache = getCache(regionName, properties, TIMESTAMPS_DEF);
return new RedissonTimestampsRegion(mapCache, ((Redisson)redisson).getConnectionManager(),this, properties, TIMESTAMPS_DEF);
return new RedissonTimestampsRegion(mapCache, ((Redisson)redisson).getServiceManager(),this, properties, TIMESTAMPS_DEF);
}
protected RMapCache<Object, Object> getCache(String regionName, Properties properties, String defaultKey) {

@ -15,11 +15,6 @@
*/
package org.redisson.hibernate.region;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.GeneralDataRegion;
@ -28,11 +23,16 @@ import org.hibernate.cache.spi.TransactionalDataRegion;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.redisson.api.RFuture;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import org.redisson.hibernate.RedissonRegionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
/**
*
* @author Nikita Koksharov
@ -45,7 +45,7 @@ public class BaseRegion implements TransactionalDataRegion, GeneralDataRegion {
final RMapCache<Object, Object> mapCache;
final RegionFactory regionFactory;
final CacheDataDescription metadata;
final ConnectionManager connectionManager;
final ServiceManager serviceManager;
int ttl;
int maxIdle;
@ -53,12 +53,12 @@ public class BaseRegion implements TransactionalDataRegion, GeneralDataRegion {
boolean fallback;
volatile boolean fallbackMode;
public BaseRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager, RegionFactory regionFactory, CacheDataDescription metadata, Properties properties, String defaultKey) {
public BaseRegion(RMapCache<Object, Object> mapCache, ServiceManager serviceManager, RegionFactory regionFactory, CacheDataDescription metadata, Properties properties, String defaultKey) {
super();
this.mapCache = mapCache;
this.regionFactory = regionFactory;
this.metadata = metadata;
this.connectionManager = connectionManager;
this.serviceManager = serviceManager;
String maxEntries = getProperty(properties, mapCache.getName(), defaultKey, RedissonRegionFactory.MAX_ENTRIES_SUFFIX);
if (maxEntries != null) {
@ -92,7 +92,7 @@ public class BaseRegion implements TransactionalDataRegion, GeneralDataRegion {
private void ping() {
fallbackMode = true;
connectionManager.newTimeout(t -> {
serviceManager.newTimeout(t -> {
RFuture<Boolean> future = mapCache.isExistsAsync();
future.whenComplete((r, ex) -> {
if (ex == null) {

@ -15,8 +15,6 @@
*/
package org.redisson.hibernate.region;
import java.util.Properties;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.CacheKeysFactory;
@ -26,12 +24,14 @@ import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
import org.hibernate.cfg.Settings;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import org.redisson.hibernate.strategy.NonStrictReadWriteCollectionRegionAccessStrategy;
import org.redisson.hibernate.strategy.ReadOnlyCollectionRegionAccessStrategy;
import org.redisson.hibernate.strategy.ReadWriteCollectionRegionAccessStrategy;
import org.redisson.hibernate.strategy.TransactionalCollectionRegionAccessStrategy;
import java.util.Properties;
/**
*
* @author Nikita Koksharov
@ -42,9 +42,9 @@ public class RedissonCollectionRegion extends BaseRegion implements CollectionRe
private final Settings settings;
private final CacheKeysFactory cacheKeysFactory;
public RedissonCollectionRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager, RegionFactory regionFactory,
public RedissonCollectionRegion(RMapCache<Object, Object> mapCache, ServiceManager serviceManager, RegionFactory regionFactory,
CacheDataDescription metadata, Settings settings, Properties properties, String defaultKey, CacheKeysFactory cacheKeysFactory) {
super(mapCache, connectionManager, regionFactory, metadata, properties, defaultKey);
super(mapCache, serviceManager, regionFactory, metadata, properties, defaultKey);
this.settings = settings;
this.cacheKeysFactory = cacheKeysFactory;
}

@ -15,8 +15,6 @@
*/
package org.redisson.hibernate.region;
import java.util.Properties;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.CacheKeysFactory;
@ -26,12 +24,14 @@ import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
import org.hibernate.cfg.Settings;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import org.redisson.hibernate.strategy.NonStrictReadWriteEntityRegionAccessStrategy;
import org.redisson.hibernate.strategy.ReadOnlyEntityRegionAccessStrategy;
import org.redisson.hibernate.strategy.ReadWriteEntityRegionAccessStrategy;
import org.redisson.hibernate.strategy.TransactionalEntityRegionAccessStrategy;
import java.util.Properties;
/**
*
* @author Nikita Koksharov
@ -42,9 +42,9 @@ public class RedissonEntityRegion extends BaseRegion implements EntityRegion {
private final Settings settings;
private final CacheKeysFactory cacheKeysFactory;
public RedissonEntityRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager, RegionFactory regionFactory,
public RedissonEntityRegion(RMapCache<Object, Object> mapCache, ServiceManager serviceManager, RegionFactory regionFactory,
CacheDataDescription metadata, Settings settings, Properties properties, String defaultKey, CacheKeysFactory cacheKeysFactory) {
super(mapCache, connectionManager, regionFactory, metadata, properties, defaultKey);
super(mapCache, serviceManager, regionFactory, metadata, properties, defaultKey);
this.settings = settings;
this.cacheKeysFactory = cacheKeysFactory;
}

@ -15,8 +15,6 @@
*/
package org.redisson.hibernate.region;
import java.util.Properties;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.CacheDataDescription;
import org.hibernate.cache.spi.CacheKeysFactory;
@ -26,12 +24,14 @@ import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy;
import org.hibernate.cfg.Settings;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import org.redisson.hibernate.strategy.NonStrictReadWriteNaturalIdRegionAccessStrategy;
import org.redisson.hibernate.strategy.ReadOnlyNaturalIdRegionAccessStrategy;
import org.redisson.hibernate.strategy.ReadWriteNaturalIdRegionAccessStrategy;
import org.redisson.hibernate.strategy.TransactionalNaturalIdRegionAccessStrategy;
import java.util.Properties;
/**
*
* @author Nikita Koksharov
@ -42,9 +42,9 @@ public class RedissonNaturalIdRegion extends BaseRegion implements NaturalIdRegi
private final Settings settings;
private final CacheKeysFactory cacheKeysFactory;
public RedissonNaturalIdRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager, RegionFactory regionFactory,
public RedissonNaturalIdRegion(RMapCache<Object, Object> mapCache, ServiceManager serviceManager, RegionFactory regionFactory,
CacheDataDescription metadata, Settings settings, Properties properties, String defaultKey, CacheKeysFactory cacheKeysFactory) {
super(mapCache, connectionManager, regionFactory, metadata, properties, defaultKey);
super(mapCache, serviceManager, regionFactory, metadata, properties, defaultKey);
this.settings = settings;
this.cacheKeysFactory = cacheKeysFactory;
}

@ -15,12 +15,12 @@
*/
package org.redisson.hibernate.region;
import java.util.Properties;
import org.hibernate.cache.spi.QueryResultsRegion;
import org.hibernate.cache.spi.RegionFactory;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import java.util.Properties;
/**
*
@ -29,9 +29,9 @@ import org.redisson.connection.ConnectionManager;
*/
public class RedissonQueryRegion extends BaseRegion implements QueryResultsRegion {
public RedissonQueryRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager,
public RedissonQueryRegion(RMapCache<Object, Object> mapCache, ServiceManager serviceManager,
RegionFactory regionFactory, Properties properties, String defaultKey) {
super(mapCache, connectionManager, regionFactory, null, properties, defaultKey);
super(mapCache, serviceManager, regionFactory, null, properties, defaultKey);
}
}

@ -15,12 +15,12 @@
*/
package org.redisson.hibernate.region;
import java.util.Properties;
import org.hibernate.cache.spi.RegionFactory;
import org.hibernate.cache.spi.TimestampsRegion;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import java.util.Properties;
/**
*
@ -29,9 +29,9 @@ import org.redisson.connection.ConnectionManager;
*/
public class RedissonTimestampsRegion extends BaseRegion implements TimestampsRegion {
public RedissonTimestampsRegion(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager,
public RedissonTimestampsRegion(RMapCache<Object, Object> mapCache, ServiceManager serviceManager,
RegionFactory regionFactory, Properties properties, String defaultKey) {
super(mapCache, connectionManager, regionFactory, null, properties, defaultKey);
super(mapCache, serviceManager, regionFactory, null, properties, defaultKey);
}
}

@ -212,7 +212,7 @@ public class RedissonRegionFactory extends RegionFactoryTemplate {
}
RMapCache<Object, Object> mapCache = getCache(qualifyName(regionConfig.getRegionName()), buildingContext.getSessionFactory().getProperties(), defaultKey);
return new RedissonStorage(mapCache, ((Redisson)redisson).getConnectionManager(), buildingContext.getSessionFactory().getProperties(), defaultKey);
return new RedissonStorage(mapCache, ((Redisson)redisson).getServiceManager(), buildingContext.getSessionFactory().getProperties(), defaultKey);
}
private String qualifyName(String name) {
@ -223,14 +223,14 @@ public class RedissonRegionFactory extends RegionFactoryTemplate {
protected StorageAccess createQueryResultsRegionStorageAccess(String regionName,
SessionFactoryImplementor sessionFactory) {
RMapCache<Object, Object> mapCache = getCache(qualifyName(regionName), sessionFactory.getProperties(), QUERY_DEF);
return new RedissonStorage(mapCache, ((Redisson)redisson).getConnectionManager(), sessionFactory.getProperties(), QUERY_DEF);
return new RedissonStorage(mapCache, ((Redisson)redisson).getServiceManager(), sessionFactory.getProperties(), QUERY_DEF);
}
@Override
protected StorageAccess createTimestampsRegionStorageAccess(String regionName,
SessionFactoryImplementor sessionFactory) {
RMapCache<Object, Object> mapCache = getCache(qualifyName(regionName), sessionFactory.getProperties(), TIMESTAMPS_DEF);
return new RedissonStorage(mapCache, ((Redisson)redisson).getConnectionManager(), sessionFactory.getProperties(), TIMESTAMPS_DEF);
return new RedissonStorage(mapCache, ((Redisson)redisson).getServiceManager(), sessionFactory.getProperties(), TIMESTAMPS_DEF);
}
protected RMapCache<Object, Object> getCache(String regionName, Map properties, String defaultKey) {

@ -21,6 +21,7 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.redisson.api.RFuture;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -38,7 +39,7 @@ public class RedissonStorage implements DomainDataStorageAccess {
private final RMapCache<Object, Object> mapCache;
private final ConnectionManager connectionManager;
private final ServiceManager serviceManager;
int ttl;
int maxIdle;
@ -46,10 +47,10 @@ public class RedissonStorage implements DomainDataStorageAccess {
boolean fallback;
volatile boolean fallbackMode;
public RedissonStorage(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager, Map<String, Object> properties, String defaultKey) {
public RedissonStorage(RMapCache<Object, Object> mapCache, ServiceManager serviceManager, Map<String, Object> properties, String defaultKey) {
super();
this.mapCache = mapCache;
this.connectionManager = connectionManager;
this.serviceManager = serviceManager;
String maxEntries = getProperty(properties, mapCache.getName(), defaultKey, RedissonRegionFactory.MAX_ENTRIES_SUFFIX);
if (maxEntries != null) {
@ -83,7 +84,7 @@ public class RedissonStorage implements DomainDataStorageAccess {
private void ping() {
fallbackMode = true;
connectionManager.newTimeout(t -> {
serviceManager.newTimeout(t -> {
RFuture<Boolean> future = mapCache.isExistsAsync();
future.whenComplete((r, ex) -> {
if (ex == null) {

@ -213,7 +213,7 @@ public class RedissonRegionFactory extends RegionFactoryTemplate {
}
RMapCache<Object, Object> mapCache = getCache(qualifyName(regionConfig.getRegionName()), buildingContext.getSessionFactory().getProperties(), defaultKey);
return new RedissonStorage(mapCache, ((Redisson)redisson).getConnectionManager(), buildingContext.getSessionFactory().getProperties(), defaultKey);
return new RedissonStorage(mapCache, ((Redisson)redisson).getServiceManager(), buildingContext.getSessionFactory().getProperties(), defaultKey);
}
private String qualifyName(String name) {
@ -224,14 +224,14 @@ public class RedissonRegionFactory extends RegionFactoryTemplate {
protected StorageAccess createQueryResultsRegionStorageAccess(String regionName,
SessionFactoryImplementor sessionFactory) {
RMapCache<Object, Object> mapCache = getCache(qualifyName(regionName), sessionFactory.getProperties(), QUERY_DEF);
return new RedissonStorage(mapCache, ((Redisson)redisson).getConnectionManager(), sessionFactory.getProperties(), QUERY_DEF);
return new RedissonStorage(mapCache, ((Redisson)redisson).getServiceManager(), sessionFactory.getProperties(), QUERY_DEF);
}
@Override
protected StorageAccess createTimestampsRegionStorageAccess(String regionName,
SessionFactoryImplementor sessionFactory) {
RMapCache<Object, Object> mapCache = getCache(qualifyName(regionName), sessionFactory.getProperties(), TIMESTAMPS_DEF);
return new RedissonStorage(mapCache, ((Redisson)redisson).getConnectionManager(), sessionFactory.getProperties(), TIMESTAMPS_DEF);
return new RedissonStorage(mapCache, ((Redisson)redisson).getServiceManager(), sessionFactory.getProperties(), TIMESTAMPS_DEF);
}
protected RMapCache<Object, Object> getCache(String regionName, Map properties, String defaultKey) {

@ -20,7 +20,7 @@ import org.hibernate.cache.spi.support.DomainDataStorageAccess;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.redisson.api.RFuture;
import org.redisson.api.RMapCache;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -38,7 +38,7 @@ public class RedissonStorage implements DomainDataStorageAccess {
private final RMapCache<Object, Object> mapCache;
private final ConnectionManager connectionManager;
private final ServiceManager serviceManager;
int ttl;
int maxIdle;
@ -46,10 +46,10 @@ public class RedissonStorage implements DomainDataStorageAccess {
boolean fallback;
volatile boolean fallbackMode;
public RedissonStorage(RMapCache<Object, Object> mapCache, ConnectionManager connectionManager, Map<String, Object> properties, String defaultKey) {
public RedissonStorage(RMapCache<Object, Object> mapCache, ServiceManager serviceManager, Map<String, Object> properties, String defaultKey) {
super();
this.mapCache = mapCache;
this.connectionManager = connectionManager;
this.serviceManager = serviceManager;
String maxEntries = getProperty(properties, mapCache.getName(), defaultKey, RedissonRegionFactory.MAX_ENTRIES_SUFFIX);
if (maxEntries != null) {
@ -83,7 +83,7 @@ public class RedissonStorage implements DomainDataStorageAccess {
private void ping() {
fallbackMode = true;
connectionManager.newTimeout(t -> {
serviceManager.newTimeout(t -> {
RFuture<Boolean> future = mapCache.isExistsAsync();
future.whenComplete((r, ex) -> {
if (ex == null) {

@ -16,7 +16,7 @@
package org.redisson;
import org.redisson.api.RFuture;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
@ -31,10 +31,10 @@ import java.util.function.Supplier;
public class ElementsSubscribeService {
private final Map<Integer, CompletableFuture<?>> subscribeListeners = new ConcurrentHashMap<>();
private final ConnectionManager connectionManager;
private final ServiceManager serviceManager;
public ElementsSubscribeService(ConnectionManager connectionManager) {
this.connectionManager = connectionManager;
public ElementsSubscribeService(ServiceManager serviceManager) {
this.serviceManager = serviceManager;
}
public <V> int subscribeOnElements(Supplier<RFuture<V>> func, Consumer<V> consumer) {
@ -65,7 +65,7 @@ public class ElementsSubscribeService {
f.whenComplete((r, e) -> {
if (e != null) {
connectionManager.newTimeout(t -> {
serviceManager.newTimeout(t -> {
resubscribe(func, consumer);
}, 1, TimeUnit.SECONDS);
return;

@ -70,7 +70,7 @@ public class MapWriteBehindTask {
return;
}
commandExecutor.getConnectionManager().getExecutor().execute(() -> {
commandExecutor.getServiceManager().getExecutor().execute(() -> {
if (task != null) {
processTask(addedMap, deletedKeys, task);
pollTask(addedMap, deletedKeys);
@ -151,7 +151,7 @@ public class MapWriteBehindTask {
return;
}
commandExecutor.getConnectionManager().newTimeout(t -> {
commandExecutor.getServiceManager().newTimeout(t -> {
if (!isStarted.get()) {
return;
}

@ -115,7 +115,7 @@ public abstract class QueueTransferTask {
long delay = startTime - System.currentTimeMillis();
if (delay > 10) {
Timeout timeout = connectionManager.newTimeout(new TimerTask() {
Timeout timeout = connectionManager.getServiceManager().newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
pushTask();

@ -18,14 +18,14 @@ package org.redisson;
import org.redisson.api.ClusterNode;
import org.redisson.api.ClusterNodesGroup;
import org.redisson.command.CommandAsyncExecutor;
import org.redisson.connection.ConnectionEventsHub;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
@Deprecated
public class RedisClusterNodes extends RedisNodes<ClusterNode> implements ClusterNodesGroup {
public RedisClusterNodes(ConnectionManager connectionManager, ConnectionEventsHub connectionEventsHub, CommandAsyncExecutor commandExecutor) {
super(connectionManager, connectionEventsHub, commandExecutor);
public RedisClusterNodes(ConnectionManager connectionManager, ServiceManager serviceManager, CommandAsyncExecutor commandExecutor) {
super(connectionManager, serviceManager, commandExecutor);
}
}

@ -45,12 +45,12 @@ public class RedisNodes<N extends Node> implements NodesGroup<N> {
final ConnectionManager connectionManager;
final CommandAsyncExecutor commandExecutor;
final ConnectionEventsHub connectionEventsHub;
final ServiceManager serviceManager;
public RedisNodes(ConnectionManager connectionManager, ConnectionEventsHub connectionEventsHub, CommandAsyncExecutor commandExecutor) {
public RedisNodes(ConnectionManager connectionManager, ServiceManager serviceManager, CommandAsyncExecutor commandExecutor) {
this.connectionManager = connectionManager;
this.commandExecutor = commandExecutor;
this.connectionEventsHub = connectionEventsHub;
this.serviceManager = serviceManager;
}
@Override
@ -139,7 +139,7 @@ public class RedisNodes<N extends Node> implements NodesGroup<N> {
Thread.currentThread().interrupt();
}
if (System.currentTimeMillis() - time >= connectionManager.getConfig().getConnectTimeout()) {
if (System.currentTimeMillis() - time >= connectionManager.getServiceManager().getConfig().getConnectTimeout()) {
for (Entry<RedisConnection, RFuture<String>> entry : result.entrySet()) {
entry.getKey().closeAsync();
}
@ -174,12 +174,12 @@ public class RedisNodes<N extends Node> implements NodesGroup<N> {
@Override
public int addConnectionListener(ConnectionListener connectionListener) {
return connectionEventsHub.addListener(connectionListener);
return serviceManager.getConnectionEventsHub().addListener(connectionListener);
}
@Override
public void removeConnectionListener(int listenerId) {
connectionEventsHub.removeListener(listenerId);
serviceManager.getConnectionEventsHub().removeListener(listenerId);
}
}

@ -23,8 +23,8 @@ import org.redisson.command.CommandAsyncExecutor;
import org.redisson.command.CommandSyncService;
import org.redisson.config.Config;
import org.redisson.config.ConfigSupport;
import org.redisson.connection.ConnectionEventsHub;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import org.redisson.eviction.EvictionScheduler;
import org.redisson.liveobject.core.RedissonObjectBuilder;
import org.redisson.redisnode.RedissonClusterNodes;
@ -51,7 +51,6 @@ public class Redisson implements RedissonClient {
RedissonReference.warmUp();
}
private final ConnectionEventsHub connectionEventsHub = new ConnectionEventsHub();
protected final QueueTransferService queueTransferService = new QueueTransferService();
protected final EvictionScheduler evictionScheduler;
protected final WriteBehindService writeBehindService;
@ -67,7 +66,7 @@ public class Redisson implements RedissonClient {
this.config = config;
Config configCopy = new Config(config);
connectionManager = ConfigSupport.createConnectionManager(configCopy, connectionEventsHub);
connectionManager = ConfigSupport.createConnectionManager(configCopy);
RedissonObjectBuilder objectBuilder = null;
if (config.isReferenceEnabled()) {
objectBuilder = new RedissonObjectBuilder(this);
@ -89,6 +88,10 @@ public class Redisson implements RedissonClient {
return connectionManager;
}
public ServiceManager getServiceManager() {
return connectionManager.getServiceManager();
}
/**
* Create sync/async Redisson instance with default config
*
@ -416,12 +419,12 @@ public class Redisson implements RedissonClient {
@Override
public RScheduledExecutorService getExecutorService(String name) {
return getExecutorService(name, connectionManager.getCodec());
return getExecutorService(name, connectionManager.getServiceManager().getCfg().getCodec());
}
@Override
public RScheduledExecutorService getExecutorService(String name, ExecutorOptions options) {
return getExecutorService(name, connectionManager.getCodec(), options);
return getExecutorService(name, connectionManager.getServiceManager().getCfg().getCodec(), options);
}
@Override
@ -436,12 +439,12 @@ public class Redisson implements RedissonClient {
@Override
public RRemoteService getRemoteService() {
return getRemoteService("redisson_rs", connectionManager.getCodec());
return getRemoteService("redisson_rs", connectionManager.getServiceManager().getCfg().getCodec());
}
@Override
public RRemoteService getRemoteService(String name) {
return getRemoteService(name, connectionManager.getCodec());
return getRemoteService(name, connectionManager.getServiceManager().getCfg().getCodec());
}
@Override
@ -451,8 +454,8 @@ public class Redisson implements RedissonClient {
@Override
public RRemoteService getRemoteService(String name, Codec codec) {
String executorId = connectionManager.getId();
if (codec != connectionManager.getCodec()) {
String executorId = connectionManager.getServiceManager().getId();
if (codec != connectionManager.getServiceManager().getCfg().getCodec()) {
executorId = executorId + ":" + name;
}
return new RedissonRemoteService(codec, name, commandExecutor, executorId, responses);
@ -734,7 +737,7 @@ public class Redisson implements RedissonClient {
@Override
public NodesGroup<Node> getNodesGroup() {
return new RedisNodes<Node>(connectionManager, connectionEventsHub, commandExecutor);
return new RedisNodes<Node>(connectionManager, connectionManager.getServiceManager(), commandExecutor);
}
@Override
@ -742,17 +745,17 @@ public class Redisson implements RedissonClient {
if (!connectionManager.isClusterMode()) {
throw new IllegalStateException("Redisson is not in cluster mode!");
}
return new RedisClusterNodes(connectionManager, connectionEventsHub, commandExecutor);
return new RedisClusterNodes(connectionManager, connectionManager.getServiceManager(), commandExecutor);
}
@Override
public boolean isShutdown() {
return connectionManager.isShutdown();
return connectionManager.getServiceManager().isShutdown();
}
@Override
public boolean isShuttingDown() {
return connectionManager.isShuttingDown();
return connectionManager.getServiceManager().isShuttingDown();
}
@Override
@ -798,7 +801,7 @@ public class Redisson implements RedissonClient {
@Override
public String getId() {
return connectionManager.getId();
return connectionManager.getServiceManager().getId();
}
}

@ -107,8 +107,8 @@ public abstract class RedissonBaseLock extends RedissonExpirable implements RLoc
public RedissonBaseLock(CommandAsyncExecutor commandExecutor, String name) {
super(commandExecutor, name);
this.commandExecutor = commandExecutor;
this.id = commandExecutor.getConnectionManager().getId();
this.internalLockLeaseTime = commandExecutor.getConnectionManager().getCfg().getLockWatchdogTimeout();
this.id = commandExecutor.getServiceManager().getId();
this.internalLockLeaseTime = commandExecutor.getServiceManager().getCfg().getLockWatchdogTimeout();
this.entryName = id + ":" + name;
}
@ -126,7 +126,7 @@ public abstract class RedissonBaseLock extends RedissonExpirable implements RLoc
return;
}
Timeout task = commandExecutor.getConnectionManager().newTimeout(new TimerTask() {
Timeout task = commandExecutor.getServiceManager().newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
ExpirationEntry ent = EXPIRATION_RENEWAL_MAP.get(getEntryName());
@ -227,7 +227,7 @@ public abstract class RedissonBaseLock extends RedissonExpirable implements RLoc
if (ex != null) {
throw new CompletionException(ex);
}
if (commandExecutor.getConnectionManager().getCfg().isCheckLockSyncedSlaves()
if (commandExecutor.getServiceManager().getCfg().isCheckLockSyncedSlaves()
&& res.getSyncedSlaves() == 0 && availableSlaves > 0) {
throw new CompletionException(
new IllegalStateException("None of slaves were synced"));

@ -268,12 +268,12 @@ public class RedissonBlockingDeque<V> extends RedissonDeque<V> implements RBlock
@Override
public int subscribeOnFirstElements(Consumer<V> consumer) {
return commandExecutor.getConnectionManager().getElementsSubscribeService().subscribeOnElements(this::takeFirstAsync, consumer);
return commandExecutor.getServiceManager().getElementsSubscribeService().subscribeOnElements(this::takeFirstAsync, consumer);
}
@Override
public int subscribeOnLastElements(Consumer<V> consumer) {
return commandExecutor.getConnectionManager().getElementsSubscribeService().subscribeOnElements(this::takeLastAsync, consumer);
return commandExecutor.getServiceManager().getElementsSubscribeService().subscribeOnElements(this::takeLastAsync, consumer);
}
@Override

@ -135,7 +135,7 @@ public class RedissonBlockingQueue<V> extends RedissonQueue<V> implements RBlock
@Override
public RFuture<Map<String, List<V>>> pollFirstFromAnyAsync(Duration duration, int count, String... queueNames) {
List<String> mappedNames = Arrays.stream(queueNames).map(m -> commandExecutor.getConnectionManager().getConfig().getNameMapper().map(m)).collect(Collectors.toList());
List<String> mappedNames = Arrays.stream(queueNames).map(m -> commandExecutor.getServiceManager().getConfig().getNameMapper().map(m)).collect(Collectors.toList());
List<Object> params = new ArrayList<>();
params.add(toSeconds(duration.getSeconds(), TimeUnit.SECONDS));
params.add(queueNames.length + 1);
@ -154,7 +154,7 @@ public class RedissonBlockingQueue<V> extends RedissonQueue<V> implements RBlock
@Override
public RFuture<Map<String, List<V>>> pollLastFromAnyAsync(Duration duration, int count, String... queueNames) {
List<String> mappedNames = Arrays.stream(queueNames).map(m -> commandExecutor.getConnectionManager().getConfig().getNameMapper().map(m)).collect(Collectors.toList());
List<String> mappedNames = Arrays.stream(queueNames).map(m -> commandExecutor.getServiceManager().getConfig().getNameMapper().map(m)).collect(Collectors.toList());
List<Object> params = new ArrayList<>();
params.add(toSeconds(duration.getSeconds(), TimeUnit.SECONDS));
params.add(queueNames.length + 1);
@ -172,7 +172,7 @@ public class RedissonBlockingQueue<V> extends RedissonQueue<V> implements RBlock
return new CompletableFutureWrapper<>((V) null);
}
String mappedName = commandExecutor.getConnectionManager().getConfig().getNameMapper().map(queueName);
String mappedName = commandExecutor.getServiceManager().getConfig().getNameMapper().map(queueName);
return commandExecutor.writeAsync(getRawName(), codec, RedisCommands.BRPOPLPUSH, getRawName(), mappedName, toSeconds(timeout, unit));
}
@ -237,12 +237,12 @@ public class RedissonBlockingQueue<V> extends RedissonQueue<V> implements RBlock
@Override
public int subscribeOnElements(Consumer<V> consumer) {
return commandExecutor.getConnectionManager().getElementsSubscribeService().subscribeOnElements(this::takeAsync, consumer);
return commandExecutor.getServiceManager().getElementsSubscribeService().subscribeOnElements(this::takeAsync, consumer);
}
@Override
public void unsubscribe(int listenerId) {
commandExecutor.getConnectionManager().getElementsSubscribeService().unsubscribe(listenerId);
commandExecutor.getServiceManager().getElementsSubscribeService().unsubscribe(listenerId);
}
}

@ -48,7 +48,7 @@ public class RedissonBoundedBlockingQueue<V> extends RedissonQueue<V> implements
protected RedissonBoundedBlockingQueue(CommandAsyncExecutor commandExecutor, String name, RedissonClient redisson) {
super(commandExecutor, name, redisson);
blockingQueue = new RedissonBlockingQueue<>(commandExecutor, name, redisson);
semaphore = new RedissonQueueSemaphore(commandExecutor, getSemaphoreName(), commandExecutor.getConnectionManager().getCodec());
semaphore = new RedissonQueueSemaphore(commandExecutor, getSemaphoreName(), commandExecutor.getServiceManager().getCfg().getCodec());
channelName = RedissonSemaphore.getChannelName(semaphore.getRawName());
}
@ -248,12 +248,12 @@ public class RedissonBoundedBlockingQueue<V> extends RedissonQueue<V> implements
@Override
public int subscribeOnElements(Consumer<V> consumer) {
return commandExecutor.getConnectionManager().getElementsSubscribeService().subscribeOnElements(this::takeAsync, consumer);
return commandExecutor.getServiceManager().getElementsSubscribeService().subscribeOnElements(this::takeAsync, consumer);
}
@Override
public void unsubscribe(int listenerId) {
commandExecutor.getConnectionManager().getElementsSubscribeService().unsubscribe(listenerId);
commandExecutor.getServiceManager().getElementsSubscribeService().unsubscribe(listenerId);
}
@Override

@ -44,7 +44,7 @@ public class RedissonBuckets implements RBuckets {
protected final CommandAsyncExecutor commandExecutor;
public RedissonBuckets(CommandAsyncExecutor commandExecutor) {
this(commandExecutor.getConnectionManager().getCodec(), commandExecutor);
this(commandExecutor.getServiceManager().getCfg().getCodec(), commandExecutor);
}
public RedissonBuckets(Codec codec, CommandAsyncExecutor commandExecutor) {
@ -77,7 +77,7 @@ public class RedissonBuckets implements RBuckets {
}
List<Object> keysList = Arrays.stream(keys)
.map(k -> commandExecutor.getConnectionManager().getConfig().getNameMapper().map(k))
.map(k -> commandExecutor.getServiceManager().getConfig().getNameMapper().map(k))
.collect(Collectors.toList());
Codec commandCodec = new CompositeCodec(StringCodec.INSTANCE, codec, codec);
@ -90,7 +90,7 @@ public class RedissonBuckets implements RBuckets {
public void onSlotResult(Map<Object, Object> result) {
for (Map.Entry<Object, Object> entry : result.entrySet()) {
if (entry.getKey() != null && entry.getValue() != null) {
String key = commandExecutor.getConnectionManager().getConfig().getNameMapper().unmap((String) entry.getKey());
String key = commandExecutor.getServiceManager().getConfig().getNameMapper().unmap((String) entry.getKey());
results.put(key, (V) entry.getValue());
}
}
@ -149,7 +149,7 @@ public class RedissonBuckets implements RBuckets {
private Map<String, ?> map(Map<String, ?> buckets) {
return buckets.entrySet().stream().collect(
Collectors.toMap(e -> commandExecutor.getConnectionManager().getConfig().getNameMapper().map(e.getKey()),
Collectors.toMap(e -> commandExecutor.getServiceManager().getConfig().getNameMapper().map(e.getKey()),
e -> e.getValue()));
}

@ -48,7 +48,7 @@ public class RedissonCountDownLatch extends RedissonObject implements RCountDown
protected RedissonCountDownLatch(CommandAsyncExecutor commandExecutor, String name) {
super(commandExecutor, name);
this.id = commandExecutor.getConnectionManager().getId();
this.id = commandExecutor.getServiceManager().getId();
this.pubSub = commandExecutor.getConnectionManager().getSubscribeService().getCountDownLatchPubSub();
}
@ -217,7 +217,7 @@ public class RedissonCountDownLatch extends RedissonObject implements RCountDown
entry.addListener(listener);
if (!executed.get()) {
Timeout timeoutFuture = commandExecutor.getConnectionManager().newTimeout(new TimerTask() {
Timeout timeoutFuture = commandExecutor.getServiceManager().newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
if (entry.removeListener(listener)) {

@ -108,15 +108,15 @@ public class RedissonExecutorService implements RScheduledExecutorService {
this.codec = codec;
this.commandExecutor = commandExecutor;
this.connectionManager = commandExecutor.getConnectionManager();
this.name = commandExecutor.getConnectionManager().getConfig().getNameMapper().map(name);
this.name = commandExecutor.getServiceManager().getConfig().getNameMapper().map(name);
this.redisson = redisson;
this.queueTransferService = queueTransferService;
this.responses = responses;
if (codec == connectionManager.getCodec()) {
this.executorId = connectionManager.getId();
if (codec == connectionManager.getServiceManager().getCfg().getCodec()) {
this.executorId = connectionManager.getServiceManager().getId();
} else {
this.executorId = connectionManager.getId() + ":" + RemoteExecutorServiceAsync.class.getName() + ":" + name;
this.executorId = connectionManager.getServiceManager().getId() + ":" + RemoteExecutorServiceAsync.class.getName() + ":" + name;
}
remoteService = new RedissonExecutorRemoteService(codec, name, commandExecutor, executorId, responses);
@ -311,7 +311,7 @@ public class RedissonExecutorService implements RScheduledExecutorService {
service.setTasksInjector(options.getTasksInjector());
}
ExecutorService es = commandExecutor.getConnectionManager().getExecutor();
ExecutorService es = commandExecutor.getServiceManager().getExecutor();
if (options.getExecutorService() != null) {
es = options.getExecutorService();
}
@ -493,7 +493,7 @@ public class RedissonExecutorService implements RScheduledExecutorService {
@Override
public String getName() {
return commandExecutor.getConnectionManager().getConfig().getNameMapper().unmap(name);
return commandExecutor.getServiceManager().getConfig().getNameMapper().unmap(name);
}
@Override

@ -199,7 +199,7 @@ public class RedissonFencedLock extends RedissonLock implements RFencedLock {
tryLockAsync(time, waitTime, leaseTime, unit, r, result, currentThreadId);
});
if (!subscribeFuture.isDone()) {
Timeout scheduledFuture = commandExecutor.getConnectionManager().newTimeout(new TimerTask() {
Timeout scheduledFuture = commandExecutor.getServiceManager().newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
if (!subscribeFuture.isDone()) {
@ -282,7 +282,7 @@ public class RedissonFencedLock extends RedissonLock implements RFencedLock {
t = ttl;
}
if (!executed.get()) {
Timeout scheduledFuture = commandExecutor.getConnectionManager().newTimeout(timeout -> {
Timeout scheduledFuture = commandExecutor.getServiceManager().newTimeout(timeout -> {
if (entry.removeListener(listener)) {
long elapsed = System.currentTimeMillis() - current;
time.addAndGet(-elapsed);

@ -39,7 +39,7 @@ public class RedissonFuction implements RFunction {
public RedissonFuction(CommandAsyncExecutor commandExecutor) {
this.commandExecutor = commandExecutor;
this.codec = commandExecutor.getConnectionManager().getCodec();
this.codec = commandExecutor.getServiceManager().getCfg().getCodec();
}
public RedissonFuction(CommandAsyncExecutor commandExecutor, Codec codec) {
@ -200,7 +200,7 @@ public class RedissonFuction implements RFunction {
args.add(name);
args.add(keys.size());
if (keys.size() > 0) {
args.addAll(keys.stream().map(k -> commandExecutor.getConnectionManager().getConfig().getNameMapper().map((String) k))
args.addAll(keys.stream().map(k -> commandExecutor.getServiceManager().getConfig().getNameMapper().map((String) k))
.collect(Collectors.toList()));
}
args.addAll(encode(Arrays.asList(values), codec));
@ -214,7 +214,7 @@ public class RedissonFuction implements RFunction {
public <R> RFuture<R> callAsync(FunctionMode mode, String name, FunctionResult returnType, List<Object> keys, Object... values) {
String key = null;
if (keys.size() > 0) {
key = commandExecutor.getConnectionManager().getConfig().getNameMapper().map((String) keys.get(0));
key = commandExecutor.getServiceManager().getConfig().getNameMapper().map((String) keys.get(0));
}
return callAsync(key, mode, name, returnType, keys, values);
}

@ -76,7 +76,7 @@ public class RedissonIdGenerator extends RedissonExpirable implements RIdGenerat
private void startIdRequestsHandle() {
if (!isWorkerActive.compareAndSet(false, true)
|| commandExecutor.getConnectionManager().getExecutor().isShutdown()) {
|| commandExecutor.getServiceManager().getExecutor().isShutdown()) {
return;
}
@ -128,7 +128,7 @@ public class RedissonIdGenerator extends RedissonExpirable implements RIdGenerat
log.error(ex.getMessage(), ex);
commandExecutor.getConnectionManager().newTimeout(task -> {
commandExecutor.getServiceManager().newTimeout(task -> {
handleIdRequests();
}, 1, TimeUnit.SECONDS);
return;

@ -253,7 +253,7 @@ public class RedissonKeys implements RKeys {
for (MasterSlaveEntry entry : commandExecutor.getConnectionManager().getEntrySet()) {
CompletableFuture<Long> future = new CompletableFuture<>();
futures.add(future);
commandExecutor.getConnectionManager().getExecutor().execute(() -> {
commandExecutor.getServiceManager().getExecutor().execute(() -> {
long count = 0;
try {
Iterator<String> keysIterator = createKeysIterator(entry, scan, pattern, batchSize);
@ -345,22 +345,22 @@ public class RedissonKeys implements RKeys {
}
private String map(String key) {
return commandExecutor.getConnectionManager().getConfig().getNameMapper().map(key);
return commandExecutor.getServiceManager().getConfig().getNameMapper().map(key);
}
private String unmap(String key) {
return commandExecutor.getConnectionManager().getConfig().getNameMapper().unmap(key);
return commandExecutor.getServiceManager().getConfig().getNameMapper().unmap(key);
}
private List<String> unmap(List<String> keys) {
return keys.stream()
.map(k -> commandExecutor.getConnectionManager().getConfig().getNameMapper().unmap(k))
.map(k -> commandExecutor.getServiceManager().getConfig().getNameMapper().unmap(k))
.collect(Collectors.toList());
}
private String[] map(String[] keys) {
return Arrays.stream(keys)
.map(k -> commandExecutor.getConnectionManager().getConfig().getNameMapper().map(k))
.map(k -> commandExecutor.getServiceManager().getConfig().getNameMapper().map(k))
.toArray(String[]::new);
}

@ -54,7 +54,7 @@ public class RedissonLock extends RedissonBaseLock {
public RedissonLock(CommandAsyncExecutor commandExecutor, String name) {
super(commandExecutor, name);
this.commandExecutor = commandExecutor;
this.internalLockLeaseTime = commandExecutor.getConnectionManager().getCfg().getLockWatchdogTimeout();
this.internalLockLeaseTime = commandExecutor.getServiceManager().getCfg().getLockWatchdogTimeout();
this.pubSub = commandExecutor.getConnectionManager().getSubscribeService().getLockPubSub();
}
@ -307,7 +307,7 @@ public class RedissonLock extends RedissonBaseLock {
@Override
protected void cancelExpirationRenewal(Long threadId) {
super.cancelExpirationRenewal(threadId);
this.internalLockLeaseTime = commandExecutor.getConnectionManager().getCfg().getLockWatchdogTimeout();
this.internalLockLeaseTime = commandExecutor.getServiceManager().getCfg().getLockWatchdogTimeout();
}
@Override
@ -410,7 +410,7 @@ public class RedissonLock extends RedissonBaseLock {
entry.addListener(listener);
if (ttl >= 0) {
Timeout scheduledFuture = commandExecutor.getConnectionManager().newTimeout(timeout -> {
Timeout scheduledFuture = commandExecutor.getServiceManager().newTimeout(timeout -> {
if (entry.removeListener(listener)) {
lockAsync(leaseTime, unit, entry, result, currentThreadId);
}
@ -476,7 +476,7 @@ public class RedissonLock extends RedissonBaseLock {
tryLockAsync(time, waitTime, leaseTime, unit, r, result, currentThreadId);
});
if (!subscribeFuture.isDone()) {
Timeout scheduledFuture = commandExecutor.getConnectionManager().newTimeout(new TimerTask() {
Timeout scheduledFuture = commandExecutor.getServiceManager().newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
if (!subscribeFuture.isDone()) {
@ -558,7 +558,7 @@ public class RedissonLock extends RedissonBaseLock {
t = ttl;
}
if (!executed.get()) {
Timeout scheduledFuture = commandExecutor.getConnectionManager().newTimeout(timeout -> {
Timeout scheduledFuture = commandExecutor.getServiceManager().newTimeout(timeout -> {
if (entry.removeListener(listener)) {
long elapsed = System.currentTimeMillis() - current;
time.addAndGet(-elapsed);

@ -204,7 +204,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
return oldValueFuture.thenCompose(oldValue -> {
CompletableFuture<V> newValuePromise = new CompletableFuture<>();
if (oldValue != null) {
commandExecutor.getConnectionManager().getExecutor().execute(() -> {
commandExecutor.getServiceManager().getExecutor().execute(() -> {
V newValue;
try {
newValue = remappingFunction.apply(oldValue, value);
@ -252,7 +252,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
RFuture<V> oldValueFuture = getAsync(key, threadId);
return oldValueFuture.thenCompose(oldValue -> {
CompletableFuture<V> result = new CompletableFuture<>();
commandExecutor.getConnectionManager().getExecutor().execute(() -> {
commandExecutor.getServiceManager().getExecutor().execute(() -> {
V newValue;
try {
newValue = remappingFunction.apply(key, oldValue);
@ -348,7 +348,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
}
CompletableFuture<V> result = new CompletableFuture<>();
commandExecutor.getConnectionManager().getExecutor().execute(() -> {
commandExecutor.getServiceManager().getExecutor().execute(() -> {
V newValue;
try {
newValue = mappingFunction.apply(key);
@ -425,7 +425,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
}
CompletableFuture<V> result = new CompletableFuture<>();
commandExecutor.getConnectionManager().getExecutor().execute(() -> {
commandExecutor.getServiceManager().getExecutor().execute(() -> {
V newValue;
try {
newValue = remappingFunction.apply(key, oldValue);
@ -736,7 +736,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
if (condition.apply(res)) {
if (options.getWriter() != null) {
CompletableFuture<M> promise = new CompletableFuture<>();
commandExecutor.getConnectionManager().getExecutor().execute(() -> {
commandExecutor.getServiceManager().getExecutor().execute(() -> {
try {
if (task instanceof MapWriterTask.Add) {
options.getWriter().write(task.getMap());
@ -1425,7 +1425,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
} else {
if (options.getWriter() != null) {
CompletableFuture<Long> future = new CompletableFuture<>();
commandExecutor.getConnectionManager().getExecutor().execute(() -> {
commandExecutor.getServiceManager().getExecutor().execute(() -> {
try {
options.getWriter().delete(deletedKeys);
} catch (Exception ex) {
@ -1708,7 +1708,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
private CompletableFuture<V> loadValue(K key, RLock lock, long threadId) {
if (options.getLoader() != null) {
CompletableFuture<V> result = new CompletableFuture<>();
commandExecutor.getConnectionManager().getExecutor().execute(new Runnable() {
commandExecutor.getServiceManager().getExecutor().execute(new Runnable() {
@Override
public void run() {
V value;

@ -170,7 +170,7 @@ public final class RedissonNode {
CompletionStage<RedisConnection> readFuture = entry.connectionReadOp(null);
RedisConnection readConnection = null;
try {
readConnection = readFuture.toCompletableFuture().get(connectionManager.getConfig().getConnectTimeout(), TimeUnit.MILLISECONDS);
readConnection = readFuture.toCompletableFuture().get(connectionManager.getServiceManager().getConfig().getConnectTimeout(), TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Exception e) {
@ -186,7 +186,7 @@ public final class RedissonNode {
CompletionStage<RedisConnection> writeFuture = entry.connectionWriteOp(null);
RedisConnection writeConnection = null;
try {
writeConnection = writeFuture.toCompletableFuture().get(connectionManager.getConfig().getConnectTimeout(), TimeUnit.MILLISECONDS);
writeConnection = writeFuture.toCompletableFuture().get(connectionManager.getServiceManager().getConfig().getConnectTimeout(), TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Exception e) {

@ -57,7 +57,7 @@ public abstract class RedissonObject implements RObject {
}
public RedissonObject(CommandAsyncExecutor commandExecutor, String name) {
this(commandExecutor.getConnectionManager().getCodec(), commandExecutor, name);
this(commandExecutor.getServiceManager().getCfg().getCodec(), commandExecutor, name);
}
public static String prefixName(String prefix, String name) {
@ -93,7 +93,7 @@ public abstract class RedissonObject implements RObject {
@Override
public String getName() {
return commandExecutor.getConnectionManager().getConfig().getNameMapper().unmap(name);
return commandExecutor.getServiceManager().getConfig().getNameMapper().unmap(name);
}
public final String getRawName() {
@ -105,7 +105,7 @@ public abstract class RedissonObject implements RObject {
}
protected final void setName(String name) {
this.name = commandExecutor.getConnectionManager().getConfig().getNameMapper().map(name);
this.name = commandExecutor.getServiceManager().getConfig().getNameMapper().map(name);
}
@Override

@ -51,7 +51,7 @@ public class RedissonPatternTopic implements RPatternTopic {
private final Codec codec;
protected RedissonPatternTopic(CommandAsyncExecutor commandExecutor, String name) {
this(commandExecutor.getConnectionManager().getCodec(), commandExecutor, name);
this(commandExecutor.getServiceManager().getCfg().getCodec(), commandExecutor, name);
}
protected RedissonPatternTopic(Codec codec, CommandAsyncExecutor commandExecutor, String name) {
@ -100,7 +100,7 @@ public class RedissonPatternTopic implements RPatternTopic {
}
protected void acquire(AsyncSemaphore semaphore) {
MasterSlaveServersConfig config = commandExecutor.getConnectionManager().getConfig();
MasterSlaveServersConfig config = commandExecutor.getServiceManager().getConfig();
int timeout = config.getTimeout() + config.getRetryInterval() * config.getRetryAttempts();
if (!semaphore.tryAcquire(timeout)) {
throw new RedisTimeoutException("Remove listeners operation timeout: (" + timeout + "ms) for " + name + " topic");

@ -192,7 +192,7 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen
Timeout scheduledFuture;
if (nearestTimeout != null) {
scheduledFuture = commandExecutor.getConnectionManager().newTimeout(new TimerTask() {
scheduledFuture = commandExecutor.getServiceManager().newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
if (waitTimeoutFutureRef.get() != null && !waitTimeoutFutureRef.get().cancel()) {
@ -227,7 +227,7 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen
entry.addListener(listener);
long t = time.get();
Timeout waitTimeoutFuture = commandExecutor.getConnectionManager().newTimeout(new TimerTask() {
Timeout waitTimeoutFuture = commandExecutor.getServiceManager().newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
if (scheduledFuture != null && !scheduledFuture.cancel()) {
@ -275,7 +275,7 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen
CompletableFuture<String> res = new CompletableFuture<>();
Timeout scheduledFuture;
if (nearestTimeout != null) {
scheduledFuture = commandExecutor.getConnectionManager().newTimeout(timeout -> {
scheduledFuture = commandExecutor.getServiceManager().newTimeout(timeout -> {
CompletableFuture<String> r = acquireAsync(permits, entry, ttl, timeUnit);
commandExecutor.transfer(r, res);
}, nearestTimeout, TimeUnit.MILLISECONDS);
@ -509,7 +509,7 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen
});
if (!subscribeFuture.isDone()) {
Timeout scheduledFuture = commandExecutor.getConnectionManager().newTimeout(new TimerTask() {
Timeout scheduledFuture = commandExecutor.getServiceManager().newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
if (!subscribeFuture.isDone()) {

@ -126,12 +126,12 @@ public class RedissonPriorityBlockingDeque<V> extends RedissonPriorityDeque<V> i
@Override
public int subscribeOnElements(Consumer<V> consumer) {
return commandExecutor.getConnectionManager().getElementsSubscribeService().subscribeOnElements(this::takeAsync, consumer);
return commandExecutor.getServiceManager().getElementsSubscribeService().subscribeOnElements(this::takeAsync, consumer);
}
@Override
public void unsubscribe(int listenerId) {
commandExecutor.getConnectionManager().getElementsSubscribeService().unsubscribe(listenerId);
commandExecutor.getServiceManager().getElementsSubscribeService().unsubscribe(listenerId);
}
public RFuture<V> takeLastAndOfferFirstToAsync(String queueName) {
@ -257,12 +257,12 @@ public class RedissonPriorityBlockingDeque<V> extends RedissonPriorityDeque<V> i
@Override
public int subscribeOnFirstElements(Consumer<V> consumer) {
return commandExecutor.getConnectionManager().getElementsSubscribeService().subscribeOnElements(this::takeFirstAsync, consumer);
return commandExecutor.getServiceManager().getElementsSubscribeService().subscribeOnElements(this::takeFirstAsync, consumer);
}
@Override
public int subscribeOnLastElements(Consumer<V> consumer) {
return commandExecutor.getConnectionManager().getElementsSubscribeService().subscribeOnElements(this::takeLastAsync, consumer);
return commandExecutor.getServiceManager().getElementsSubscribeService().subscribeOnElements(this::takeLastAsync, consumer);
}
@Override

@ -73,7 +73,7 @@ public class RedissonPriorityBlockingQueue<V> extends RedissonPriorityQueue<V> i
protected <T> void takeAsync(CompletableFuture<V> result, long delay, long timeoutInMicro, RedisCommand<T> command, Object... params) {
long start = System.currentTimeMillis();
commandExecutor.getConnectionManager().getGroup().schedule(() -> {
commandExecutor.getServiceManager().getGroup().schedule(() -> {
RFuture<V> future = wrapLockedAsync(command, params);
future.whenComplete((res, e) -> {
if (e != null && !(e instanceof RedisConnectionException)) {
@ -169,12 +169,12 @@ public class RedissonPriorityBlockingQueue<V> extends RedissonPriorityQueue<V> i
@Override
public int subscribeOnElements(Consumer<V> consumer) {
return commandExecutor.getConnectionManager().getElementsSubscribeService().subscribeOnElements(this::takeAsync, consumer);
return commandExecutor.getServiceManager().getElementsSubscribeService().subscribeOnElements(this::takeAsync, consumer);
}
@Override
public void unsubscribe(int listenerId) {
commandExecutor.getConnectionManager().getElementsSubscribeService().unsubscribe(listenerId);
commandExecutor.getServiceManager().getElementsSubscribeService().unsubscribe(listenerId);
}
public RFuture<V> takeLastAndOfferFirstToAsync(String queueName) {

@ -48,7 +48,7 @@ public class RedissonRateLimiter extends RedissonExpirable implements RRateLimit
}
String getClientPermitsName() {
return suffixName(getPermitsName(), commandExecutor.getConnectionManager().getId());
return suffixName(getPermitsName(), commandExecutor.getServiceManager().getId());
}
String getValueName() {
@ -56,7 +56,7 @@ public class RedissonRateLimiter extends RedissonExpirable implements RRateLimit
}
String getClientValueName() {
return suffixName(getValueName(), commandExecutor.getConnectionManager().getId());
return suffixName(getValueName(), commandExecutor.getServiceManager().getId());
}
@Override
@ -135,7 +135,7 @@ public class RedissonRateLimiter extends RedissonExpirable implements RRateLimit
if (timeoutInMillis == -1) {
CompletableFuture<Boolean> f = new CompletableFuture<>();
commandExecutor.getConnectionManager().getGroup().schedule(() -> {
commandExecutor.getServiceManager().getGroup().schedule(() -> {
CompletableFuture<Boolean> r = tryAcquireAsync(permits, timeoutInMillis);
commandExecutor.transfer(r, f);
}, delay, TimeUnit.MILLISECONDS);
@ -150,12 +150,12 @@ public class RedissonRateLimiter extends RedissonExpirable implements RRateLimit
CompletableFuture<Boolean> f = new CompletableFuture<>();
if (remains < delay) {
commandExecutor.getConnectionManager().getGroup().schedule(() -> {
commandExecutor.getServiceManager().getGroup().schedule(() -> {
f.complete(false);
}, remains, TimeUnit.MILLISECONDS);
} else {
long start = System.currentTimeMillis();
commandExecutor.getConnectionManager().getGroup().schedule(() -> {
commandExecutor.getServiceManager().getGroup().schedule(() -> {
long elapsed = System.currentTimeMillis() - start;
if (remains <= elapsed) {
f.complete(false);

@ -20,7 +20,6 @@ import org.redisson.client.codec.Codec;
import org.redisson.codec.JsonCodec;
import org.redisson.config.Config;
import org.redisson.config.ConfigSupport;
import org.redisson.connection.ConnectionEventsHub;
import org.redisson.connection.ConnectionManager;
import org.redisson.eviction.EvictionScheduler;
import org.redisson.liveobject.core.RedissonObjectBuilder;
@ -42,8 +41,6 @@ import java.util.concurrent.ConcurrentMap;
*/
public class RedissonReactive implements RedissonReactiveClient {
private final ConnectionEventsHub connectionEventsHub = new ConnectionEventsHub();
protected final WriteBehindService writeBehindService;
protected final EvictionScheduler evictionScheduler;
protected final CommandReactiveExecutor commandExecutor;
@ -53,7 +50,7 @@ public class RedissonReactive implements RedissonReactiveClient {
protected RedissonReactive(Config config) {
Config configCopy = new Config(config);
connectionManager = ConfigSupport.createConnectionManager(configCopy, connectionEventsHub);
connectionManager = ConfigSupport.createConnectionManager(configCopy);
RedissonObjectBuilder objectBuilder = null;
if (config.isReferenceEnabled()) {
objectBuilder = new RedissonObjectBuilder(this);
@ -68,7 +65,7 @@ public class RedissonReactive implements RedissonReactiveClient {
WriteBehindService writeBehindService, ConcurrentMap<String, ResponseEntry> responses) {
this.connectionManager = connectionManager;
RedissonObjectBuilder objectBuilder = null;
if (connectionManager.getCfg().isReferenceEnabled()) {
if (connectionManager.getServiceManager().getCfg().isReferenceEnabled()) {
objectBuilder = new RedissonObjectBuilder(this);
}
commandExecutor = new CommandReactiveService(connectionManager, objectBuilder);
@ -508,12 +505,12 @@ public class RedissonReactive implements RedissonReactiveClient {
@Override
public RRemoteService getRemoteService() {
return getRemoteService("redisson_rs", connectionManager.getCodec());
return getRemoteService("redisson_rs", connectionManager.getServiceManager().getCfg().getCodec());
}
@Override
public RRemoteService getRemoteService(String name) {
return getRemoteService(name, connectionManager.getCodec());
return getRemoteService(name, connectionManager.getServiceManager().getCfg().getCodec());
}
@Override
@ -523,8 +520,8 @@ public class RedissonReactive implements RedissonReactiveClient {
@Override
public RRemoteService getRemoteService(String name, Codec codec) {
String executorId = connectionManager.getId();
if (codec != connectionManager.getCodec()) {
String executorId = connectionManager.getServiceManager().getId();
if (codec != connectionManager.getServiceManager().getCfg().getCodec()) {
executorId = executorId + ":" + name;
}
return new RedissonRemoteService(codec, name, commandExecutor, executorId, responses);
@ -572,12 +569,12 @@ public class RedissonReactive implements RedissonReactiveClient {
@Override
public Config getConfig() {
return connectionManager.getCfg();
return connectionManager.getServiceManager().getCfg();
}
@Override
public NodesGroup<Node> getNodesGroup() {
return new RedisNodes<Node>(connectionManager, connectionEventsHub, commandExecutor);
return new RedisNodes<>(connectionManager, connectionManager.getServiceManager(), commandExecutor);
}
@Override
@ -585,7 +582,7 @@ public class RedissonReactive implements RedissonReactiveClient {
if (!connectionManager.isClusterMode()) {
throw new IllegalStateException("Redisson not in cluster mode!");
}
return new RedisNodes<ClusterNode>(connectionManager, connectionEventsHub, commandExecutor);
return new RedisNodes<>(connectionManager, connectionManager.getServiceManager(), commandExecutor);
}
@Override
@ -596,12 +593,12 @@ public class RedissonReactive implements RedissonReactiveClient {
@Override
public boolean isShutdown() {
return connectionManager.isShutdown();
return connectionManager.getServiceManager().isShutdown();
}
@Override
public boolean isShuttingDown() {
return connectionManager.isShuttingDown();
return connectionManager.getServiceManager().isShuttingDown();
}
@Override
@ -688,7 +685,7 @@ public class RedissonReactive implements RedissonReactiveClient {
@Override
public String getId() {
return commandExecutor.getConnectionManager().getId();
return commandExecutor.getServiceManager().getId();
}
}

@ -168,7 +168,7 @@ public class RedissonReliableTopic extends RedissonExpirable implements RReliabl
+ "redis.call('zadd', KEYS[1], value, ARGV[2]); "
+ "redis.call('hset', KEYS[2], ARGV[2], ARGV[1]); ",
Arrays.asList(getSubscribersName(), getMapName(), getCounter(), getTimeout()),
startId, id, System.currentTimeMillis() + commandExecutor.getConnectionManager().getCfg().getReliableTopicWatchdogTimeout());
startId, id, System.currentTimeMillis() + commandExecutor.getServiceManager().getCfg().getReliableTopicWatchdogTimeout());
CompletionStage<String> f = addFuture.thenApply(r -> {
poll(id, startId);
return id;
@ -194,13 +194,13 @@ public class RedissonReliableTopic extends RedissonExpirable implements RReliabl
log.error(ex.getMessage(), ex);
commandExecutor.getConnectionManager().newTimeout(task -> {
commandExecutor.getServiceManager().newTimeout(task -> {
poll(id, startId);
}, 1, TimeUnit.SECONDS);
return;
}
commandExecutor.getConnectionManager().getExecutor().execute(() -> {
commandExecutor.getServiceManager().getExecutor().execute(() -> {
res.values().forEach(entry -> {
Object m = entry.get("m");
listeners.values().forEach(e -> {
@ -324,7 +324,7 @@ public class RedissonReliableTopic extends RedissonExpirable implements RReliabl
}
private void renewExpiration() {
timeoutTask = commandExecutor.getConnectionManager().newTimeout(t -> {
timeoutTask = commandExecutor.getServiceManager().newTimeout(t -> {
RFuture<Boolean> future = commandExecutor.evalWriteAsync(getRawName(), StringCodec.INSTANCE, RedisCommands.EVAL_BOOLEAN,
"if redis.call('zscore', KEYS[1], ARGV[2]) == false then "
+ "return 0; "
@ -332,7 +332,7 @@ public class RedissonReliableTopic extends RedissonExpirable implements RReliabl
+ "redis.call('zadd', KEYS[1], ARGV[1], ARGV[2]); "
+ "return 1; ",
Arrays.asList(getTimeout()),
System.currentTimeMillis() + commandExecutor.getConnectionManager().getCfg().getReliableTopicWatchdogTimeout(), subscriberId.get());
System.currentTimeMillis() + commandExecutor.getServiceManager().getCfg().getReliableTopicWatchdogTimeout(), subscriberId.get());
future.whenComplete((res, e) -> {
if (e != null) {
log.error("Can't update reliable topic {} expiration time", getRawName(), e);
@ -344,7 +344,7 @@ public class RedissonReliableTopic extends RedissonExpirable implements RReliabl
renewExpiration();
}
});
}, commandExecutor.getConnectionManager().getCfg().getReliableTopicWatchdogTimeout() / 3, TimeUnit.MILLISECONDS);
}, commandExecutor.getServiceManager().getCfg().getReliableTopicWatchdogTimeout() / 3, TimeUnit.MILLISECONDS);
}

@ -141,7 +141,7 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
@Override
public <T> void register(Class<T> remoteInterface, T object, int workers) {
register(remoteInterface, object, workers, commandExecutor.getConnectionManager().getExecutor());
register(remoteInterface, object, workers, commandExecutor.getServiceManager().getExecutor());
}
private <V> RBlockingQueue<V> getBlockingQueue(String name, Codec codec) {
@ -165,7 +165,7 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
@Override
public <T> boolean tryExecute(Class<T> remoteInterface, T object, long timeout, TimeUnit timeUnit) throws InterruptedException {
return tryExecute(remoteInterface, object, commandExecutor.getConnectionManager().getExecutor(), timeout, timeUnit);
return tryExecute(remoteInterface, object, commandExecutor.getServiceManager().getExecutor(), timeout, timeUnit);
}
@Override
@ -192,7 +192,7 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
@Override
public <T> RFuture<Boolean> tryExecuteAsync(Class<T> remoteInterface, T object, long timeout, TimeUnit timeUnit) {
return tryExecuteAsync(remoteInterface, object, commandExecutor.getConnectionManager().getExecutor(), timeout, timeUnit);
return tryExecuteAsync(remoteInterface, object, commandExecutor.getServiceManager().getExecutor(), timeout, timeUnit);
}
@Override
@ -427,7 +427,7 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
});
java.util.concurrent.Future<?> submitFuture = executor.submit(() -> {
if (commandExecutor.getConnectionManager().isShuttingDown()) {
if (commandExecutor.getServiceManager().isShuttingDown()) {
return;
}

@ -50,9 +50,9 @@ public class RedissonRx implements RedissonRxClient {
protected RedissonRx(Config config) {
Config configCopy = new Config(config);
connectionManager = ConfigSupport.createConnectionManager(configCopy, connectionEventsHub);
connectionManager = ConfigSupport.createConnectionManager(configCopy);
RedissonObjectBuilder objectBuilder = null;
if (connectionManager.getCfg().isReferenceEnabled()) {
if (connectionManager.getServiceManager().getCfg().isReferenceEnabled()) {
objectBuilder = new RedissonObjectBuilder(this);
}
commandExecutor = new CommandRxService(connectionManager, objectBuilder);
@ -65,7 +65,7 @@ public class RedissonRx implements RedissonRxClient {
WriteBehindService writeBehindService, ConcurrentMap<String, ResponseEntry> responses) {
this.connectionManager = connectionManager;
RedissonObjectBuilder objectBuilder = null;
if (connectionManager.getCfg().isReferenceEnabled()) {
if (connectionManager.getServiceManager().getCfg().isReferenceEnabled()) {
objectBuilder = new RedissonObjectBuilder(this);
}
commandExecutor = new CommandRxService(connectionManager, objectBuilder);
@ -486,12 +486,12 @@ public class RedissonRx implements RedissonRxClient {
@Override
public RRemoteService getRemoteService() {
return getRemoteService("redisson_rs", connectionManager.getCodec());
return getRemoteService("redisson_rs", connectionManager.getServiceManager().getCfg().getCodec());
}
@Override
public RRemoteService getRemoteService(String name) {
return getRemoteService(name, connectionManager.getCodec());
return getRemoteService(name, connectionManager.getServiceManager().getCfg().getCodec());
}
@Override
@ -501,8 +501,8 @@ public class RedissonRx implements RedissonRxClient {
@Override
public RRemoteService getRemoteService(String name, Codec codec) {
String executorId = connectionManager.getId();
if (codec != connectionManager.getCodec()) {
String executorId = connectionManager.getServiceManager().getId();
if (codec != connectionManager.getServiceManager().getCfg().getCodec()) {
executorId = executorId + ":" + name;
}
return new RedissonRemoteService(codec, name, commandExecutor, executorId, responses);
@ -550,12 +550,12 @@ public class RedissonRx implements RedissonRxClient {
@Override
public Config getConfig() {
return connectionManager.getCfg();
return connectionManager.getServiceManager().getCfg();
}
@Override
public NodesGroup<Node> getNodesGroup() {
return new RedisNodes<Node>(connectionManager, connectionEventsHub, commandExecutor);
return new RedisNodes<Node>(connectionManager, connectionManager.getServiceManager(), commandExecutor);
}
@Override
@ -563,7 +563,7 @@ public class RedissonRx implements RedissonRxClient {
if (!connectionManager.isClusterMode()) {
throw new IllegalStateException("Redisson not in cluster mode!");
}
return new RedisNodes<ClusterNode>(connectionManager, connectionEventsHub, commandExecutor);
return new RedisNodes<ClusterNode>(connectionManager, connectionManager.getServiceManager(), commandExecutor);
}
@Override
@ -574,12 +574,12 @@ public class RedissonRx implements RedissonRxClient {
@Override
public boolean isShutdown() {
return connectionManager.isShutdown();
return connectionManager.getServiceManager().isShutdown();
}
@Override
public boolean isShuttingDown() {
return connectionManager.isShuttingDown();
return connectionManager.getServiceManager().isShuttingDown();
}
@Override
@ -665,7 +665,7 @@ public class RedissonRx implements RedissonRxClient {
@Override
public String getId() {
return commandExecutor.getConnectionManager().getId();
return commandExecutor.getServiceManager().getId();
}
}

@ -1790,17 +1790,17 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
@Override
public int subscribeOnFirstElements(Consumer<V> consumer) {
return commandExecutor.getConnectionManager().getElementsSubscribeService().subscribeOnElements(this::takeFirstAsync, consumer);
return commandExecutor.getServiceManager().getElementsSubscribeService().subscribeOnElements(this::takeFirstAsync, consumer);
}
@Override
public int subscribeOnLastElements(Consumer<V> consumer) {
return commandExecutor.getConnectionManager().getElementsSubscribeService().subscribeOnElements(this::takeLastAsync, consumer);
return commandExecutor.getServiceManager().getElementsSubscribeService().subscribeOnElements(this::takeLastAsync, consumer);
}
@Override
public void unsubscribe(int listenerId) {
commandExecutor.getConnectionManager().getElementsSubscribeService().unsubscribe(listenerId);
commandExecutor.getServiceManager().getElementsSubscribeService().unsubscribe(listenerId);
}
@Override

@ -40,7 +40,7 @@ public class RedissonScript implements RScript {
public RedissonScript(CommandAsyncExecutor commandExecutor) {
this.commandExecutor = commandExecutor;
this.codec = commandExecutor.getConnectionManager().getCodec();
this.codec = commandExecutor.getServiceManager().getCfg().getCodec();
}
public RedissonScript(CommandAsyncExecutor commandExecutor, Codec codec) {
@ -201,9 +201,9 @@ public class RedissonScript implements RScript {
public <R> RFuture<R> evalShaAsync(String key, Mode mode, String shaDigest, ReturnType returnType,
List<Object> keys, Object... values) {
RedisCommand command = new RedisCommand(returnType.getCommand(), "EVALSHA");
String mappedKey = commandExecutor.getConnectionManager().getConfig().getNameMapper().map((String) key);
String mappedKey = commandExecutor.getServiceManager().getConfig().getNameMapper().map((String) key);
List<Object> mappedKeys = keys.stream()
.map(k -> commandExecutor.getConnectionManager().getConfig().getNameMapper().map((String) k))
.map(k -> commandExecutor.getServiceManager().getConfig().getNameMapper().map((String) k))
.collect(Collectors.toList());
if (mode == Mode.READ_ONLY && commandExecutor.isEvalShaROSupported()) {
RedisCommand cmd = new RedisCommand(returnType.getCommand(), "EVALSHA_RO");
@ -226,9 +226,9 @@ public class RedissonScript implements RScript {
@Override
public <R> RFuture<R> evalAsync(String key, Mode mode, String luaScript, ReturnType returnType, List<Object> keys,
Object... values) {
String mappedKey = commandExecutor.getConnectionManager().getConfig().getNameMapper().map((String) key);
String mappedKey = commandExecutor.getServiceManager().getConfig().getNameMapper().map((String) key);
List<Object> mappedKeys = keys.stream()
.map(k -> commandExecutor.getConnectionManager().getConfig().getNameMapper().map((String) k))
.map(k -> commandExecutor.getServiceManager().getConfig().getNameMapper().map((String) k))
.collect(Collectors.toList());
if (mode == Mode.READ_ONLY) {
return commandExecutor.evalReadAsync(mappedKey, codec, returnType.getCommand(), luaScript, mappedKeys, encode(Arrays.asList(values), codec).toArray());

@ -189,7 +189,7 @@ public class RedissonSemaphore extends RedissonExpirable implements RSemaphore {
long t = time.get();
if (!executed.get()) {
Timeout scheduledFuture = commandExecutor.getConnectionManager().newTimeout(new TimerTask() {
Timeout scheduledFuture = commandExecutor.getServiceManager().newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
if (entry.removeListener(listener)) {

@ -231,7 +231,7 @@ public class RedissonSortedSet<V> extends RedissonObject implements RSortedSet<V
@Override
public RFuture<Boolean> addAsync(final V value) {
CompletableFuture<Boolean> promise = new CompletableFuture<>();
commandExecutor.getConnectionManager().getExecutor().execute(new Runnable() {
commandExecutor.getServiceManager().getExecutor().execute(new Runnable() {
public void run() {
try {
boolean res = add(value);
@ -247,7 +247,7 @@ public class RedissonSortedSet<V> extends RedissonObject implements RSortedSet<V
@Override
public RFuture<Boolean> removeAsync(final Object value) {
CompletableFuture<Boolean> promise = new CompletableFuture<>();
commandExecutor.getConnectionManager().getExecutor().execute(new Runnable() {
commandExecutor.getServiceManager().getExecutor().execute(new Runnable() {
@Override
public void run() {
try {

@ -52,7 +52,7 @@ public class RedissonSpinLock extends RedissonBaseLock {
LockOptions.BackOff backOff) {
super(commandExecutor, name);
this.commandExecutor = commandExecutor;
this.internalLockLeaseTime = commandExecutor.getConnectionManager().getCfg().getLockWatchdogTimeout();
this.internalLockLeaseTime = commandExecutor.getServiceManager().getCfg().getLockWatchdogTimeout();
this.backOff = backOff;
}
@ -184,7 +184,7 @@ public class RedissonSpinLock extends RedissonBaseLock {
@Override
protected void cancelExpirationRenewal(Long threadId) {
super.cancelExpirationRenewal(threadId);
this.internalLockLeaseTime = commandExecutor.getConnectionManager().getCfg().getLockWatchdogTimeout();
this.internalLockLeaseTime = commandExecutor.getServiceManager().getCfg().getLockWatchdogTimeout();
}
@Override
@ -244,7 +244,7 @@ public class RedissonSpinLock extends RedissonBaseLock {
}
long nextSleepPeriod = backOffPolicy.getNextSleepPeriod();
commandExecutor.getConnectionManager().newTimeout(
commandExecutor.getServiceManager().newTimeout(
timeout -> lockAsync(leaseTime, unit, currentThreadId, result, backOffPolicy),
nextSleepPeriod, TimeUnit.MILLISECONDS);
});
@ -296,7 +296,7 @@ public class RedissonSpinLock extends RedissonBaseLock {
}
long nextSleepPeriod = backOffPolicy.getNextSleepPeriod();
commandExecutor.getConnectionManager().newTimeout(
commandExecutor.getServiceManager().newTimeout(
timeout -> tryLock(leaseTime, unit, currentThreadId, result, time, backOffPolicy),
nextSleepPeriod, TimeUnit.MILLISECONDS);
});

@ -51,11 +51,11 @@ public class RedissonTopic implements RTopic {
final Codec codec;
public RedissonTopic(CommandAsyncExecutor commandExecutor, String name) {
this(commandExecutor.getConnectionManager().getCodec(), commandExecutor, name);
this(commandExecutor.getServiceManager().getCfg().getCodec(), commandExecutor, name);
}
public static RedissonTopic createRaw(CommandAsyncExecutor commandExecutor, String name) {
return new RedissonTopic(commandExecutor.getConnectionManager().getCodec(), commandExecutor, NameMapper.direct(), name);
return new RedissonTopic(commandExecutor.getServiceManager().getCfg().getCodec(), commandExecutor, NameMapper.direct(), name);
}
public static RedissonTopic createRaw(Codec codec, CommandAsyncExecutor commandExecutor, String name) {
@ -63,7 +63,7 @@ public class RedissonTopic implements RTopic {
}
public RedissonTopic(Codec codec, CommandAsyncExecutor commandExecutor, String name) {
this(codec, commandExecutor, commandExecutor.getConnectionManager().getConfig().getNameMapper(), name);
this(codec, commandExecutor, commandExecutor.getServiceManager().getConfig().getNameMapper(), name);
}
public RedissonTopic(Codec codec, CommandAsyncExecutor commandExecutor, NameMapper nameMapper, String name) {

@ -193,7 +193,7 @@ public class RedissonTransferQueue<V> extends RedissonExpirable implements RTran
long remainTime = unit.toMillis(timeout);
long startTime = System.currentTimeMillis();
Timeout timeoutFuture = commandExecutor.getConnectionManager().newTimeout(tt -> {
Timeout timeoutFuture = commandExecutor.getServiceManager().newTimeout(tt -> {
if (!future.getAddFuture().cancel(false)) {
future.cancelAsync(false);
}
@ -250,7 +250,7 @@ public class RedissonTransferQueue<V> extends RedissonExpirable implements RTran
long time = remainTime - (System.currentTimeMillis() - startTime);
if (time > 0) {
commandExecutor.getConnectionManager().newTimeout(tt -> {
commandExecutor.getServiceManager().newTimeout(tt -> {
task.run();
}, time, TimeUnit.MILLISECONDS);
} else {
@ -637,12 +637,12 @@ public class RedissonTransferQueue<V> extends RedissonExpirable implements RTran
@Override
public int subscribeOnElements(Consumer<V> consumer) {
return commandExecutor.getConnectionManager().getElementsSubscribeService().subscribeOnElements(this::takeAsync, consumer);
return commandExecutor.getServiceManager().getElementsSubscribeService().subscribeOnElements(this::takeAsync, consumer);
}
@Override
public void unsubscribe(int listenerId) {
commandExecutor.getConnectionManager().getElementsSubscribeService().unsubscribe(listenerId);
commandExecutor.getServiceManager().getElementsSubscribeService().unsubscribe(listenerId);
}
@Override

@ -284,7 +284,7 @@ public abstract class LocalCacheListener {
cache.remove(key);
}
commandExecutor.getConnectionManager().getGroup().schedule(new Runnable() {
commandExecutor.getServiceManager().getGroup().schedule(new Runnable() {
@Override
public void run() {
for (CacheKey cacheKey : keys) {

@ -26,7 +26,10 @@ import org.redisson.client.protocol.RedisCommands;
import org.redisson.client.protocol.RedisStrictCommand;
import org.redisson.cluster.ClusterNodeInfo.Flag;
import org.redisson.cluster.ClusterPartition.Type;
import org.redisson.config.*;
import org.redisson.config.BaseMasterSlaveServersConfig;
import org.redisson.config.ClusterServersConfig;
import org.redisson.config.MasterSlaveServersConfig;
import org.redisson.config.ReadMode;
import org.redisson.connection.*;
import org.redisson.connection.ClientConnectionsEntry.FreezeReason;
import org.redisson.misc.RedisURI;
@ -65,8 +68,9 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
private ClusterServersConfig cfg;
public ClusterConnectionManager(ClusterServersConfig cfg, Config config, UUID id, ConnectionEventsHub connectionEventsHub) {
super(cfg, config, id, connectionEventsHub);
public ClusterConnectionManager(ClusterServersConfig cfg, ServiceManager serviceManager) {
super(cfg, serviceManager);
this.serviceManager.setNatMapper(cfg.getNatMapper());
}
@Override
@ -306,12 +310,12 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
MasterSlaveEntry entry;
if (config.checkSkipSlavesInit()) {
entry = new SingleEntry(this, connectionWatcher, config);
entry = new SingleEntry(this, serviceManager.getConnectionWatcher(), config);
} else {
Set<String> slaveAddresses = partition.getSlaveAddresses().stream().map(r -> r.toString()).collect(Collectors.toSet());
config.setSlaveAddresses(slaveAddresses);
entry = new MasterSlaveEntry(ClusterConnectionManager.this, connectionWatcher, config);
entry = new MasterSlaveEntry(ClusterConnectionManager.this, serviceManager.getConnectionWatcher(), config);
}
CompletableFuture<RedisClient> f = entry.setupMasterEntry(new RedisURI(config.getMasterAddress()), configEndpointHostName);
@ -364,13 +368,13 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
}
private void scheduleClusterChangeCheck(ClusterServersConfig cfg) {
monitorFuture = group.schedule(new Runnable() {
monitorFuture = serviceManager.getGroup().schedule(new Runnable() {
@Override
public void run() {
if (configEndpointHostName != null) {
String address = cfg.getNodeAddresses().iterator().next();
RedisURI uri = new RedisURI(address);
AddressResolver<InetSocketAddress> resolver = resolverGroup.getResolver(getGroup().next());
AddressResolver<InetSocketAddress> resolver = serviceManager.getResolverGroup().getResolver(serviceManager.getGroup().next());
Future<List<InetSocketAddress>> allNodes = resolver.resolveAll(InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort()));
allNodes.addListener(new FutureListener<List<InetSocketAddress>>() {
@Override
@ -383,7 +387,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
List<RedisURI> nodes = new ArrayList<>();
for (InetSocketAddress addr : future.getNow()) {
RedisURI address = toURI(uri.getScheme(), addr.getAddress().getHostAddress(), "" + addr.getPort());
RedisURI address = serviceManager.toURI(uri.getScheme(), addr.getAddress().getHostAddress(), "" + addr.getPort());
nodes.add(address);
}
@ -392,7 +396,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
}
});
} else {
AtomicReference<Throwable> lastException = new AtomicReference<Throwable>();
AtomicReference<Throwable> lastException = new AtomicReference<>();
List<RedisURI> nodes = new ArrayList<>();
List<RedisURI> slaves = new ArrayList<>();
@ -428,7 +432,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
scheduleClusterChangeCheck(cfg);
return;
}
if (!getShutdownLatch().acquire()) {
if (!serviceManager.getShutdownLatch().acquire()) {
return;
}
RedisURI uri = iterator.next();
@ -436,7 +440,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
connectionFuture.whenComplete((connection, e) -> {
if (e != null) {
lastException.set(e);
getShutdownLatch().release();
serviceManager.getShutdownLatch().release();
checkClusterState(cfg, iterator, lastException);
return;
}
@ -452,14 +456,14 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
if (e != null) {
log.error("Unable to execute {}", clusterNodesCommand, e);
lastException.set(e);
getShutdownLatch().release();
serviceManager.getShutdownLatch().release();
checkClusterState(cfg, iterator, lastException);
return;
}
if (nodes.isEmpty()) {
log.debug("cluster nodes state got from {}: doesn't contain any nodes", connection.getRedisClient().getAddr());
getShutdownLatch().release();
serviceManager.getShutdownLatch().release();
checkClusterState(cfg, iterator, lastException);
return;
}
@ -484,7 +488,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
}
log.error("Unable to parse cluster nodes state got from: {}:\n{}", connection.getRedisClient().getAddr(), nodesValue, ex);
lastException.set(ex);
getShutdownLatch().release();
serviceManager.getShutdownLatch().release();
checkClusterState(cfg, iterator, lastException);
}
})
@ -495,7 +499,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
.thenApply(newPartitions -> {
checkSlotsMigration(newPartitions);
checkSlotsChange(newPartitions);
getShutdownLatch().release();
serviceManager.getShutdownLatch().release();
scheduleClusterChangeCheck(cfg);
return newPartitions;
});
@ -817,11 +821,6 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
return result;
}
@Override
public RedisURI applyNatMap(RedisURI address) {
return cfg.getNatMapper().map(address);
}
private CompletableFuture<Collection<ClusterPartition>> parsePartitions(List<ClusterNodeInfo> nodes) {
Map<String, ClusterPartition> partitions = new ConcurrentHashMap<>();
List<CompletableFuture<Void>> futures = new ArrayList<>();
@ -846,7 +845,7 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
continue;
}
CompletableFuture<RedisURI> ipFuture = resolveIP(clusterNodeInfo.getAddress());
CompletableFuture<RedisURI> ipFuture = serviceManager.resolveIP(clusterNodeInfo.getAddress());
CompletableFuture<Void> f = ipFuture.thenAccept(address -> {
if (clusterNodeInfo.containsFlag(Flag.SLAVE)) {

@ -78,7 +78,7 @@ public class BaseRedisBatchExecutor<V, R> extends RedisExecutor<V, R> {
if (source.getSlot() != null) {
MasterSlaveEntry entry = connectionManager.getEntry(source.getSlot());
if (entry == null) {
throw connectionManager.createNodeNotFoundException(source);
throw connectionManager.getServiceManager().createNodeNotFoundException(source);
}
return entry;
}

@ -25,6 +25,7 @@ import org.redisson.client.protocol.RedisCommand;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.MasterSlaveEntry;
import org.redisson.connection.NodeSource;
import org.redisson.connection.ServiceManager;
import org.redisson.liveobject.core.RedissonObjectBuilder;
import java.util.List;
@ -42,6 +43,8 @@ public interface CommandAsyncExecutor {
ConnectionManager getConnectionManager();
ServiceManager getServiceManager();
RedisException convertException(ExecutionException e);
<V> void transfer(CompletableFuture<V> future1, CompletableFuture<V> future2);

@ -33,6 +33,7 @@ import org.redisson.client.protocol.RedisCommands;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.MasterSlaveEntry;
import org.redisson.connection.NodeSource;
import org.redisson.connection.ServiceManager;
import org.redisson.liveobject.core.RedissonObjectBuilder;
import org.redisson.misc.CompletableFutureWrapper;
import org.slf4j.Logger;
@ -59,6 +60,7 @@ public class CommandAsyncService implements CommandAsyncExecutor {
static final Logger log = LoggerFactory.getLogger(CommandAsyncService.class);
final Codec codec;
final ConnectionManager connectionManager;
final RedissonObjectBuilder objectBuilder;
final RedissonObjectBuilder.ReferenceType referenceType;
@ -67,6 +69,7 @@ public class CommandAsyncService implements CommandAsyncExecutor {
this.connectionManager = connectionManager;
this.objectBuilder = objectBuilder;
this.referenceType = referenceType;
this.codec = connectionManager.getServiceManager().getCfg().getCodec();
}
@Override
@ -229,7 +232,7 @@ public class CommandAsyncService implements CommandAsyncExecutor {
@Override
public <R> List<CompletableFuture<R>> writeAllAsync(RedisCommand<?> command, Object... params) {
return writeAllAsync(command, connectionManager.getCodec(), params);
return writeAllAsync(command, codec, params);
}
private <R> List<CompletableFuture<R>> writeAllAsync(RedisCommand<?> command, Codec codec, Object... params) {
@ -252,7 +255,7 @@ public class CommandAsyncService implements CommandAsyncExecutor {
@Override
public <R> List<CompletableFuture<R>> readAllAsync(RedisCommand<?> command, Object... params) {
return readAllAsync(connectionManager.getCodec(), command, params);
return readAllAsync(codec, command, params);
}
@Override
@ -261,12 +264,12 @@ public class CommandAsyncService implements CommandAsyncExecutor {
List<CompletableFuture<R>> futures = new ArrayList<>();
nodes.forEach(e -> {
RFuture<R> promise = async(false, new NodeSource(e),
connectionManager.getCodec(), command, params, true, false);
codec, command, params, true, false);
futures.add(promise.toCompletableFuture());
e.getAllEntries().stream().filter(c -> c.getNodeType() == NodeType.SLAVE && !c.isFreezed()).forEach(c -> {
RFuture<R> slavePromise = async(true, new NodeSource(e, c.getClient()),
connectionManager.getCodec(), command, params, true, false);
codec, command, params, true, false);
futures.add(slavePromise.toCompletableFuture());
});
});
@ -319,7 +322,7 @@ public class CommandAsyncService implements CommandAsyncExecutor {
@Override
public <T, R> RFuture<R> readAsync(String key, RedisCommand<T> command, Object... params) {
return readAsync(key, connectionManager.getCodec(), command, params);
return readAsync(key, codec, command, params);
}
@Override
@ -364,7 +367,7 @@ public class CommandAsyncService implements CommandAsyncExecutor {
}
protected boolean isEvalCacheActive() {
return getConnectionManager().getCfg().isUseScriptCache();
return connectionManager.getServiceManager().getCfg().isUseScriptCache();
}
private static final Map<String, String> SHA_CACHE = new LRUCacheMap<>(500, 0, 0);
@ -485,7 +488,7 @@ public class CommandAsyncService implements CommandAsyncExecutor {
@Override
public <T, R> RFuture<R> writeAsync(String key, RedisCommand<T> command, Object... params) {
return writeAsync(key, connectionManager.getCodec(), command, params);
return writeAsync(key, codec, command, params);
}
@Override
@ -613,6 +616,10 @@ public class CommandAsyncService implements CommandAsyncExecutor {
return objectBuilder;
}
public ServiceManager getServiceManager() {
return connectionManager.getServiceManager();
}
@Override
public ByteBuf encode(Codec codec, Object value) {
if (isRedissonReferenceSupportEnabled()) {
@ -663,7 +670,7 @@ public class CommandAsyncService implements CommandAsyncExecutor {
@Override
public <V> RFuture<V> pollFromAnyAsync(String name, Codec codec, RedisCommand<?> command, long secondsTimeout, String... queueNames) {
List<String> mappedNames = Arrays.stream(queueNames).map(m -> connectionManager.getConfig().getNameMapper().map(m)).collect(Collectors.toList());
List<String> mappedNames = Arrays.stream(queueNames).map(m -> connectionManager.getServiceManager().getConfig().getNameMapper().map(m)).collect(Collectors.toList());
if (connectionManager.isClusterMode() && queueNames.length > 0) {
AtomicReference<Iterator<String>> ref = new AtomicReference<>();
List<String> names = new ArrayList<>();

@ -364,10 +364,10 @@ public class CommandBatchService extends CommandAsyncService {
if (options.getResponseTimeout() > 0) {
responseTimeout = options.getResponseTimeout();
} else {
responseTimeout = connectionManager.getConfig().getTimeout();
responseTimeout = connectionManager.getServiceManager().getConfig().getTimeout();
}
Timeout timeout = connectionManager.newTimeout(new TimerTask() {
Timeout timeout = connectionManager.getServiceManager().newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
connections.values().forEach(c -> {
@ -409,7 +409,7 @@ public class CommandBatchService extends CommandAsyncService {
List<CompletableFuture<Void>> futures = new ArrayList<>(commands.size());
for (Map.Entry<MasterSlaveEntry, Entry> entry : commands.entrySet()) {
RFuture<List<Object>> execPromise = async(entry.getValue().isReadOnlyMode(), new NodeSource(entry.getKey()),
connectionManager.getCodec(), RedisCommands.EXEC, new Object[] {}, false, false);
codec, RedisCommands.EXEC, new Object[] {}, false, false);
CompletionStage<Void> f = execPromise.thenCompose(r -> {
BatchCommandData<?, Integer> lastCommand = (BatchCommandData<?, Integer>) entry.getValue().getCommands().peekLast();

@ -34,7 +34,7 @@ public class CommandSyncService extends CommandAsyncService implements CommandEx
@Override
public <T, R> R read(String key, RedisCommand<T> command, Object... params) {
return read(key, connectionManager.getCodec(), command, params);
return read(key, codec, command, params);
}
@Override

@ -101,9 +101,9 @@ public class RedisExecutor<V, R> {
this.objectBuilder = objectBuilder;
this.noRetry = noRetry;
this.attempts = connectionManager.getConfig().getRetryAttempts();
this.retryInterval = connectionManager.getConfig().getRetryInterval();
this.responseTimeout = connectionManager.getConfig().getTimeout();
this.attempts = connectionManager.getServiceManager().getConfig().getRetryAttempts();
this.retryInterval = connectionManager.getServiceManager().getConfig().getRetryInterval();
this.responseTimeout = connectionManager.getServiceManager().getConfig().getTimeout();
this.referenceType = referenceType;
}
@ -113,7 +113,7 @@ public class RedisExecutor<V, R> {
return;
}
if (!connectionManager.getShutdownLatch().acquire()) {
if (!connectionManager.getServiceManager().getShutdownLatch().acquire()) {
free();
mainPromise.completeExceptionally(new RedissonShutdownException("Redisson is shutdown"));
return;
@ -163,12 +163,12 @@ public class RedisExecutor<V, R> {
connectionFuture.whenComplete((connection, e) -> {
if (connectionFuture.isCancelled()) {
connectionManager.getShutdownLatch().release();
connectionManager.getServiceManager().getShutdownLatch().release();
return;
}
if (connectionFuture.isDone() && connectionFuture.isCompletedExceptionally()) {
connectionManager.getShutdownLatch().release();
connectionManager.getServiceManager().getShutdownLatch().release();
exception = convertException(connectionFuture);
if (attempt == attempts) {
attemptPromise.completeExceptionally(exception);
@ -211,7 +211,7 @@ public class RedisExecutor<V, R> {
}
};
timeout = Optional.of(connectionManager.newTimeout(task, responseTimeout, TimeUnit.MILLISECONDS));
timeout = Optional.of(connectionManager.getServiceManager().newTimeout(task, responseTimeout, TimeUnit.MILLISECONDS));
}
private void scheduleWriteTimeout(CompletableFuture<R> attemptPromise) {
@ -233,7 +233,7 @@ public class RedisExecutor<V, R> {
}
};
timeout = Optional.of(connectionManager.newTimeout(task, responseTimeout, TimeUnit.MILLISECONDS));
timeout = Optional.of(connectionManager.getServiceManager().newTimeout(task, responseTimeout, TimeUnit.MILLISECONDS));
}
private void scheduleRetryTimeout(CompletableFuture<RedisConnection> connectionFuture, CompletableFuture<R> attemptPromise) {
@ -315,7 +315,7 @@ public class RedisExecutor<V, R> {
};
timeout = Optional.of(connectionManager.newTimeout(retryTimerTask, retryInterval, TimeUnit.MILLISECONDS));
timeout = Optional.of(connectionManager.getServiceManager().newTimeout(retryTimerTask, retryInterval, TimeUnit.MILLISECONDS));
}
protected void free() {
@ -380,7 +380,7 @@ public class RedisExecutor<V, R> {
return;
}
connectionManager.newTimeout(t -> {
connectionManager.getServiceManager().newTimeout(t -> {
attempt++;
if (log.isDebugEnabled()) {
log.debug("attempt {} for command {} and params {}",
@ -402,7 +402,7 @@ public class RedisExecutor<V, R> {
+ LogHelper.toString(command, params) + ", channel: " + connection.getChannel()));
};
timeout = Optional.of(connectionManager.newTimeout(timeoutResponseTask, timeoutTime, TimeUnit.MILLISECONDS));
timeout = Optional.of(connectionManager.getServiceManager().newTimeout(timeoutResponseTask, timeoutTime, TimeUnit.MILLISECONDS));
}
protected boolean isResendAllowed(int attempt, int attempts) {
@ -419,7 +419,7 @@ public class RedisExecutor<V, R> {
Timeout scheduledFuture;
if (popTimeout != 0) {
// handling cases when connection has been lost
scheduledFuture = connectionManager.newTimeout(timeout -> {
scheduledFuture = connectionManager.getServiceManager().newTimeout(timeout -> {
if (attemptPromise.complete(null)) {
connection.forceFastReconnectAsync();
}
@ -434,7 +434,7 @@ public class RedisExecutor<V, R> {
}
synchronized (listener) {
connectionManager.getShutdownPromise().removeListener(listener);
connectionManager.getServiceManager().getShutdownPromise().removeListener(listener);
}
// handling cancel operation for blocking commands
@ -455,7 +455,7 @@ public class RedisExecutor<V, R> {
synchronized (listener) {
if (!mainPromise.isDone()) {
connectionManager.getShutdownPromise().addListener(listener);
connectionManager.getServiceManager().getShutdownPromise().addListener(listener);
}
}
}
@ -491,7 +491,7 @@ public class RedisExecutor<V, R> {
onException();
CompletableFuture<RedisURI> ipAddrFuture = connectionManager.resolveIP(ex.getUrl());
CompletableFuture<RedisURI> ipAddrFuture = connectionManager.getServiceManager().resolveIP(ex.getUrl());
ipAddrFuture.whenComplete((ip, e) -> {
if (e != null) {
handleError(connectionFuture, e);
@ -508,7 +508,7 @@ public class RedisExecutor<V, R> {
onException();
CompletableFuture<RedisURI> ipAddrFuture = connectionManager.resolveIP(ex.getUrl());
CompletableFuture<RedisURI> ipAddrFuture = connectionManager.getServiceManager().resolveIP(ex.getUrl());
ipAddrFuture.whenComplete((ip, e) -> {
if (e != null) {
handleError(connectionFuture, e);
@ -527,7 +527,7 @@ public class RedisExecutor<V, R> {
|| cause instanceof RedisWaitException) {
if (attempt < attempts) {
onException();
connectionManager.newTimeout(timeout -> {
connectionManager.getServiceManager().newTimeout(timeout -> {
attempt++;
execute();
}, retryInterval, TimeUnit.MILLISECONDS);
@ -605,7 +605,7 @@ public class RedisExecutor<V, R> {
}
writeFuture = connection.send(new CommandData<>(attemptPromise, codec, command, params));
if (connectionManager.getConfig().getMasterConnectionPoolSize() < 10
if (connectionManager.getServiceManager().getConfig().getMasterConnectionPoolSize() < 10
&& !command.isBlockingCommand()) {
release(connection);
}
@ -618,8 +618,8 @@ public class RedisExecutor<V, R> {
}
RedisConnection connection = getNow(connectionFuture);
connectionManager.getShutdownLatch().release();
if (connectionManager.getConfig().getMasterConnectionPoolSize() < 10) {
connectionManager.getServiceManager().getShutdownLatch().release();
if (connectionManager.getServiceManager().getConfig().getMasterConnectionPoolSize() < 10) {
if (source.getRedirect() == Redirect.ASK
|| getClass() != RedisExecutor.class
|| (command != null && command.isBlockingCommand())) {
@ -668,7 +668,7 @@ public class RedisExecutor<V, R> {
return null;
}
if (!connectionManager.getCfg().isUseThreadClassLoader()) {
if (!connectionManager.getServiceManager().getCfg().isUseThreadClassLoader()) {
return codec;
}

@ -79,7 +79,7 @@ public class RedisQueuedBatchExecutor<V, R> extends BaseRedisBatchExecutor<V, R>
|| RedisCommands.DISCARD.getName().equals(command.getName())) {
super.releaseConnection(attemptPromise, connectionFuture);
} else {
connectionManager.getShutdownLatch().release();
connectionManager.getServiceManager().getShutdownLatch().release();
}
}

@ -179,25 +179,27 @@ public class ConfigSupport {
return yamlMapper.writeValueAsString(config);
}
public static ConnectionManager createConnectionManager(Config configCopy, ConnectionEventsHub connectionEventsHub) {
public static ConnectionManager createConnectionManager(Config configCopy) {
ServiceManager serviceManager = new ServiceManager(configCopy);
UUID id = UUID.randomUUID();
ConnectionManager cm = null;
if (configCopy.getMasterSlaveServersConfig() != null) {
validate(configCopy.getMasterSlaveServersConfig());
cm = new MasterSlaveConnectionManager(configCopy.getMasterSlaveServersConfig(), configCopy, id, connectionEventsHub);
cm = new MasterSlaveConnectionManager(configCopy.getMasterSlaveServersConfig(), serviceManager);
} else if (configCopy.getSingleServerConfig() != null) {
validate(configCopy.getSingleServerConfig());
cm = new SingleConnectionManager(configCopy.getSingleServerConfig(), configCopy, id, connectionEventsHub);
cm = new SingleConnectionManager(configCopy.getSingleServerConfig(), serviceManager);
} else if (configCopy.getSentinelServersConfig() != null) {
validate(configCopy.getSentinelServersConfig());
cm = new SentinelConnectionManager(configCopy.getSentinelServersConfig(), configCopy, id, connectionEventsHub);
cm = new SentinelConnectionManager(configCopy.getSentinelServersConfig(), serviceManager);
} else if (configCopy.getClusterServersConfig() != null) {
validate(configCopy.getClusterServersConfig());
cm = new ClusterConnectionManager(configCopy.getClusterServersConfig(), configCopy, id, connectionEventsHub);
cm = new ClusterConnectionManager(configCopy.getClusterServersConfig(), serviceManager);
} else if (configCopy.getReplicatedServersConfig() != null) {
validate(configCopy.getReplicatedServersConfig());
cm = new ReplicatedConnectionManager(configCopy.getReplicatedServersConfig(), configCopy, id, connectionEventsHub);
cm = new ReplicatedConnectionManager(configCopy.getReplicatedServersConfig(), serviceManager);
} else if (configCopy.getConnectionManager() != null) {
cm = configCopy.getConnectionManager();
}

@ -15,27 +15,16 @@
*/
package org.redisson.connection;
import io.netty.channel.EventLoopGroup;
import io.netty.util.Timeout;
import io.netty.util.TimerTask;
import io.netty.util.concurrent.Future;
import org.redisson.ElementsSubscribeService;
import org.redisson.api.NodeType;
import org.redisson.client.RedisClient;
import org.redisson.client.RedisConnection;
import org.redisson.client.RedisNodeNotFoundException;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.RedisCommand;
import org.redisson.config.Config;
import org.redisson.config.MasterSlaveServersConfig;
import org.redisson.misc.InfinitySemaphoreLatch;
import org.redisson.misc.RedisURI;
import org.redisson.pubsub.PublishSubscribeService;
import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
/**
@ -47,36 +36,16 @@ public interface ConnectionManager {
void connect();
RedisURI applyNatMap(RedisURI address);
CompletableFuture<RedisURI> resolveIP(RedisURI address);
String getId();
ElementsSubscribeService getElementsSubscribeService();
PublishSubscribeService getSubscribeService();
ExecutorService getExecutor();
RedisURI getLastClusterNode();
Config getCfg();
boolean isClusterMode();
boolean isShutdown();
boolean isShuttingDown();
int calcSlot(String key);
int calcSlot(byte[] key);
MasterSlaveServersConfig getConfig();
Codec getCodec();
Collection<MasterSlaveEntry> getEntrySet();
MasterSlaveEntry getEntry(String name);
@ -93,8 +62,6 @@ public interface ConnectionManager {
CompletableFuture<RedisConnection> connectionWriteOp(NodeSource source, RedisCommand<?> command);
RedisClient createClient(NodeType type, RedisURI address, int timeout, int commandTimeout, String sslHostname);
RedisClient createClient(NodeType type, InetSocketAddress address, RedisURI uri, String sslHostname);
RedisClient createClient(NodeType type, RedisURI address, String sslHostname);
@ -105,14 +72,6 @@ public interface ConnectionManager {
void shutdown(long quietPeriod, long timeout, TimeUnit unit);
EventLoopGroup getGroup();
Timeout newTimeout(TimerTask task, long delay, TimeUnit unit);
InfinitySemaphoreLatch getShutdownLatch();
Future<Void> getShutdownPromise();
RedisNodeNotFoundException createNodeNotFoundException(NodeSource source);
ServiceManager getServiceManager();
}

@ -51,7 +51,7 @@ public class DNSMonitor {
private long dnsMonitoringInterval;
public DNSMonitor(ConnectionManager connectionManager, RedisClient masterHost, Collection<RedisURI> slaveHosts, long dnsMonitoringInterval, AddressResolverGroup<InetSocketAddress> resolverGroup) {
this.resolver = resolverGroup.getResolver(connectionManager.getGroup().next());
this.resolver = resolverGroup.getResolver(connectionManager.getServiceManager().getGroup().next());
masterHost.resolveAddr().join();
masters.put(masterHost.getConfig().getAddress(), masterHost.getAddr());
@ -77,8 +77,8 @@ public class DNSMonitor {
}
private void monitorDnsChange() {
dnsMonitorFuture = connectionManager.getGroup().schedule(() -> {
if (connectionManager.isShuttingDown()) {
dnsMonitorFuture = connectionManager.getServiceManager().getGroup().schedule(() -> {
if (connectionManager.getServiceManager().isShuttingDown()) {
return;
}

@ -15,44 +15,20 @@
*/
package org.redisson.connection;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.epoll.EpollDatagramChannel;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.epoll.EpollSocketChannel;
import io.netty.channel.kqueue.KQueueDatagramChannel;
import io.netty.channel.kqueue.KQueueEventLoopGroup;
import io.netty.channel.kqueue.KQueueSocketChannel;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.resolver.AddressResolver;
import io.netty.resolver.AddressResolverGroup;
import io.netty.resolver.DefaultAddressResolverGroup;
import io.netty.resolver.dns.DnsServerAddressStreamProviders;
import io.netty.util.Timer;
import io.netty.util.TimerTask;
import io.netty.util.*;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.*;
import io.netty.util.internal.PlatformDependent;
import org.redisson.ElementsSubscribeService;
import org.redisson.Version;
import org.redisson.api.NodeType;
import org.redisson.client.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.RedisCommand;
import org.redisson.cluster.ClusterSlotRange;
import org.redisson.config.*;
import org.redisson.misc.InfinitySemaphoreLatch;
import org.redisson.config.BaseConfig;
import org.redisson.config.BaseMasterSlaveServersConfig;
import org.redisson.config.MasterSlaveServersConfig;
import org.redisson.config.ReadMode;
import org.redisson.misc.RedisURI;
import org.redisson.pubsub.PublishSubscribeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors;
@ -64,77 +40,26 @@ import java.util.stream.Collectors;
*/
public class MasterSlaveConnectionManager implements ConnectionManager {
public static final Timeout DUMMY_TIMEOUT = new Timeout() {
@Override
public Timer timer() {
return null;
}
@Override
public TimerTask task() {
return null;
}
@Override
public boolean isExpired() {
return false;
}
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean cancel() {
return true;
}
};
protected final String id;
public static final int MAX_SLOT = 16384;
protected final ClusterSlotRange singleSlotRange = new ClusterSlotRange(0, MAX_SLOT-1);
private final Logger log = LoggerFactory.getLogger(getClass());
private HashedWheelTimer timer;
protected Codec codec;
protected final EventLoopGroup group;
protected final Class<? extends SocketChannel> socketChannelClass;
protected DNSMonitor dnsMonitor;
protected MasterSlaveServersConfig config;
private MasterSlaveEntry masterSlaveEntry;
private final Promise<Void> shutdownPromise = ImmediateEventExecutor.INSTANCE.newPromise();
private final InfinitySemaphoreLatch shutdownLatch = new InfinitySemaphoreLatch();
protected IdleConnectionWatcher connectionWatcher;
private final ConnectionEventsHub connectionEventsHub;
private final ExecutorService executor;
private final Config cfg;
protected final AddressResolverGroup<InetSocketAddress> resolverGroup;
protected PublishSubscribeService subscribeService;
private final ElementsSubscribeService elementsSubscribeService = new ElementsSubscribeService(this);
protected final ServiceManager serviceManager;
protected PublishSubscribeService subscribeService;
private final Map<RedisURI, RedisConnection> nodeConnections = new ConcurrentHashMap<>();
public MasterSlaveConnectionManager(BaseMasterSlaveServersConfig<?> cfg, Config config, UUID id, ConnectionEventsHub connectionEventsHub) {
this(config, id, connectionEventsHub);
public MasterSlaveConnectionManager(BaseMasterSlaveServersConfig<?> cfg, ServiceManager serviceManager) {
this.serviceManager = serviceManager;
if (cfg instanceof MasterSlaveServersConfig) {
this.config = (MasterSlaveServersConfig) cfg;
@ -146,74 +71,16 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
this.config = create(cfg);
}
initTimer();
serviceManager.setConfig(this.config);
serviceManager.initTimer();
subscribeService = new PublishSubscribeService(this);
}
private MasterSlaveConnectionManager(Config cfg, UUID id, ConnectionEventsHub connectionEventsHub) {
this.id = id.toString();
Version.logVersion();
if (cfg.getTransportMode() == TransportMode.EPOLL) {
if (cfg.getEventLoopGroup() == null) {
this.group = new EpollEventLoopGroup(cfg.getNettyThreads(), new DefaultThreadFactory("redisson-netty"));
} else {
this.group = cfg.getEventLoopGroup();
}
this.socketChannelClass = EpollSocketChannel.class;
if (PlatformDependent.isAndroid()) {
this.resolverGroup = DefaultAddressResolverGroup.INSTANCE;
} else {
this.resolverGroup = cfg.getAddressResolverGroupFactory().create(EpollDatagramChannel.class, DnsServerAddressStreamProviders.platformDefault());
}
} else if (cfg.getTransportMode() == TransportMode.KQUEUE) {
if (cfg.getEventLoopGroup() == null) {
this.group = new KQueueEventLoopGroup(cfg.getNettyThreads(), new DefaultThreadFactory("redisson-netty"));
} else {
this.group = cfg.getEventLoopGroup();
}
this.socketChannelClass = KQueueSocketChannel.class;
if (PlatformDependent.isAndroid()) {
this.resolverGroup = DefaultAddressResolverGroup.INSTANCE;
} else {
this.resolverGroup = cfg.getAddressResolverGroupFactory().create(KQueueDatagramChannel.class, DnsServerAddressStreamProviders.platformDefault());
}
} else {
if (cfg.getEventLoopGroup() == null) {
this.group = new NioEventLoopGroup(cfg.getNettyThreads(), new DefaultThreadFactory("redisson-netty"));
} else {
this.group = cfg.getEventLoopGroup();
}
this.socketChannelClass = NioSocketChannel.class;
if (PlatformDependent.isAndroid()) {
this.resolverGroup = DefaultAddressResolverGroup.INSTANCE;
} else {
this.resolverGroup = cfg.getAddressResolverGroupFactory().create(NioDatagramChannel.class, DnsServerAddressStreamProviders.platformDefault());
}
}
if (cfg.getExecutor() == null) {
int threads = Runtime.getRuntime().availableProcessors() * 2;
if (cfg.getThreads() != 0) {
threads = cfg.getThreads();
}
executor = Executors.newFixedThreadPool(threads, new DefaultThreadFactory("redisson"));
} else {
executor = cfg.getExecutor();
}
this.cfg = cfg;
this.codec = cfg.getCodec();
this.connectionEventsHub = connectionEventsHub;
if (cfg.getConnectionListener() != null) {
this.connectionEventsHub.addListener(cfg.getConnectionListener());
}
@Override
public ServiceManager getServiceManager() {
return serviceManager;
}
protected void closeNodeConnections() {
nodeConnections.values().stream()
.map(c -> c.getRedisClient().shutdownAsync())
@ -269,31 +136,11 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
});
}
@Override
public String getId() {
return id;
}
@Override
public boolean isClusterMode() {
return false;
}
@Override
public Config getCfg() {
return cfg;
}
@Override
public MasterSlaveServersConfig getConfig() {
return config;
}
@Override
public Codec getCodec() {
return codec;
}
@Override
public Collection<MasterSlaveEntry> getEntrySet() {
if (masterSlaveEntry != null) {
@ -302,30 +149,12 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
return Collections.emptyList();
}
private void initTimer() {
int[] timeouts = new int[]{config.getRetryInterval(), config.getTimeout()};
Arrays.sort(timeouts);
int minTimeout = timeouts[0];
if (minTimeout % 100 != 0) {
minTimeout = (minTimeout % 100) / 2;
} else if (minTimeout == 100) {
minTimeout = 50;
} else {
minTimeout = 100;
}
timer = new HashedWheelTimer(new DefaultThreadFactory("redisson-timer"), minTimeout, TimeUnit.MILLISECONDS, 1024, false);
connectionWatcher = new IdleConnectionWatcher(group, config);
subscribeService = new PublishSubscribeService(this);
}
public void connect() {
try {
if (config.checkSkipSlavesInit()) {
masterSlaveEntry = new SingleEntry(this, connectionWatcher, config);
masterSlaveEntry = new SingleEntry(this, serviceManager.getConnectionWatcher(), config);
} else {
masterSlaveEntry = new MasterSlaveEntry(this, connectionWatcher, config);
masterSlaveEntry = new MasterSlaveEntry(this, serviceManager.getConnectionWatcher(), config);
}
CompletableFuture<RedisClient> masterFuture = masterSlaveEntry.setupMasterEntry(new RedisURI(config.getMasterAddress()));
masterFuture.join();
@ -356,7 +185,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
if (config.getDnsMonitoringInterval() != -1) {
Set<RedisURI> slaveAddresses = config.getSlaveAddresses().stream().map(r -> new RedisURI(r)).collect(Collectors.toSet());
dnsMonitor = new DNSMonitor(this, masterHost,
slaveAddresses, config.getDnsMonitoringInterval(), resolverGroup);
slaveAddresses, config.getDnsMonitoringInterval(), serviceManager.getResolverGroup());
dnsMonitor.start();
}
}
@ -419,8 +248,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
return client;
}
@Override
public RedisClient createClient(NodeType type, RedisURI address, int timeout, int commandTimeout, String sslHostname) {
protected RedisClient createClient(NodeType type, RedisURI address, int timeout, int commandTimeout, String sslHostname) {
RedisClientConfig redisConfig = createRedisConfig(type, address, timeout, commandTimeout, sslHostname);
return RedisClient.create(redisConfig);
}
@ -435,11 +263,11 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
protected RedisClientConfig createRedisConfig(NodeType type, RedisURI address, int timeout, int commandTimeout, String sslHostname) {
RedisClientConfig redisConfig = new RedisClientConfig();
redisConfig.setAddress(address)
.setTimer(timer)
.setExecutor(executor)
.setResolverGroup(resolverGroup)
.setGroup(group)
.setSocketChannelClass(socketChannelClass)
.setTimer(serviceManager.getTimer())
.setExecutor(serviceManager.getExecutor())
.setResolverGroup(serviceManager.getResolverGroup())
.setGroup(serviceManager.getGroup())
.setSocketChannelClass(serviceManager.getSocketChannelClass())
.setConnectTimeout(timeout)
.setCommandTimeout(commandTimeout)
.setSslHostname(sslHostname)
@ -451,22 +279,22 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
.setSslKeystorePassword(config.getSslKeystorePassword())
.setSslProtocols(config.getSslProtocols())
.setClientName(config.getClientName())
.setKeepPubSubOrder(cfg.isKeepPubSubOrder())
.setKeepPubSubOrder(serviceManager.getCfg().isKeepPubSubOrder())
.setPingConnectionInterval(config.getPingConnectionInterval())
.setKeepAlive(config.isKeepAlive())
.setTcpNoDelay(config.isTcpNoDelay())
.setUsername(config.getUsername())
.setPassword(config.getPassword())
.setNettyHook(cfg.getNettyHook())
.setNettyHook(serviceManager.getCfg().getNettyHook())
.setCredentialsResolver(config.getCredentialsResolver())
.setConnectedListener(addr -> {
if (!isShuttingDown()) {
connectionEventsHub.fireConnect(addr);
if (!serviceManager.isShuttingDown()) {
serviceManager.getConnectionEventsHub().fireConnect(addr);
}
})
.setDisconnectedListener(addr -> {
if (!isShuttingDown()) {
connectionEventsHub.fireDisconnect(addr);
if (!serviceManager.isShuttingDown()) {
serviceManager.getConnectionEventsHub().fireDisconnect(addr);
}
});
@ -522,7 +350,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
MasterSlaveEntry entry = getEntry(source);
if (entry == null) {
CompletableFuture<RedisConnection> f = new CompletableFuture<>();
f.completeExceptionally(createNodeNotFoundException(source));
f.completeExceptionally(serviceManager.createNodeNotFoundException(source));
return f;
}
// fix for https://github.com/redisson/redisson/issues/1548
@ -554,7 +382,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
MasterSlaveEntry entry = getEntry(source);
if (entry == null) {
CompletableFuture<RedisConnection> f = new CompletableFuture<>();
f.completeExceptionally(createNodeNotFoundException(source));
f.completeExceptionally(serviceManager.createNodeNotFoundException(source));
return f;
}
@ -568,16 +396,6 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
return entry.connectionReadOp(command);
}
public RedisNodeNotFoundException createNodeNotFoundException(NodeSource source) {
RedisNodeNotFoundException ex;
if (source.getSlot() != null && source.getAddr() == null && source.getRedisClient() == null) {
ex = new RedisNodeNotFoundException("Node for slot: " + source.getSlot() + " hasn't been discovered yet. Check cluster slots coverage using CLUSTER NODES command. Increase value of retryAttempts and/or retryInterval settings.");
} else {
ex = new RedisNodeNotFoundException("Node: " + source + " hasn't been discovered yet. Increase value of retryAttempts and/or retryInterval settings.");
}
return ex;
}
@Override
public void releaseWrite(NodeSource source, RedisConnection connection) {
MasterSlaveEntry entry = getEntry(source);
@ -609,8 +427,8 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
if (dnsMonitor != null) {
dnsMonitor.stop();
}
connectionWatcher.stop();
serviceManager.getConnectionWatcher().stop();
List<CompletableFuture<Void>> futures = new ArrayList<>();
for (MasterSlaveEntry entry : getEntrySet()) {
@ -623,64 +441,26 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
} catch (Exception e) {
// skip
}
resolverGroup.close();
serviceManager.getResolverGroup().close();
shutdownLatch.close();
if (cfg.getExecutor() == null) {
executor.shutdown();
serviceManager.getShutdownLatch().close();
if (serviceManager.getCfg().getExecutor() == null) {
serviceManager.getExecutor().shutdown();
try {
executor.awaitTermination(timeout, unit);
serviceManager.getExecutor().awaitTermination(timeout, unit);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
shutdownPromise.trySuccess(null);
shutdownLatch.awaitUninterruptibly();
if (cfg.getEventLoopGroup() == null) {
group.shutdownGracefully(quietPeriod, timeout, unit).syncUninterruptibly();
}
serviceManager.getShutdownPromise().trySuccess(null);
serviceManager.getShutdownLatch().awaitUninterruptibly();
timer.stop();
}
@Override
public boolean isShuttingDown() {
return shutdownLatch.isClosed();
}
@Override
public boolean isShutdown() {
return group.isTerminated();
}
@Override
public EventLoopGroup getGroup() {
return group;
}
@Override
public Timeout newTimeout(TimerTask task, long delay, TimeUnit unit) {
try {
return timer.newTimeout(task, delay, unit);
} catch (IllegalStateException e) {
if (isShuttingDown()) {
return DUMMY_TIMEOUT;
}
throw e;
if (serviceManager.getCfg().getEventLoopGroup() == null) {
serviceManager.getGroup().shutdownGracefully(quietPeriod, timeout, unit).syncUninterruptibly();
}
}
@Override
public InfinitySemaphoreLatch getShutdownLatch() {
return shutdownLatch;
}
@Override
public Future<Void> getShutdownPromise() {
return shutdownPromise;
serviceManager.getTimer().stop();
}
protected void stopThreads() {
@ -691,65 +471,8 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
return subscribeService;
}
public ElementsSubscribeService getElementsSubscribeService() {
return elementsSubscribeService;
}
public ExecutorService getExecutor() {
return executor;
}
public RedisURI getLastClusterNode() {
return null;
}
@Override
public RedisURI applyNatMap(RedisURI address) {
return address;
}
@Override
public CompletableFuture<RedisURI> resolveIP(RedisURI address) {
return resolveIP(address.getScheme(), address);
}
protected final CompletableFuture<RedisURI> resolveIP(String scheme, RedisURI address) {
if (address.isIP()) {
RedisURI addr = toURI(scheme, address.getHost(), "" + address.getPort());
return CompletableFuture.completedFuture(addr);
}
CompletableFuture<RedisURI> result = new CompletableFuture<>();
AddressResolver<InetSocketAddress> resolver = resolverGroup.getResolver(getGroup().next());
InetSocketAddress addr = InetSocketAddress.createUnresolved(address.getHost(), address.getPort());
Future<InetSocketAddress> future = resolver.resolve(addr);
future.addListener((FutureListener<InetSocketAddress>) f -> {
if (!f.isSuccess()) {
log.error("Unable to resolve {}", address, f.cause());
result.completeExceptionally(f.cause());
return;
}
InetSocketAddress s = f.getNow();
RedisURI uri = toURI(scheme, s.getAddress().getHostAddress(), "" + address.getPort());
result.complete(uri);
});
return result;
}
protected final RedisURI toURI(String scheme, String host, String port) {
// convert IPv6 address to unified compressed format
if (NetUtil.isValidIpV6Address(host)) {
byte[] addr = NetUtil.createByteArrayFromIpAddressString(host);
try {
InetAddress ia = InetAddress.getByAddress(host, addr);
host = ia.getHostAddress();
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
}
RedisURI uri = new RedisURI(scheme + "://" + host + ":" + port);
return applyNatMap(uri);
}
}

@ -289,7 +289,7 @@ public class MasterSlaveEntry {
MasterSlaveEntry entry = connectionManager.getEntry(key);
if (entry == null) {
connectionManager.newTimeout(timeout ->
connectionManager.getServiceManager().newTimeout(timeout ->
reattachBlockingQueue(commandData), 1, TimeUnit.SECONDS);
return;
}
@ -297,7 +297,7 @@ public class MasterSlaveEntry {
CompletableFuture<RedisConnection> newConnectionFuture = entry.connectionWriteOp(commandData.getCommand());
newConnectionFuture.whenComplete((newConnection, e) -> {
if (e != null) {
connectionManager.newTimeout(timeout ->
connectionManager.getServiceManager().newTimeout(timeout ->
reattachBlockingQueue(commandData), 1, TimeUnit.SECONDS);
return;
}
@ -310,7 +310,7 @@ public class MasterSlaveEntry {
ChannelFuture channelFuture = newConnection.send(commandData);
channelFuture.addListener(future -> {
if (!future.isSuccess()) {
connectionManager.newTimeout(timeout ->
connectionManager.getServiceManager().newTimeout(timeout ->
reattachBlockingQueue(commandData), 1, TimeUnit.SECONDS);
return;
}

@ -80,7 +80,7 @@ public class RedisClientEntry implements ClusterNode {
return res;
});
commandExecutor.getConnectionManager().newTimeout(t -> {
commandExecutor.getServiceManager().newTimeout(t -> {
RedisTimeoutException ex = new RedisTimeoutException("Command execution timeout for command: PING, Redis client: " + client);
s.completeExceptionally(ex);
}, timeout, timeUnit);

@ -21,14 +21,20 @@ import org.redisson.client.RedisClient;
import org.redisson.client.RedisConnection;
import org.redisson.client.RedisConnectionException;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.config.*;
import org.redisson.config.BaseMasterSlaveServersConfig;
import org.redisson.config.MasterSlaveServersConfig;
import org.redisson.config.ReadMode;
import org.redisson.config.ReplicatedServersConfig;
import org.redisson.connection.ClientConnectionsEntry.FreezeReason;
import org.redisson.misc.RedisURI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetSocketAddress;
import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ConcurrentHashMap;
@ -61,8 +67,8 @@ public class ReplicatedConnectionManager extends MasterSlaveConnectionManager {
private ReplicatedServersConfig cfg;
public ReplicatedConnectionManager(ReplicatedServersConfig cfg, Config config, UUID id, ConnectionEventsHub connectionEventsHub) {
super(cfg, config, id, connectionEventsHub);
public ReplicatedConnectionManager(ReplicatedServersConfig cfg, ServiceManager serviceManager) {
super(cfg, serviceManager);
}
@Override
@ -118,12 +124,12 @@ public class ReplicatedConnectionManager extends MasterSlaveConnectionManager {
}
private void scheduleMasterChangeCheck(ReplicatedServersConfig cfg) {
if (isShuttingDown()) {
if (serviceManager.isShuttingDown()) {
return;
}
monitorFuture = group.schedule(() -> {
if (isShuttingDown()) {
monitorFuture = serviceManager.getGroup().schedule(() -> {
if (serviceManager.isShuttingDown()) {
return;
}
@ -175,12 +181,12 @@ public class ReplicatedConnectionManager extends MasterSlaveConnectionManager {
return connectionFuture
.thenCompose(c -> {
if (cfg.isMonitorIPChanges()) {
return resolveIP(uri);
return serviceManager.resolveIP(uri);
}
return CompletableFuture.completedFuture(uri);
})
.thenCompose(ip -> {
if (isShuttingDown()) {
if (serviceManager.isShuttingDown()) {
return CompletableFuture.completedFuture(null);
}

@ -27,7 +27,10 @@ import org.redisson.client.*;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.client.protocol.RedisStrictCommand;
import org.redisson.config.*;
import org.redisson.config.BaseMasterSlaveServersConfig;
import org.redisson.config.MasterSlaveServersConfig;
import org.redisson.config.ReadMode;
import org.redisson.config.SentinelServersConfig;
import org.redisson.connection.ClientConnectionsEntry.FreezeReason;
import org.redisson.misc.RedisURI;
import org.slf4j.Logger;
@ -64,10 +67,11 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
private String scheme;
private SentinelServersConfig cfg;
public SentinelConnectionManager(SentinelServersConfig cfg, Config config, UUID id, ConnectionEventsHub connectionEventsHub) {
super(cfg, config, id, connectionEventsHub);
public SentinelConnectionManager(SentinelServersConfig cfg, ServiceManager serviceManager) {
super(cfg, serviceManager);
this.serviceManager.setNatMapper(cfg.getNatMapper());
this.sentinelResolver = resolverGroup.getResolver(getGroup().next());
this.sentinelResolver = serviceManager.getResolverGroup().getResolver(serviceManager.getGroup().next());
for (String address : cfg.getSentinelAddresses()) {
RedisURI addr = new RedisURI(address);
@ -111,7 +115,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
throw new RedisConnectionException("Master node is undefined! SENTINEL GET-MASTER-ADDR-BY-NAME command returns empty result!");
}
RedisURI masterHost = resolveIP(scheme, master).join();
RedisURI masterHost = serviceManager.resolveIP(scheme, master).join();
this.config.setMasterAddress(masterHost.toString());
currentMaster.set(masterHost);
log.info("master: {} added", masterHost);
@ -265,7 +269,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
}
private void scheduleSentinelDNSCheck() {
monitorFuture = group.schedule(new Runnable() {
monitorFuture = serviceManager.getGroup().schedule(new Runnable() {
@Override
public void run() {
AtomicInteger sentinelsCounter = new AtomicInteger(sentinelHosts.size());
@ -290,7 +294,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
future.getNow().stream()
.map(addr -> toURI(addr))
.filter(uri -> !sentinels.containsKey(uri) && !disconnectedSentinels.contains(uri))
.forEach(uri -> registerSentinel(uri, getConfig(), host.getHost()));
.forEach(uri -> registerSentinel(uri, serviceManager.getConfig(), host.getHost()));
});
if (commonListener != null) {
allNodes.addListener(commonListener);
@ -299,7 +303,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
}
private void scheduleChangeCheck(SentinelServersConfig cfg, Iterator<RedisClient> iterator) {
monitorFuture = group.schedule(new Runnable() {
monitorFuture = serviceManager.getGroup().schedule(new Runnable() {
@Override
public void run() {
AtomicReference<Throwable> lastException = new AtomicReference<Throwable>();
@ -325,7 +329,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
scheduleChangeCheck(cfg, null);
return;
}
if (!getShutdownLatch().acquire()) {
if (!serviceManager.getShutdownLatch().acquire()) {
return;
}
@ -335,7 +339,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
connectionFuture.whenComplete((connection, e) -> {
if (e != null) {
lastException.set(e);
getShutdownLatch().release();
serviceManager.getShutdownLatch().release();
checkState(cfg, iterator, lastException);
return;
}
@ -364,7 +368,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
log.error("Can't execute SENTINEL commands on {}", connection.getRedisClient().getAddr(), e);
}
getShutdownLatch().release();
serviceManager.getShutdownLatch().release();
if (e != null) {
scheduleChangeCheck(cfg, iterator);
} else {
@ -394,9 +398,9 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
}).map(m -> {
String ip = m.get("ip");
String port = m.get("port");
return toURI(scheme, ip, port);
return serviceManager.toURI(scheme, ip, port);
}).map(addr -> {
CompletionStage<RedisURI> f = resolveIP(addr);
CompletionStage<RedisURI> f = serviceManager.resolveIP(addr);
return f.exceptionally(ex -> {
log.error("unable to resolve hostname", ex);
return null;
@ -480,7 +484,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
MasterSlaveEntry entry = getEntry(singleSlotRange.getStartSlot());
entry.getAllEntries().stream()
.map(e -> e.getClient().getAddr())
.map(a -> toURI(scheme, a.getAddress().getHostAddress(), String.valueOf(a.getPort())))
.map(a -> serviceManager.toURI(scheme, a.getAddress().getHostAddress(), String.valueOf(a.getPort())))
.filter(a -> !currentSlaves.contains(a) && !a.equals(currentMaster.get()))
.forEach(a -> slaveDown(a));
});
@ -489,7 +493,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
private CompletionStage<RedisURI> checkMasterChange(SentinelServersConfig cfg, RedisConnection connection) {
RFuture<RedisURI> masterFuture = connection.async(StringCodec.INSTANCE, masterHostCommand, cfg.getMasterName());
return masterFuture.thenCompose(u -> resolveIP(scheme, u))
return masterFuture.thenCompose(u -> serviceManager.resolveIP(scheme, u))
.whenComplete((newMaster, e) -> {
if (e != null) {
return;
@ -512,7 +516,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
.filter(uri -> !sentinels.containsKey(uri))
.forEach(uri -> {
disconnectedSentinels.remove(uri);
registerSentinel(uri, getConfig(), null);
registerSentinel(uri, serviceManager.getConfig(), null);
});
sentinels.keySet().stream()
@ -568,12 +572,12 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
}
private CompletableFuture<RedisURI> resolveIP(String host, String port) {
RedisURI uri = toURI(scheme, host, port);
return resolveIP(uri);
RedisURI uri = serviceManager.toURI(scheme, host, port);
return serviceManager.resolveIP(uri);
}
private RedisURI toURI(InetSocketAddress addr) {
return toURI(scheme, addr.getAddress().getHostAddress(), "" + addr.getPort());
return serviceManager.toURI(scheme, addr.getAddress().getHostAddress(), "" + addr.getPort());
}
private CompletableFuture<Void> addSlave(RedisURI uri) {
@ -664,8 +668,7 @@ public class SentinelConnectionManager extends MasterSlaveConnectionManager {
super.shutdown();
}
@Override
public RedisURI applyNatMap(RedisURI address) {
private RedisURI applyNatMap(RedisURI address) {
RedisURI result = cfg.getNatMapper().map(address);
if (!result.equals(address)) {
log.debug("nat mapped uri: {} to {}", address, result);

@ -15,9 +15,10 @@
*/
package org.redisson.connection;
import org.redisson.config.*;
import java.util.UUID;
import org.redisson.config.MasterSlaveServersConfig;
import org.redisson.config.ReadMode;
import org.redisson.config.SingleServerConfig;
import org.redisson.config.SubscriptionMode;
/**
*
@ -26,8 +27,8 @@ import java.util.UUID;
*/
public class SingleConnectionManager extends MasterSlaveConnectionManager {
public SingleConnectionManager(SingleServerConfig cfg, Config config, UUID id, ConnectionEventsHub connectionEventsHub) {
super(create(cfg), config, id, connectionEventsHub);
public SingleConnectionManager(SingleServerConfig cfg, ServiceManager serviceManager) {
super(create(cfg), serviceManager);
}
private static MasterSlaveServersConfig create(SingleServerConfig cfg) {

@ -64,7 +64,7 @@ public class LoadBalancerManager {
ClientConnectionsEntry entry = getEntry(address);
if (entry != null) {
if (connectionManager.isClusterMode()) {
entry.getClient().getConfig().setReadOnly(nodeType == NodeType.SLAVE && connectionManager.getConfig().getReadMode() != ReadMode.MASTER);
entry.getClient().getConfig().setReadOnly(nodeType == NodeType.SLAVE && connectionManager.getServiceManager().getConfig().getReadMode() != ReadMode.MASTER);
}
entry.setNodeType(nodeType);
}
@ -162,7 +162,7 @@ public class LoadBalancerManager {
if (e != null) {
log.error("Unable to unfreeze entry: {}", entry, e);
entry.setInitialized(false);
connectionManager.newTimeout(t -> {
connectionManager.getServiceManager().newTimeout(t -> {
unfreeze(entry, freezeReason);
}, 1, TimeUnit.SECONDS);
return;

@ -251,7 +251,7 @@ abstract class ConnectionPool<T extends RedisConnection> {
private void connectTo(ClientConnectionsEntry entry, CompletableFuture<T> promise, RedisCommand<?> command) {
if (promise.isDone()) {
connectionManager.getGroup().submit(() -> {
connectionManager.getServiceManager().getGroup().submit(() -> {
releaseConnection(entry);
});
return;
@ -349,10 +349,10 @@ abstract class ConnectionPool<T extends RedisConnection> {
}
private void scheduleCheck(ClientConnectionsEntry entry) {
connectionManager.newTimeout(timeout -> {
connectionManager.getServiceManager().newTimeout(timeout -> {
synchronized (entry) {
if (entry.getFreezeReason() != FreezeReason.RECONNECT
|| connectionManager.isShuttingDown()) {
|| connectionManager.getServiceManager().isShuttingDown()) {
return;
}
}

@ -48,13 +48,13 @@ abstract class EvictionTask implements Runnable {
EvictionTask(CommandAsyncExecutor executor) {
super();
this.executor = executor;
this.minDelay = executor.getConnectionManager().getCfg().getMinCleanUpDelay();
this.maxDelay = executor.getConnectionManager().getCfg().getMaxCleanUpDelay();
this.keysLimit = executor.getConnectionManager().getCfg().getCleanUpKeysAmount();
this.minDelay = executor.getServiceManager().getCfg().getMinCleanUpDelay();
this.maxDelay = executor.getServiceManager().getCfg().getMaxCleanUpDelay();
this.keysLimit = executor.getServiceManager().getCfg().getCleanUpKeysAmount();
}
public void schedule() {
scheduledFuture = executor.getConnectionManager().getGroup().schedule(this, delay, TimeUnit.SECONDS);
scheduledFuture = executor.getServiceManager().getGroup().schedule(this, delay, TimeUnit.SECONDS);
}
public ScheduledFuture<?> getScheduledFuture() {
@ -67,7 +67,7 @@ abstract class EvictionTask implements Runnable {
@Override
public void run() {
if (executor.getConnectionManager().isShuttingDown()) {
if (executor.getServiceManager().isShuttingDown()) {
return;
}

@ -98,7 +98,7 @@ public class RedissonExecutorRemoteService extends RedissonRemoteService {
startedListeners.forEach(l -> l.onStarted(request.getId()));
if (taskTimeout > 0) {
commandExecutor.getConnectionManager().getGroup().schedule(() -> {
commandExecutor.getServiceManager().getGroup().schedule(() -> {
cancelRequestFuture.complete(new RemoteServiceCancelRequest(true, false));
}, taskTimeout, TimeUnit.MILLISECONDS);
}

@ -233,7 +233,7 @@ public class TasksRunnerService implements RemoteExecutorService {
return;
}
commandExecutor.getConnectionManager().newTimeout(timeout -> renewRetryTime(requestId),
commandExecutor.getServiceManager().newTimeout(timeout -> renewRetryTime(requestId),
Math.max(1000, retryInterval / 2), TimeUnit.MILLISECONDS);
}

@ -217,7 +217,7 @@ public class TasksService extends BaseRemoteService {
});
removeFuture.thenAccept(r -> {
commandExecutor.getConnectionManager().newTimeout(timeout -> {
commandExecutor.getServiceManager().newTimeout(timeout -> {
f.complete(false);
}, 60, TimeUnit.SECONDS);
});
@ -228,7 +228,7 @@ public class TasksService extends BaseRemoteService {
private CompletableFuture<RemoteServiceCancelResponse> scheduleCancelResponseCheck(String mapName, String requestId) {
CompletableFuture<RemoteServiceCancelResponse> cancelResponse = new CompletableFuture<>();
commandExecutor.getConnectionManager().newTimeout(timeout -> {
commandExecutor.getServiceManager().newTimeout(timeout -> {
if (cancelResponse.isDone()) {
return;
}

@ -262,7 +262,7 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
if (value == null) {
cacheManager.getStatBean(this).addMisses(1);
if (config.isReadThrough()) {
redisson.getConnectionManager().getExecutor().execute(() -> {
redisson.getServiceManager().getExecutor().execute(() -> {
try {
V val = loadValue(key);
result.complete(val);
@ -1059,7 +1059,7 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
int nullValues = r.size() - notNullEntries.size();
if (config.isReadThrough() && nullValues > 0) {
cacheManager.getStatBean(this).addMisses(nullValues);
commandExecutor.getConnectionManager().getExecutor().execute(() -> {
commandExecutor.getServiceManager().getExecutor().execute(() -> {
try {
Set<K> nullKeys = r.entrySet().stream()
.filter(e -> e.getValue() == null)
@ -1129,7 +1129,7 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
return;
}
commandExecutor.getConnectionManager().getExecutor().execute(new Runnable() {
commandExecutor.getServiceManager().getExecutor().execute(new Runnable() {
@Override
public void run() {
for (K key : keys) {
@ -1299,7 +1299,7 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
}
if (atomicExecution) {
commandExecutor.getConnectionManager().getExecutor().execute(r);
commandExecutor.getServiceManager().getExecutor().execute(r);
} else {
r.run();
}
@ -1667,7 +1667,7 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
if (atomicExecution) {
future.whenComplete((res, ex) -> {
if (config.isWriteThrough()) {
commandExecutor.getConnectionManager().getExecutor().execute(r);
commandExecutor.getServiceManager().getExecutor().execute(r);
} else {
result.complete(null);
}
@ -1734,7 +1734,7 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
if (r) {
cacheManager.getStatBean(this).addPuts(1);
if (config.isWriteThrough()) {
commandExecutor.getConnectionManager().getExecutor().execute(() -> {
commandExecutor.getServiceManager().getExecutor().execute(() -> {
try {
cacheWriter.write(new JCacheEntry<K, V>(key, value));
} catch (Exception e) {
@ -1818,7 +1818,7 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
return;
}
commandExecutor.getConnectionManager().getExecutor().submit(() -> {
commandExecutor.getServiceManager().getExecutor().submit(() -> {
try {
cacheWriter.delete(key);
if (oldValue != null) {
@ -1978,7 +1978,7 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
}
if (r) {
commandExecutor.getConnectionManager().getExecutor().submit(() -> {
commandExecutor.getServiceManager().getExecutor().submit(() -> {
try {
cacheWriter.delete(key);
} catch (Exception e) {
@ -2268,7 +2268,7 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
}
if (config.isWriteThrough()) {
commandExecutor.getConnectionManager().getExecutor().submit(() -> {
commandExecutor.getServiceManager().getExecutor().submit(() -> {
try {
cacheWriter.delete(key);
} catch (Exception ex) {
@ -2490,7 +2490,7 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
if (res == 1) {
if (config.isWriteThrough()) {
commandExecutor.getConnectionManager().getExecutor().submit(() -> {
commandExecutor.getServiceManager().getExecutor().submit(() -> {
try {
cacheWriter.write(new JCacheEntry<K, V>(key, newValue));
} catch (Exception e) {
@ -2809,7 +2809,7 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
if (r) {
if (config.isWriteThrough()) {
commandExecutor.getConnectionManager().getExecutor().submit(() -> {
commandExecutor.getServiceManager().getExecutor().submit(() -> {
try {
cacheWriter.write(new JCacheEntry<K, V>(key, value));
} catch (Exception e) {
@ -2874,7 +2874,7 @@ public class JCache<K, V> extends RedissonObject implements Cache<K, V>, CacheAs
if (r != null) {
if (config.isWriteThrough()) {
commandExecutor.getConnectionManager().getExecutor().submit(() -> {
commandExecutor.getServiceManager().getExecutor().submit(() -> {
cacheManager.getStatBean(this).addHits(1);
cacheManager.getStatBean(this).addPuts(1);
try {

@ -135,7 +135,7 @@ public class CoordinatorTask<KOut, VOut> implements Callable<Object>, Serializab
return executeCollator();
}
private Object executeCollator() throws ExecutionException, Exception {
private Object executeCollator() throws Exception {
if (collator == null) {
if (timeout > 0) {
redisson.getMap(resultMapName).clearExpire();
@ -143,14 +143,14 @@ public class CoordinatorTask<KOut, VOut> implements Callable<Object>, Serializab
return null;
}
Callable<Object> collatorTask = new CollatorTask<KOut, VOut, Object>(redisson, collator, resultMapName, objectCodecClass);
Callable<Object> collatorTask = new CollatorTask<>(redisson, collator, resultMapName, objectCodecClass);
long timeSpent = System.currentTimeMillis() - startTime;
if (isTimeoutExpired(timeSpent)) {
throw new MapReduceTimeoutException();
}
if (timeout > 0) {
ExecutorService executor = ((Redisson) redisson).getConnectionManager().getExecutor();
ExecutorService executor = ((Redisson) redisson).getServiceManager().getExecutor();
java.util.concurrent.Future<?> collatorFuture = executor.submit(collatorTask);
try {
return collatorFuture.get(timeout - timeSpent, TimeUnit.MILLISECONDS);

@ -111,7 +111,7 @@ abstract class MapReduceExecutor<M, VIn, KOut, VOut> implements RMapReduceExecut
});
if (timeout > 0) {
commandExecutor.getConnectionManager().newTimeout(task -> {
commandExecutor.getServiceManager().newTimeout(task -> {
f.completeExceptionally(new MapReduceTimeoutException());
}, timeout, TimeUnit.MILLISECONDS);
}

@ -23,7 +23,7 @@ import org.redisson.client.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.pubsub.PubSubStatusMessage;
import org.redisson.client.protocol.pubsub.PubSubType;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ServiceManager;
import java.util.EventListener;
import java.util.LinkedList;
@ -47,13 +47,13 @@ public class PubSubConnectionEntry {
private static final Queue<RedisPubSubListener<?>> EMPTY_QUEUE = new LinkedList<>();
private final ConnectionManager connectionManager;
private final ServiceManager serviceManager;
public PubSubConnectionEntry(RedisPubSubConnection conn, ConnectionManager connectionManager) {
public PubSubConnectionEntry(RedisPubSubConnection conn, ServiceManager serviceManager) {
super();
this.conn = conn;
this.connectionManager = connectionManager;
this.subscribedChannelsAmount = new AtomicInteger(connectionManager.getConfig().getSubscriptionsPerConnection());
this.serviceManager = serviceManager;
this.subscribedChannelsAmount = new AtomicInteger(serviceManager.getConfig().getSubscriptionsPerConnection());
}
public int countListeners(ChannelName channelName) {
@ -157,7 +157,7 @@ public class PubSubConnectionEntry {
}
public boolean isFree() {
return subscribedChannelsAmount.get() == connectionManager.getConfig().getSubscriptionsPerConnection();
return subscribedChannelsAmount.get() == serviceManager.getConfig().getSubscriptionsPerConnection();
}
public void subscribe(Codec codec, PubSubType type, ChannelName channelName, CompletableFuture<Void> subscribeFuture) {
@ -176,11 +176,11 @@ public class PubSubConnectionEntry {
return;
}
connectionManager.newTimeout(t -> {
serviceManager.newTimeout(t -> {
subscribeFuture.completeExceptionally(new RedisTimeoutException(
"Subscription timeout after " + connectionManager.getConfig().getTimeout() + "ms. " +
"Subscription timeout after " + serviceManager.getConfig().getTimeout() + "ms. " +
"Check network and/or increase 'timeout' parameter."));
}, connectionManager.getConfig().getTimeout(), TimeUnit.MILLISECONDS);
}, serviceManager.getConfig().getTimeout(), TimeUnit.MILLISECONDS);
});
}
@ -223,12 +223,12 @@ public class PubSubConnectionEntry {
return;
}
connectionManager.newTimeout(timeout -> {
serviceManager.newTimeout(timeout -> {
if (executed.get()) {
return;
}
conn.onMessage(new PubSubStatusMessage(commandType, channel));
}, connectionManager.getConfig().getTimeout(), TimeUnit.MILLISECONDS);
}, serviceManager.getConfig().getTimeout(), TimeUnit.MILLISECONDS);
});
}

@ -104,7 +104,7 @@ public class PublishSubscribeService {
public PublishSubscribeService(ConnectionManager connectionManager) {
super();
this.connectionManager = connectionManager;
this.config = connectionManager.getConfig();
this.config = connectionManager.getServiceManager().getConfig();
for (int i = 0; i < locks.length; i++) {
locks[i] = new AsyncSemaphore(1);
}
@ -202,7 +202,7 @@ public class PublishSubscribeService {
CompletableFuture<PubSubConnectionEntry> promise = new CompletableFuture<>();
AsyncSemaphore lock = getSemaphore(channelName);
int timeout = config.getTimeout() + config.getRetryInterval() * config.getRetryAttempts();
Timeout lockTimeout = connectionManager.newTimeout(t -> {
Timeout lockTimeout = connectionManager.getServiceManager().newTimeout(t -> {
promise.completeExceptionally(new RedisTimeoutException(
"Unable to acquire subscription lock after " + timeout + "ms. " +
"Try to increase 'timeout', 'subscriptionsPerConnection', 'subscriptionConnectionPoolSize' parameters."));
@ -255,7 +255,7 @@ public class PublishSubscribeService {
}
public void timeout(CompletableFuture<?> promise, long timeout) {
Timeout task = connectionManager.newTimeout(t -> {
Timeout task = connectionManager.getServiceManager().newTimeout(t -> {
promise.completeExceptionally(new RedisTimeoutException(
"Unable to acquire subscription lock after " + timeout + "ms. " +
"Try to increase 'timeout', 'subscriptionsPerConnection', 'subscriptionConnectionPoolSize' parameters."));
@ -287,7 +287,7 @@ public class PublishSubscribeService {
MasterSlaveEntry entry = getEntry(channelName);
if (entry == null) {
connectionManager.newTimeout(tt -> {
connectionManager.getServiceManager().newTimeout(tt -> {
trySubscribe(codec, channelName, promise, type, lock, attempts, listeners);
}, config.getRetryInterval(), TimeUnit.MILLISECONDS);
return;
@ -319,7 +319,7 @@ public class PublishSubscribeService {
freePubSubLock.release();
CompletableFuture<RedisPubSubConnection> connectFuture = connect(codec, channelName, entry, promise, type, lock, listeners);
connectionManager.newTimeout(t -> {
connectionManager.getServiceManager().newTimeout(t -> {
if (!connectFuture.cancel(false)
&& !connectFuture.isCompletedExceptionally()) {
return;
@ -413,7 +413,7 @@ public class PublishSubscribeService {
connFuture.thenAccept(conn -> {
freePubSubLock.acquire().thenAccept(c -> {
PubSubConnectionEntry entry = new PubSubConnectionEntry(conn, connectionManager);
PubSubConnectionEntry entry = new PubSubConnectionEntry(conn, connectionManager.getServiceManager());
int remainFreeAmount = entry.tryAcquire();
PubSubKey key = new PubSubKey(channelName, msEntry);
@ -447,7 +447,7 @@ public class PublishSubscribeService {
public CompletableFuture<Void> unsubscribe(PubSubType topicType, ChannelName channelName) {
PubSubConnectionEntry entry = name2PubSubConnection.remove(createKey(channelName));
if (entry == null || connectionManager.isShuttingDown()) {
if (entry == null || connectionManager.getServiceManager().isShuttingDown()) {
return CompletableFuture.completedFuture(null);
}
@ -515,7 +515,7 @@ public class PublishSubscribeService {
}
private CompletableFuture<Codec> unsubscribe(ChannelName channelName, MasterSlaveEntry e, PubSubType topicType) {
if (connectionManager.isShuttingDown()) {
if (connectionManager.getServiceManager().isShuttingDown()) {
return CompletableFuture.completedFuture(null);
}
@ -634,7 +634,7 @@ public class PublishSubscribeService {
subscribe(subscribeCodec, channelName, listeners.toArray(new RedisPubSubListener[0]));
subscribeFuture.whenComplete((res, e) -> {
if (e != null) {
connectionManager.newTimeout(task -> {
connectionManager.getServiceManager().newTimeout(task -> {
subscribe(channelName, listeners, subscribeCodec);
}, 1, TimeUnit.SECONDS);
return;
@ -650,7 +650,7 @@ public class PublishSubscribeService {
ssubscribe(subscribeCodec, channelName, listeners.toArray(new RedisPubSubListener[0]));
subscribeFuture.whenComplete((res, e) -> {
if (e != null) {
connectionManager.newTimeout(task -> {
connectionManager.getServiceManager().newTimeout(task -> {
ssubscribe(channelName, listeners, subscribeCodec);
}, 1, TimeUnit.SECONDS);
return;
@ -671,7 +671,7 @@ public class PublishSubscribeService {
.orElse(null);
}
if (entry == null) {
connectionManager.newTimeout(task -> {
connectionManager.getServiceManager().newTimeout(task -> {
psubscribe(oldEntry, channelName, listeners, subscribeCodec);
}, 1, TimeUnit.SECONDS);
return;
@ -681,7 +681,7 @@ public class PublishSubscribeService {
subscribe(PubSubType.PSUBSCRIBE, subscribeCodec, channelName, entry, listeners.toArray(new RedisPubSubListener[0]));
subscribeFuture.whenComplete((res, e) -> {
if (e != null) {
connectionManager.newTimeout(task -> {
connectionManager.getServiceManager().newTimeout(task -> {
psubscribe(oldEntry, channelName, listeners, subscribeCodec);
}, 1, TimeUnit.SECONDS);
return;
@ -709,7 +709,7 @@ public class PublishSubscribeService {
AsyncSemaphore semaphore = getSemaphore(channelName);
CompletableFuture<Void> sf = semaphore.acquire();
int timeout = config.getTimeout() + config.getRetryInterval() * config.getRetryAttempts();
connectionManager.newTimeout(t -> {
connectionManager.getServiceManager().newTimeout(t -> {
sf.completeExceptionally(new RedisTimeoutException("Remove listeners operation timeout: (" + timeout + "ms) for " + channelName + " topic"));
}, timeout, TimeUnit.MILLISECONDS);
@ -758,7 +758,7 @@ public class PublishSubscribeService {
CompletableFuture<Void> sf = semaphore.acquire();
int timeout = config.getTimeout() + config.getRetryInterval() * config.getRetryAttempts();
connectionManager.newTimeout(t -> {
connectionManager.getServiceManager().newTimeout(t -> {
sf.completeExceptionally(new RedisTimeoutException("Remove listeners operation timeout: (" + timeout + "ms) for " + channelName + " topic"));
}, timeout, TimeUnit.MILLISECONDS);

@ -75,7 +75,7 @@ public class RedisNode implements RedisClusterMaster, RedisClusterSlave, RedisMa
public RFuture<Boolean> pingAsync(long timeout, TimeUnit timeUnit) {
RFuture<Boolean> f = commandExecutor.readAsync(client, null, RedisCommands.PING_BOOL);
CompletionStage<Boolean> s = f.exceptionally(e -> false);
commandExecutor.getConnectionManager().newTimeout(t -> {
commandExecutor.getServiceManager().newTimeout(t -> {
RedisTimeoutException ex = new RedisTimeoutException("Command execution timeout (" + timeUnit.toMillis(timeout) + "ms) for command: PING, Redis client: " + client);
s.toCompletableFuture().completeExceptionally(ex);
}, timeout, timeUnit);

@ -83,7 +83,7 @@ public abstract class BaseRemoteProxy {
Arrays.asList(ackName), optionsCopy.getAckTimeoutInMillis());
return ackClientsFuture.thenCompose(res -> {
if (res) {
return pollResponse(commandExecutor.getConnectionManager().getConfig().getTimeout(), requestId, true);
return pollResponse(commandExecutor.getServiceManager().getConfig().getTimeout(), requestId, true);
}
return CompletableFuture.completedFuture(null);
});
@ -121,7 +121,7 @@ public abstract class BaseRemoteProxy {
}
private <T extends RRemoteServiceResponse> ScheduledFuture<?> createResponseTimeout(long timeout, String requestId, CompletableFuture<T> responseFuture) {
return commandExecutor.getConnectionManager().getGroup().schedule(new Runnable() {
return commandExecutor.getServiceManager().getGroup().schedule(new Runnable() {
@Override
public void run() {
synchronized (responses) {

@ -65,7 +65,7 @@ public abstract class BaseRemoteService {
public BaseRemoteService(Codec codec, String name, CommandAsyncExecutor commandExecutor, String executorId, ConcurrentMap<String, ResponseEntry> responses) {
this.codec = codec;
this.name = commandExecutor.getConnectionManager().getConfig().getNameMapper().map(name);
this.name = commandExecutor.getServiceManager().getConfig().getNameMapper().map(name);
this.commandExecutor = commandExecutor;
this.executorId = executorId;
this.responses = responses;
@ -143,7 +143,7 @@ public abstract class BaseRemoteService {
}
protected <T> void scheduleCheck(String mapName, String requestId, CompletableFuture<T> cancelRequest) {
commandExecutor.getConnectionManager().newTimeout(new TimerTask() {
commandExecutor.getServiceManager().newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
if (cancelRequest.isDone()) {

@ -517,7 +517,7 @@ public class RedissonTransaction implements RTransaction {
RFuture<BatchResult<?>> publishFuture = publishBatch.executeAsync();
publishFuture.thenAccept(res2 -> {
commandExecutor.getConnectionManager().newTimeout(timeout ->
commandExecutor.getServiceManager().newTimeout(timeout ->
result.completeExceptionally(
new TransactionTimeoutException("Unable to execute transaction within "
+ options.getResponseTimeout() + "ms")),

@ -1061,7 +1061,7 @@ public abstract class BaseMapTest extends BaseTest {
Assumptions.assumeTrue(!(map instanceof RMapCache));
map.put("1", "1234");
assertThat(map.valueSize("4")).isZero();
assertThat(map.valueSize("1")).isEqualTo(7);
assertThat(map.valueSize("1")).isEqualTo(5);
destroy(map);
}

@ -121,10 +121,10 @@ public class RedissonListMultimapTest extends BaseTest {
public void testSizeInMemory() {
RListMultimap<String, String> list = redisson.getListMultimap("test");
list.put("1", "2");
assertThat(list.sizeInMemory()).isEqualTo(160);
assertThat(list.sizeInMemory()).isEqualTo(159);
list.put("1", "3");
assertThat(list.sizeInMemory()).isEqualTo(166);
assertThat(list.sizeInMemory()).isEqualTo(164);
}
@Test

@ -223,10 +223,10 @@ public class RedissonSetMultimapTest extends BaseTest {
public void testSizeInMemory() {
RSetMultimap<String, String> set = redisson.getSetMultimap("test");
set.put("1", "2");
assertThat(set.sizeInMemory()).isEqualTo(229);
assertThat(set.sizeInMemory()).isEqualTo(228);
set.put("1", "3");
assertThat(set.sizeInMemory()).isEqualTo(259);
assertThat(set.sizeInMemory()).isEqualTo(257);
}
@Test

@ -2,24 +2,18 @@ package org.redisson;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;
import org.redisson.api.HostPortNatMapper;
import org.redisson.api.NatMapper;
import org.redisson.api.RTopic;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.connection.balancer.RandomLoadBalancer;
import org.redisson.misc.RedisURI;
import org.testcontainers.containers.FixedHostPortGenericContainer;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.startupcheck.IsRunningStartupCheckStrategy;
import org.testcontainers.containers.startupcheck.MinimumDurationRunningStartupCheckStrategy;
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import static org.assertj.core.api.Assertions.assertThat;

@ -133,7 +133,7 @@ public class RedissonTransactionalBucketReactiveTest extends BaseReactiveTest {
RTransactionReactive transaction = redisson.createTransaction(TransactionOptions.defaults());
RBucketReactive<String> set = transaction.getBucket("test");
assertThat(sync(set.get())).isEqualTo("123");
assertThat(sync(set.size())).isEqualTo(6);
assertThat(sync(set.size())).isEqualTo(4);
assertThat(sync(set.getAndDelete())).isEqualTo("123");
assertThat(sync(set.size())).isEqualTo(0);
assertThat(sync(set.get())).isNull();

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save