Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3851f19
AmqpConnection implements AutoCloseable. Add getEndpointStates().
conniey Nov 21, 2019
0c6c6a9
AmqpConnection/Link/Session. implements AutoCloseable. Add getEndpoin…
conniey Nov 21, 2019
278ae19
CBSNode implements AutoCloseable.
conniey Nov 21, 2019
d299eb3
Delete EndpointStateNotifier. Add ShutdownSignals to Connection.
conniey Nov 21, 2019
d71e863
Delete EndpointStateNotifierBase.
conniey Nov 22, 2019
6a4ccce
Update parameter name for MessageConstant.fromValue
conniey Nov 22, 2019
c813b11
Move AmqpExceptionHandler into implementation class.
conniey Nov 22, 2019
91bca87
Update documentation in AmqpReceiveLink.
conniey Nov 22, 2019
39633d1
Update CBS -> Cbs.
conniey Nov 22, 2019
d6e3a0b
Fix CBSChannel.
conniey Nov 22, 2019
9dfae9c
Add AmqpEndpointStateUtil.
conniey Nov 22, 2019
b6ed6c0
Fix ReactorConnection.
conniey Nov 22, 2019
a3e203a
Fix errors in updated sender and receiver.
conniey Nov 22, 2019
c3cf06d
Fix test errors.
conniey Nov 22, 2019
815c789
Fix close build issue.
conniey Nov 22, 2019
15b2dde
Fix try/catch IOException.
conniey Nov 22, 2019
0bd64d1
Fixing test breaks.
conniey Nov 22, 2019
6de70bd
Fix assertions in test.
conniey Nov 22, 2019
59ebdef
Fixing test issue.
conniey Nov 22, 2019
08837ea
Closing ReactorReceiver on errors or closures in link.
conniey Nov 22, 2019
868a2db
Fix test failures.
conniey Nov 22, 2019
7911c72
Fixing checkstyle issue.
conniey Nov 23, 2019
dc5d2e2
Merge branch 'master' of https://github.com/azure/azure-sdk-for-java …
conniey Nov 24, 2019
45fc100
Fixing tests.
conniey Nov 24, 2019
b244790
rename connectionStates -> endpointStates
conniey Nov 24, 2019
7b54ace
Fix problem with sends.
conniey Nov 24, 2019
66c5736
Add timeouts to test.
conniey Nov 24, 2019
00c51a7
Fix event position test.
conniey Nov 24, 2019
5297688
Fix tests.
conniey Nov 25, 2019
d797d21
Fixing checkstyle issues.
conniey Nov 25, 2019
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 @@ -3,15 +3,16 @@

package com.azure.core.amqp;

import com.azure.core.amqp.exception.AmqpException;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.io.Closeable;
import java.util.Map;

