Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// Copyright 2015-2019 SWIM.AI inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package swim.io.mqtt;
import java.net.InetSocketAddress;
import swim.concurrent.Stage;
import swim.io.Endpoint;
import swim.io.ServiceRef;
import swim.io.SocketModem;
import swim.io.SocketRef;
public class MqttEndpoint {
protected final Endpoint endpoint;
protected MqttSettings mqttSettings;
public MqttEndpoint(Endpoint endpoint, MqttSettings mqttSettings) {
this.endpoint = endpoint;
this.mqttSettings = mqttSettings;
}
public MqttEndpoint(Endpoint endpoint) {
this(endpoint, MqttSettings.standard());
}
public MqttEndpoint(Stage stage, MqttSettings mqttSettings) {
this(new Endpoint(stage), mqttSettings);
}
public MqttEndpoint(Stage stage) {
this(new Endpoint(stage), MqttSettings.standard());
}
public final MqttSettings mqttSettings() {
return this.mqttSettings;
}
public final Stage stage() {
return this.endpoint.stage();
}
public final Endpoint endpoint() {
return this.endpoint;
}
public void start() {
this.endpoint.start();
}
public void stop() {
this.endpoint.stop();
}
public ServiceRef bindMqtt(InetSocketAddress localAddress, MqttService service, MqttSettings mqttSettings) {
final MqttSocketService tcpService = new MqttSocketService(service, mqttSettings);
return this.endpoint.bindTcp(localAddress, tcpService, mqttSettings.socketSettings());
}
public ServiceRef bindMqtt(InetSocketAddress localAddress, MqttService service) {
return bindMqtt(localAddress, service, this.mqttSettings);
}
public ServiceRef bindMqtt(String address, int port, MqttService service, MqttSettings mqttSettings) {
return bindMqtt(new InetSocketAddress(address, port), service, mqttSettings);
}
public ServiceRef bindMqtt(String address, int port, MqttService service) {
return bindMqtt(new InetSocketAddress(address, port), service, this.mqttSettings);
}
public ServiceRef bindMqtts(InetSocketAddress localAddress, MqttService service, MqttSettings mqttSettings) {
final MqttSocketService tlsService = new MqttSocketService(service, mqttSettings);
return this.endpoint.bindTls(localAddress, tlsService, mqttSettings.socketSettings());
}
public ServiceRef bindMqtts(InetSocketAddress localAddress, MqttService service) {
return bindMqtts(localAddress, service, this.mqttSettings);
}
public ServiceRef bindMqtts(String address, int port, MqttService service, MqttSettings mqttSettings) {
return bindMqtts(new InetSocketAddress(address, port), service, mqttSettings);
}
public ServiceRef bindMqtts(String address, int port, MqttService service) {
return bindMqtts(new InetSocketAddress(address, port), service, this.mqttSettings);
}
public SocketRef connectMqtt(InetSocketAddress localAddress, MqttSocket socket, MqttSettings mqttSettings) {
final MqttSocketModem modem = new MqttSocketModem(socket, mqttSettings);
final SocketModem