use of com.tencent.polaris.api.config.global.ClusterType 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.api.config.global.ClusterType in project polaris-java by polarismesh.
the class GrpcConnector method submitServiceHandler.
@Override
protected void submitServiceHandler(ServiceUpdateTask updateTask, long delayMs) {
ClusterType targetCluster = updateTask.getTargetClusterType();
if (updateTask.setStatus(Status.READY, Status.RUNNING)) {
if (targetCluster == ClusterType.BUILTIN_CLUSTER) {
LOG.info("[ServerConnector]task for service {} has been scheduled builtin", updateTask);
buildInExecutor.schedule(updateTask, delayMs, TimeUnit.MILLISECONDS);
} else {
LOG.debug("[ServerConnector]task for service {} has been scheduled discover", updateTask);
sendDiscoverExecutor.schedule(updateTask, delayMs, TimeUnit.MILLISECONDS);
}
}
}
use of com.tencent.polaris.api.config.global.ClusterType in project polaris-java by polarismesh.
the class GrpcServiceUpdateTask method execute.
public void execute(ServiceUpdateTask serviceUpdateTask) {
if (getTaskType() == Type.FIRST) {
LOG.info("[ServerConnector]start to run first task {}", serviceUpdateTask);
} else {
LOG.debug("[ServerConnector]start to run task {}", serviceUpdateTask);
}
GrpcConnector grpcConnector = (GrpcConnector) serverConnector;
ConnectionManager connectionManager = grpcConnector.getConnectionManager();
ClusterType clusterType = targetClusterType.get();
boolean clusterReady = connectionManager.checkReady(clusterType);
if (!clusterReady) {
// 没有ready,就重试
LOG.info("{} service is not ready", clusterType);
grpcConnector.retryServiceUpdateTask(serviceUpdateTask);
return;
}
if (grpcConnector.isDestroyed()) {
LOG.info("{} grpc connection is destroyed", clusterType);
grpcConnector.retryServiceUpdateTask(serviceUpdateTask);
return;
}
AtomicReference<SpecStreamClient> streamClientAtomicReference = grpcConnector.getStreamClient(clusterType);
SpecStreamClient specStreamClient = streamClientAtomicReference.get();
boolean available = checkStreamClientAvailable(specStreamClient, serviceUpdateTask);
if (!available) {
LOG.debug("[ServerConnector]start to get connection for task {}", serviceUpdateTask);
Connection connection = null;
try {
connection = connectionManager.getConnection(GrpcUtil.OP_KEY_DISCOVER, clusterType);
} catch (PolarisException e) {
LOG.error("[ServerConnector]fail to get connection to {}", clusterType, e);
}
if (null == connection) {
LOG.error("[ServerConnector]get null connection for {}", serviceUpdateTask);
grpcConnector.retryServiceUpdateTask(serviceUpdateTask);
return;
}
specStreamClient = new SpecStreamClient(connection, grpcConnector.getConnectionIdleTimeoutMs(), serviceUpdateTask);
streamClientAtomicReference.set(specStreamClient);
LOG.info("[ServerConnector]success to create stream client for task {}", serviceUpdateTask);
}
msgSendTime.set(System.currentTimeMillis());
totalRequests.addAndGet(1);
specStreamClient.sendRequest(serviceUpdateTask);
}
use of com.tencent.polaris.api.config.global.ClusterType in project polaris-java by polarismesh.
the class PolarisConfigFileConnector method init.
@Override
public void init(InitContext ctx) throws PolarisException {
CompletableFuture<String> readyFuture = new CompletableFuture<>();
Map<ClusterType, CompletableFuture<String>> futures = new HashMap<>();
futures.put(ClusterType.SERVICE_DISCOVER_CLUSTER, readyFuture);
connectionManager = new ConnectionManager(ctx, null, futures);
}
Aggregations