/**
* Represents a TCP connection between the client and a service that uses the AMQP protocol.
*/
public interface AmqpConnection extends EndpointStateNotifier, Closeable {
public interface AmqpConnection extends AutoCloseable {
/**
* Gets the connection identifier.
*
Expand Down Expand Up @@ -62,4 +63,25 @@ public interface AmqpConnection extends EndpointStateNotifier, Closeable {
* @return {@code true} if a session with the name was removed; {@code false} otherwise.
*/
boolean removeSession(String sessionName);

/**
* Gets the endpoint states for the AMQP connection. {@link AmqpException AmqpExceptions} that occur on the link are
* reported in the connection state. When the stream terminates, the connection is closed.
*
* @return A stream of endpoint states for the AMQP connection.
*/
Flux<AmqpEndpointState> getEndpointStates();

/**
* Gets any shutdown signals that occur in the AMQP endpoint.
*
* @return A stream of shutdown signals that occur in the AMQP endpoint.
*/
Flux<AmqpShutdownSignal> getShutdownSignals();

/**
* Closes the AMQP connection.
*/
@Override
void close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

package com.azure.core.amqp;

import java.io.Closeable;
import com.azure.core.amqp.exception.AmqpException;
import reactor.core.publisher.Flux;

/**
* Represents a unidirectional AMQP link.
*/
public interface AmqpLink extends EndpointStateNotifier, Closeable {
public interface AmqpLink extends AutoCloseable {
/**
* Gets the name of the link.
*
Expand All @@ -29,4 +30,18 @@ public interface AmqpLink extends EndpointStateNotifier, Closeable {
* @return The host name of the message broker that this link that is connected to.
*/
String getHostname();

/**
* Gets the endpoint states for the AMQP link. {@link AmqpException AmqpExceptions} that occur on the link are
* reported in the connection state. When the stream terminates, the link is closed.
*
* @return A stream of endpoint states for the AMQP link.
*/
Flux<AmqpEndpointState> getEndpointStates();

/**
* Closes the AMQP link.
*/
@Override
void close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ public String getValue() {
/**
* Parses an header value to its message constant.
*
* @param headerValue the messaging header value to parse.
* @param value the messaging header value to parse.
* @return the parsed MessageConstant object, or {@code null} if unable to parse.
* @throws NullPointerException if {@code constant} is {@code null}.
*/
public static AmqpMessageConstant fromString(String headerValue) {
Objects.requireNonNull(headerValue, "'headerValue' cannot be null.");
public static AmqpMessageConstant fromString(String value) {
Objects.requireNonNull(value, "'value' cannot be null.");

return RESERVED_CONSTANTS_MAP.get(headerValue);
return RESERVED_CONSTANTS_MAP.get(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

package com.azure.core.amqp;

import com.azure.core.amqp.exception.AmqpException;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.io.Closeable;
import java.time.Duration;

/**
* An AMQP session representing bidirectional communication that supports multiple {@link AmqpLink AMQP links}.
*/
public interface AmqpSession extends EndpointStateNotifier, Closeable {
public interface AmqpSession extends AutoCloseable {
/**
* Gets the name for this AMQP session.
*
Expand Down Expand Up @@ -55,4 +56,18 @@ public interface AmqpSession extends EndpointStateNotifier, Closeable {
* @return {@code true} if the link was removed; {@code false} otherwise.
*/
boolean removeLink(String linkName);

/**
* Gets the endpoint states for the AMQP session. {@link AmqpException AmqpExceptions} that occur on the link are
* reported in the connection state. When the stream terminates, the session is closed.
*
* @return A stream of endpoint states for the AMQP session.
*/
Flux<AmqpEndpointState> getEndpointStates();

/**
* Closes the AMQP session.
*/
@Override
void close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.azure.core.credential.TokenCredential;
import reactor.core.publisher.Mono;

import java.io.Closeable;
import java.time.OffsetDateTime;

/**
Expand All @@ -15,7 +14,7 @@
* @see <a href="https://www.oasis-open.org/committees/download.php/62097/amqp-cbs-v1.0-wd05.doc">
* AMPQ Claims-based Security v1.0</a>
*/
public interface ClaimsBasedSecurityNode extends EndpointStateNotifier, Closeable {
public interface ClaimsBasedSecurityNode extends AutoCloseable {
/**
* Authorizes the caller with the CBS node to access resources for the {@code audience}.
*
Expand All @@ -26,4 +25,10 @@ public interface ClaimsBasedSecurityNode extends EndpointStateNotifier, Closeabl
* CBS node.
*/
Mono<OffsetDateTime> authorize(String audience, String scopes);

/**
* Closes session to the claims-based security node.
*/
@Override
void close();
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.amqp.implementation;

import com.azure.core.amqp.AmqpEndpointState;
import org.apache.qpid.proton.engine.EndpointState;

/**
* Helper class for managing endpoint states from proton-j.
*/
class AmqpEndpointStateUtil {
/**
* Translates proton-j endpoint states into an AMQP endpoint state.
* @param state proton-j endpoint state.
* @return The corresponding {@link AmqpEndpointState}.
* @throws IllegalArgumentException if {@code state} is not a supported {@link AmqpEndpointState}.
*/
static AmqpEndpointState getConnectionState(EndpointState state) {
switch (state) {
case ACTIVE:
return AmqpEndpointState.ACTIVE;
case UNINITIALIZED:
return AmqpEndpointState.UNINITIALIZED;
case CLOSED:
return AmqpEndpointState.CLOSED;
default:
throw new IllegalArgumentException("This endpoint state is not supported. State:" + state);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.amqp;
package com.azure.core.amqp.implementation;

import com.azure.core.amqp.AmqpShutdownSignal;
import com.azure.core.util.logging.ClientLogger;

/**
* Handles exceptions generated by AMQP connections, sessions, and/or links.
*/
public abstract class AmqpExceptionHandler {
abstract class AmqpExceptionHandler {
private final ClientLogger logger = new ClientLogger(AmqpExceptionHandler.class);

/**
* Creates a new instance of the exception handler.
*/
protected AmqpExceptionHandler() {
AmqpExceptionHandler() {
}

/**
* Notifies the exception handler of an exception.
*
* @param exception The exception that caused the connection error.
*/
public void onConnectionError(Throwable exception) {
void onConnectionError(Throwable exception) {
logger.warning("Connection exception encountered: " + exception.toString(), exception);
}

Expand All @@ -31,7 +32,7 @@ public void onConnectionError(Throwable exception) {
*
* @param shutdownSignal The shutdown signal that was received.
*/
public void onConnectionShutdown(AmqpShutdownSignal shutdownSignal) {
void onConnectionShutdown(AmqpShutdownSignal shutdownSignal) {
logger.info("Shutdown received: {}", shutdownSignal);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.apache.qpid.proton.message.Message;
import reactor.core.publisher.Flux;

import java.io.Closeable;
import java.util.function.Supplier;

/**
Expand All @@ -21,7 +20,7 @@ public interface AmqpReceiveLink extends AmqpLink {
* Initialises the link from the client to the message broker and begins to receive messages from the broker.
*
* @return A Flux of AMQP messages which completes when the client calls
* {@link Closeable#close() AmqpReceiveLink.close()} or an unrecoverable error occurs on the AMQP link.
* {@link AutoCloseable#close() AmqpReceiveLink.close()} or an unrecoverable error occurs on the AMQP link.
*/
Flux<Message> receive();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class AzureTokenManagerProvider implements TokenManagerProvider {
static final String TOKEN_AUDIENCE_FORMAT = "amqp://%s/%s";

private final ClientLogger logger = new ClientLogger(AzureTokenManagerProvider.class);
private final CBSAuthorizationType authorizationType;
private final CbsAuthorizationType authorizationType;
private final String fullyQualifiedNamespace;
private final String activeDirectoryScope;

Expand All @@ -29,7 +29,7 @@ public class AzureTokenManagerProvider implements TokenManagerProvider {
* @param fullyQualifiedNamespace Fully-qualified namespace of the message broker.
* @param activeDirectoryScope Scope used to access AD resources for the Azure service.
*/
public AzureTokenManagerProvider(CBSAuthorizationType authorizationType, String fullyQualifiedNamespace,
public AzureTokenManagerProvider(CbsAuthorizationType authorizationType, String fullyQualifiedNamespace,
String activeDirectoryScope) {
this.activeDirectoryScope = Objects.requireNonNull(activeDirectoryScope,
"'activeDirectoryScope' cannot be null.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* An enumeration of supported authorization methods with the {@link ClaimsBasedSecurityNode}.
*/
public enum CBSAuthorizationType {
public enum CbsAuthorizationType {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to expand CBS here just like we have done for other types?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CbsAuthorizationType is used in the ClaimsBasedSecurityNode class, I thought it would be overkill.

/**
* Authorize with CBS through a shared access signature.
*/
Expand All @@ -23,7 +23,7 @@ public enum CBSAuthorizationType {

private final String scheme;

CBSAuthorizationType(String scheme) {
CbsAuthorizationType(String scheme) {
this.scheme = scheme;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.azure.core.amqp.ClaimsBasedSecurityNode;
import com.azure.core.credential.TokenCredential;
import com.azure.core.credential.TokenRequestContext;
import com.azure.core.util.logging.ClientLogger;
import org.apache.qpid.proton.Proton;
import org.apache.qpid.proton.amqp.messaging.AmqpValue;
import org.apache.qpid.proton.amqp.messaging.ApplicationProperties;
Expand All @@ -19,20 +18,19 @@
import java.util.Map;
import java.util.Objects;

public class ClaimsBasedSecurityChannel extends EndpointStateNotifierBase implements ClaimsBasedSecurityNode {
static final String PUT_TOKEN_OPERATION = "operation";
static final String PUT_TOKEN_OPERATION_VALUE = "put-token";
public class ClaimsBasedSecurityChannel implements ClaimsBasedSecurityNode {
static final String PUT_TOKEN_TYPE = "type";
static final String PUT_TOKEN_AUDIENCE = "name";
private static final String PUT_TOKEN_OPERATION = "operation";
private static final String PUT_TOKEN_OPERATION_VALUE = "put-token";

private final TokenCredential credential;
private final Mono<RequestResponseChannel> cbsChannelMono;
private final CBSAuthorizationType authorizationType;
private final CbsAuthorizationType authorizationType;
private final AmqpRetryOptions retryOptions;

public ClaimsBasedSecurityChannel(Mono<RequestResponseChannel> responseChannelMono, TokenCredential tokenCredential,
CBSAuthorizationType authorizationType, AmqpRetryOptions retryOptions) {
super(new ClientLogger(ClaimsBasedSecurityChannel.class));
CbsAuthorizationType authorizationType, AmqpRetryOptions retryOptions) {

this.authorizationType = Objects.requireNonNull(authorizationType, "'authorizationType' cannot be null.");
this.retryOptions = Objects.requireNonNull(retryOptions, "'retryOptions' cannot be null.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public class ConnectionOptions {
private final Scheduler scheduler;
private final String fullyQualifiedNamespace;
private final String entityPath;
private final CBSAuthorizationType authorizationType;
private final CbsAuthorizationType authorizationType;

public ConnectionOptions(String fullyQualifiedNamespace, String entityPath, TokenCredential tokenCredential,
CBSAuthorizationType authorizationType, AmqpTransportType transport, AmqpRetryOptions retryOptions,
CbsAuthorizationType authorizationType, AmqpTransportType transport, AmqpRetryOptions retryOptions,
ProxyOptions proxyOptions, Scheduler scheduler) {
this.fullyQualifiedNamespace = Objects.requireNonNull(fullyQualifiedNamespace,
"'fullyQualifiedNamespace' is required.");
Expand All @@ -52,7 +52,7 @@ public TokenCredential getTokenCredential() {
return tokenCredential;
}

public CBSAuthorizationType getAuthorizationType() {
public CbsAuthorizationType getAuthorizationType() {
return authorizationType;
}

Expand Down
Loading