Skip to content

Commit

Permalink
feat: 优化配置初始化逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou-hao committed Jun 12, 2024
1 parent ed30208 commit 36be9b7
Showing 1 changed file with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ProcessZLMediaRuntime implements ZLMediaRuntime {
private final ZLMediaConfigs mediaConfigs;

//api访问密钥
private String secret = "zlmedia4jStartup";
private final String secret = UUID.randomUUID().toString().replace("-", "");

public ProcessZLMediaRuntime(String processFile) {
this(processFile, new ZLMediaConfigs());
Expand Down Expand Up @@ -83,6 +83,7 @@ public ProcessZLMediaRuntime(String processFile,
this.processFile = processFile;
this.mediaConfigs = configs;
this.configs.putAll(configs.createConfigs());
this.configs.put("api.secret",secret);
this.operations = new RestfulZLMediaOperations(
builder
.clone()
Expand All @@ -108,20 +109,9 @@ public Mono<Void> start() {
.fromRunnable(this::start0)
.subscribeOn(Schedulers.boundedElastic())
//等待
.then(startAwait.asMono())
//保存配置
.then(saveConfigs());
.then(startAwait.asMono());
}

private Mono<Void> saveConfigs() {
String newSecret = UUID.randomUUID().toString().replace("-", "");
configs.put("api.secret", newSecret);
return operations
.opsForState()
.setConfigs(configs)
.doOnNext(ignore -> secret = ignore.getOrDefault("api.secret", newSecret))
.then();
}

protected long getPid() {
try {
Expand Down Expand Up @@ -160,7 +150,7 @@ protected void start0() {
.command(file.getAbsolutePath())
.directory(file.getParentFile())
.redirectErrorStream(true)
//.inheritIO()
.inheritIO()
.start();
long pid = getPid();

Expand Down

0 comments on commit 36be9b7

Please sign in to comment.