use of com.tencent.polaris.client.util.NamedThreadFactory in project polaris-java by polarismesh.
the class InMemoryRegistry method init.
@Override
public void init(InitContext ctx) throws PolarisException {
// 获取系统服务配置
Collection<ServerServiceInfo> serverServices = ctx.getServerServices();
for (ServerServiceInfo serverServiceInfo : serverServices) {
if (serverServiceInfo.getClusterType() == ClusterType.SERVICE_DISCOVER_CLUSTER) {
hasDiscoverCluster = true;
}
serverServiceMap.put(serverServiceInfo.getServiceKey(), serverServiceInfo);
}
// 加载cacheHandler
ServiceLoader<CacheHandler> handlers = ServiceLoader.load(CacheHandler.class);
for (CacheHandler handler : handlers) {
cacheHandlers.put(handler.getTargetEventType(), handler);
}
// Load server connector.
connector = (ServerConnector) ctx.getPlugins().getPlugin(PluginTypes.SERVER_CONNECTOR.getBaseType(), ctx.getValueContext().getServerConnectorProtocol());
// 构建基础属性
String persistDir = ctx.getConfig().getConsumer().getLocalCache().getPersistDir();
int maxReadRetry = ctx.getConfig().getConsumer().getLocalCache().getPersistMaxReadRetry();
int maxWriteRetry = ctx.getConfig().getConsumer().getLocalCache().getPersistMaxWriteRetry();
long retryIntervalMs = ctx.getConfig().getConsumer().getLocalCache().getPersistRetryInterval();
this.serviceRefreshIntervalMs = ctx.getConfig().getConsumer().getLocalCache().getServiceRefreshInterval();
boolean configPersistEnable = ctx.getConfig().getConsumer().getLocalCache().isPersistEnable();
persistEnable = configPersistEnable && StringUtils.isNotBlank(persistDir);
// 启动本地缓存
if (persistEnable) {
messagePersistHandler = new MessagePersistHandler(persistDir, maxWriteRetry, maxReadRetry, retryIntervalMs);
try {
messagePersistHandler.init();
} catch (IOException e) {
throw new PolarisException(ErrorCode.PLUGIN_ERROR, String.format("plugin %s init failed", getName()), e);
}
loadFileCache(persistDir);
}
NamedThreadFactory namedThreadFactory = new NamedThreadFactory(getName());
serviceExpireTimeMs = ctx.getConfig().getConsumer().getLocalCache().getServiceExpireTime();
persistExecutor = Executors.newSingleThreadExecutor(namedThreadFactory);
expireExecutor = Executors.newSingleThreadScheduledExecutor(namedThreadFactory);
if (hasDiscoverCluster) {
serverServicesDiscoverExecutor = new ThreadPoolExecutor(0, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), namedThreadFactory);
}
}
use of com.tencent.polaris.client.util.NamedThreadFactory in project polaris-java by polarismesh.
the class GrpcConnector method initActually.
private void initActually(InitContext ctx, ServerConnectorConfig connectorConfig) {
readyFuture = new CompletableFuture<>();
Map<ClusterType, CompletableFuture<String>> futures = new HashMap<>();
futures.put(ClusterType.SERVICE_DISCOVER_CLUSTER, readyFuture);
connectionManager = new ConnectionManager(ctx, connectorConfig, futures);
connectionIdleTimeoutMs = connectorConfig.getConnectionIdleTimeout();
messageTimeoutMs = connectorConfig.getMessageTimeout();
sendDiscoverExecutor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory(getName() + "-send-discovery"), new CallerRunsPolicy());
sendDiscoverExecutor.setMaximumPoolSize(1);
buildInExecutor = new ScheduledThreadPoolExecutor(0, new NamedThreadFactory(getName() + "-builtin-discovery"), new CallerRunsPolicy());
buildInExecutor.setMaximumPoolSize(1);
streamClients.put(ClusterType.BUILTIN_CLUSTER, new AtomicReference<>());
streamClients.put(ClusterType.SERVICE_DISCOVER_CLUSTER, new AtomicReference<>());
updateServiceExecutor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory(getName() + "-update-service"));
updateServiceExecutor.setMaximumPoolSize(1);
initialized = true;
}
use of com.tencent.polaris.client.util.NamedThreadFactory in project polaris-java by polarismesh.
the class CompositeConnector method init.
@Override
public void init(InitContext ctx) throws PolarisException {
if (getName().equals(ctx.getValueContext().getServerConnectorProtocol())) {
if (CollectionUtils.isEmpty(serverConnectors)) {
serverConnectors = new ArrayList<>();
}
List<ServerConnectorConfigImpl> serverConnectorConfigs = ctx.getConfig().getGlobal().getServerConnectors();
for (ServerConnectorConfigImpl serverConnectorConfig : serverConnectorConfigs) {
DestroyableServerConnector serverConnector = (DestroyableServerConnector) ctx.getPlugins().getPlugin(PluginTypes.SERVER_CONNECTOR.getBaseType(), serverConnectorConfig.getProtocol());
serverConnector.init(ctx);
serverConnectors.add(serverConnector);
}
sendDiscoverExecutor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory(getName() + "-send-discovery"), new CallerRunsPolicy());
sendDiscoverExecutor.setMaximumPoolSize(1);
updateServiceExecutor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory(getName() + "-update-service"));
updateServiceExecutor.setMaximumPoolSize(1);
initialized = true;
}
}
Aggregations