org.nervousync.cache.builder.CacheServerConfigBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cache-api-jdk11 Show documentation
Show all versions of cache-api-jdk11 Show documentation
Cache API Package, development by Nervousync Studio (NSYC)
The newest version!
/*
* Licensed to the Nervousync Studio (NSYC) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.nervousync.cache.builder;
import org.nervousync.builder.AbstractBuilder;
import org.nervousync.cache.config.CacheConfig;
import org.nervousync.commons.Globals;
import org.nervousync.exceptions.builder.BuilderException;
/**
* Cache server configure builder
* 缓存服务器配置构建器
*
* @author Steven Wee [email protected]
* @version $Revision: 1.0 $ $Date: 2023-03-14 09:33 $
*/
public final class CacheServerConfigBuilder extends AbstractBuilder> {
/**
* Cache server config instance
* 缓存服务器配置信息
*/
private final CacheConfig.ServerConfig serverConfig;
/**
* Constructor for cache server configure builder
* 缓存服务器配置构造器构建方法
*
* @param parentBuilder Parent builder instance
* 上级构建器实例
* @param serverConfig Current server configure instance or null for generate new configure
* 当前的服务器缓存配置,如果传入null则生成一个新的配置
*/
private CacheServerConfigBuilder(final AbstractCacheConfigBuilder parentBuilder,
final CacheConfig.ServerConfig serverConfig) {
super(parentBuilder);
this.serverConfig = (serverConfig == null) ? new CacheConfig.ServerConfig() : serverConfig;
}
/**
* Static method for create cache server configure builder
* 静态方法用于创建缓存服务器配置构造器
*
* @param parentBuilder Parent builder instance
* 上级构建器实例
* @param serverConfig Current server configure instance or null for generate new configure
* 当前的服务器缓存配置,如果传入null则生成一个新的配置
*/
public static CacheServerConfigBuilder newBuilder(final AbstractCacheConfigBuilder parentBuilder,
final CacheConfig.ServerConfig serverConfig) {
return new CacheServerConfigBuilder<>(parentBuilder, serverConfig);
}
/**
* Configure cache server address by default port number
* 配置缓存服务器地址,使用默认端口号
*
* @param serverAddress Server address
* 服务器地址
*
* @return Current cache server configure builder
* 当前缓存服务器配置构建器
*/
public CacheServerConfigBuilder serverConfig(final String serverAddress) {
return this.serverConfig(serverAddress, Globals.DEFAULT_VALUE_INT);
}
/**
* Configure cache server address and port number
* 配置缓存服务器地址和端口号
*
* @param serverAddress Server address
* 服务器地址
* @param serverPort Server port
* 服务器端口号
*
* @return Current cache server configure builder
* 当前缓存服务器配置构建器
*/
public CacheServerConfigBuilder serverConfig(final String serverAddress, final int serverPort) {
this.serverConfig.setServerAddress(serverAddress);
this.serverConfig.setServerPort(serverPort);
return this;
}
/**
* Configure cache server weight
* 配置缓存服务器权重
*
* @param serverWeight Server weight
* 服务器权重
*
* @return Current cache server configure builder
* 当前缓存服务器配置构建器
*/
public CacheServerConfigBuilder serverWeight(final int serverWeight) {
this.serverConfig.setServerWeight(serverWeight);
return this;
}
/**
* Confirm configure information
* 确认配置信息
*
* @throws BuilderException Throws if cache server address is empty
* 如果缓存服务器地址未配置,则抛出异常
*/
@Override
protected void build() throws BuilderException {
this.parentBuilder.serverConfig(this.serverConfig);
}
}