Skip to content

Feature/proxy #364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 2, 2020
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
84 changes: 75 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,37 @@ ext {

dependencies {
api group: 'io.reactivex.rxjava2', name: 'rxjava', version: rxJavaVersion

implementation group: 'io.netty', name: 'netty-buffer', version: nettyVersion
implementation group: 'io.netty', name: 'netty-codec', version: nettyVersion
implementation group: 'io.netty', name: 'netty-common', version: nettyVersion
implementation group: 'io.netty', name: 'netty-handler', version: nettyVersion
implementation group: 'io.netty', name: 'netty-codec-http', version: nettyVersion
implementation group: 'io.netty', name: 'netty-transport-native-epoll', version: nettyVersion, classifier: 'linux-x86_64'
implementation group: 'io.netty', name: 'netty-transport', version: nettyVersion
implementation group: 'org.jctools', name: 'jctools-core', version: jcToolsVersion
implementation group: 'org.jetbrains', name: 'annotations', version: jetbrainsAnnotationsVersion
implementation group: 'com.google.dagger', name: 'dagger', version: daggerVersion
annotationProcessor group: 'com.google.dagger', name: 'dagger-compiler', version: daggerVersion

compileOnly group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion

annotationProcessor group: 'com.google.dagger', name: 'dagger-compiler', version: daggerVersion
}


/* ******************** optional dependencies ******************** */

def features = ['websocket', 'proxy', 'epoll']
java {
features.each {
registerFeature(it) {
usingSourceSet(sourceSets.main)
}
}
}

dependencies {
websocketImplementation group: 'io.netty', name: 'netty-codec-http', version: nettyVersion
proxyImplementation group: 'io.netty', name: 'netty-handler-proxy', version: nettyVersion
epollImplementation group: 'io.netty', name: 'netty-transport-native-epoll', version: nettyVersion, classifier: 'linux-x86_64'
}


Expand Down Expand Up @@ -236,11 +259,12 @@ allprojects {
url = project.issuesUrl
}
}
artifact javadocJar
artifact sourcesJar
}
normal(MavenPublication) {
from components.java
from project.components.java
artifact project.tasks.javadocJar
artifact project.tasks.sourcesJar
suppressAllPomMetadataWarnings()
}
}
}
Expand Down Expand Up @@ -276,6 +300,19 @@ allprojects {
}
}
}

// workaround for publishing gradle metadata https://github.com/bintray/gradle-bintray-plugin/issues/229
//noinspection UnnecessaryQualifiedReference
project.tasks.withType(com.jfrog.bintray.gradle.tasks.BintrayUploadTask) {
doFirst {
publishing.publications.withType(MavenPublication).each { publication ->
def moduleFile = new File(new File(new File(project.buildDir, 'publications'), publication.name), 'module.json')
if (moduleFile.exists()) {
publication.artifact(moduleFile).setExtension('module')
}
}
}
}
}
}

