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.
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.activemq.apollo.mqtt;
import org.apache.activemq.apollo.broker.*;
import org.apache.activemq.apollo.broker.protocol.AbstractProtocolHandler;
import org.apache.activemq.apollo.broker.protocol.ProtocolFilter3;
import org.apache.activemq.apollo.broker.protocol.ProtocolFilter3$;
import org.apache.activemq.apollo.broker.security.SecurityContext;
import org.apache.activemq.apollo.dto.AcceptingConnectorDTO;
import org.apache.activemq.apollo.dto.ProtocolDTO;
import org.apache.activemq.apollo.mqtt.dto.MqttConnectionStatusDTO;
import org.apache.activemq.apollo.mqtt.dto.MqttDTO;
import org.apache.activemq.apollo.util.*;
import org.fusesource.hawtbuf.UTF8Buffer;
import org.fusesource.hawtdispatch.DispatchQueue;
import org.fusesource.hawtdispatch.Task;
import org.fusesource.hawtdispatch.transport.HeartBeatMonitor;
import org.fusesource.mqtt.codec.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import static org.apache.activemq.apollo.util.Scala2Java.*;
import static org.fusesource.hawtdispatch.Dispatch.NOOP;
/**
* @author Hiram Chirino
*/
public class MqttProtocolHandler extends AbstractProtocolHandler {
public static final Scala2Java.Logger log = new Scala2Java.Logger(Log$.MODULE$.apply(MqttProtocolHandler.class));
public static T received(T value) {
log.trace("received: %s", value);
return value;
}
static Fn0 WAITING_ON_CLIENT_REQUEST = new Fn0() {
@Override
public String apply() {
return "client request";
}
};
public String protocol() {
return "mqtt";
}
public Broker broker() {
return connection().connector().broker();
}
public DispatchQueue queue() {
return connection().dispatch_queue();
}
Scala2Java.Logger connection_log = log;
MqttDTO config = null;
public DestinationParser destination_parser() {
DestinationParser destination_parser = MqttProtocol.destination_parser;
if (config.queue_prefix != null ||
config.path_separator != null ||
config.any_child_wildcard != null ||
config.any_descendant_wildcard != null ||
config.regex_wildcard_start != null ||
config.regex_wildcard_end != null ||
config.part_pattern != null
) {
destination_parser = new DestinationParser().copy(destination_parser);
if (config.queue_prefix != null) {
destination_parser.queue_prefix_$eq(config.queue_prefix);
}
if (config.path_separator != null) {
destination_parser.path_separator_$eq(config.path_separator);
}
if (config.any_child_wildcard != null) {
destination_parser.any_child_wildcard_$eq(config.any_child_wildcard);
}
if (config.any_descendant_wildcard != null) {
destination_parser.any_descendant_wildcard_$eq(config.any_descendant_wildcard);
}
if (config.regex_wildcard_start != null) {
destination_parser.regex_wildcard_start_$eq(config.regex_wildcard_start);
}
if (config.regex_wildcard_end != null) {
destination_parser.regex_wildcard_end_$eq(config.regex_wildcard_end);
}
if (config.part_pattern != null) {
destination_parser.part_pattern_$eq(Pattern.compile(config.part_pattern));
}
}
return destination_parser;
}
final ArrayList protocol_filters = new ArrayList();
/////////////////////////////////////////////////////////////////////
//
// Bits related setting up a client connection
//
/////////////////////////////////////////////////////////////////////
public String session_id() {
return security_context.session_id();
}
final SecurityContext security_context = new SecurityContext();
SinkMux sink_manager = null;
Sink connection_sink = null;
MQTTProtocolCodec codec = null;
static private MqttDTO find_config(AcceptingConnectorDTO connector_config) {
for (ProtocolDTO protocol : connector_config.protocols) {
if (protocol instanceof MqttDTO) {
return (MqttDTO) protocol;
}
}
return new MqttDTO();
}
public void on_transport_connected() {
codec = (MQTTProtocolCodec) connection().transport().getProtocolCodec();
AcceptingConnectorDTO connector_config = (AcceptingConnectorDTO) connection().connector().config();
config = find_config(connector_config);
codec.setMaxMessageLength(get(config.max_message_length, codec.getMaxMessageLength()));
protocol_filters.clear();
protocol_filters.addAll(ProtocolFilter3$.MODULE$.create_filters(config.protocol_filters, this));
security_context.local_address_$eq(connection().transport().getLocalAddress());
security_context.remote_address_$eq(connection().transport().getRemoteAddress());
security_context.connector_id_$eq(connection().connector().id());
security_context.certificates_$eq(connection().certificates());
connection_log = new Scala2Java.Logger(connection().connector().broker().connection_log());
Sink filtering_sink = new AbstractSinkMapper() {
public Sink