Skip to content

Commit 21e5ba4

Browse files
authored
Merge pull request #2 from seymourtang/refactor
refactor:Refactor project structure
2 parents 4326f25 + 5ea97da commit 21e5ba4

File tree

22 files changed

+192
-203
lines changed

22 files changed

+192
-203
lines changed

README.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<img alt="Maven Central Version" src="https://img.shields.io/maven-central/v/io.agora/agora-rest-client-core?colorB=brightgreen">
55
<img alt="GitHub License" src="https://img.shields.io/github/license/AgoraIO-Community/agora-rest-client-java">
66
<a href="https://github.com/AgoraIO-Community/agora-rest-client-java/actions/workflows/maven.yml"><img alt="Java CI with Maven" src="https://github.com/AgoraIO-Community/agora-rest-client-java/actions/workflows/maven.yml/badge.svg"></a>
7+
<a href="https://github.com/AgoraIO-Community/agora-rest-client-java/actions/workflows/gitee-sync.yml"><img alt="gitee-sync" src="https://github.com/AgoraIO-Community/agora-rest-client-java/actions/workflows/gitee-sync.yml/badge.svg?branch=main"></a>
78
<img alt="GitHub" src="https://img.shields.io/github/v/release/AgoraIO-Community/agora-rest-client-java">
89
<img alt="GitHub Issues or Pull Requests" src="https://img.shields.io/github/issues-pr/AgoraIO-Community/agora-rest-client-java">
910
</p>
@@ -53,15 +54,15 @@ API 接口的包装和内部实现,可以帮助开发者更加方便的集成
5354
package com.company.example;
5455