Expand All @@ -285,9 +322,11 @@ allprojects {
publications {
shaded(MavenPublication) {
artifactId project.name + '-' + project.shadedAppendix
artifact shadowJar
pom.withXml { xml ->
def dependenciesNode = xml.asNode().appendNode('dependencies')
artifact project.tasks.shadowJar
artifact project.tasks.javadocJar
artifact project.tasks.sourcesJar
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')

project.configurations.api.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
Expand All @@ -303,6 +342,33 @@ allprojects {
}
}

features.each { feature ->
publishing {
publications {
create(feature, MavenPublication) {
artifactId project.name + '-' + feature
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')

def rootDependencyNode = dependenciesNode.appendNode('dependency')
rootDependencyNode.appendNode('groupId', project.group)
rootDependencyNode.appendNode('artifactId', project.name)
rootDependencyNode.appendNode('version', project.version)
rootDependencyNode.appendNode('scope', 'compile')

project.configurations.getByName(feature + 'Implementation').allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
dependencyNode.appendNode('scope', 'runtime')
}
}
}
}
}
}

apply plugin: 'com.github.breadmoirai.github-release'

githubRelease {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Wed Sep 25 23:53:09 CEST 2019
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static class Nested<P> extends MqttClientExecutorConfigImplBuilder<Nested

private final @NotNull Function<? super MqttClientExecutorConfigImpl, P> parentConsumer;

public Nested(
Nested(
final @NotNull MqttClientExecutorConfigImpl executorConfig,
final @NotNull Function<? super MqttClientExecutorConfigImpl, P> parentConsumer) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static class Nested<P> extends MqttClientSslConfigImplBuilder<Nested<P>>

private final @NotNull Function<? super MqttClientSslConfigImpl, P> parentConsumer;

public Nested(
Nested(
final @Nullable MqttClientSslConfigImpl sslConfig,
final @NotNull Function<? super MqttClientSslConfigImpl, P> parentConsumer) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@

package com.hivemq.client.internal.mqtt;

import com.hivemq.client.mqtt.MqttClient;
import com.hivemq.client.mqtt.MqttClientSslConfig;
import com.hivemq.client.mqtt.MqttClientTransportConfig;
import com.hivemq.client.mqtt.MqttWebSocketConfig;
import com.hivemq.client.mqtt.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.net.InetSocketAddress;
import java.util.Objects;
import java.util.Optional;

/**
Expand All @@ -34,22 +32,24 @@ public class MqttClientTransportConfigImpl implements MqttClientTransportConfig

public static final @NotNull MqttClientTransportConfigImpl DEFAULT = new MqttClientTransportConfigImpl(
InetSocketAddress.createUnresolved(MqttClient.DEFAULT_SERVER_HOST, MqttClient.DEFAULT_SERVER_PORT), null,
null, null);
null, null, null);

private final @NotNull InetSocketAddress serverAddress;
private final @Nullable InetSocketAddress localAddress;
private final @Nullable MqttClientSslConfigImpl sslConfig;
private final @Nullable MqttWebSocketConfigImpl webSocketConfig;
private final @Nullable MqttProxyConfigImpl proxyConfig;

MqttClientTransportConfigImpl(
final @NotNull InetSocketAddress serverAddress, final @Nullable InetSocketAddress localAddress,
final @Nullable MqttClientSslConfigImpl sslConfig,
final @Nullable MqttWebSocketConfigImpl webSocketConfig) {
final @Nullable MqttClientSslConfigImpl sslConfig, final @Nullable MqttWebSocketConfigImpl webSocketConfig,
final @Nullable MqttProxyConfigImpl proxyConfig) {

this.serverAddress = serverAddress;
this.localAddress = localAddress;
this.sslConfig = sslConfig;
this.webSocketConfig = webSocketConfig;
this.proxyConfig = proxyConfig;
}

@Override
Expand Down Expand Up @@ -84,8 +84,42 @@ public class MqttClientTransportConfigImpl implements MqttClientTransportConfig
return webSocketConfig;
}

@Override
public @NotNull Optional<MqttProxyConfig> getProxyConfig() {
return Optional.ofNullable(proxyConfig);
}

public @Nullable MqttProxyConfigImpl getRawProxyConfig() {
return proxyConfig;
}

@Override
public @NotNull MqttClientTransportConfigImplBuilder.Default extend() {
return new MqttClientTransportConfigImplBuilder.Default(this);
}

@Override
public boolean equals(final @Nullable Object o) {
if (this == o) {
return true;
}
if (!(o instanceof MqttClientTransportConfigImpl)) {
return false;
}
final MqttClientTransportConfigImpl that = (MqttClientTransportConfigImpl) o;

return serverAddress.equals(that.serverAddress) && Objects.equals(localAddress, that.localAddress) &&
Objects.equals(sslConfig, that.sslConfig) && Objects.equals(webSocketConfig, that.webSocketConfig) &&
Objects.equals(proxyConfig, that.proxyConfig);
}

@Override
public int hashCode() {
int result = serverAddress.hashCode();
result = 31 * result + Objects.hashCode(localAddress);
result = 31 * result + Objects.hashCode(sslConfig);
result = 31 * result + Objects.hashCode(webSocketConfig);
result = 31 * result + Objects.hashCode(proxyConfig);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.hivemq.client.internal.util.Checks;
import com.hivemq.client.mqtt.MqttClientSslConfig;
import com.hivemq.client.mqtt.MqttClientTransportConfigBuilder;
import com.hivemq.client.mqtt.MqttProxyConfig;
import com.hivemq.client.mqtt.MqttWebSocketConfig;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -41,6 +42,7 @@ public abstract class MqttClientTransportConfigImplBuilder<B extends MqttClientT
private @Nullable InetSocketAddress localAddress;
private @Nullable MqttClientSslConfigImpl sslConfig;
private @Nullable MqttWebSocketConfigImpl webSocketConfig;
private @Nullable MqttProxyConfigImpl proxyConfig;

MqttClientTransportConfigImplBuilder() {}

Expand All @@ -55,12 +57,15 @@ public abstract class MqttClientTransportConfigImplBuilder<B extends MqttClientT
localAddress = builder.localAddress;
sslConfig = builder.sslConfig;
webSocketConfig = builder.webSocketConfig;
proxyConfig = builder.proxyConfig;
}

void set(final @NotNull MqttClientTransportConfigImpl transportConfig) {
serverAddress = transportConfig.getServerAddress();
localAddress = transportConfig.getRawLocalAddress();
sslConfig = transportConfig.getRawSslConfig();
webSocketConfig = transportConfig.getRawWebSocketConfig();
proxyConfig = transportConfig.getRawProxyConfig();
}

abstract @NotNull B self();
Expand Down Expand Up @@ -194,6 +199,15 @@ private int getLocalPort() {
return new MqttWebSocketConfigImplBuilder.Nested<>(webSocketConfig, this::webSocketConfig);
}

public @NotNull B proxyConfig(final @Nullable MqttProxyConfig proxyConfig) {
this.proxyConfig = Checks.notImplementedOrNull(proxyConfig, MqttProxyConfigImpl.class, "Proxy config");
return self();
}

public @NotNull MqttProxyConfigImplBuilder.Nested<B> proxyConfig() {
return new MqttProxyConfigImplBuilder.Nested<>(proxyConfig, this::proxyConfig);
}

private @NotNull InetSocketAddress getServerAddress() {
if (serverAddress != null) {
return serverAddress;
Expand Down Expand Up @@ -221,7 +235,8 @@ private int getServerPort() {
}

@NotNull MqttClientTransportConfigImpl buildTransportConfig() {
return new MqttClientTransportConfigImpl(getServerAddress(), localAddress, sslConfig, webSocketConfig);
return new MqttClientTransportConfigImpl(
getServerAddress(), localAddress, sslConfig, webSocketConfig, proxyConfig);
}

public static class Default extends MqttClientTransportConfigImplBuilder<Default>
Expand Down Expand Up @@ -249,10 +264,6 @@ public static class Nested<P> extends MqttClientTransportConfigImplBuilder<Neste

private final @NotNull Function<? super MqttClientTransportConfigImpl, P> parentConsumer;

public Nested(final @NotNull Function<? super MqttClientTransportConfigImpl, P> parentConsumer) {
this.parentConsumer = parentConsumer;
}

public Nested(
final @NotNull MqttClientTransportConfigImpl transportConfig,
final @NotNull Function<? super MqttClientTransportConfigImpl, P> parentConsumer) {
Expand Down
Loading