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

org.redisson.api.MapOptions Maven / Gradle / Ivy

There is a newer version: 0.40.13
Show newest version
/**
 * Copyright 2018 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.api;

import org.redisson.api.map.MapLoader;
import org.redisson.api.map.MapWriter;

/**
 * Configuration for Map object.
 * 
 * @author Nikita Koksharov
 *
 * @param  key type
 * @param  value type
 */
public class MapOptions {
    
    public enum WriteMode {
        
        /**
         * In write behind mode all data written in map object 
         * also written using MapWriter in asynchronous mode.
         */
        WRITE_BEHIND,
        
        /**
         * In write through mode all write operations for map object 
         * are synchronized with MapWriter write operations.
         * If MapWriter throws an error then it will be re-thrown to Map operation caller.
         */
        WRITE_THROUGH
        
    }
    
    private MapLoader loader;
    private MapWriter writer;
    private WriteMode writeMode = WriteMode.WRITE_THROUGH;
    private int writeBehindThreads = 1;
    
    protected MapOptions() {
    }
    
    protected MapOptions(MapOptions copy) {
    }
    
    /**
     * Creates a new instance of MapOptions with default options.
     * 

* This is equivalent to: *

     *     new MapOptions()
     *      .writer(null, null).loader(null);
     * 
* * @param key type * @param value type * * @return MapOptions instance * */ public static MapOptions defaults() { return new MapOptions(); } /** * Sets {@link MapWriter} object. * * @param writer object * @return MapOptions instance */ public MapOptions writer(MapWriter writer) { this.writer = writer; return this; } public MapWriter getWriter() { return writer; } /** * Sets threads amount used in write behind mode. *

* Default is 1 * * @param writeBehindThreads - threads amount * @return MapOptions instance */ public MapOptions writeBehindThreads(int writeBehindThreads) { this.writeBehindThreads = writeBehindThreads; return this; } public int getWriteBehindThreads() { return writeBehindThreads; } /** * Sets write mode. *

* Default is {@link WriteMode#WRITE_THROUGH} * * @param writeMode - write mode * @return MapOptions instance */ public MapOptions writeMode(WriteMode writeMode) { this.writeMode = writeMode; return this; } public WriteMode getWriteMode() { return writeMode; } /** * Sets {@link MapLoader} object. * * @param loader object * @return MapOptions instance */ public MapOptions loader(MapLoader loader) { this.loader = loader; return this; } public MapLoader getLoader() { return loader; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy