use of org.redisson.client.codec.Codec in project redisson by redisson.
the class PublishSubscribeService method reattachPubSub.
public void reattachPubSub(int slot) {
name2PubSubConnection.entrySet().stream().filter(e -> connectionManager.calcSlot(e.getKey().getChannelName().getName()) == slot).forEach(entry -> {
PubSubConnectionEntry pubSubEntry = entry.getValue();
MasterSlaveEntry ee = entry.getKey().getEntry();
Codec codec = pubSubEntry.getConnection().getChannels().get(entry.getKey().getChannelName());
if (codec != null) {
Queue<RedisPubSubListener<?>> listeners = pubSubEntry.getListeners(entry.getKey().getChannelName());
unsubscribe(entry.getKey().getChannelName(), ee, PubSubType.UNSUBSCRIBE);
subscribe(codec, entry.getKey().getChannelName(), listeners.toArray(new RedisPubSubListener[0]));
}
Codec patternCodec = pubSubEntry.getConnection().getPatternChannels().get(entry.getKey().getChannelName());
if (patternCodec != null) {
Queue<RedisPubSubListener<?>> listeners = pubSubEntry.getListeners(entry.getKey().getChannelName());
unsubscribe(entry.getKey().getChannelName(), ee, PubSubType.PUNSUBSCRIBE);
psubscribe(entry.getKey().getChannelName(), patternCodec, listeners.toArray(new RedisPubSubListener[0]));
}
});
}
use of org.redisson.client.codec.Codec in project redisson by redisson.
the class PublishSubscribeService method connect.
private CompletableFuture<RedisPubSubConnection> connect(Codec codec, ChannelName channelName, MasterSlaveEntry msEntry, CompletableFuture<PubSubConnectionEntry> promise, PubSubType type, AsyncSemaphore lock, RedisPubSubListener<?>... listeners) {
CompletableFuture<RedisPubSubConnection> connFuture = nextPubSubConnection(msEntry, channelName);
promise.whenComplete((res, e) -> {
if (e != null) {
connFuture.completeExceptionally(e);
}
});
connFuture.whenComplete((conn, ex) -> {
if (ex != null) {
// freePubSubLock.release();
lock.release();
if (!connFuture.isCancelled()) {
promise.completeExceptionally(ex);
}
return;
}
freePubSubLock.acquire(() -> {
PubSubConnectionEntry entry = new PubSubConnectionEntry(conn, config.getSubscriptionsPerConnection());
int remainFreeAmount = entry.tryAcquire();
PubSubKey key = new PubSubKey(channelName, msEntry);
PubSubConnectionEntry oldEntry = name2PubSubConnection.putIfAbsent(key, entry);
if (oldEntry != null) {
msEntry.returnPubSubConnection(conn);
freePubSubLock.release();
addListeners(channelName, promise, type, lock, oldEntry, listeners);
return;
}
if (remainFreeAmount > 0) {
addFreeConnectionEntry(channelName, entry);
}
freePubSubLock.release();
addListeners(channelName, promise, type, lock, entry, listeners);
ChannelFuture future;
if (PubSubType.PSUBSCRIBE == type) {
future = entry.psubscribe(codec, channelName);
} else {
future = entry.subscribe(codec, channelName);
}
future.addListener((ChannelFutureListener) future1 -> {
if (!future1.isSuccess()) {
if (!promise.isDone()) {
promise.cancel(false);
}
return;
}
connectionManager.newTimeout(timeout -> promise.cancel(false), config.getTimeout(), TimeUnit.MILLISECONDS);
});
});
});
return connFuture;
}
use of org.redisson.client.codec.Codec in project redisson by redisson.
the class RedissonLocalCachedMapTest method testReadAllValues2.
@Test
public void testReadAllValues2() {
ObjectMapper objectMapper = new JsonJacksonCodec().getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Codec codec = new TypedJsonJacksonCodec(String.class, SimpleValue.class, objectMapper);
RLocalCachedMap<String, SimpleValue> map1 = redisson.getLocalCachedMap("test", codec, LocalCachedMapOptions.defaults());
RLocalCachedMap<String, SimpleValue> map2 = redisson.getLocalCachedMap("test", codec, LocalCachedMapOptions.defaults());
map1.put("key", new SimpleValue("3"));
Collection<SimpleValue> s = map1.readAllValues();
assertThat(s).hasSize(1);
Collection<SimpleValue> s2 = map2.readAllValues();
assertThat(s2).hasSize(1);
}
use of org.redisson.client.codec.Codec in project killbill by killbill.
the class RedissonCacheClientProvider method get.
@Override
public RedissonClient get() {
// JDK serialization codec for now, but we can do better in speed and space
final Codec codec = new SerializationCodec();
final Config redissonCfg = new Config();
redissonCfg.setCodec(codec).useSingleServer().setAddress(address).setPassword(password).setConnectionMinimumIdleSize(connectionMinimumIdleSize);
return Redisson.create(redissonCfg);
}
Aggregations