All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.redisson.reactive.RedissonBitSetReactive Maven / Gradle / Ivy

/**
 * Copyright 2016 Nikita Koksharov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.redisson.reactive;

import java.util.BitSet;
import java.util.function.Supplier;

import org.reactivestreams.Publisher;
import org.redisson.RedissonBitSet;
import org.redisson.api.RBitSetReactive;
import org.redisson.api.RFuture;
import org.redisson.client.codec.BitSetCodec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.command.CommandReactiveExecutor;

import reactor.core.publisher.Mono;

/**
 * 
 * @author Nikita Koksharov
 *
 */
public class RedissonBitSetReactive extends RedissonExpirableReactive implements RBitSetReactive {

    private final RedissonBitSet instance;
    
    public RedissonBitSetReactive(CommandReactiveExecutor connectionManager, String name) {
        super(connectionManager, name);
        this.instance = new RedissonBitSet(connectionManager, name);
    }

    public Publisher get(final long bitIndex) {
        return reactive(new Supplier>() {
            @Override
            public RFuture get() {
                return instance.getAsync(bitIndex);
            }
        });
    }

    public Publisher set(final long bitIndex, final boolean value) {
        return reactive(new Supplier>() {
            @Override
            public RFuture get() {
                return instance.setAsync(bitIndex, value);
            }
        });
    }

    public Publisher toByteArray() {
        return reactive(new Supplier>() {
            @Override
            public RFuture get() {
                return instance.toByteArrayAsync();
            }
        });
    }

    public Publisher asBitSet() {
        return commandExecutor.readReactive(getName(), BitSetCodec.INSTANCE, RedisCommands.GET, getName());
    }

    @Override
    public Publisher length() {
        return reactive(new Supplier>() {
            @Override
            public RFuture get() {
                return instance.lengthAsync();
            }
        });
    }

    @Override
    public Publisher set(final long fromIndex, final long toIndex, final boolean value) {
        return reactive(new Supplier>() {
            @Override
            public RFuture get() {
                return instance.setAsync(fromIndex, toIndex, value);
            }
        });
    }

    @Override
    public Publisher clear(final long fromIndex, final long toIndex) {
        return reactive(new Supplier>() {
            @Override
            public RFuture get() {
                return instance.clearAsync(fromIndex, toIndex);
            }
        });
    }

    @Override
    public Publisher set(final BitSet bs) {
        return reactive(new Supplier>() {
            @Override
            public RFuture get() {
                return instance.setAsync(bs);
            }
        });
    }

    @Override
    public Publisher not() {
        return reactive(new Supplier>() {
            @Override
            public RFuture get() {
                return instance.notAsync();
            }
        });
    }

    @Override
    public Publisher set(final long fromIndex, final long toIndex) {
        return reactive(new Supplier>() {
            @Override
            public RFuture get() {
                return instance.setAsync(fromIndex, toIndex);
            }
        });
    }

    @Override
    public Publisher size() {
        return reactive(new Supplier>() {
            @Override
            public RFuture get() {
                return instance.sizeAsync();
            }
        });
    }

    @Override
    public Publisher set(final long bitIndex) {
        return reactive(new Supplier>() {
            @Override
            public RFuture get() {
                return instance.setAsync(bitIndex);
            }
        });
    }

    @Override
    public Publisher cardinality() {
        return reactive(new Supplier>() {
            @Override
            public RFuture get() {
                return instance.cardinalityAsync();
            }
        });
    }

    @Override
    public Publisher clear(final long bitIndex) {
        return reactive(new Supplier>() {
            @Override
            public RFuture get() {
                return instance.clearAsync(bitIndex);
            }
        });
    }

    @Override
    public Publisher clear() {
        return reactive(new Supplier>() {
            @Override
            public RFuture get() {
                return instance.clearAsync();
            }
        });
    }

    @Override
    public Publisher or(final String... bitSetNames) {
        return reactive(new Supplier>() {
            @Override
            public RFuture get() {
                return instance.orAsync(bitSetNames);
            }
        });
    }

    @Override
    public Publisher and(final String... bitSetNames) {
        return reactive(new Supplier>() {
            @Override
            public RFuture get() {
                return instance.andAsync(bitSetNames);
            }
        });
    }

    @Override
    public Publisher xor(final String... bitSetNames) {
        return reactive(new Supplier>() {
            @Override
            public RFuture get() {
                return instance.xorAsync(bitSetNames);
            }
        });
    }

    @Override
    public String toString() {
        return Mono.from(asBitSet()).block().toString();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy