org.redisson.client.codec.Codec Java Examples

The following examples show how to use org.redisson.client.codec.Codec. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedissonReactiveSubscription.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<Void> pUnsubscribe(ByteBuffer... patterns) {
    monosListener.acquire();
    return Mono.defer(() -> {
        RedissonPromise<Void> result = new RedissonPromise<>();
        result.onComplete((r, ex) -> {
            monosListener.release();
        });
        CountableListener<Void> listener = new CountableListener<>(result, null, patterns.length);
        for (ByteBuffer channel : patterns) {
            ChannelName cn = toChannelName(channel);
            RFuture<Codec> f = subscribeService.unsubscribe(cn, PubSubType.PUNSUBSCRIBE);
            f.onComplete((res, e) -> {
                synchronized (RedissonReactiveSubscription.this.patterns) {
                    PubSubConnectionEntry entry = RedissonReactiveSubscription.this.patterns.get(cn);
                    if (!entry.hasListeners(cn)) {
                        RedissonReactiveSubscription.this.patterns.remove(cn);
                    }
                }
            });
            f.onComplete(listener);
        }
        return Mono.fromFuture(result);
    });
}
 
Example #2
Source File: KlockAutoConfiguration.java    From spring-boot-klock-starter with Apache License 2.0 6 votes vote down vote up
@Bean(destroyMethod = "shutdown")
@ConditionalOnMissingBean
RedissonClient redisson() throws Exception {
    Config config = new Config();
    if(klockConfig.getClusterServer()!=null){
        config.useClusterServers().setPassword(klockConfig.getPassword())
                .addNodeAddress(klockConfig.getClusterServer().getNodeAddresses());
    }else {
        config.useSingleServer().setAddress(klockConfig.getAddress())
                .setDatabase(klockConfig.getDatabase())
                .setPassword(klockConfig.getPassword());
    }
    Codec codec=(Codec) ClassUtils.forName(klockConfig.getCodec(),ClassUtils.getDefaultClassLoader()).newInstance();
    config.setCodec(codec);
    config.setEventLoopGroup(new NioEventLoopGroup());
    return Redisson.create(config);
}
 
Example #3
Source File: DefaultReferenceCodecProvider.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends Codec> T getCodec(REntity anno, Class<?> cls, Config config) {
    if (!ClassUtils.isAnnotationPresent(cls, anno.annotationType())) {
        throw new IllegalArgumentException("Annotation REntity does not present on type [" + cls.getCanonicalName() + "]");
    }
    
    Class<?> codecClass;
    if (anno.codec() == REntity.DEFAULT.class) {
        codecClass = config.getCodec().getClass();
    } else {
        codecClass = anno.codec();
    }

    return this.getCodec((Class<T>) codecClass);
}
 
Example #4
Source File: RedissonConfig.java    From kkbinlog with Apache License 2.0 5 votes vote down vote up
@Bean(destroyMethod = "shutdown")
RedissonClient redisson() throws Exception {
    Config config = new Config();
    config.setKeepPubSubOrder(keepPubSubOrder).useSingleServer().setAddress(address)
            .setConnectionMinimumIdleSize(connectionMinimumIdleSize)
            .setConnectionPoolSize(connectionPoolSize)
            .setDatabase(database)
            .setDnsMonitoring(dnsMonitoring)
            .setDnsMonitoringInterval(dnsMonitoringInterval)
            .setSubscriptionConnectionMinimumIdleSize(subscriptionConnectionMinimumIdleSize)
            .setSubscriptionConnectionPoolSize(subscriptionConnectionPoolSize)
            .setSubscriptionsPerConnection(subscriptionsPerConnection)
            .setClientName(clientName)
            .setFailedAttempts(failedAttempts)
            .setRetryAttempts(retryAttempts)
            .setRetryInterval(retryInterval)
            .setReconnectionTimeout(reconnectionTimeout)
            .setTimeout(timeout)
            .setConnectTimeout(connectTimeout)
            .setIdleConnectionTimeout(idleConnectionTimeout)
            .setPingTimeout(pingTimeout)
            .setPassword(password);
    Codec codec = (Codec) ClassUtils.forName(getCodec(), ClassUtils.getDefaultClassLoader()).newInstance();
    config.setCodec(codec);
    config.setThreads(thread);
    config.setEventLoopGroup(new NioEventLoopGroup());
    config.setUseLinuxNativeEpoll(false);
    return Redisson.create(config);
}
 
Example #5
Source File: RedissonTransactionalBuckets.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonTransactionalBuckets(Codec codec, CommandAsyncExecutor commandExecutor, 
        long timeout, List<TransactionalOperation> operations, AtomicBoolean executed, String transactionId) {
    super(codec, commandExecutor);
    
    this.timeout = timeout;
    this.operations = operations;
    this.executed = executed;
    this.transactionId = transactionId;
}
 
