Search in sources :

Example 1 with ByteArrayCodec

use of com.lambdaworks.redis.codec.ByteArrayCodec in project moleculer-java by moleculer-java.

the class RedisPubSubClient method connect.

// --- CONNECT ---
public final void connect() {
    DefaultClientResources.Builder builder = DefaultClientResources.builder();
    acceptor = Executors.newSingleThreadExecutor();
    group = new NioEventLoopGroup(1, acceptor);
    builder.eventLoopGroupProvider(new EventLoopGroupProvider() {

        @Override
        public final int threadPoolSize() {
            return 1;
        }

        @Override
        public final Future<Boolean> shutdown(long quietPeriod, long timeout, TimeUnit timeUnit) {
            return null;
        }

        @Override
        public final Future<Boolean> release(EventExecutorGroup eventLoopGroup, long quietPeriod, long timeout, TimeUnit unit) {
            return null;
        }

        @SuppressWarnings("unchecked")
        @Override
        public final <T extends EventLoopGroup> T allocate(Class<T> type) {
            return (T) group;
        }
    });
    builder.eventExecutorGroup(new DefaultEventExecutor(executor));
    if (eventBus == null) {
        builder.eventBus(new EventBus() {

            @Override
            public final void publish(Event event) {
            }

            @Override
            public final Observable<Event> get() {
                return null;
            }
        });
    } else {
        builder.eventBus(eventBus);
    }
    resources = builder.build();
    List<RedisURI> redisURIs = parseURLs(urls, password, secure);
    StatefulRedisPubSubConnection<byte[], byte[]> connection;
    ByteArrayCodec codec = new ByteArrayCodec();
    if (urls.length > 1) {
        // Clustered client
        connection = RedisClusterClient.create(resources, redisURIs).connectPubSub(codec);
    } else {
        // Single connection
        connection = RedisClient.create(resources, redisURIs.get(0)).connectPubSub(codec);
    }
    // Add listener
    if (listener != null) {
        connection.addListener(listener);
    }
    commands = connection.async();
}
Also used : EventExecutorGroup(io.netty.util.concurrent.EventExecutorGroup) DefaultEventExecutor(io.netty.util.concurrent.DefaultEventExecutor) RedisURI(com.lambdaworks.redis.RedisURI) EventBus(com.lambdaworks.redis.event.EventBus) DefaultClientResources(com.lambdaworks.redis.resource.DefaultClientResources) Observable(rx.Observable) ByteArrayCodec(com.lambdaworks.redis.codec.ByteArrayCodec) EventLoopGroupProvider(com.lambdaworks.redis.resource.EventLoopGroupProvider) TimeUnit(java.util.concurrent.TimeUnit) Future(io.netty.util.concurrent.Future) Event(com.lambdaworks.redis.event.Event) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 2 with ByteArrayCodec

use of com.lambdaworks.redis.codec.ByteArrayCodec in project moleculer-java by moleculer-java.

the class RedisGetSetClient method connect.

// --- CONNECT ---
public final void connect() {
    DefaultClientResources.Builder builder = DefaultClientResources.builder();
    acceptor = Executors.newSingleThreadExecutor();
    group = new NioEventLoopGroup(1, acceptor);
    builder.eventLoopGroupProvider(new EventLoopGroupProvider() {

        @Override
        public final int threadPoolSize() {
            return 1;
        }

        @Override
        public final Future<Boolean> shutdown(long quietPeriod, long timeout, TimeUnit timeUnit) {
            return null;
        }

        @Override
        public final Future<Boolean> release(EventExecutorGroup eventLoopGroup, long quietPeriod, long timeout, TimeUnit unit) {
            return null;
        }

        @SuppressWarnings("unchecked")
        @Override
        public final <T extends EventLoopGroup> T allocate(Class<T> type) {
            return (T) group;
        }
    });
    builder.eventExecutorGroup(new DefaultEventExecutor(executor));
    if (eventBus == null) {
        builder.eventBus(new EventBus() {

            @Override
            public final void publish(Event event) {
            }

            @Override
            public final Observable<Event> get() {
                return null;
            }
        });
    } else {
        builder.eventBus(eventBus);
    }
    resources = builder.build();
    List<RedisURI> redisURIs = parseURLs(urls, password, secure);
    ByteArrayCodec codec = new ByteArrayCodec();
    if (urls.length > 1) {
        // Clustered client
        clusteredClient = RedisClusterClient.create(resources, redisURIs).connect(codec).async();
    } else {
        // Single server connection
        client = RedisClient.create(resources, redisURIs.get(0)).connect(codec).async();
    }
}
Also used : EventExecutorGroup(io.netty.util.concurrent.EventExecutorGroup) DefaultEventExecutor(io.netty.util.concurrent.DefaultEventExecutor) RedisURI(com.lambdaworks.redis.RedisURI) EventBus(com.lambdaworks.redis.event.EventBus) DefaultClientResources(com.lambdaworks.redis.resource.DefaultClientResources) Observable(rx.Observable) ByteArrayCodec(com.lambdaworks.redis.codec.ByteArrayCodec) EventLoopGroupProvider(com.lambdaworks.redis.resource.EventLoopGroupProvider) TimeUnit(java.util.concurrent.TimeUnit) CompletableFuture(java.util.concurrent.CompletableFuture) RedisFuture(com.lambdaworks.redis.RedisFuture) Future(io.netty.util.concurrent.Future) Event(com.lambdaworks.redis.event.Event) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

RedisURI (com.lambdaworks.redis.RedisURI)2 ByteArrayCodec (com.lambdaworks.redis.codec.ByteArrayCodec)2 Event (com.lambdaworks.redis.event.Event)2 EventBus (com.lambdaworks.redis.event.EventBus)2 DefaultClientResources (com.lambdaworks.redis.resource.DefaultClientResources)2 EventLoopGroupProvider (com.lambdaworks.redis.resource.EventLoopGroupProvider)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2 DefaultEventExecutor (io.netty.util.concurrent.DefaultEventExecutor)2 EventExecutorGroup (io.netty.util.concurrent.EventExecutorGroup)2 Future (io.netty.util.concurrent.Future)2 TimeUnit (java.util.concurrent.TimeUnit)2 Observable (rx.Observable)2 RedisFuture (com.lambdaworks.redis.RedisFuture)1 CompletableFuture (java.util.concurrent.CompletableFuture)1