com.github.lontime.shaded.org.redisson.api.MapOptions Maven / Gradle / Ivy
/**
* Copyright (c) 2013-2021 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 com.github.lontime.shaded.org.redisson.api;
import com.github.lontime.shaded.org.redisson.api.map.MapLoader;
import com.github.lontime.shaded.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 writeBehindBatchSize = 50;
private int writeBehindDelay = 1000;
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 write behind tasks batch size.
* All updates accumulated into a batch of specified size and written with {@link MapWriter}.
*
* Default is 50
*
* @param writeBehindBatchSize - size of batch
* @return MapOptions instance
*/
public MapOptions writeBehindBatchSize(int writeBehindBatchSize) {
this.writeBehindBatchSize = writeBehindBatchSize;
return this;
}
public int getWriteBehindBatchSize() {
return writeBehindBatchSize;
}
/**
* Sets write behind tasks execution delay.
* All updates written with {@link MapWriter} and lag not more than specified delay.
*
* Default is 1000
milliseconds
*
* @param writeBehindDelay - delay in milliseconds
* @return MapOptions instance
*/
public MapOptions writeBehindDelay(int writeBehindDelay) {
this.writeBehindDelay = writeBehindDelay;
return this;
}
public int getWriteBehindDelay() {
return writeBehindDelay;
}
/**
* 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;
}
}