Search in sources :

Example 6 with Codec

use of org.redisson.client.codec.Codec in project redisson by redisson.

the class MasterSlaveConnectionManager method unsubscribe.

@Override
public RFuture<Codec> unsubscribe(final String channelName, boolean temporaryDown) {
    final PubSubConnectionEntry entry = name2PubSubConnection.remove(channelName);
    if (entry == null) {
        return null;
    }
    freePubSubConnections.remove(entry);
    final Codec entryCodec = entry.getConnection().getChannels().get(channelName);
    if (temporaryDown) {
        final RPromise<Codec> result = newPromise();
        entry.unsubscribe(channelName, new BaseRedisPubSubListener() {

            @Override
            public boolean onStatus(PubSubType type, String channel) {
                if (type == PubSubType.UNSUBSCRIBE && channel.equals(channelName)) {
                    result.trySuccess(entryCodec);
                    return true;
                }
                return false;
            }
        });
        return result;
    }
    entry.unsubscribe(channelName, null);
    return newSucceededFuture(entryCodec);
}
Also used : Codec(org.redisson.client.codec.Codec) BaseRedisPubSubListener(org.redisson.client.BaseRedisPubSubListener) PubSubType(org.redisson.client.protocol.pubsub.PubSubType)

Example 7 with Codec

use of org.redisson.client.codec.Codec in project redisson by redisson.

the class MasterSlaveConnectionManager method punsubscribe.

public Codec punsubscribe(final String channelName, final AsyncSemaphore lock) {
    final PubSubConnectionEntry entry = name2PubSubConnection.remove(channelName);
    if (entry == null) {
        lock.release();
        return null;
    }
    Codec entryCodec = entry.getConnection().getPatternChannels().get(channelName);
    entry.punsubscribe(channelName, new BaseRedisPubSubListener() {

        @Override
        public boolean onStatus(PubSubType type, String channel) {
            if (type == PubSubType.PUNSUBSCRIBE && channel.equals(channelName)) {
                if (entry.release() == 1) {
                    freePubSubConnections.add(entry);
                }
                lock.release();
                return true;
            }
            return false;
        }
    });
    return entryCodec;
}
Also used : Codec(org.redisson.client.codec.Codec) BaseRedisPubSubListener(org.redisson.client.BaseRedisPubSubListener) PubSubType(org.redisson.client.protocol.pubsub.PubSubType)

Example 8 with Codec

use of org.redisson.client.codec.Codec in project redisson by redisson.

the class RedissonCodecTest method testAvro.

@Test
public void testAvro() throws IOException {
    AvroMapper am = new AvroMapper();
    AvroSchema schema = am.schemaFor(TestObject.class);
    Codec avroCodec = new AvroJacksonCodec(TestObject.class, schema);
    Config config = createConfig();
    config.setCodec(avroCodec);
    RedissonClient redisson = Redisson.create(config);
    RBucket<TestObject> b = redisson.getBucket("bucket");
    b.set(new TestObject("1", "2"));
    assertThat(b.get()).isEqualTo(new TestObject("1", "2"));
}
Also used : Codec(org.redisson.client.codec.Codec) JsonJacksonCodec(org.redisson.codec.JsonJacksonCodec) KryoCodec(org.redisson.codec.KryoCodec) MsgPackJacksonCodec(org.redisson.codec.MsgPackJacksonCodec) SnappyCodec(org.redisson.codec.SnappyCodec) JsonJacksonMapValueCodec(org.redisson.client.codec.JsonJacksonMapValueCodec) SerializationCodec(org.redisson.codec.SerializationCodec) LZ4Codec(org.redisson.codec.LZ4Codec) SmileJacksonCodec(org.redisson.codec.SmileJacksonCodec) CborJacksonCodec(org.redisson.codec.CborJacksonCodec) FstCodec(org.redisson.codec.FstCodec) AvroJacksonCodec(org.redisson.codec.AvroJacksonCodec) AvroSchema(com.fasterxml.jackson.dataformat.avro.AvroSchema) AvroJacksonCodec(org.redisson.codec.AvroJacksonCodec) RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config) AvroMapper(com.fasterxml.jackson.dataformat.avro.AvroMapper) Test(org.junit.Test)

Aggregations

Codec (org.redisson.client.codec.Codec)8 BaseRedisPubSubListener (org.redisson.client.BaseRedisPubSubListener)4 PubSubType (org.redisson.client.protocol.pubsub.PubSubType)4 NamingScheme (org.redisson.liveobject.resolver.NamingScheme)2 AvroMapper (com.fasterxml.jackson.dataformat.avro.AvroMapper)1 AvroSchema (com.fasterxml.jackson.dataformat.avro.AvroSchema)1 Method (java.lang.reflect.Method)1 Test (org.junit.Test)1 RedissonReference (org.redisson.RedissonReference)1 RLiveObjectService (org.redisson.api.RLiveObjectService)1 RObject (org.redisson.api.RObject)1 RedissonClient (org.redisson.api.RedissonClient)1 REntity (org.redisson.api.annotation.REntity)1 JsonJacksonMapValueCodec (org.redisson.client.codec.JsonJacksonMapValueCodec)1 AvroJacksonCodec (org.redisson.codec.AvroJacksonCodec)1 CborJacksonCodec (org.redisson.codec.CborJacksonCodec)1 CodecProvider (org.redisson.codec.CodecProvider)1 FstCodec (org.redisson.codec.FstCodec)1 JsonJacksonCodec (org.redisson.codec.JsonJacksonCodec)1 KryoCodec (org.redisson.codec.KryoCodec)1