Skip to content

Commit

Permalink
remove clientlogger from Handler ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Dec 14, 2021
1 parent 6425523 commit c2aa854
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.azure.core.util.ClientOptions;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.UserAgentUtil;
import com.azure.core.util.logging.ClientLogger;
import org.apache.qpid.proton.Proton;
import org.apache.qpid.proton.amqp.Symbol;
import org.apache.qpid.proton.amqp.transport.ErrorCondition;
Expand All @@ -30,7 +29,6 @@
import java.util.Objects;

import static com.azure.core.amqp.implementation.AmqpLoggingUtils.addErrorCondition;
import static com.azure.core.amqp.implementation.AmqpLoggingUtils.createContextWithConnectionId;
import static com.azure.core.amqp.implementation.ClientConstants.FULLY_QUALIFIED_NAMESPACE_KEY;
import static com.azure.core.amqp.implementation.ClientConstants.HOSTNAME_KEY;

Expand Down Expand Up @@ -62,8 +60,7 @@ public class ConnectionHandler extends Handler {
public ConnectionHandler(final String connectionId, final ConnectionOptions connectionOptions,
SslPeerDetails peerDetails) {
super(connectionId,
Objects.requireNonNull(connectionOptions, "'connectionOptions' cannot be null.").getHostname(),
new ClientLogger(ConnectionHandler.class, createContextWithConnectionId(connectionId)));
Objects.requireNonNull(connectionOptions, "'connectionOptions' cannot be null.").getHostname());
add(new Handshaker());

this.connectionOptions = connectionOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.concurrent.atomic.AtomicBoolean;

import static com.azure.core.amqp.implementation.AmqpLoggingUtils.addSignalTypeAndResult;
import static com.azure.core.amqp.implementation.AmqpLoggingUtils.createContextWithConnectionId;

/**
* Base class for all proton-j handlers.
Expand All @@ -34,14 +35,13 @@ public abstract class Handler extends BaseHandler implements Closeable {
* @param hostname Hostname of the connection. This could be the DNS hostname or the IP address of the
* connection. Usually of the form {@literal "<your-namespace>.service.windows.net"} but can change if the
* messages are brokered through an intermediary.
* @param logger Logger to use for messages.
*
* @throws NullPointerException if {@code connectionId}, {@code hostname}, or {@code logger} is null.
* @throws NullPointerException if {@code connectionId} or {@code hostname} is null.
*/
Handler(final String connectionId, final String hostname, final ClientLogger logger) {
Handler(final String connectionId, final String hostname) {
this.connectionId = Objects.requireNonNull(connectionId, "'connectionId' cannot be null.");
this.hostname = Objects.requireNonNull(hostname, "'hostname' cannot be null.");
this.logger = Objects.requireNonNull(logger, "'logger' cannot be null.");
this.logger = new ClientLogger(getClass(), createContextWithConnectionId(connectionId));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.azure.core.amqp.exception.AmqpErrorContext;
import com.azure.core.amqp.exception.LinkErrorContext;
import com.azure.core.amqp.implementation.ExceptionUtil;
import com.azure.core.util.logging.ClientLogger;
import org.apache.qpid.proton.amqp.transport.ErrorCondition;
import org.apache.qpid.proton.engine.EndpointState;
import org.apache.qpid.proton.engine.Event;
Expand All @@ -15,8 +14,8 @@
import java.util.Objects;

import static com.azure.core.amqp.implementation.AmqpErrorCode.TRACKING_ID_PROPERTY;
import static com.azure.core.amqp.implementation.ClientConstants.LINK_NAME_KEY;
import static com.azure.core.amqp.implementation.AmqpLoggingUtils.addErrorCondition;
import static com.azure.core.amqp.implementation.ClientConstants.LINK_NAME_KEY;
import static com.azure.core.amqp.implementation.ClientConstants.NOT_APPLICABLE;

/**
Expand All @@ -36,13 +35,12 @@ abstract class LinkHandler extends Handler {
* connection. Usually of the form {@literal "<your-namespace>.service.windows.net"} but can change if the
* messages are brokered through an intermediary.
* @param entityPath The address within the message broker for this link.
* @param logger Logger to use for messages.
*
* @throws NullPointerException if {@code connectionId}, {@code hostname}, {@code entityPath}, or {@code logger} is
* null.
*/
LinkHandler(String connectionId, String hostname, String entityPath, ClientLogger logger) {
super(connectionId, hostname, logger);
LinkHandler(String connectionId, String hostname, String entityPath) {
super(connectionId, hostname);
this.entityPath = Objects.requireNonNull(entityPath, "'entityPath' cannot be null.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

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

import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.logging.LoggingEventBuilder;
import org.apache.qpid.proton.amqp.Symbol;
import org.apache.qpid.proton.amqp.messaging.Modified;
Expand All @@ -26,7 +25,6 @@
import java.util.concurrent.atomic.AtomicBoolean;

import static com.azure.core.amqp.implementation.AmqpLoggingUtils.addErrorCondition;
import static com.azure.core.amqp.implementation.AmqpLoggingUtils.createContextWithConnectionId;
import static com.azure.core.amqp.implementation.ClientConstants.EMIT_RESULT_KEY;
import static com.azure.core.amqp.implementation.ClientConstants.ENTITY_PATH_KEY;
import static com.azure.core.amqp.implementation.ClientConstants.LINK_NAME_KEY;
Expand All @@ -53,7 +51,7 @@ public class ReceiveLinkHandler extends LinkHandler {
private final String entityPath;

public ReceiveLinkHandler(String connectionId, String hostname, String linkName, String entityPath) {
super(connectionId, hostname, entityPath, new ClientLogger(ReceiveLinkHandler.class, createContextWithConnectionId(connectionId)));
super(connectionId, hostname, entityPath);
this.linkName = Objects.requireNonNull(linkName, "'linkName' cannot be null.");
this.entityPath = Objects.requireNonNull(entityPath, "'entityPath' cannot be null.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

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

import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.logging.LoggingEventBuilder;
import org.apache.qpid.proton.engine.BaseHandler;
import org.apache.qpid.proton.engine.Delivery;
Expand All @@ -21,7 +20,6 @@
import java.util.concurrent.atomic.AtomicBoolean;

import static com.azure.core.amqp.implementation.AmqpLoggingUtils.addSignalTypeAndResult;
import static com.azure.core.amqp.implementation.AmqpLoggingUtils.createContextWithConnectionId;
import static com.azure.core.amqp.implementation.ClientConstants.EMIT_RESULT_KEY;
import static com.azure.core.amqp.implementation.ClientConstants.ENTITY_PATH_KEY;
import static com.azure.core.amqp.implementation.ClientConstants.LINK_NAME_KEY;
Expand All @@ -47,7 +45,7 @@ public class SendLinkHandler extends LinkHandler {
private final Sinks.Many<Delivery> deliveryProcessor = Sinks.many().multicast().onBackpressureBuffer();

public SendLinkHandler(String connectionId, String hostname, String linkName, String entityPath) {
super(connectionId, hostname, entityPath, new ClientLogger(SendLinkHandler.class, createContextWithConnectionId(connectionId)));
super(connectionId, hostname, entityPath);
this.linkName = Objects.requireNonNull(linkName, "'linkName' cannot be null.");
this.entityPath = entityPath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.azure.core.amqp.exception.SessionErrorContext;
import com.azure.core.amqp.implementation.ExceptionUtil;
import com.azure.core.amqp.implementation.ReactorDispatcher;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.logging.LoggingEventBuilder;
import org.apache.qpid.proton.amqp.transport.ErrorCondition;
import org.apache.qpid.proton.engine.EndpointState;
Expand All @@ -21,7 +20,6 @@
import java.util.concurrent.RejectedExecutionException;

import static com.azure.core.amqp.implementation.AmqpLoggingUtils.addErrorCondition;
import static com.azure.core.amqp.implementation.AmqpLoggingUtils.createContextWithConnectionId;
import static com.azure.core.amqp.implementation.ClientConstants.SESSION_NAME_KEY;

public class SessionHandler extends Handler {
Expand All @@ -31,7 +29,7 @@ public class SessionHandler extends Handler {

public SessionHandler(String connectionId, String hostname, String sessionName, ReactorDispatcher reactorDispatcher,
Duration openTimeout) {
super(connectionId, hostname, new ClientLogger(SessionHandler.class, createContextWithConnectionId(connectionId)));
super(connectionId, hostname);
this.sessionName = sessionName;
this.openTimeout = openTimeout;
this.reactorDispatcher = reactorDispatcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
package com.azure.core.amqp.implementation.handler;

import com.azure.core.amqp.implementation.ConnectionOptions;
import com.azure.core.util.logging.ClientLogger;
import com.microsoft.azure.proton.transport.ws.impl.WebSocketImpl;
import org.apache.qpid.proton.engine.Event;
import org.apache.qpid.proton.engine.SslPeerDetails;
import org.apache.qpid.proton.engine.impl.TransportInternal;
import static com.azure.core.amqp.implementation.AmqpLoggingUtils.createContextWithConnectionId;

import static com.azure.core.amqp.implementation.ClientConstants.HOSTNAME_KEY;

/**
Expand All @@ -24,7 +23,6 @@ public class WebSocketsConnectionHandler extends ConnectionHandler {

private static final String SOCKET_PATH = "/$servicebus/websocket";
private static final String PROTOCOL = "AMQPWSB10";
private final ClientLogger logger;

/**
* Creates a handler that handles proton-j's connection events using web sockets.
Expand All @@ -35,7 +33,6 @@ public class WebSocketsConnectionHandler extends ConnectionHandler {
public WebSocketsConnectionHandler(String connectionId, ConnectionOptions connectionOptions,
SslPeerDetails peerDetails) {
super(connectionId, connectionOptions, peerDetails);
logger = new ClientLogger(WebSocketsConnectionHandler.class, createContextWithConnectionId(connectionId));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.azure.core.amqp.implementation.AmqpErrorCode;
import com.azure.core.amqp.implementation.ConnectionOptions;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.logging.ClientLogger;
import com.microsoft.azure.proton.transport.proxy.ProxyHandler;
import com.microsoft.azure.proton.transport.proxy.impl.ProxyHandlerImpl;
import com.microsoft.azure.proton.transport.proxy.impl.ProxyImpl;
Expand All @@ -30,7 +29,6 @@
import java.util.Objects;
import java.util.stream.Collectors;

import static com.azure.core.amqp.implementation.AmqpLoggingUtils.createContextWithConnectionId;
import static com.azure.core.amqp.implementation.AmqpLoggingUtils.addErrorCondition;
import static com.azure.core.amqp.implementation.ClientConstants.HOSTNAME_KEY;

Expand All @@ -40,7 +38,6 @@
public class WebSocketsProxyConnectionHandler extends WebSocketsConnectionHandler {
private static final String HTTPS_URI_FORMAT = "https://%s:%s";

private final ClientLogger logger;
private final InetSocketAddress connectionHostname;
private final ProxyOptions proxyOptions;
private final String fullyQualifiedNamespace;
Expand All @@ -64,7 +61,6 @@ public WebSocketsProxyConnectionHandler(String connectionId, ConnectionOptions c
this.proxyOptions = Objects.requireNonNull(proxyOptions, "'proxyConfiguration' cannot be null.");
this.fullyQualifiedNamespace = connectionOptions.getFullyQualifiedNamespace();
this.amqpBrokerHostname = connectionOptions.getFullyQualifiedNamespace() + ":" + connectionOptions.getPort();
this.logger = new ClientLogger(WebSocketsProxyConnectionHandler.class, createContextWithConnectionId(connectionId));
if (proxyOptions.isProxyAddressConfigured()) {
this.connectionHostname = (InetSocketAddress) proxyOptions.getProxyAddress().address();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@

import com.azure.core.amqp.exception.AmqpErrorContext;
import com.azure.core.amqp.exception.AmqpException;
import com.azure.core.util.logging.ClientLogger;
import org.apache.qpid.proton.engine.EndpointState;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import reactor.test.StepVerifier;

import static com.azure.core.amqp.implementation.AmqpLoggingUtils.createContextWithConnectionId;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

Expand Down Expand Up @@ -44,9 +42,8 @@ public void constructor() {
final String hostname = "hostname";

// Act
assertThrows(NullPointerException.class, () -> new TestHandler(null, hostname, new ClientLogger(TestHandler.class)));
assertThrows(NullPointerException.class, () -> new TestHandler(connectionId, null, new ClientLogger(TestHandler.class)));
assertThrows(NullPointerException.class, () -> new TestHandler(connectionId, hostname, null));
assertThrows(NullPointerException.class, () -> new TestHandler(null, hostname));
assertThrows(NullPointerException.class, () -> new TestHandler(connectionId, null));
}

@Test
Expand Down Expand Up @@ -158,11 +155,11 @@ private static class TestHandler extends Handler {
static final String HOSTNAME = "test-hostname";

TestHandler() {
super(CONNECTION_ID, HOSTNAME, new ClientLogger(TestHandler.class, createContextWithConnectionId(CONNECTION_ID)));
super(CONNECTION_ID, HOSTNAME);
}

TestHandler(String connectionId, String hostname, ClientLogger logger) {
super(connectionId, hostname, logger);
TestHandler(String connectionId, String hostname) {
super(connectionId, hostname);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.azure.core.amqp.exception.AmqpErrorContext;
import com.azure.core.amqp.exception.AmqpException;
import com.azure.core.amqp.exception.LinkErrorContext;
import com.azure.core.util.logging.ClientLogger;
import org.apache.qpid.proton.amqp.Symbol;
import org.apache.qpid.proton.amqp.transport.ErrorCondition;
import org.apache.qpid.proton.engine.EndpointState;
Expand Down Expand Up @@ -62,8 +61,7 @@ public class LinkHandlerTest {
private final AmqpErrorCondition linkStolen = LINK_STOLEN;
private final Symbol symbol = Symbol.getSymbol(linkStolen.getErrorCondition());
private final String description = "test-description";
private final ClientLogger logger = new ClientLogger(LinkHandlerTest.class);
private final LinkHandler handler = new MockLinkHandler(CONNECTION_ID, HOSTNAME, ENTITY_PATH, logger);
private final LinkHandler handler = new MockLinkHandler(CONNECTION_ID, HOSTNAME, ENTITY_PATH);
private AutoCloseable mocksCloseable;

@BeforeEach
Expand Down Expand Up @@ -333,13 +331,9 @@ public void onLinkFinal() {
public void constructor() {
// Act
assertThrows(NullPointerException.class,
() -> new MockLinkHandler(null, HOSTNAME, ENTITY_PATH, logger));
() -> new MockLinkHandler(null, HOSTNAME, ENTITY_PATH));
assertThrows(NullPointerException.class,
() -> new MockLinkHandler(CONNECTION_ID, null, ENTITY_PATH, logger));
assertThrows(NullPointerException.class,
() -> new MockLinkHandler(CONNECTION_ID, HOSTNAME, null, logger));
assertThrows(NullPointerException.class,
() -> new MockLinkHandler(CONNECTION_ID, HOSTNAME, ENTITY_PATH, null));
() -> new MockLinkHandler(CONNECTION_ID, null, ENTITY_PATH));
}

/**
Expand Down Expand Up @@ -409,8 +403,8 @@ public void errorContextNoReferenceId(Map<Symbol, Object> properties) {
}

private static final class MockLinkHandler extends LinkHandler {
MockLinkHandler(String connectionId, String hostname, String entityPath, ClientLogger logger) {
super(connectionId, hostname, entityPath, logger);
MockLinkHandler(String connectionId, String hostname, String entityPath) {
super(connectionId, hostname, entityPath);
}
}
}

0 comments on commit c2aa854

Please sign in to comment.