Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(solon-admin): javadoc #182

Merged
merged 4 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

import java.util.concurrent.TimeUnit;

/**
* 配置文件检查和注入
*
* @author shaokeyibb
* @since 2.3
*/
@Slf4j
@Configuration
public class AdminClientBootstrapConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

import lombok.Data;

/**
* 云模式配置文件
*
* @author shaokeyibb
* @since 2.3
*/
@Data
public class CloudClientProperties implements IClientProperties {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

/**
* 指示此服务作为 solon-admin 客户端,此注解一般用在启动类上。
*
* @author shaokeyibb
* @since 2.3
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.noear.solon.admin.client.config;

/**
* @author shaokeyibb
* @since 2.3
*/
public interface IClientProperties {

boolean isEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

import lombok.Data;

/**
* 本地模式配置文件
*
* @author shaokeyibb
* @since 2.3
*/
@Data
public class LocalClientProperties implements IClientProperties {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

import java.util.Collection;

/**
* 监视器 Controller,用于分发客户端监视器信息
*
* @author shaokeyibb
* @since 2.3
*/
@Controller
@Mapping("/api/monitor")
public class MonitorController {
Expand All @@ -20,6 +26,10 @@ public class MonitorController {
@Inject
private ApplicationRegistrationService applicationRegistrationService;

/**
* 获取所有监视器信息
* @return 所有监视器信息
*/
@Get
@Mapping("/all")
public Collection<Detector> register() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
import lombok.EqualsAndHashCode;
import lombok.ToString;

/**
* 应用程序数据
*
* @author shaokeyibb
* @since 2.3
*/
@Data
@Builder
public class Application {
Expand All @@ -17,10 +23,16 @@ public class Application {
@EqualsAndHashCode.Exclude
private final String metadata;

/**
* 是否展示敏感信息,如:环境变量
*/
@ToString.Exclude
@EqualsAndHashCode.Exclude
private final boolean showSecretInformation;

/**
* 环境信息
*/
@ToString.Exclude
@EqualsAndHashCode.Exclude
private final EnvironmentInformation environmentInformation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
import lombok.NoArgsConstructor;
import org.noear.solon.lang.Nullable;

/**
* 应用程序数据传输 Dto
*
* @param <T> 要传输的数据类型
* @author shaokeyibb
* @since 2.3
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

import java.util.Map;

/**
* 监视器数据
*
* @author shaokeyibb
* @since 2.3
*/
@AllArgsConstructor
@Data
public class Detector {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,23 @@
import java.util.HashMap;
import java.util.Map;

/**
* 应用环境信息
*
* @author shaokeyibb
* @since 2.3
*/
@Data
@Value
public class EnvironmentInformation {

// 系统环境变量
Map<String, String> systemEnvironment;

// 系统属性
Map<String, String> systemProperties;

// 应用配置
Map<String, String> applicationProperties;

public static EnvironmentInformation create() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
import java.util.Timer;
import java.util.TimerTask;

/**
* 自动向 Solon Admin Server 注册客户端信息
*
* @author shaokeyibb
* @since 2.3
*/
@Configuration
public class AutoRegistrationConfiguration {

Expand All @@ -26,12 +32,17 @@ public void afterInjection(
@Inject ApplicationRegistrationService applicationRegistrationService
) {
if (marked == null) return;

// 订阅事件
EventBus.subscribe(AppLoadEndEvent.class, e -> onStart(applicationRegistrationService));
EventBus.subscribe(AppPrestopEndEvent.class, e -> onStop(applicationRegistrationService));
}

public void onStart(ApplicationRegistrationService applicationRegistrationService) {
// 注册应用程序
applicationRegistrationService.register();

// 计划心跳
timer.schedule(new TimerTask() {
@Override
public void run() {
Expand All @@ -41,6 +52,7 @@ public void run() {
}

public void onStop(ApplicationRegistrationService applicationRegistrationService) {
// 取消心跳计时器
timer.cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

import java.net.URL;

/**
* 应用程序注册服务
*
* @author shaokeyibb
* @since 2.3
*/
@Slf4j
@Component
public class ApplicationRegistrationService {
Expand All @@ -31,13 +37,22 @@ private Application.ApplicationBuilder getApplicationBuilder() {
.baseUrl(NetworkUtils.getHostAndPort());
}

/**
* 获取当前应用程序信息
*
* @return 当前应用程序信息
*/
public Application getCurrentApplication() {
return getApplicationBuilder().build();
}

/**
* 向 Solon Admin Server 注册当前应用程序
*/
public void register() {
log.info("Attempting to register this client as an application with Solon Admin server...");
val serverUrl = this.properties.getServerUrl().replaceAll("/+$", "");
// 向 Server 发送注册请求
try (Response response = client.newCall(new Request.Builder()
.url(new URL(serverUrl + "/api/application/register"))
.put(RequestBody.create(MediaType.parse("application/json"),
Expand All @@ -59,9 +74,13 @@ public void register() {
}
}

/**
* 向 Solon Admin Server 注销
*/
public void unregister() {
log.info("Attempting to unregister this client from Solon Admin server...");
val serverUrl = this.properties.getServerUrl().replaceAll("/+$", "");
// 向 Server 发送注销请求
try (Response response = client.newCall(new Request.Builder()
.url(new URL(serverUrl + "/api/application/unregister"))
.delete(RequestBody.create(MediaType.parse("application/json"),
Expand All @@ -77,9 +96,13 @@ public void unregister() {
}
}

/**
* 向 Solon Admin Server 发送心跳
*/
public void heartbeat() {
log.debug("Attempting to send heartbeat to Solon Admin server...");
val serverUrl = this.properties.getServerUrl().replaceAll("/+$", "");
// 向 Server 发送心跳请求
try (Response response = client.newCall(new Request.Builder()
.url(new URL(serverUrl + "/api/application/heartbeat"))
.post(RequestBody.create(MediaType.parse("application/json"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@
import java.util.Collection;
import java.util.stream.Collectors;

/**
* 监视器服务
*
* @author shaokeyibb
* @since 2.3
*/
@Slf4j
@Component
public class MonitorService {

/**
* 获取所有监视器信息
*
* @return 所有监视器信息
*/
public Collection<Detector> getMonitors() {
return DetectorManager.all().parallelStream().map(it -> new Detector(it.getName(), it.getInfo())).collect(Collectors.toSet());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import org.noear.solon.cloud.utils.LocalUtils;
import org.noear.solon.core.Signal;

/**
* @author shaokeyibb
* @since 2.3
*/
public class NetworkUtils {

public static String getHostAndPort() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
* 配置文件检查和注入
*
* @author shaokeyibb
* @since 2.3
*/
@Slf4j
@Configuration
public class AdminServerBootstrapConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

/**
* 指示此服务作为 solon-admin 服务端,此注解一般用在启动类上。
*
* @author shaokeyibb
* @since 2.3
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Inject;

/**
* 配置文件
*
* @author shaokeyibb
* @since 2.3
*/
@Inject(value = "${solon.admin.server}", required = false)
@Configuration
@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
import java.util.ArrayList;
import java.util.List;

/**
* WebSocket 初始化
*
* @author shaokeyibb
* @since 2.3
*/
@Configuration
public class WebSocketConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import org.noear.solon.core.AopContext;
import org.noear.solon.core.Plugin;

/**
* @author shaokeyibb
* @since 2.3
*/
public class XPluginImpl implements Plugin {
@Override
public void start(AopContext context) {
Expand Down
Loading
Loading