Skip to content

Commit 0a1eceb

Browse files
committed
Merge branch 'main' into manual-puback
2 parents 61dde73 + 65e4e97 commit 0a1eceb

32 files changed

Lines changed: 703 additions & 126 deletions

crt/aws-c-auth

crt/aws-lc

src/main/java/software/amazon/awssdk/crt/http/HttpStreamBase.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55

66
package software.amazon.awssdk.crt.http;
77

8-
import software.amazon.awssdk.crt.CRT;
98
import software.amazon.awssdk.crt.CrtResource;
10-
import software.amazon.awssdk.crt.CrtRuntimeException;
11-
12-
import java.util.concurrent.CompletableFuture;
139

1410
/**
1511
* An base class represents a single Http Request/Response for both HTTP/1.1 and
@@ -100,6 +96,22 @@ public int getResponseStatusCode() {
10096
throw new IllegalStateException("Can't get Status Code on Closed Stream");
10197
}
10298

99+
/**
100+
* Cancels the stream with the default error code (AWS_ERROR_HTTP_STREAM_CANCELLED).
101+
* <p>
102+
* For HTTP/1.1 streams, this is equivalent to closing the connection.
103+
* For HTTP/2 streams, this sends a RST_STREAM frame with AWS_HTTP2_ERR_CANCEL.
104+
* <p>
105+
* The stream will complete with AWS_ERROR_HTTP_STREAM_CANCELLED, unless the stream is
106+
* already completing for other reasons, or the stream is not activated,
107+
* in which case this call will have no effect.
108+
*/
109+
public void cancel() {
110+
if (!isNull()) {
111+
httpStreamBaseCancelDefaultError(getNativeHandle());
112+
}
113+
}
114+
103115
/*******************************************************************************
104116
* Native methods
105117
******************************************************************************/
@@ -111,4 +123,6 @@ public int getResponseStatusCode() {
111123
private static native void httpStreamBaseActivate(long http_stream, HttpStreamBase streamObj);
112124

113125
private static native int httpStreamBaseGetResponseStatusCode(long http_stream);
126+
127+
private static native void httpStreamBaseCancelDefaultError(long http_stream);
114128
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
package software.amazon.awssdk.crt.internal;
6+
7+
/**
8+
* @internal
9+
* IoT Device SDK Metrics Structure. Not for external usage.
10+
*/
11+
public class IoTDeviceSDKMetrics {
12+
private String libraryName;
13+
14+
public IoTDeviceSDKMetrics() {
15+
this.libraryName = "IoTDeviceSDK/Java";
16+
}
17+
18+
public String getLibraryName() {
19+
return libraryName;
20+
}
21+
}

src/main/java/software/amazon/awssdk/crt/mqtt/MqttClientConnection.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import software.amazon.awssdk.crt.mqtt5.Mqtt5Client;
1818
import software.amazon.awssdk.crt.mqtt5.Mqtt5ClientOptions;
1919
import software.amazon.awssdk.crt.mqtt5.packets.ConnectPacket;
20+
import software.amazon.awssdk.crt.internal.IoTDeviceSDKMetrics;
2021

2122
import java.util.concurrent.CompletableFuture;
2223
import java.util.function.Consumer;
@@ -77,6 +78,7 @@ private static MqttConnectionConfig s_toMqtt3ConnectionConfig(Mqtt5ClientOptions
7778
options.setProtocolOperationTimeoutMs(mqtt5options.getAckTimeoutSeconds() != null
7879
? Math.toIntExact(mqtt5options.getAckTimeoutSeconds()) * 1000
7980
: 0);
81+
options.setMetricsEnabled(mqtt5options.getMetricsEnabled());
8082
return options;
8183
}
8284

@@ -162,6 +164,10 @@ private void SetupConfig(MqttConnectionConfig config) throws MqttException {
162164
mqttClientConnectionSetLogin(getNativeHandle(), config.getUsername(), config.getPassword());
163165
}
164166

167+
if (config.getMetricsEnabled()) {
168+
mqttClientConnectionSetMetrics(getNativeHandle(), new IoTDeviceSDKMetrics());
169+
}
170+
165171
if (config.getMinReconnectTimeoutSecs() != 0L && config.getMaxReconnectTimeoutSecs() != 0L) {
166172
mqttClientConnectionSetReconnectTimeout(getNativeHandle(), config.getMinReconnectTimeoutSecs(),
167173
config.getMaxReconnectTimeoutSecs());
@@ -502,6 +508,9 @@ private static native boolean mqttClientConnectionSetWill(long connection, Strin
502508
private static native void mqttClientConnectionSetLogin(long connection, String username, String password)
503509
throws CrtRuntimeException;
504510

511+
private static native void mqttClientConnectionSetMetrics(long connection, IoTDeviceSDKMetrics metrics)
512+
throws CrtRuntimeException;
513+
505514
private static native void mqttClientConnectionSetReconnectTimeout(long connection, long minTimeout,
506515
long maxTimeout)
507516
throws CrtRuntimeException;

src/main/java/software/amazon/awssdk/crt/mqtt/MqttConnectionConfig.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public final class MqttConnectionConfig extends CrtResource {
4646
private HttpProxyOptions proxyOptions;
4747
private Consumer<WebsocketHandshakeTransformArgs> websocketHandshakeTransform;
4848

49+
/* metrics */
50+
private boolean metricsEnabled = true;
51+
4952
public MqttConnectionConfig() {}
5053

5154

@@ -538,6 +541,24 @@ public Consumer<WebsocketHandshakeTransformArgs> getWebsocketHandshakeTransform(
538541
return websocketHandshakeTransform;
539542
}
540543

544+
/**
545+
* Enables or disables IoT Device SDK metrics collection. The metrics includes SDK name, version, and platform.
546+
*
547+
* @param enabled true to enable metrics, false to disable
548+
*/
549+
public void setMetricsEnabled(boolean enabled) {
550+
this.metricsEnabled = enabled;
551+
}
552+
553+
/**
554+
* Queries whether IoT Device SDK metrics collection is enabled
555+
*
556+
* @return true if metrics are enabled, false if disabled
557+
*/
558+
public boolean getMetricsEnabled() {
559+
return metricsEnabled;
560+
}
561+
541562
/**
542563
* Creates a (shallow) clone of this config object
543564
*
@@ -567,6 +588,7 @@ public MqttConnectionConfig clone() {
567588
clone.setWebsocketHandshakeTransform(getWebsocketHandshakeTransform());
568589

569590
clone.setReconnectTimeoutSecs(getMinReconnectTimeoutSecs(), getMaxReconnectTimeoutSecs());
591+
clone.setMetricsEnabled(getMetricsEnabled());
570592

571593
// success, bump up the ref count so we can escape the try-with-resources block
572594
clone.addRef();

src/main/java/software/amazon/awssdk/crt/mqtt5/Mqtt5ClientOptions.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import software.amazon.awssdk.crt.mqtt5.packets.ConnectPacket;
1414
import software.amazon.awssdk.crt.mqtt.MqttConnectionConfig;
15+
import software.amazon.awssdk.crt.internal.IoTDeviceSDKMetrics;
1516

1617
import java.util.Map;
1718
import java.util.function.Function;
@@ -45,6 +46,12 @@ public class Mqtt5ClientOptions {
4546
private Consumer<Mqtt5WebsocketHandshakeTransformArgs> websocketHandshakeTransform;
4647
private PublishEvents publishEvents;
4748
private TopicAliasingOptions topicAliasingOptions;
49+
// Indicates whether AWS IoT Metrics are enabled for this client, default to true.
50+
// We don't expose iotDeviceSDKMetrics in the builder, and only allow setting
51+
// metricsEnabled for now.
52+
private boolean metricsEnabled = true;
53+
private IoTDeviceSDKMetrics iotDeviceSDKMetrics;
54+
4855

4956
/**
5057
* Returns the host name of the MQTT server to connect to.
@@ -263,6 +270,24 @@ public TopicAliasingOptions getTopicAliasingOptions() {
263270
return this.topicAliasingOptions;
264271
}
265272

273+
/**
274+
* Returns whether AWS IoT Device SDK metrics collection is enabled
275+
*
276+
* @return true if metrics are enabled, false otherwise
277+
*/
278+
public boolean getMetricsEnabled() {
279+
return this.metricsEnabled;
280+
}
281+
282+
/**
283+
* Enables or disables IoT Device SDK metrics collection. The metrics includes SDK name, version, and platform.
284+
*
285+
* @param enabled true to enable metrics, false to disable
286+
*/
287+
public void setMetricsEnabled(boolean enabled) {
288+
this.metricsEnabled = enabled;
289+
}
290+
266291
/**
267292
* Creates a Mqtt5ClientOptionsBuilder instance
268293
* @param builder The builder to get the Mqtt5ClientOptions values from
@@ -289,6 +314,8 @@ public Mqtt5ClientOptions(Mqtt5ClientOptionsBuilder builder) {
289314
this.websocketHandshakeTransform = builder.websocketHandshakeTransform;
290315
this.publishEvents = builder.publishEvents;
291316
this.topicAliasingOptions = builder.topicAliasingOptions;
317+
this.metricsEnabled = builder.metricsEnabled;
318+
this.iotDeviceSDKMetrics = new IoTDeviceSDKMetrics();
292319
}
293320

294321
/*******************************************************************************
@@ -591,6 +618,7 @@ static final public class Mqtt5ClientOptionsBuilder {
591618
private Consumer<Mqtt5WebsocketHandshakeTransformArgs> websocketHandshakeTransform;
592619
private PublishEvents publishEvents;
593620
private TopicAliasingOptions topicAliasingOptions;
621+
private boolean metricsEnabled = true;
594622

595623
/**
596624
* Sets the host name of the MQTT server to connect to.
@@ -858,6 +886,17 @@ public Mqtt5ClientOptionsBuilder withTopicAliasingOptions(TopicAliasingOptions o
858886
return this;
859887
}
860888

889+
/**
890+
* Enables or disables IoT Device SDK metrics collection. The metrics includes SDK name, version, and platform.
891+
*
892+
* @param enabled true to enable metrics, false to disable.
893+
* @return The Mqtt5ClientOptionsBuilder after setting the metrics option
894+
*/
895+
public Mqtt5ClientOptionsBuilder withMetricsEnabled(boolean enabled) {
896+
this.metricsEnabled = enabled;
897+
return this;
898+
}
899+
861900
/**
862901
* Creates a new Mqtt5ClientOptionsBuilder instance
863902
*

src/main/resources/META-INF/native-image/software.amazon.awssdk/crt/aws-crt/jni-config.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,14 @@
12561256
}
12571257
]
12581258
},
1259+
{
1260+
"name": "software.amazon.awssdk.crt.internal.IoTDeviceSDKMetrics",
1261+
"fields": [
1262+
{
1263+
"name": "libraryName"
1264+
}
1265+
]
1266+
},
12591267
{
12601268
"name": "software.amazon.awssdk.crt.mqtt5.Mqtt5ClientOptions",
12611269
"fields": [
@@ -1306,6 +1314,12 @@
13061314
},
13071315
{
13081316
"name": "topicAliasingOptions"
1317+
},
1318+
{
1319+
"name": "iotDeviceSDKMetrics"
1320+
},
1321+
{
1322+
"name": "metricsEnabled"
13091323
}
13101324
],
13111325
"methods": [

0 commit comments

Comments
 (0)