use of org.redisson.client.codec.Codec in project redisson by redisson.
the class RedissonCodecTest method testSnappyBigV2.
@Test
public void testSnappyBigV2() throws IOException {
Codec sc = new SnappyCodecV2();
String randomData = RandomString.make(Short.MAX_VALUE * 2 + 142);
ByteBuf g = sc.getValueEncoder().encode(randomData);
String decompressedData = (String) sc.getValueDecoder().decode(g, null);
assertThat(decompressedData).isEqualTo(randomData);
}
use of org.redisson.client.codec.Codec in project killbill by killbill.
the class TestDefaultTenant method testExternalizable.
@Test(groups = "fast")
public void testExternalizable() throws IOException {
final DefaultTenant tenantdata = new DefaultTenant(UUID.randomUUID(), clock.getUTCNow(), clock.getUTCNow(), "er44TT-yy4r", "TTR445ee2", null);
final Codec code = new SerializationCodec();
final ByteBuf byteBuf = code.getValueEncoder().encode(tenantdata);
final DefaultTenant tenantData2 = (DefaultTenant) code.getValueDecoder().decode(byteBuf, null);
Assert.assertEquals(tenantData2, tenantdata);
}
use of org.redisson.client.codec.Codec in project redisson by redisson.
the class RedissonFactory method cache.
@EachBean(RedissonCacheConfiguration.class)
public RedissonSyncCache cache(@Parameter RedissonCacheConfiguration configuration, RedissonClient redisson, ConversionService<?> conversionService, @Named(TaskExecutors.IO) ExecutorService executorService) {
Codec codec = Optional.ofNullable(configuration.getCodec()).orElse(redisson.getConfig().getCodec());
if (configuration.getExpireAfterAccess().toMillis() != 0 || configuration.getExpireAfterWrite().toMillis() != 0 || configuration.getMaxSize() != 0) {
RMapCache<Object, Object> mapCache = redisson.getMapCache(configuration.getName(), codec);
return new RedissonSyncCache(conversionService, mapCache, mapCache, executorService, configuration);
}
RMap<Object, Object> map = redisson.getMap(configuration.getName(), codec);
return new RedissonSyncCache(conversionService, null, map, executorService, configuration);
}
use of org.redisson.client.codec.Codec in project redisson by redisson.
the class RedissonObjectBuilder method fillCodecMethods.
private static void fillCodecMethods(Map<Class<?>, CodecMethodRef> map, Class<?> clientClazz, Class<?> objectClazz) {
for (Method method : clientClazz.getDeclaredMethods()) {
if (!method.getReturnType().equals(Void.TYPE) && objectClazz.isAssignableFrom(method.getReturnType()) && method.getName().startsWith("get")) {
Class<?> cls = method.getReturnType();
if (!map.containsKey(cls)) {
map.put(cls, new CodecMethodRef());
}
CodecMethodRef builder = map.get(cls);
if (// first param is name, second param is codec.
method.getParameterTypes().length == 2 && Codec.class.isAssignableFrom(method.getParameterTypes()[1])) {
builder.customCodecMethod = method;
} else if (method.getParameterTypes().length == 1) {
builder.defaultCodecMethod = method;
}
}
}
}
use of org.redisson.client.codec.Codec in project redisson by redisson.
the class PublishSubscribeService method unsubscribe.
private CompletableFuture<Codec> unsubscribe(ChannelName channelName, MasterSlaveEntry e, PubSubType topicType) {
if (connectionManager.isShuttingDown()) {
return CompletableFuture.completedFuture(null);
}
CompletableFuture<Codec> result = new CompletableFuture<>();
AsyncSemaphore lock = getSemaphore(channelName);
lock.acquire(() -> {
PubSubConnectionEntry entry = name2PubSubConnection.remove(new PubSubKey(channelName, e));
if (entry == null) {
lock.release();
result.complete(null);
return;
}
freePubSubLock.acquire(() -> {
PubSubEntry ee = entry2PubSubConnection.getOrDefault(e, new PubSubEntry());
Queue<PubSubConnectionEntry> freePubSubConnections = ee.getEntries();
freePubSubConnections.remove(entry);
freePubSubLock.release();
Codec entryCodec;
if (topicType == PubSubType.PUNSUBSCRIBE) {
entryCodec = entry.getConnection().getPatternChannels().get(channelName);
} else {
entryCodec = entry.getConnection().getChannels().get(channelName);
}
AtomicBoolean executed = new AtomicBoolean();
RedisPubSubListener<Object> listener = new BaseRedisPubSubListener() {
@Override
public boolean onStatus(PubSubType type, CharSequence channel) {
if (type == topicType && channel.equals(channelName)) {
executed.set(true);
lock.release();
result.complete(entryCodec);
return true;
}
return false;
}
};
ChannelFuture future;
if (topicType == PubSubType.PUNSUBSCRIBE) {
future = entry.punsubscribe(channelName, listener);
} else {
future = entry.unsubscribe(channelName, listener);
}
future.addListener((ChannelFutureListener) f -> {
if (!f.isSuccess()) {
return;
}
connectionManager.newTimeout(timeout -> {
if (executed.get()) {
return;
}
entry.getConnection().onMessage(new PubSubStatusMessage(topicType, channelName));
}, config.getTimeout(), TimeUnit.MILLISECONDS);
});
});
});
return result;
}
Aggregations