Example #6
Source File: RedisConnection.java    From redisson with Apache License 2.0 5 votes vote down vote up
public <T, R> RFuture<R> async(long timeout, Codec encoder, RedisCommand<T> command, Object... params) {
    RPromise<R> promise = new RedissonPromise<R>();
    if (timeout == -1) {
        timeout = redisClient.getCommandTimeout();
    }
    
    if (redisClient.getEventLoopGroup().isShuttingDown()) {
        RedissonShutdownException cause = new RedissonShutdownException("Redisson is shutdown");
        return RedissonPromise.newFailedFuture(cause);
    }

    Timeout scheduledFuture = redisClient.getTimer().newTimeout(t -> {
        RedisTimeoutException ex = new RedisTimeoutException("Command execution timeout for command: "
                + LogHelper.toString(command, params) + ", Redis client: " + redisClient);
        promise.tryFailure(ex);
    }, timeout, TimeUnit.MILLISECONDS);
    
    promise.onComplete((res, e) -> {
        scheduledFuture.cancel();
    });
    
    ChannelFuture writeFuture = send(new CommandData<T, R>(promise, encoder, command, params));
    writeFuture.addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            if (!future.isSuccess()) {
                promise.tryFailure(future.cause());
            }
        }
    });
    return promise;
}
 
Example #7
Source File: RedissonTransactionalBucket.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonTransactionalBucket(Codec codec, CommandAsyncExecutor commandExecutor, long timeout, String name, List<TransactionalOperation> operations, AtomicBoolean executed, String transactionId) {
    super(codec, commandExecutor, name);
    this.operations = operations;
    this.executed = executed;
    this.transactionId = transactionId;
    this.timeout = timeout;
}
 
Example #8
Source File: RedissonObjectBuilder.java    From redisson with Apache License 2.0 5 votes vote down vote up
public void store(RObject ar, String fieldName, RMap<String, Object> liveMap) {
    Codec codec = ar.getCodec();
    if (codec != null) {
        codecProvider.registerCodec((Class) codec.getClass(), codec);
    }
    liveMap.fastPut(fieldName,
            new RedissonReference(ar.getClass(), ar.getName(), codec));
}
 
Example #9
Source File: DefaultReferenceCodecProvider.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends Codec> void registerCodec(Class<T> cls, T codec) {
    if (!cls.isInstance(codec)) {
        throw new IllegalArgumentException("codec is not an instance of the class [" + cls.getCanonicalName() + "]");
    }
    codecCache.putIfAbsent(cls, codec);
}
 
Example #10
Source File: AbstractRedisSetWrapper.java    From geowave with Apache License 2.0 5 votes vote down vote up
public AbstractRedisSetWrapper(
    final RedissonClient client,
    final String setName,
    final Codec codec) {
  this.setName = setName;
  this.client = client;
  this.codec = codec;
}
 
Example #11
Source File: LocalCacheListener.java    From redisson with Apache License 2.0 5 votes vote down vote up
public LocalCacheListener(String name, CommandAsyncExecutor commandExecutor,
        RObject object, Codec codec, LocalCachedMapOptions<?, ?> options, long cacheUpdateLogTime) {
    super();
    this.name = name;
    this.commandExecutor = commandExecutor;
    this.object = object;
    this.codec = codec;
    this.options = options;
    this.cacheUpdateLogTime = cacheUpdateLogTime;
    
    ThreadLocalRandom.current().nextBytes(instanceId);
}
 
Example #12
Source File: RedissonTransferQueue.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonTransferQueue(Codec codec, CommandAsyncExecutor commandExecutor, String name, RRemoteService remoteService) {
    super(codec, commandExecutor, name);
    service = remoteService.get(TransferQueueServiceAsync.class, RemoteInvocationOptions.defaults().noAck());
    this.remoteService = remoteService;

    queueName = ((RedissonRemoteService) remoteService).getRequestQueueName(TransferQueueService.class);
    mapName = ((RedissonRemoteService) remoteService).getRequestTasksMapName(TransferQueueService.class);
}
 
Example #13
Source File: CommandAsyncService.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public <T, R> RFuture<R> writeAsync(String key, Codec codec, RedisCommand<T> command, Object... params) {
    RPromise<R> mainPromise = createPromise();
    NodeSource source = getNodeSource(key);
    async(false, source, codec, command, params, mainPromise, false);
    return mainPromise;
}
 
Example #14
Source File: BucketGetAndDeleteOperation.java    From redisson with Apache License 2.0 4 votes vote down vote up
public BucketGetAndDeleteOperation(String name, String lockName, Codec codec, String transactionId) {
    super(name, codec);
    this.lockName = lockName;
    this.transactionId = transactionId;
}
 