5556
import io.agora.rest.AgoraException;
56-
import io.agora.rest.AgoraService;
57-
import io.agora.rest.core.AgoraProperty;
57+
import io.agora.rest.core.AgoraConfig;
5858
import io.agora.rest.core.BasicAuthCredential;
5959
import io.agora.rest.core.Credential;
60-
import io.agora.rest.core.RegionArea;
60+
import io.agora.rest.core.DomainArea;
6161
import io.agora.rest.services.cloudrecording.api.req.StartResourceReq;
6262
import io.agora.rest.services.cloudrecording.api.res.AcquireResourceRes;
6363
import io.agora.rest.services.cloudrecording.api.res.StartResourceRes;
6464
import io.agora.rest.services.cloudrecording.api.res.StopResourceRes;
65+
import io.agora.rest.services.cloudrecording.CloudRecordingClient;
6566
import io.agora.rest.services.cloudrecording.scenario.mix.req.AcquireMixRecordingResourceClientReq;
6667
import io.agora.rest.services.cloudrecording.scenario.mix.req.StartMixRecordingResourceClientReq;
6768
import io.agora.rest.services.cloudrecording.scenario.mix.res.QueryMixHLSAndMP4RecordingResourceRes;
@@ -94,26 +95,28 @@ public class Main {
9495

9596
public static void main(String[] args) throws Exception {
9697

97-
Credential basicAuthCredential = new BasicAuthCredential(username, password);
98+
Credential credential = new BasicAuthCredential(username, password);
9899

99-
// Initialize AgoraService
100-
AgoraService agoraService = new AgoraService(
101-
AgoraProperty.builder()
102-
.appId(appId)
103-
.credential(basicAuthCredential)
104-
// Specify the region where the server is located.
105-
// Optional values are CN, NA, EU, AP, and the client will automatically
106-
// switch to use the best domain name according to the configured region
107-
.regionArea(RegionArea.CNRegionArea)
108-
.build()
109-
);
100+
// Initialize AgoraConfig
101+
AgoraConfig agoraConfig = AgoraConfig.builder()
102+
.appId(appId)
103+
.credential(credential)
104+
// Specify the region where the server is located.
105+
// Optional values are CN, US, EU, AP, and the client will automatically
106+
// switch to use the best domain name according to the configured region
107+
.domainArea(DomainArea.)
108+
.build();
109+
110+
// Initialize CloudRecordingClient
111+
112+
CloudRecordingClient cloudRecordingClient = CloudRecordingClient.create(agoraConfig);
110113

111114

112115
AcquireResourceRes acquireResourceRes;
113116

114117
// Acquire resource
115118
try {
116-
acquireResourceRes = agoraService.cloudRecording()
119+
acquireResourceRes = cloudRecordingClient
117120
.mixScenario()
118121
.acquire(cname, uid, AcquireMixRecordingResourceClientReq.builder()
119122
.build())
@@ -176,7 +179,7 @@ public class Main {
176179

177180
// Start resource
178181
try {
179-
startResourceRes = agoraService.cloudRecording()
182+
startResourceRes = cloudRecordingClient
180183
.mixScenario()
181184
.start(cname, uid,
182185
acquireResourceRes.getResourceId(),
@@ -203,11 +206,11 @@ public class Main {
203206

204207
Thread.sleep(3000);
205208

206-
QueryMixHLSAndMP4RecordingResourceRes queryResourceResp;
209+
QueryMixHLSAndMP4RecordingResourceRes queryResourceRes;
207210

208211
// Query resource
209212
try {
210-
queryResourceRes = agoraService.cloudRecording()
213+
queryResourceRes = cloudRecordingClient
211214
.mixScenario()
212215
.queryHLSAndMP4(startResourceRes.getResourceId(), startResourceRes.getSid())
213216
.block();
@@ -220,7 +223,7 @@ public class Main {
220223
return;
221224
}
222225

223-
if (queryResourceRes == null || queryResourceResp.getServerResponse() == null) {
226+
if (queryResourceRes == null || queryResourceRes.getServerResponse() == null) {
224227
System.out.println("failed to query resource");
225228
return;
226229
}
@@ -233,7 +236,7 @@ public class Main {
233236

234237
// Stop resource
235238
try {
236-
stopResourceRes = agoraService.cloudRecording()
239+
stopResourceRes = cloudRecordingClient
237240
.mixScenario()
238241
.stop(cname, uid, startResourceRes.getResourceId(), startResourceRes.getSid(),
239242
true)
@@ -256,7 +259,6 @@ public class Main {
256259
}
257260
}
258261

259-
260262
```
261263

262264
更多的示例可在 [Example](./examples) 查看

agora-rest-client-core/src/main/java/io/agora/rest/AgoraService.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

agora-rest-client-core/src/main/java/io/agora/rest/core/AgoraProperty.java renamed to agora-rest-client-core/src/main/java/io/agora/rest/core/AgoraConfig.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package io.agora.rest.core;
22

3-
public class AgoraProperty {
3+
public class AgoraConfig {
44
private final String appId;
55

66
private final Credential credential;
77

8-
private final RegionArea regionArea;
8+
private final DomainArea domainArea;
99

1010
private final HttpProperty httpProperty;
1111

12-
private AgoraProperty(Builder builder) {
12+
private AgoraConfig(Builder builder) {
1313
this.appId = builder.appId;
1414
this.credential = builder.credential;
15-
this.regionArea = builder.regionArea;
15+
this.domainArea = builder.domainArea;
1616
this.httpProperty = builder.httpProperty;
1717
}
1818

@@ -28,8 +28,8 @@ public Credential getCredential() {
2828
return credential;
2929
}
3030

31-
public RegionArea getRegionArea() {
32-
return regionArea;
31+
public DomainArea getDomainArea() {
32+
return domainArea;
3333
}
3434

3535
public HttpProperty getHttpProperty() {
@@ -38,10 +38,10 @@ public HttpProperty getHttpProperty() {
3838

3939
@Override
4040
public String toString() {
41-
return "AgoraProperty{" +
41+
return "AgoraConfig{" +
4242
"appId='" + appId + '\'' +
4343
", credential=" + credential +
44-
", regionArea=" + regionArea +
44+
", domainArea=" + domainArea +
4545
", httpProperty=" + httpProperty +
4646
'}';
4747
}
@@ -52,7 +52,7 @@ public static class Builder {
5252

5353
private Credential credential;
5454

55-
private RegionArea regionArea;
55+
private DomainArea domainArea;
5656

5757
private HttpProperty httpProperty;
5858

@@ -69,8 +69,8 @@ public Builder credential(Credential credential) {
6969
return this;
7070
}
7171

72-
public Builder regionArea(RegionArea regionArea) {
73-
this.regionArea = regionArea;
72+
public Builder domainArea(DomainArea domainArea) {
73+
this.domainArea = domainArea;
7474
return this;
7575
}
7676

@@ -79,11 +79,11 @@ private Builder httpProperty(HttpProperty httpProperty) {
7979
return this;
8080
}
8181

82-
public AgoraProperty build() {
82+
public AgoraConfig build() {
8383
if (httpProperty == null) {
8484
this.httpProperty = HttpProperty.builder().build();
8585
}
86-
return new AgoraProperty(this);
86+
return new AgoraConfig(this);
8787
}
8888
}
8989
}

agora-rest-client-core/src/main/java/io/agora/rest/core/Context.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ public interface Context {
77

88
<T> Mono<T> sendRequest(String path, HttpMethod method, Object requestBody, Class<T> clazz);
99

10-
AgoraProperty getProperty();
10+
AgoraConfig getAgoraConfig();
1111
}

agora-rest-client-core/src/main/java/io/agora/rest/core/DefaultContext.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ public class DefaultContext implements Context {
1616

1717
private static final Logger logger = LoggerFactory.getLogger(DefaultContext.class);
1818

19-
private final AgoraProperty property;
19+
private final AgoraConfig agoraConfig;
2020

2121
private final HttpClient httpClient;
2222

2323
private final Codec codec;
2424

2525
private final DomainPool domainPool;
2626

27-
public DefaultContext(AgoraProperty property) {
28-
this.property = property;
29-
this.httpClient = HttpClientFactory.createHttpClient(property);
30-
this.domainPool = new DomainPool(property.getRegionArea());
27+
public DefaultContext(AgoraConfig agoraConfig) {
28+
this.agoraConfig = agoraConfig;
29+
this.httpClient = HttpClientFactory.createHttpClient(agoraConfig);
30+
this.domainPool = new DomainPool(agoraConfig.getDomainArea());
3131
this.codec = new JsonCodec();
3232
}
3333

@@ -73,7 +73,7 @@ public <T> Mono<T> sendRequest(String path, HttpMethod method, Object requestBod
7373
}
7474

7575
@Override
76-
public AgoraProperty getProperty() {
77-
return this.property;
76+
public AgoraConfig getAgoraConfig() {
77+
return this.agoraConfig;
7878
}
7979
}

agora-rest-client-core/src/main/java/io/agora/rest/core/RegionArea.java renamed to agora-rest-client-core/src/main/java/io/agora/rest/core/DomainArea.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,45 @@
44
import java.util.Collections;
55
import java.util.List;
66

7-
public enum RegionArea {
7+
public enum DomainArea {
88
/**
9-
* Unknown region area
9+
* Unknown domain area
1010
*/
11-
UnkonwnRegionArea(Collections.emptyList(), Collections.emptyList()),
11+
Unknown(Collections.emptyList(), Collections.emptyList()),
1212

1313
/**
14-
* US region area
14+
* US domain area
1515
*/
16-
USRegionArea(
16+
US(
1717
Arrays.asList("api-us-west-1", "api-us-east-1"),
1818
Arrays.asList("agora.io", "sd-rtn.com")),
1919

2020
/**
21-
* EU region area
21+
* EU domain area
2222
*/
23-
EURegionArea(
23+
EU(
2424
Arrays.asList("api-eu-west-1", "api-eu-central-1"),
2525
Arrays.asList("agora.io", "sd-rtn.com")),
2626

2727
/**
28-
* AP region area
28+
* AP domain area
2929
*/
30-
APRegionArea(
30+
AP(
3131
Arrays.asList("api-ap-southeast-1", "api-ap-northeast-1"),
3232
Arrays.asList("agora.io", "sd-rtn.com")),
3333

3434
/**
35-
* CN region area
35+
* CN domain area
3636
*/
37-
CNRegionArea(
37+
CN(
3838
Arrays.asList("api-cn-east-1", "api-cn-north-1"),
3939
Arrays.asList("sd-rtn.com", "agora.io"));
4040

4141
private final List<String> regionDomainPrefixes;
4242

4343
private final List<String> majorDomainSuffixes;
4444

45-
RegionArea(List<String> regionDomainPrefixes, List<String> majorDomainSuffixes) {
45+
DomainArea(List<String> regionDomainPrefixes, List<String> majorDomainSuffixes) {
4646
this.regionDomainPrefixes = Collections.unmodifiableList(regionDomainPrefixes);
4747
this.majorDomainSuffixes = Collections.unmodifiableList(majorDomainSuffixes);
4848
}

agora-rest-client-core/src/main/java/io/agora/rest/core/DomainPool.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public class DomainPool {
3030

3131
private final Logger logger = LoggerFactory.getLogger(DomainPool.class);
3232

33-
public DomainPool(RegionArea domainArea) {
34-
if (domainArea == null || domainArea == RegionArea.UnkonwnRegionArea) {
33+
public DomainPool(DomainArea domainArea) {
34+
if (domainArea == null || domainArea == DomainArea.Unknown) {
3535
throw new AgoraInvalidArgumentException("invalid domain area");
3636
}
3737

agora-rest-client-core/src/main/java/io/agora/rest/core/HttpClientFactory.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ public class HttpClientFactory {
1313

1414
private static final Logger logger = LoggerFactory.getLogger(HttpClientFactory.class);
1515

16-
public static HttpClient createHttpClient(AgoraProperty agoraProperty) {
16+
public static HttpClient createHttpClient(AgoraConfig agoraConfig) {
1717
ConnectionProvider connectionProvider = ConnectionProvider.builder("agora-rest-client")
18-
.maxConnections(agoraProperty.getHttpProperty().getHttpConnectionPoolSize())
19-
.pendingAcquireTimeout(Duration.ofMillis(agoraProperty.getHttpProperty().getHttpConnectionPendingAcquireTimout()))
20-
.maxIdleTime(Duration.ofMillis(agoraProperty.getHttpProperty().getHttpConnectionMaxIdleTime()))
21-
.maxLifeTime(Duration.ofMillis(agoraProperty.getHttpProperty().getHttpConnectionMaxLifeTime()))
22-
.evictInBackground(Duration.ofMillis(agoraProperty.getHttpProperty().getHttpConnectionEvictInBackground()))
23-
.pendingAcquireMaxCount(agoraProperty.getHttpProperty().getHttpConnectionPendingAcquireMaxCount())
18+
.maxConnections(agoraConfig.getHttpProperty().getHttpConnectionPoolSize())
19+
.pendingAcquireTimeout(Duration.ofMillis(agoraConfig.getHttpProperty().getHttpConnectionPendingAcquireTimout()))
20+
.maxIdleTime(Duration.ofMillis(agoraConfig.getHttpProperty().getHttpConnectionMaxIdleTime()))
21+
.maxLifeTime(Duration.ofMillis(agoraConfig.getHttpProperty().getHttpConnectionMaxLifeTime()))
22+
.evictInBackground(Duration.ofMillis(agoraConfig.getHttpProperty().getHttpConnectionEvictInBackground()))
23+
.pendingAcquireMaxCount(agoraConfig.getHttpProperty().getHttpConnectionPendingAcquireMaxCount())
2424
.lifo()
2525
.build();
2626

@@ -32,11 +32,11 @@ public static HttpClient createHttpClient(AgoraProperty agoraProperty) {
3232
System.getProperty("os.arch"),
3333
System.getProperty("os.name"),
3434
AgoraVersion.getVersion()));
35-
if (agoraProperty.getCredential() != null) {
36-
agoraProperty.getCredential().setAuthorization(h);
35+
if (agoraConfig.getCredential() != null) {
36+
agoraConfig.getCredential().setAuthorization(h);
3737
}
3838
})
39-
.wiretap("io.agora.rest.core.http", LogLevel.DEBUG, agoraProperty.getHttpProperty().getHttpLogFormat())
39+
.wiretap("io.agora.rest.core.http", LogLevel.DEBUG, agoraConfig.getHttpProperty().getHttpLogFormat())
4040
.doOnRequestError((req, t) -> logger.error("request error:{}", t.getMessage()));
4141

4242
}

0 commit comments

Comments
 (0)