Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Note: Replace <code>VERSION-YOU-WANT-TO-BE-USED</code> by a Jackson version of a
...
```

## Changelog & Migration
## Changelog & Migration
For information about the latest changes in the SDK, please refer to the [CHANGELOG](CHANGELOG.md) file
and the [MIGRATION-GUIDE](MIGRATION-GUIDE.md) for instructions on how to update your code when upgrading to a new major version of the SDK.

Expand Down
77 changes: 52 additions & 25 deletions client/src/main/com/sinch/sdk/SinchClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public class SinchClient {

private final Configuration configuration;

private NumbersService numbers;
private SMSService sms;
private VerificationService verification;
private VoiceService voice;
private ConversationService conversation;
private HttpClientApache httpClient;
private volatile NumbersService numbers;
private volatile SMSService sms;
private volatile VerificationService verification;
private volatile VoiceService voice;
private volatile ConversationService conversation;
private volatile HttpClientApache httpClient;

/**
* Create a Sinch Client instance based onto configuration
Expand Down Expand Up @@ -247,7 +247,11 @@ public Configuration getConfiguration() {
*/
public NumbersService numbers() {
if (null == numbers) {
numbers = numbersInit();
synchronized (this) {
if (null == numbers) {
numbers = numbersInit();
}
}
}
return numbers;
}
Expand All @@ -262,7 +266,11 @@ public NumbersService numbers() {
*/
public SMSService sms() {
if (null == sms) {
sms = smsInit();
synchronized (this) {
if (null == sms) {
sms = smsInit();
}
}
}
return sms;
}
Expand All @@ -277,7 +285,11 @@ public SMSService sms() {
*/
public VerificationService verification() {
if (null == verification) {
verification = verificationInit();
synchronized (this) {
if (null == verification) {
verification = verificationInit();
}
}
}
return verification;
}
Expand All @@ -292,7 +304,11 @@ public VerificationService verification() {
*/
public VoiceService voice() {
if (null == voice) {
voice = voiceInit();
synchronized (this) {
if (null == voice) {
voice = voiceInit();
}
}
}
return voice;
}
Expand All @@ -307,7 +323,11 @@ public VoiceService voice() {
*/
public ConversationService conversation() {
if (null == conversation) {
conversation = conversationInit();
synchronized (this) {
if (null == conversation) {
conversation = conversationInit();
}
}
}
return conversation;
}
Expand Down Expand Up @@ -375,21 +395,28 @@ private Properties handlePropertiesFile(String fileName) {
}

private HttpClientApache getHttpClient() {
if (null == httpClient || httpClient.isClosed()) {
// TODO: by adding a setter, we could imagine having another HTTP client provided
// programmatically or use
// configuration file referencing another class by name
this.httpClient = new HttpClientApache();

// set SDK User-Agent
String userAgent = formatSdkUserAgentHeader();
this.httpClient.setRequestHeaders(
Stream.of(new String[][] {{SDK_USER_AGENT_HEADER, userAgent}})
.collect(Collectors.toMap(data -> data[0], data -> data[1])));

LOGGER.finest(String.format("HTTP client loaded (%s='%s'", SDK_USER_AGENT_HEADER, userAgent));
HttpClientApache local = httpClient;
if (null == local || local.isClosed()) {
synchronized (this) {
local = httpClient;
if (null == local || local.isClosed()) {
// TODO: by adding a setter, we could imagine having another HTTP client provided
// programmatically or use configuration file referencing another class by name
local = new HttpClientApache();

// set SDK User-Agent
String userAgent = formatSdkUserAgentHeader();
local.setRequestHeaders(
Stream.of(new String[][] {{SDK_USER_AGENT_HEADER, userAgent}})
.collect(Collectors.toMap(data -> data[0], data -> data[1])));

LOGGER.finest(
String.format("HTTP client loaded (%s='%s'", SDK_USER_AGENT_HEADER, userAgent));
this.httpClient = local;
}
}
}
return this.httpClient;
return local;
}

private String formatSdkUserAgentHeader() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class ConversationService implements com.sinch.sdk.domains.conversation.C
private final ServerConfiguration oAuthServer;
private final Supplier<HttpClient> httpClientSupplier;

private com.sinch.sdk.domains.conversation.api.v1.ConversationService conversationV1;
private TemplatesService templates;
private volatile com.sinch.sdk.domains.conversation.api.v1.ConversationService conversationV1;
private volatile TemplatesService templates;

public ConversationService(
UnifiedCredentials credentials,
Expand All @@ -30,17 +30,25 @@ public ConversationService(

public com.sinch.sdk.domains.conversation.api.v1.ConversationService v1() {
if (null == this.conversationV1) {
this.conversationV1 =
new com.sinch.sdk.domains.conversation.api.v1.adapters.ConversationService(
credentials, context, oAuthServer, httpClientSupplier);
synchronized (this) {
if (null == this.conversationV1) {
this.conversationV1 =
new com.sinch.sdk.domains.conversation.api.v1.adapters.ConversationService(
credentials, context, oAuthServer, httpClientSupplier);
}
}
}

return this.conversationV1;
}

public TemplatesService templates() {
if (null == this.templates) {
this.templates = new TemplatesService(credentials, context, oAuthServer, httpClientSupplier);
synchronized (this) {
if (null == this.templates) {
this.templates =
new TemplatesService(credentials, context, oAuthServer, httpClientSupplier);
}
}
}
return this.templates;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* callback URL
*
* <p>see <a
* href="https://developers.sinch.com/docs/numbers/api-reference/numbers/tag/Numbers-Callbacks/#tag/Numbers-Callbacks/operation/ImportedNumberService_EventsCallback">online
* href="https://developers.sinch.com/docs/conversation/callbacks#conversation-api-callbacks">online
* documentation</a>
*
* @since 2.0
Expand Down
Loading
Loading