Example #15
Source File: RedissonReactive.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public RPatternTopicReactive getPatternTopic(String pattern, Codec codec) {
    return ReactiveProxyBuilder.create(commandExecutor, new RedissonPatternTopic(codec, commandExecutor, pattern), RPatternTopicReactive.class);
}
 
Example #16
Source File: RedissonConnection.java    From redisson with Apache License 2.0 4 votes vote down vote up
<T> T write(byte[] key, Codec codec, RedisCommand<?> command, Object... params) {
    RFuture<T> f = executorService.writeAsync(key, codec, command, params);
    indexCommand(command);
    return sync(f);
}
 
Example #17
Source File: RedissonBatch.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public <V> RBlockingQueueAsync<V> getBlockingQueue(String name, Codec codec) {
    return new RedissonBlockingQueue<V>(codec, executorService, name, null);
}
 
Example #18
Source File: RedissonBatch.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public <K, V> RMultimapAsync<K, V> getListMultimap(String name, Codec codec) {
    return new RedissonListMultimap<K, V>(codec, executorService, name);
}
 
Example #19
Source File: RedissonConnection.java    From redisson with Apache License 2.0 4 votes vote down vote up
<T> T write(byte[] key, Codec codec, RedisCommand<?> command, Object... params) {
    RFuture<T> f = executorService.writeAsync(key, codec, command, params);
    indexCommand(command);
    return sync(f);
}
 
Example #20
Source File: Redisson.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public <V> RRingBuffer<V> getRingBuffer(String name, Codec codec) {
    return new RedissonRingBuffer<V>(codec, connectionManager.getCommandExecutor(), name, this);
}
 
Example #21
Source File: AbstractNamingScheme.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public Codec getCodec() {
    return codec;
}
 
Example #22
Source File: CommandAsyncService.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public <T, R> RFuture<R> evalReadAsync(MasterSlaveEntry entry, Codec codec, RedisCommand<T> evalCommandType, String script, List<Object> keys, Object... params) {
    return evalAsync(new NodeSource(entry), true, codec, evalCommandType, script, keys, params);
}
 
Example #23
Source File: Redisson.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public <V> RTransferQueue<V> getTransferQueue(String name, Codec codec) {
    String remoteName = RedissonObject.suffixName(name, "remoteService");
    RRemoteService service = getRemoteService(remoteName);
    return new RedissonTransferQueue<V>(codec, connectionManager.getCommandExecutor(), name, service);
}
 
Example #24
Source File: Redisson.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public <V> RBucket<V> getBucket(String name, Codec codec) {
    return new RedissonBucket<V>(codec, connectionManager.getCommandExecutor(), name);
}
 
Example #25
Source File: TracingRedissonClient.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public <V> RDeque<V> getDeque(String name, Codec codec) {
  return new TracingRDeque<>(redissonClient.getDeque(name, codec), tracingRedissonHelper);
}
 
Example #26
Source File: CommandAsyncService.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public <T, R> RFuture<R> evalReadAsync(String key, Codec codec, RedisCommand<T> evalCommandType, String script, List<Object> keys, Object... params) {
    NodeSource source = getNodeSource(key);
    return evalAsync(source, true, codec, evalCommandType, script, keys, params);
}
 
Example #27
Source File: ReactiveRemoteProxy.java    From redisson with Apache License 2.0 4 votes vote down vote up
public ReactiveRemoteProxy(CommandAsyncExecutor commandExecutor, String name, String responseQueueName,
        ConcurrentMap<String, ResponseEntry> responses, Codec codec, String executorId,
        String cancelRequestMapName, BaseRemoteService remoteService) {
    super(commandExecutor, name, responseQueueName, responses, codec, executorId, cancelRequestMapName,
            remoteService);
}
 
Example #28
Source File: RedissonTransactionReactive.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public <K, V> RMapReactive<K, V> getMap(String name, Codec codec) {
    RMap<K, V> map = transaction.<K, V>getMap(name, codec);
    return ReactiveProxyBuilder.create(executorService, map, 
            new RedissonMapReactive<K, V>(map, null), RMapReactive.class);
}
 
Example #29
Source File: CommandAsyncService.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public <T, R> RFuture<Collection<R>> readAllAsync(Codec codec, RedisCommand<T> command, Object... params) {
    List<R> results = new ArrayList<R>();
    return readAllAsync(results, codec, command, params);
}
 
Example #30
Source File: RedissonExpirable.java    From redisson with Apache License 2.0 4 votes vote down vote up
RedissonExpirable(Codec codec, CommandAsyncExecutor connectionManager, String name) {
    super(codec, connectionManager, name);
}