├── .gitignore ├── README.md ├── auth-db ├── build.gradle └── src │ └── main │ └── java │ └── org │ └── jmqtt │ └── auth │ └── impl │ ├── DBAuthenticator.java │ ├── Product.java │ └── ProductRepository.java ├── auth-file ├── build.gradle └── src │ └── main │ └── java │ └── org │ └── jmqtt │ └── auth │ └── impl │ ├── ACLFileParser.java │ ├── Authorization.java │ ├── AuthorizationsCollector.java │ └── FileAuthenticator.java ├── auth-mongo ├── build.gradle ├── build │ └── classes │ │ └── main │ │ └── org │ │ └── jmqtt │ │ └── auth │ │ └── impl │ │ ├── MongoAuthenticator.class │ │ ├── model │ │ └── Product.class │ │ └── repository │ │ └── ProductRepository.class └── src │ └── main │ └── java │ └── org │ └── jmqtt │ └── auth │ └── impl │ ├── MongoAuthenticator.java │ ├── model │ └── Product.java │ └── repository │ └── ProductRepository.java ├── auth ├── build.gradle ├── build │ ├── classes │ │ └── main │ │ │ └── org │ │ │ └── jmqtt │ │ │ └── auth │ │ │ ├── IAuthenticator.class │ │ │ ├── IAuthorizator.class │ │ │ └── impl │ │ │ ├── ACLFileParser.class │ │ │ ├── AcceptAllAuthenticator.class │ │ │ ├── Authorization$Permission.class │ │ │ ├── Authorization.class │ │ │ ├── AuthorizationsCollector.class │ │ │ ├── DBAuthenticator.class │ │ │ ├── DenyAllAuthorizator.class │ │ │ ├── FileAuthenticator.class │ │ │ └── PermitAllAuthorizator.class │ ├── libs │ │ └── auth-1.0-SNAPSHOT.jar │ └── tmp │ │ └── jar │ │ └── MANIFEST.MF └── src │ └── main │ └── java │ └── org │ └── jmqtt │ └── auth │ ├── IAuthenticator.java │ ├── IAuthorizator.java │ └── impl │ ├── AcceptAllAuthenticator.java │ └── PermitAllAuthorizator.java ├── broker ├── build.gradle ├── build │ ├── classes │ │ └── main │ │ │ ├── META-INF │ │ │ └── spring-configuration-metadata.json │ │ │ └── org │ │ │ └── jmqtt │ │ │ └── broker │ │ │ ├── BrokerApplication.class │ │ │ ├── ConnectionDescriptor.class │ │ │ ├── Constants.class │ │ │ ├── acceptor │ │ │ ├── NettyAcceptor$1.class │ │ │ ├── NettyAcceptor$2.class │ │ │ ├── NettyAcceptor$3.class │ │ │ ├── NettyAcceptor$4.class │ │ │ ├── NettyAcceptor$5.class │ │ │ ├── NettyAcceptor$ByteBufToWebSocketFrameEncoder.class │ │ │ ├── NettyAcceptor$PipelineInitializer.class │ │ │ ├── NettyAcceptor$WebSocketFrameToByteBufDecoder.class │ │ │ └── NettyAcceptor.class │ │ │ ├── config │ │ │ ├── AcceptorProperties.class │ │ │ ├── DbProperties.class │ │ │ ├── RedissonProperties.class │ │ │ ├── ServerConfig.class │ │ │ └── SslProperties.class │ │ │ ├── handler │ │ │ ├── AutoFlushHandler$WriterIdleTimeoutTask.class │ │ │ ├── AutoFlushHandler.class │ │ │ ├── IdleTimeoutHandler.class │ │ │ └── NettyMQTTHandler.class │ │ │ ├── interceptor │ │ │ ├── BrokerInterceptor$1.class │ │ │ ├── BrokerInterceptor$2.class │ │ │ ├── BrokerInterceptor$3.class │ │ │ ├── BrokerInterceptor$4.class │ │ │ ├── BrokerInterceptor$5.class │ │ │ ├── BrokerInterceptor$6.class │ │ │ └── BrokerInterceptor.class │ │ │ ├── metrics │ │ │ ├── BytesMetrics.class │ │ │ ├── BytesMetricsCollector.class │ │ │ ├── BytesMetricsHandler.class │ │ │ ├── MessageMetrics.class │ │ │ ├── MessageMetricsCollector.class │ │ │ └── MessageMetricsHandler.class │ │ │ ├── process │ │ │ ├── ProtocolProcessor$1.class │ │ │ ├── ProtocolProcessor$WillMessage.class │ │ │ └── ProtocolProcessor.class │ │ │ ├── security │ │ │ ├── DefaultSslContextCreator.class │ │ │ └── ISslContextCreator.class │ │ │ └── util │ │ │ ├── DebugUtils.class │ │ │ └── NettyUtils.class │ ├── libs │ │ ├── broker-1.0-SNAPSHOT.jar │ │ └── broker-1.0-SNAPSHOT.jar.original │ ├── resources │ │ └── main │ │ │ └── application.properties │ └── tmp │ │ └── jar │ │ └── MANIFEST.MF └── src │ └── main │ ├── java │ └── org │ │ └── jmqtt │ │ └── broker │ │ ├── BrokerApplication.java │ │ ├── ConnectionDescriptor.java │ │ ├── Constants.java │ │ ├── acceptor │ │ └── NettyAcceptor.java │ │ ├── config │ │ ├── AcceptorProperties.java │ │ ├── RedissonProperties.java │ │ ├── ServerConfig.java │ │ └── SslProperties.java │ │ ├── handler │ │ ├── AutoFlushHandler.java │ │ ├── IdleTimeoutHandler.java │ │ └── NettyMQTTHandler.java │ │ ├── metrics │ │ ├── BytesMetrics.java │ │ ├── BytesMetricsCollector.java │ │ ├── BytesMetricsHandler.java │ │ ├── MessageMetrics.java │ │ ├── MessageMetricsCollector.java │ │ └── MessageMetricsHandler.java │ │ ├── process │ │ └── ProtocolProcessor.java │ │ ├── security │ │ ├── DefaultSslContextCreator.java │ │ └── ISslContextCreator.java │ │ └── util │ │ ├── DebugUtils.java │ │ └── NettyUtils.java │ └── resources │ └── application.properties ├── build.gradle ├── cluster └── build.gradle ├── core ├── build.gradle ├── build │ ├── classes │ │ └── main │ │ │ └── org │ │ │ └── jmqtt │ │ │ └── core │ │ │ ├── codec │ │ │ ├── ConnAckDecoder.class │ │ │ ├── ConnAckEncoder.class │ │ │ ├── ConnectDecoder.class │ │ │ ├── ConnectEncoder.class │ │ │ ├── DemuxDecoder.class │ │ │ ├── DemuxEncoder.class │ │ │ ├── DisconnectDecoder.class │ │ │ ├── DisconnectEncoder.class │ │ │ ├── MQTTDecoder.class │ │ │ ├── MQTTEncoder.class │ │ │ ├── MessageIDDecoder.class │ │ │ ├── PingReqDecoder.class │ │ │ ├── PingReqEncoder.class │ │ │ ├── PingRespDecoder.class │ │ │ ├── PingRespEncoder.class │ │ │ ├── PubAckDecoder.class │ │ │ ├── PubAckEncoder.class │ │ │ ├── PubCompDecoder.class │ │ │ ├── PubCompEncoder.class │ │ │ ├── PubRecDecoder.class │ │ │ ├── PubRecEncoder.class │ │ │ ├── PubRelDecoder.class │ │ │ ├── PubRelEncoder.class │ │ │ ├── PublishDecoder.class │ │ │ ├── PublishEncoder.class │ │ │ ├── SubAckDecoder.class │ │ │ ├── SubAckEncoder.class │ │ │ ├── SubscribeDecoder.class │ │ │ ├── SubscribeEncoder.class │ │ │ ├── UnsubAckDecoder.class │ │ │ ├── UnsubAckEncoder.class │ │ │ ├── UnsubscribeDecoder.class │ │ │ └── UnsubscribeEncoder.class │ │ │ ├── constant │ │ │ ├── QosType$1.class │ │ │ └── QosType.class │ │ │ ├── exception │ │ │ └── MQTTException.class │ │ │ ├── packet │ │ │ ├── AbstractPacket.class │ │ │ ├── ConnAckPacket.class │ │ │ ├── ConnectPacket.class │ │ │ ├── DisconnectPacket.class │ │ │ ├── PacketIdPacket.class │ │ │ ├── PingReqPacket.class │ │ │ ├── PingRespPacket.class │ │ │ ├── PubAckPacket.class │ │ │ ├── PubCompPacket.class │ │ │ ├── PubRecPacket.class │ │ │ ├── PubRelPacket.class │ │ │ ├── PublishPacket.class │ │ │ ├── SubAckPacket.class │ │ │ ├── SubscribePacket$Couple.class │ │ │ ├── SubscribePacket.class │ │ │ ├── UnsubAckPacket.class │ │ │ ├── UnsubscribePacket.class │ │ │ └── ZeroLengthPacket.class │ │ │ └── util │ │ │ └── MqttUtils.class │ ├── libs │ │ └── core-1.0-SNAPSHOT.jar │ └── tmp │ │ └── jar │ │ └── MANIFEST.MF └── src │ └── main │ └── java │ └── org │ └── jmqtt │ └── core │ ├── codec │ ├── ConnAckDecoder.java │ ├── ConnAckEncoder.java │ ├── ConnectDecoder.java │ ├── ConnectEncoder.java │ ├── DemuxDecoder.java │ ├── DemuxEncoder.java │ ├── DisconnectDecoder.java │ ├── DisconnectEncoder.java │ ├── MQTTDecoder.java │ ├── MQTTEncoder.java │ ├── MessageIDDecoder.java │ ├── PingReqDecoder.java │ ├── PingReqEncoder.java │ ├── PingRespDecoder.java │ ├── PingRespEncoder.java │ ├── PubAckDecoder.java │ ├── PubAckEncoder.java │ ├── PubCompDecoder.java │ ├── PubCompEncoder.java │ ├── PubRecDecoder.java │ ├── PubRecEncoder.java │ ├── PubRelDecoder.java │ ├── PubRelEncoder.java │ ├── PublishDecoder.java │ ├── PublishEncoder.java │ ├── SubAckDecoder.java │ ├── SubAckEncoder.java │ ├── SubscribeDecoder.java │ ├── SubscribeEncoder.java │ ├── UnsubAckDecoder.java │ ├── UnsubAckEncoder.java │ ├── UnsubscribeDecoder.java │ └── UnsubscribeEncoder.java │ ├── constant │ └── QosType.java │ ├── exception │ └── MQTTException.java │ ├── packet │ ├── AbstractPacket.java │ ├── ConnAckPacket.java │ ├── ConnectPacket.java │ ├── DisconnectPacket.java │ ├── PacketIdPacket.java │ ├── PingReqPacket.java │ ├── PingRespPacket.java │ ├── PubAckPacket.java │ ├── PubCompPacket.java │ ├── PubRecPacket.java │ ├── PubRelPacket.java │ ├── PublishPacket.java │ ├── SubAckPacket.java │ ├── SubscribePacket.java │ ├── UnsubAckPacket.java │ ├── UnsubscribePacket.java │ └── ZeroLengthPacket.java │ └── util │ └── MqttUtils.java ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── interception ├── build.gradle ├── build │ ├── classes │ │ └── main │ │ │ └── org │ │ │ └── jmqtt │ │ │ └── interception │ │ │ ├── AbstractInterceptHandler.class │ │ │ ├── BrokerInterceptor$1.class │ │ │ ├── BrokerInterceptor$2.class │ │ │ ├── BrokerInterceptor$3.class │ │ │ ├── BrokerInterceptor$4.class │ │ │ ├── BrokerInterceptor$5.class │ │ │ ├── BrokerInterceptor$6.class │ │ │ ├── BrokerInterceptor.class │ │ │ ├── HazelcastMsg.class │ │ │ ├── InterceptHandler.class │ │ │ ├── Interceptor.class │ │ │ └── messages │ │ │ ├── InterceptAbstractMessage.class │ │ │ ├── InterceptAcknowledgedMessage.class │ │ │ ├── InterceptConnectMessage.class │ │ │ ├── InterceptDisconnectMessage.class │ │ │ ├── InterceptPublishMessage.class │ │ │ ├── InterceptSubscribeMessage.class │ │ │ └── InterceptUnsubscribeMessage.class │ ├── libs │ │ └── interception-1.0-SNAPSHOT.jar │ └── tmp │ │ └── jar │ │ └── MANIFEST.MF └── src │ └── main │ └── java │ └── org │ └── jmqtt │ └── interception │ ├── AbstractInterceptHandler.java │ ├── BrokerInterceptor.java │ ├── InterceptHandler.java │ ├── Interceptor.java │ └── messages │ ├── InterceptAbstractMessage.java │ ├── InterceptAcknowledgedMessage.java │ ├── InterceptConnectMessage.java │ ├── InterceptDisconnectMessage.java │ ├── InterceptPublishMessage.java │ ├── InterceptSubscribeMessage.java │ └── InterceptUnsubscribeMessage.java ├── session-redisson ├── build.gradle ├── build │ ├── classes │ │ └── main │ │ │ └── org │ │ │ └── jmqtt │ │ │ └── persistence │ │ │ ├── RedissonMessageStore.class │ │ │ ├── RedissonPersistentStore$PersistentSession.class │ │ │ ├── RedissonPersistentStore.class │ │ │ └── RedissonSessionsStore.class │ ├── libs │ │ └── persistence-1.0-SNAPSHOT.jar │ └── tmp │ │ └── jar │ │ └── MANIFEST.MF └── src │ └── main │ └── java │ └── org │ └── jmqtt │ └── persistence │ ├── RedissonMessageStore.java │ ├── RedissonPersistentStore.java │ └── RedissonSessionsStore.java ├── session ├── build.gradle ├── build │ ├── classes │ │ └── main │ │ │ └── org │ │ │ └── jmqtt │ │ │ └── session │ │ │ ├── ClientSession.class │ │ │ ├── IMatchingCondition.class │ │ │ ├── IMessagesStore.class │ │ │ ├── IPersistenceStore.class │ │ │ ├── ISessionsStore.class │ │ │ └── model │ │ │ ├── ClientTopicCouple.class │ │ │ ├── Message.class │ │ │ ├── SessionStatus.class │ │ │ ├── Subscription.class │ │ │ ├── SubscriptionsStore$1.class │ │ │ ├── SubscriptionsStore$DumpTreeVisitor.class │ │ │ ├── SubscriptionsStore$IVisitor.class │ │ │ ├── SubscriptionsStore$NodeCouple.class │ │ │ ├── SubscriptionsStore.class │ │ │ ├── Token.class │ │ │ ├── TreeNode.class │ │ │ └── WillMessage.class │ ├── libs │ │ └── session-1.0-SNAPSHOT.jar │ └── tmp │ │ └── jar │ │ └── MANIFEST.MF └── src │ └── main │ └── java │ └── org │ └── jmqtt │ └── session │ ├── ClientSession.java │ ├── IMatchingCondition.java │ ├── IMessagesStore.java │ ├── ISessionsStore.java │ └── model │ ├── ClientTopicCouple.java │ ├── Message.java │ ├── SessionStatus.java │ ├── Subscription.java │ ├── SubscriptionsStore.java │ ├── Token.java │ ├── TreeNode.java │ └── WillMessage.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .gradle 3 | *.iml 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JMQTT 2 | 3 | Java mqtt broker/server base on moquette 4 | 5 | The broker supports QoS 0, QoS 1 and QoS 2. 6 | 7 | Use Netty for the protocol encoding and decoding. 8 | 9 | Use redisson store mqtt session. 10 | 11 | Use spring boot build jar. 12 | 13 | Use mongodb or jpa for auth. 14 | -------------------------------------------------------------------------------- /auth-db/build.gradle: -------------------------------------------------------------------------------- 1 | group 'org.jmqtt' 2 | version '1.0-SNAPSHOT' 3 | 4 | apply plugin: 'java' 5 | 6 | dependencies { 7 | compile project(":auth") 8 | compile "org.springframework.boot:spring-boot-starter-data-jpa" 9 | compile "org.springframework.security:spring-security-crypto:4.0.3.RELEASE" 10 | } 11 | -------------------------------------------------------------------------------- /auth-db/src/main/java/org/jmqtt/auth/impl/DBAuthenticator.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.auth.impl; 2 | 3 | import org.jmqtt.auth.IAuthenticator; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.security.crypto.password.PasswordEncoder; 8 | import org.springframework.security.crypto.password.StandardPasswordEncoder; 9 | 10 | /** 11 | * Load user credentials from a SQL database. 12 | * sql driver must be provided at runtime 13 | * 14 | * @author mackristof 15 | */ 16 | public class DBAuthenticator implements IAuthenticator { 17 | 18 | private static final Logger LOG = LoggerFactory.getLogger(DBAuthenticator.class); 19 | 20 | @Autowired 21 | ProductRepository repository; 22 | 23 | @Override 24 | public synchronized boolean checkValid(String clientId, String username, byte[] password, boolean allowZeroByteClientId) { 25 | 26 | Product product = repository.findByUsername(username); 27 | 28 | if (product == null) { 29 | return false; 30 | } 31 | 32 | PasswordEncoder passwordEncoder = new StandardPasswordEncoder(product.getSalt()); 33 | 34 | if (!passwordEncoder.matches(new String(password), product.getPassword())) { 35 | return false; 36 | } 37 | 38 | if (!allowZeroByteClientId && !product.getClients().contains(clientId)) { 39 | return false; 40 | } 41 | 42 | return true; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /auth-db/src/main/java/org/jmqtt/auth/impl/Product.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.auth.impl; 2 | 3 | 4 | import javax.persistence.*; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /** 9 | * Created by gavin on 16/9/21. 10 | */ 11 | @Entity 12 | public class Product { 13 | 14 | @Id 15 | @GeneratedValue 16 | private Long id; 17 | 18 | @Column(nullable = false) 19 | private String username; 20 | 21 | @Column(nullable = false) 22 | private String password; 23 | 24 | @Column(nullable = false) 25 | private String salt; 26 | 27 | @Column(nullable = false) 28 | private String type; 29 | 30 | @ElementCollection 31 | private List clients = new ArrayList<>(); 32 | 33 | public Long getId() { 34 | return id; 35 | } 36 | 37 | public void setId(Long id) { 38 | this.id = id; 39 | } 40 | 41 | public String getUsername() { 42 | return username; 43 | } 44 | 45 | public void setUsername(String username) { 46 | this.username = username; 47 | } 48 | 49 | public String getPassword() { 50 | return password; 51 | } 52 | 53 | public void setPassword(String password) { 54 | this.password = password; 55 | } 56 | 57 | public String getSalt() { 58 | return salt; 59 | } 60 | 61 | public void setSalt(String salt) { 62 | this.salt = salt; 63 | } 64 | 65 | public String getType() { 66 | return type; 67 | } 68 | 69 | public void setType(String type) { 70 | this.type = type; 71 | } 72 | 73 | public List getClients() { 74 | return clients; 75 | } 76 | 77 | public void setClients(List clients) { 78 | this.clients = clients; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /auth-db/src/main/java/org/jmqtt/auth/impl/ProductRepository.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.auth.impl; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | /** 6 | * Created by gavin on 16/9/21. 7 | */ 8 | public interface ProductRepository extends JpaRepository { 9 | 10 | Product findByUsername(String username); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /auth-file/build.gradle: -------------------------------------------------------------------------------- 1 | group 'org.jmqtt' 2 | version '1.0-SNAPSHOT' 3 | 4 | apply plugin: 'java' 5 | 6 | dependencies { 7 | compile project(":auth") 8 | } 9 | -------------------------------------------------------------------------------- /auth-file/src/main/java/org/jmqtt/auth/impl/Authorization.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.auth.impl; 17 | 18 | 19 | import static org.jmqtt.auth.impl.Authorization.Permission.READWRITE; 20 | 21 | /** 22 | * Carries the read/write authorization to topics for the users. 23 | * 24 | * @author andrea 25 | */ 26 | public class Authorization { 27 | protected final String topic; 28 | protected final Permission permission; 29 | 30 | /** 31 | * Access rights 32 | */ 33 | enum Permission { 34 | READ, WRITE, READWRITE 35 | } 36 | 37 | Authorization(String topic) { 38 | this(topic, READWRITE); 39 | } 40 | 41 | Authorization(String topic, Permission permission) { 42 | this.topic = topic; 43 | this.permission = permission; 44 | } 45 | 46 | public boolean grant(Permission desiredPermission) { 47 | return permission == desiredPermission || permission == READWRITE; 48 | } 49 | 50 | @Override 51 | public boolean equals(Object o) { 52 | if (this == o) return true; 53 | if (o == null || getClass() != o.getClass()) return false; 54 | 55 | Authorization that = (Authorization) o; 56 | 57 | if (permission != that.permission) return false; 58 | if (!topic.equals(that.topic)) return false; 59 | 60 | return true; 61 | } 62 | 63 | @Override 64 | public int hashCode() { 65 | int result = topic.hashCode(); 66 | result = 31 * result + permission.hashCode(); 67 | return result; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /auth-mongo/build.gradle: -------------------------------------------------------------------------------- 1 | group 'org.jmqtt' 2 | version '1.0-SNAPSHOT' 3 | 4 | apply plugin: 'java' 5 | 6 | dependencies { 7 | compile project(":auth") 8 | compile "org.springframework.boot:spring-boot-starter-data-mongodb" 9 | compile "org.springframework.security:spring-security-crypto:4.0.3.RELEASE" 10 | } 11 | -------------------------------------------------------------------------------- /auth-mongo/build/classes/main/org/jmqtt/auth/impl/MongoAuthenticator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/auth-mongo/build/classes/main/org/jmqtt/auth/impl/MongoAuthenticator.class -------------------------------------------------------------------------------- /auth-mongo/build/classes/main/org/jmqtt/auth/impl/model/Product.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/auth-mongo/build/classes/main/org/jmqtt/auth/impl/model/Product.class -------------------------------------------------------------------------------- /auth-mongo/build/classes/main/org/jmqtt/auth/impl/repository/ProductRepository.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/auth-mongo/build/classes/main/org/jmqtt/auth/impl/repository/ProductRepository.class -------------------------------------------------------------------------------- /auth-mongo/src/main/java/org/jmqtt/auth/impl/MongoAuthenticator.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.auth.impl; 2 | 3 | import org.jmqtt.auth.IAuthenticator; 4 | import org.jmqtt.auth.impl.model.Product; 5 | import org.jmqtt.auth.impl.repository.ProductRepository; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.security.crypto.password.PasswordEncoder; 10 | import org.springframework.security.crypto.password.StandardPasswordEncoder; 11 | 12 | /** 13 | * Created by gavin on 16/9/21. 14 | */ 15 | public class MongoAuthenticator implements IAuthenticator { 16 | 17 | private static final Logger LOG = LoggerFactory.getLogger(MongoAuthenticator.class); 18 | 19 | @Autowired 20 | ProductRepository repository; 21 | 22 | @Override 23 | public boolean checkValid(String clientId, String username, byte[] password, boolean allowZeroByteClientId) { 24 | 25 | Product product = repository.findByUsername(username); 26 | 27 | if (product == null) { 28 | return false; 29 | } 30 | 31 | PasswordEncoder passwordEncoder = new StandardPasswordEncoder(product.getSalt()); 32 | 33 | if (!passwordEncoder.matches(new String(password), product.getPassword())) { 34 | return false; 35 | } 36 | 37 | if (!allowZeroByteClientId && !product.getClients().contains(clientId)) { 38 | return false; 39 | } 40 | 41 | return true; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /auth-mongo/src/main/java/org/jmqtt/auth/impl/model/Product.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.auth.impl.model; 2 | 3 | import org.springframework.data.annotation.Id; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /** 9 | * Created by gavin on 16/9/21. 10 | */ 11 | public class Product { 12 | 13 | @Id 14 | private String id; 15 | 16 | private String username; 17 | 18 | private String password; 19 | 20 | private String salt; 21 | 22 | private String type; 23 | 24 | private List clients = new ArrayList<>(); 25 | 26 | public String getId() { 27 | return id; 28 | } 29 | 30 | public void setId(String id) { 31 | this.id = id; 32 | } 33 | 34 | public String getUsername() { 35 | return username; 36 | } 37 | 38 | public void setUsername(String username) { 39 | this.username = username; 40 | } 41 | 42 | public String getPassword() { 43 | return password; 44 | } 45 | 46 | public void setPassword(String password) { 47 | this.password = password; 48 | } 49 | 50 | public String getSalt() { 51 | return salt; 52 | } 53 | 54 | public void setSalt(String salt) { 55 | this.salt = salt; 56 | } 57 | 58 | public String getType() { 59 | return type; 60 | } 61 | 62 | public void setType(String type) { 63 | this.type = type; 64 | } 65 | 66 | public List getClients() { 67 | return clients; 68 | } 69 | 70 | public void setClients(List clients) { 71 | this.clients = clients; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /auth-mongo/src/main/java/org/jmqtt/auth/impl/repository/ProductRepository.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.auth.impl.repository; 2 | 3 | import org.jmqtt.auth.impl.model.Product; 4 | import org.springframework.data.mongodb.repository.MongoRepository; 5 | 6 | /** 7 | * Created by gavin on 16/9/21. 8 | */ 9 | public interface ProductRepository extends MongoRepository { 10 | Product findByUsername(String username); 11 | } 12 | -------------------------------------------------------------------------------- /auth/build.gradle: -------------------------------------------------------------------------------- 1 | group 'org.jmqtt' 2 | version '1.0-SNAPSHOT' 3 | 4 | apply plugin: 'java' 5 | 6 | dependencies { 7 | compile project(":session") 8 | compile "commons-codec:commons-codec" 9 | } 10 | -------------------------------------------------------------------------------- /auth/build/classes/main/org/jmqtt/auth/IAuthenticator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/auth/build/classes/main/org/jmqtt/auth/IAuthenticator.class -------------------------------------------------------------------------------- /auth/build/classes/main/org/jmqtt/auth/IAuthorizator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/auth/build/classes/main/org/jmqtt/auth/IAuthorizator.class -------------------------------------------------------------------------------- /auth/build/classes/main/org/jmqtt/auth/impl/ACLFileParser.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/auth/build/classes/main/org/jmqtt/auth/impl/ACLFileParser.class -------------------------------------------------------------------------------- /auth/build/classes/main/org/jmqtt/auth/impl/AcceptAllAuthenticator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/auth/build/classes/main/org/jmqtt/auth/impl/AcceptAllAuthenticator.class -------------------------------------------------------------------------------- /auth/build/classes/main/org/jmqtt/auth/impl/Authorization$Permission.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/auth/build/classes/main/org/jmqtt/auth/impl/Authorization$Permission.class -------------------------------------------------------------------------------- /auth/build/classes/main/org/jmqtt/auth/impl/Authorization.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/auth/build/classes/main/org/jmqtt/auth/impl/Authorization.class -------------------------------------------------------------------------------- /auth/build/classes/main/org/jmqtt/auth/impl/AuthorizationsCollector.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/auth/build/classes/main/org/jmqtt/auth/impl/AuthorizationsCollector.class -------------------------------------------------------------------------------- /auth/build/classes/main/org/jmqtt/auth/impl/DBAuthenticator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/auth/build/classes/main/org/jmqtt/auth/impl/DBAuthenticator.class -------------------------------------------------------------------------------- /auth/build/classes/main/org/jmqtt/auth/impl/DenyAllAuthorizator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/auth/build/classes/main/org/jmqtt/auth/impl/DenyAllAuthorizator.class -------------------------------------------------------------------------------- /auth/build/classes/main/org/jmqtt/auth/impl/FileAuthenticator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/auth/build/classes/main/org/jmqtt/auth/impl/FileAuthenticator.class -------------------------------------------------------------------------------- /auth/build/classes/main/org/jmqtt/auth/impl/PermitAllAuthorizator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/auth/build/classes/main/org/jmqtt/auth/impl/PermitAllAuthorizator.class -------------------------------------------------------------------------------- /auth/build/libs/auth-1.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/auth/build/libs/auth-1.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /auth/build/tmp/jar/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | 3 | -------------------------------------------------------------------------------- /auth/src/main/java/org/jmqtt/auth/IAuthenticator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.auth; 17 | 18 | /** 19 | * username and password checker 20 | * 21 | * @author andrea 22 | */ 23 | public interface IAuthenticator { 24 | 25 | boolean checkValid(String clientId, String username, byte[] password, boolean allowZeroByteClientId); 26 | } 27 | -------------------------------------------------------------------------------- /auth/src/main/java/org/jmqtt/auth/IAuthorizator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.auth; 17 | 18 | /** 19 | * ACL checker. 20 | *

21 | * Create an authorizator that matches topic names with same grammar of subscriptions. 22 | * The # is always a terminator and its the multilevel matcher. 23 | * The + sign is the single level matcher. 24 | * 25 | * @author andrea 26 | */ 27 | public interface IAuthorizator { 28 | 29 | /** 30 | * Ask the implementation of the authorizator if the topic can be used in a publish. 31 | */ 32 | boolean canWrite(String topic, String user, String client); 33 | 34 | boolean canRead(String topic, String user, String client); 35 | } 36 | -------------------------------------------------------------------------------- /auth/src/main/java/org/jmqtt/auth/impl/AcceptAllAuthenticator.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.auth.impl; 2 | 3 | 4 | import org.jmqtt.auth.IAuthenticator; 5 | 6 | /** 7 | * Created by andrea on 8/23/14. 8 | */ 9 | public class AcceptAllAuthenticator implements IAuthenticator { 10 | public boolean checkValid(String clientId, String username, byte[] password, boolean allowZeroByteClientId) { 11 | return true; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /auth/src/main/java/org/jmqtt/auth/impl/PermitAllAuthorizator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.auth.impl; 17 | 18 | 19 | import org.jmqtt.auth.IAuthorizator; 20 | 21 | /** 22 | * @author andrea 23 | */ 24 | public class PermitAllAuthorizator implements IAuthorizator { 25 | @Override 26 | public boolean canWrite(String topic, String user, String client) { 27 | return true; 28 | } 29 | 30 | @Override 31 | public boolean canRead(String topic, String user, String client) { 32 | return true; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /broker/build.gradle: -------------------------------------------------------------------------------- 1 | group 'org.jmqtt' 2 | version '1.0-SNAPSHOT' 3 | 4 | apply plugin: 'java' 5 | 6 | springBoot { 7 | executable = true 8 | } 9 | 10 | dependencies { 11 | compile project(":core") 12 | compile project(":session") 13 | compile project(":auth") 14 | compile project(":auth-mongo") 15 | compile project(":interception") 16 | compile project(":session-redisson") 17 | compile "io.netty:netty-transport:4.0.40.Final" 18 | compile "io.netty:netty-handler:4.0.40.Final" 19 | compile "io.netty:netty-codec-http:4.0.40.Final" 20 | } 21 | -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/BrokerApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/BrokerApplication.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/ConnectionDescriptor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/ConnectionDescriptor.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/Constants.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/Constants.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/acceptor/NettyAcceptor$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/acceptor/NettyAcceptor$1.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/acceptor/NettyAcceptor$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/acceptor/NettyAcceptor$2.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/acceptor/NettyAcceptor$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/acceptor/NettyAcceptor$3.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/acceptor/NettyAcceptor$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/acceptor/NettyAcceptor$4.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/acceptor/NettyAcceptor$5.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/acceptor/NettyAcceptor$5.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/acceptor/NettyAcceptor$ByteBufToWebSocketFrameEncoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/acceptor/NettyAcceptor$ByteBufToWebSocketFrameEncoder.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/acceptor/NettyAcceptor$PipelineInitializer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/acceptor/NettyAcceptor$PipelineInitializer.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/acceptor/NettyAcceptor$WebSocketFrameToByteBufDecoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/acceptor/NettyAcceptor$WebSocketFrameToByteBufDecoder.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/acceptor/NettyAcceptor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/acceptor/NettyAcceptor.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/config/AcceptorProperties.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/config/AcceptorProperties.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/config/DbProperties.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/config/DbProperties.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/config/RedissonProperties.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/config/RedissonProperties.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/config/ServerConfig.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/config/ServerConfig.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/config/SslProperties.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/config/SslProperties.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/handler/AutoFlushHandler$WriterIdleTimeoutTask.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/handler/AutoFlushHandler$WriterIdleTimeoutTask.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/handler/AutoFlushHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/handler/AutoFlushHandler.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/handler/IdleTimeoutHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/handler/IdleTimeoutHandler.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/handler/NettyMQTTHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/handler/NettyMQTTHandler.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/interceptor/BrokerInterceptor$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/interceptor/BrokerInterceptor$1.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/interceptor/BrokerInterceptor$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/interceptor/BrokerInterceptor$2.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/interceptor/BrokerInterceptor$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/interceptor/BrokerInterceptor$3.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/interceptor/BrokerInterceptor$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/interceptor/BrokerInterceptor$4.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/interceptor/BrokerInterceptor$5.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/interceptor/BrokerInterceptor$5.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/interceptor/BrokerInterceptor$6.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/interceptor/BrokerInterceptor$6.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/interceptor/BrokerInterceptor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/interceptor/BrokerInterceptor.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/metrics/BytesMetrics.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/metrics/BytesMetrics.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/metrics/BytesMetricsCollector.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/metrics/BytesMetricsCollector.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/metrics/BytesMetricsHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/metrics/BytesMetricsHandler.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/metrics/MessageMetrics.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/metrics/MessageMetrics.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/metrics/MessageMetricsCollector.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/metrics/MessageMetricsCollector.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/metrics/MessageMetricsHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/metrics/MessageMetricsHandler.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/process/ProtocolProcessor$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/process/ProtocolProcessor$1.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/process/ProtocolProcessor$WillMessage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/process/ProtocolProcessor$WillMessage.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/process/ProtocolProcessor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/process/ProtocolProcessor.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/security/DefaultSslContextCreator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/security/DefaultSslContextCreator.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/security/ISslContextCreator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/security/ISslContextCreator.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/util/DebugUtils.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/util/DebugUtils.class -------------------------------------------------------------------------------- /broker/build/classes/main/org/jmqtt/broker/util/NettyUtils.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/classes/main/org/jmqtt/broker/util/NettyUtils.class -------------------------------------------------------------------------------- /broker/build/libs/broker-1.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/libs/broker-1.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /broker/build/libs/broker-1.0-SNAPSHOT.jar.original: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/broker/build/libs/broker-1.0-SNAPSHOT.jar.original -------------------------------------------------------------------------------- /broker/build/resources/main/application.properties: -------------------------------------------------------------------------------- 1 | jmqtt.redisson.address=127.0.0.1:6379 2 | jmqtt.redisson.password=Yunwa123 3 | jmqtt.redisson.database=7 4 | spring.data.mongodb.uri=mongodb://localhost/jmqtt 5 | spring.data.mongodb.repositories.enabled=true -------------------------------------------------------------------------------- /broker/build/tmp/jar/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | 3 | -------------------------------------------------------------------------------- /broker/src/main/java/org/jmqtt/broker/BrokerApplication.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.broker; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.ComponentScan; 6 | 7 | import java.io.IOException; 8 | 9 | /** 10 | * Created by gavin on 16/9/20. 11 | */ 12 | @ComponentScan("org.jmqtt") 13 | @SpringBootApplication 14 | public class BrokerApplication { 15 | 16 | public static void main(String[] args) throws IOException, InterruptedException { 17 | SpringApplication.run(BrokerApplication.class, args); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /broker/src/main/java/org/jmqtt/broker/ConnectionDescriptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.broker; 17 | 18 | import io.netty.channel.Channel; 19 | 20 | /** 21 | * Value object to maintain the information of single connection, like ClientID, IoSession, 22 | * and other clean session fla. 23 | * 24 | * @author andrea 25 | */ 26 | public class ConnectionDescriptor { 27 | 28 | public final String clientId; 29 | public final Channel channel; 30 | public final boolean cleanSession; 31 | 32 | public ConnectionDescriptor(String clientId, Channel session, boolean cleanSession) { 33 | this.clientId = clientId; 34 | this.channel = session; 35 | this.cleanSession = cleanSession; 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return "ConnectionDescriptor{" + "clientId=" + clientId + ", cleanSession=" + cleanSession + '}'; 41 | } 42 | 43 | @Override 44 | public boolean equals(Object o) { 45 | if (this == o) return true; 46 | if (o == null || getClass() != o.getClass()) return false; 47 | 48 | ConnectionDescriptor that = (ConnectionDescriptor) o; 49 | 50 | if (clientId != null ? !clientId.equals(that.clientId) : that.clientId != null) return false; 51 | return !(channel != null ? !channel.equals(that.channel) : that.channel != null); 52 | 53 | } 54 | 55 | @Override 56 | public int hashCode() { 57 | int result = clientId != null ? clientId.hashCode() : 0; 58 | result = 31 * result + (channel != null ? channel.hashCode() : 0); 59 | return result; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /broker/src/main/java/org/jmqtt/broker/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.broker; 17 | 18 | /** 19 | * Server constants keeper 20 | */ 21 | public class Constants { 22 | public static final int DEFAULT_CONNECT_TIMEOUT = 10; 23 | } 24 | -------------------------------------------------------------------------------- /broker/src/main/java/org/jmqtt/broker/config/RedissonProperties.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.broker.config; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | 5 | /** 6 | * Created by gavin on 16/9/14. 7 | */ 8 | @ConfigurationProperties("jmqtt.redisson") 9 | public class RedissonProperties { 10 | 11 | private String address = "127.0.0.1:6379"; 12 | 13 | private Integer database = 0; 14 | 15 | private String password; 16 | 17 | public String getAddress() { 18 | return address; 19 | } 20 | 21 | public void setAddress(String address) { 22 | this.address = address; 23 | } 24 | 25 | public Integer getDatabase() { 26 | return database; 27 | } 28 | 29 | public void setDatabase(Integer database) { 30 | this.database = database; 31 | } 32 | 33 | public String getPassword() { 34 | return password; 35 | } 36 | 37 | public void setPassword(String password) { 38 | this.password = password; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /broker/src/main/java/org/jmqtt/broker/config/ServerConfig.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.broker.config; 2 | 3 | import org.jmqtt.auth.IAuthenticator; 4 | import org.jmqtt.auth.IAuthorizator; 5 | import org.jmqtt.auth.impl.MongoAuthenticator; 6 | import org.jmqtt.auth.impl.PermitAllAuthorizator; 7 | import org.jmqtt.broker.acceptor.NettyAcceptor; 8 | import org.jmqtt.interception.BrokerInterceptor; 9 | import org.jmqtt.persistence.RedissonPersistentStore; 10 | import org.jmqtt.session.IMessagesStore; 11 | import org.jmqtt.session.ISessionsStore; 12 | import org.redisson.config.Config; 13 | import org.redisson.config.SingleServerConfig; 14 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 15 | import org.springframework.context.annotation.Bean; 16 | import org.springframework.context.annotation.Configuration; 17 | import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; 18 | import org.springframework.util.StringUtils; 19 | 20 | import java.util.ArrayList; 21 | 22 | /** 23 | * Created by gavin on 16/9/14. 24 | */ 25 | @Configuration 26 | @EnableConfigurationProperties({AcceptorProperties.class, RedissonProperties.class}) 27 | @EnableMongoRepositories("org.jmqtt.**.repository") 28 | public class ServerConfig { 29 | 30 | @Bean 31 | NettyAcceptor acceptor() { 32 | return new NettyAcceptor(); 33 | } 34 | 35 | @Bean 36 | IAuthenticator authenticator() { 37 | return new MongoAuthenticator(); 38 | } 39 | 40 | @Bean 41 | IAuthorizator authorizator() { 42 | return new PermitAllAuthorizator(); 43 | } 44 | 45 | @Bean(destroyMethod = "close") 46 | RedissonPersistentStore persistenceStore(RedissonProperties properties) { 47 | Config config = new Config(); 48 | SingleServerConfig singleServerConfig = config.useSingleServer(); 49 | 50 | singleServerConfig.setAddress(properties.getAddress()); 51 | 52 | singleServerConfig.setDatabase(properties.getDatabase()); 53 | 54 | if (!StringUtils.isEmpty(properties.getPassword())) { 55 | singleServerConfig.setPassword(properties.getPassword()); 56 | } 57 | return new RedissonPersistentStore(config); 58 | } 59 | 60 | @Bean 61 | IMessagesStore messagesStore(RedissonPersistentStore persistenceStore) { 62 | return persistenceStore.messagesStore(); 63 | } 64 | 65 | @Bean 66 | ISessionsStore sessionsStore(RedissonPersistentStore persistenceStore, IMessagesStore messagesStore) { 67 | return persistenceStore.sessionsStore(messagesStore); 68 | } 69 | 70 | @Bean(destroyMethod = "stop") 71 | BrokerInterceptor brokerInterceptor() { 72 | return new BrokerInterceptor(new ArrayList<>()); 73 | } 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /broker/src/main/java/org/jmqtt/broker/config/SslProperties.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.broker.config; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | 5 | /** 6 | * Created by gavin on 16/9/14. 7 | */ 8 | @ConfigurationProperties("jmqtt.ssl") 9 | public class SslProperties { 10 | 11 | private String keyStorePassword; 12 | 13 | private String keyManagerPassword; 14 | 15 | private String jksPath; 16 | 17 | private Boolean needsClientAuth = false; 18 | 19 | public String getKeyStorePassword() { 20 | return keyStorePassword; 21 | } 22 | 23 | public void setKeyStorePassword(String keyStorePassword) { 24 | this.keyStorePassword = keyStorePassword; 25 | } 26 | 27 | public String getKeyManagerPassword() { 28 | return keyManagerPassword; 29 | } 30 | 31 | public void setKeyManagerPassword(String keyManagerPassword) { 32 | this.keyManagerPassword = keyManagerPassword; 33 | } 34 | 35 | public String getJksPath() { 36 | return jksPath; 37 | } 38 | 39 | public void setJksPath(String jksPath) { 40 | this.jksPath = jksPath; 41 | } 42 | 43 | public Boolean getNeedsClientAuth() { 44 | return needsClientAuth; 45 | } 46 | 47 | public void setNeedsClientAuth(Boolean needsClientAuth) { 48 | this.needsClientAuth = needsClientAuth; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /broker/src/main/java/org/jmqtt/broker/handler/IdleTimeoutHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.broker.handler; 17 | 18 | import io.netty.channel.ChannelDuplexHandler; 19 | import io.netty.channel.ChannelHandler.Sharable; 20 | import io.netty.channel.ChannelHandlerContext; 21 | import io.netty.handler.timeout.IdleState; 22 | import io.netty.handler.timeout.IdleStateEvent; 23 | 24 | @Sharable 25 | public class IdleTimeoutHandler extends ChannelDuplexHandler { 26 | @Override 27 | public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { 28 | if (evt instanceof IdleStateEvent) { 29 | IdleState e = ((IdleStateEvent) evt).state(); 30 | if (e == IdleState.ALL_IDLE) { 31 | //fire a channelInactive to trigger publish of Will 32 | ctx.fireChannelInactive(); 33 | ctx.close(); 34 | } 35 | } else { 36 | super.userEventTriggered(ctx, evt); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /broker/src/main/java/org/jmqtt/broker/metrics/BytesMetrics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.broker.metrics; 17 | 18 | public class BytesMetrics { 19 | private long readBytes = 0; 20 | private long wroteBytes = 0; 21 | 22 | void incrementRead(long numBytes) { 23 | readBytes += numBytes; 24 | } 25 | 26 | void incrementWrote(long numBytes) { 27 | wroteBytes += numBytes; 28 | } 29 | 30 | public long readBytes() { 31 | return readBytes; 32 | } 33 | 34 | public long wroteBytes() { 35 | return wroteBytes; 36 | } 37 | } -------------------------------------------------------------------------------- /broker/src/main/java/org/jmqtt/broker/metrics/BytesMetricsCollector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.broker.metrics; 17 | 18 | import java.util.concurrent.atomic.AtomicLong; 19 | 20 | /** 21 | * Collects all the metrics from the various pipeline. 22 | */ 23 | public class BytesMetricsCollector { 24 | 25 | private AtomicLong readBytes = new AtomicLong(); 26 | private AtomicLong wroteBytes = new AtomicLong(); 27 | 28 | public BytesMetrics computeMetrics() { 29 | BytesMetrics allMetrics = new BytesMetrics(); 30 | allMetrics.incrementRead(readBytes.get()); 31 | allMetrics.incrementWrote(wroteBytes.get()); 32 | return allMetrics; 33 | } 34 | 35 | public void sumReadBytes(long count) { 36 | readBytes.getAndAdd(count); 37 | } 38 | 39 | public void sumWroteBytes(long count) { 40 | wroteBytes.getAndAdd(count); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /broker/src/main/java/org/jmqtt/broker/metrics/BytesMetricsHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.broker.metrics; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.channel.ChannelDuplexHandler; 20 | import io.netty.channel.ChannelHandlerContext; 21 | import io.netty.channel.ChannelPromise; 22 | import io.netty.util.Attribute; 23 | import io.netty.util.AttributeKey; 24 | 25 | public class BytesMetricsHandler extends ChannelDuplexHandler { 26 | 27 | private static final AttributeKey ATTR_KEY_METRICS = AttributeKey.valueOf("BytesMetrics"); 28 | 29 | private BytesMetricsCollector collector; 30 | 31 | public BytesMetricsHandler(BytesMetricsCollector collector) { 32 | this.collector = collector; 33 | } 34 | 35 | @Override 36 | public void channelActive(ChannelHandlerContext ctx) throws Exception { 37 | Attribute attr = ctx.attr(ATTR_KEY_METRICS); 38 | attr.set(new BytesMetrics()); 39 | 40 | super.channelActive(ctx); 41 | } 42 | 43 | @Override 44 | public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { 45 | BytesMetrics metrics = ctx.attr(ATTR_KEY_METRICS).get(); 46 | metrics.incrementRead(((ByteBuf) msg).readableBytes()); 47 | ctx.fireChannelRead(msg); 48 | } 49 | 50 | @Override 51 | public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { 52 | BytesMetrics metrics = ctx.attr(ATTR_KEY_METRICS).get(); 53 | metrics.incrementWrote(((ByteBuf) msg).writableBytes()); 54 | ctx.write(msg, promise); 55 | } 56 | 57 | 58 | @Override 59 | public void close(ChannelHandlerContext ctx, 60 | ChannelPromise promise) throws Exception { 61 | BytesMetrics metrics = ctx.attr(ATTR_KEY_METRICS).get(); 62 | collector.sumReadBytes(metrics.readBytes()); 63 | collector.sumWroteBytes(metrics.wroteBytes()); 64 | super.close(ctx, promise); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /broker/src/main/java/org/jmqtt/broker/metrics/MessageMetrics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.broker.metrics; 17 | 18 | public class MessageMetrics { 19 | private long messagesRead = 0; 20 | private long messageWrote = 0; 21 | 22 | void incrementRead(long numMessages) { 23 | messagesRead += numMessages; 24 | } 25 | 26 | void incrementWrote(long numMessages) { 27 | messageWrote += numMessages; 28 | } 29 | 30 | public long messagesRead() { 31 | return messagesRead; 32 | } 33 | 34 | public long messagesWrote() { 35 | return messageWrote; 36 | } 37 | } -------------------------------------------------------------------------------- /broker/src/main/java/org/jmqtt/broker/metrics/MessageMetricsCollector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.broker.metrics; 17 | 18 | import java.util.concurrent.atomic.AtomicLong; 19 | 20 | /** 21 | * Collects all the metrics from the various pipeline. 22 | */ 23 | public class MessageMetricsCollector { 24 | private AtomicLong readMsgs = new AtomicLong(); 25 | private AtomicLong wroteMsgs = new AtomicLong(); 26 | 27 | public MessageMetrics computeMetrics() { 28 | MessageMetrics allMetrics = new MessageMetrics(); 29 | allMetrics.incrementRead(readMsgs.get()); 30 | allMetrics.incrementWrote(wroteMsgs.get()); 31 | return allMetrics; 32 | } 33 | 34 | public void sumReadMessages(long count) { 35 | readMsgs.getAndAdd(count); 36 | } 37 | 38 | public void sumWroteMessages(long count) { 39 | wroteMsgs.getAndAdd(count); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /broker/src/main/java/org/jmqtt/broker/metrics/MessageMetricsHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.broker.metrics; 17 | 18 | import io.netty.channel.ChannelDuplexHandler; 19 | import io.netty.channel.ChannelHandlerContext; 20 | import io.netty.channel.ChannelPromise; 21 | import io.netty.util.Attribute; 22 | import io.netty.util.AttributeKey; 23 | 24 | public class MessageMetricsHandler extends ChannelDuplexHandler { 25 | 26 | private static final AttributeKey ATTR_KEY_METRICS = AttributeKey.valueOf("MessageMetrics"); 27 | 28 | private MessageMetricsCollector collector; 29 | 30 | public MessageMetricsHandler(MessageMetricsCollector collector) { 31 | this.collector = collector; 32 | } 33 | 34 | @Override 35 | public void channelActive(ChannelHandlerContext ctx) throws Exception { 36 | Attribute attr = ctx.attr(ATTR_KEY_METRICS); 37 | attr.set(new MessageMetrics()); 38 | 39 | super.channelActive(ctx); 40 | } 41 | 42 | @Override 43 | public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { 44 | MessageMetrics metrics = ctx.attr(ATTR_KEY_METRICS).get(); 45 | metrics.incrementRead(1); 46 | ctx.fireChannelRead(msg); 47 | } 48 | 49 | @Override 50 | public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { 51 | MessageMetrics metrics = ctx.attr(ATTR_KEY_METRICS).get(); 52 | metrics.incrementWrote(1); 53 | ctx.write(msg, promise); 54 | } 55 | 56 | 57 | @Override 58 | public void close(ChannelHandlerContext ctx, 59 | ChannelPromise promise) throws Exception { 60 | MessageMetrics metrics = ctx.attr(ATTR_KEY_METRICS).get(); 61 | collector.sumReadMessages(metrics.messagesRead()); 62 | collector.sumWroteMessages(metrics.messagesWrote()); 63 | super.close(ctx, promise); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /broker/src/main/java/org/jmqtt/broker/security/ISslContextCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.broker.security; 17 | 18 | import javax.net.ssl.SSLContext; 19 | 20 | /** 21 | * SSL certificate loader used to open SSL connections (websocket and MQTT-S). 22 | *

23 | * Created by andrea on 13/12/15. 24 | */ 25 | public interface ISslContextCreator { 26 | 27 | SSLContext initSSLContext(); 28 | } 29 | -------------------------------------------------------------------------------- /broker/src/main/java/org/jmqtt/broker/util/DebugUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.broker.util; 17 | 18 | import java.nio.ByteBuffer; 19 | 20 | /** 21 | * @author andrea 22 | */ 23 | public class DebugUtils { 24 | public static String payload2Str(ByteBuffer content) { 25 | byte[] b = new byte[content.remaining()]; 26 | content.mark(); 27 | content.get(b); 28 | content.reset(); 29 | return new String(b); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /broker/src/main/java/org/jmqtt/broker/util/NettyUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.broker.util; 17 | 18 | import io.netty.channel.Channel; 19 | import io.netty.channel.ChannelHandlerContext; 20 | import io.netty.util.Attribute; 21 | import io.netty.util.AttributeKey; 22 | 23 | /** 24 | * Some Netty's channels utilities. 25 | * 26 | * @author andrea 27 | */ 28 | public class NettyUtils { 29 | 30 | public static final String ATTR_USERNAME = "username"; 31 | public static final String ATTR_SESSION_STOLEN = "sessionStolen"; 32 | public static final String ATTR_CLIENTID = "ClientID"; 33 | public static final String CLEAN_SESSION = "cleanSession"; 34 | public static final String KEEP_ALIVE = "keepAlive"; 35 | 36 | private static final AttributeKey ATTR_KEY_KEEPALIVE = AttributeKey.valueOf(KEEP_ALIVE); 37 | private static final AttributeKey ATTR_KEY_CLEANSESSION = AttributeKey.valueOf(CLEAN_SESSION); 38 | private static final AttributeKey ATTR_KEY_CLIENTID = AttributeKey.valueOf(ATTR_CLIENTID); 39 | private static final AttributeKey ATTR_KEY_USERNAME = AttributeKey.valueOf(ATTR_USERNAME); 40 | private static final AttributeKey ATTR_KEY_SESSION_STOLEN = AttributeKey.valueOf(ATTR_SESSION_STOLEN); 41 | 42 | public static Object getAttribute(ChannelHandlerContext ctx, AttributeKey key) { 43 | Attribute attr = ctx.channel().attr(key); 44 | return attr.get(); 45 | } 46 | 47 | public static void keepAlive(Channel channel, int keepAlive) { 48 | channel.attr(NettyUtils.ATTR_KEY_KEEPALIVE).set(keepAlive); 49 | } 50 | 51 | public static void cleanSession(Channel channel, boolean cleanSession) { 52 | channel.attr(NettyUtils.ATTR_KEY_CLEANSESSION).set(cleanSession); 53 | } 54 | 55 | public static boolean cleanSession(Channel channel) { 56 | return (Boolean) channel.attr(NettyUtils.ATTR_KEY_CLEANSESSION).get(); 57 | } 58 | 59 | public static void clientId(Channel channel, String clientID) { 60 | channel.attr(NettyUtils.ATTR_KEY_CLIENTID).set(clientID); 61 | } 62 | 63 | public static String clientId(Channel channel) { 64 | return (String) channel.attr(NettyUtils.ATTR_KEY_CLIENTID).get(); 65 | } 66 | 67 | public static void userName(Channel channel, String username) { 68 | channel.attr(NettyUtils.ATTR_KEY_USERNAME).set(username); 69 | } 70 | 71 | public static String userName(Channel channel) { 72 | return (String) channel.attr(NettyUtils.ATTR_KEY_USERNAME).get(); 73 | } 74 | 75 | public static void sessionStolen(Channel channel, boolean value) { 76 | channel.attr(NettyUtils.ATTR_KEY_SESSION_STOLEN).set(value); 77 | } 78 | 79 | public static Boolean sessionStolen(Channel channel) { 80 | return (Boolean) channel.attr(NettyUtils.ATTR_KEY_SESSION_STOLEN).get(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /broker/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | jmqtt.redisson.address=127.0.0.1:6379 2 | jmqtt.redisson.password=Yunwa123 3 | jmqtt.redisson.database=7 4 | spring.data.mongodb.uri=mongodb://localhost/jmqtt 5 | spring.data.mongodb.repositories.enabled=true -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | mavenCentral() 5 | maven { url 'http://repo.spring.io/plugins-release' } 6 | } 7 | 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE") 10 | classpath 'org.springframework.build.gradle:propdeps-plugin:0.0.7' 11 | } 12 | 13 | } 14 | 15 | group 'org.jmqtt' 16 | version '1.0-SNAPSHOT' 17 | 18 | subprojects { 19 | apply plugin: 'java' 20 | apply plugin: 'propdeps' 21 | apply plugin: 'spring-boot' 22 | sourceCompatibility = 1.8 23 | targetCompatibility = 1.8 24 | 25 | repositories { 26 | jcenter() 27 | mavenCentral() 28 | } 29 | 30 | dependencies { 31 | compile "org.springframework.boot:spring-boot-starter" 32 | optional "org.springframework.boot:spring-boot-configuration-processor" 33 | testCompile("org.springframework.boot:spring-boot-starter-test") 34 | } 35 | 36 | compileJava.dependsOn(processResources) 37 | } 38 | -------------------------------------------------------------------------------- /cluster/build.gradle: -------------------------------------------------------------------------------- 1 | group 'org.jmqtt' 2 | version '1.0-SNAPSHOT' 3 | 4 | apply plugin: 'java' 5 | 6 | sourceCompatibility = 1.5 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | testCompile group: 'junit', name: 'junit', version: '4.11' 14 | } 15 | -------------------------------------------------------------------------------- /core/build.gradle: -------------------------------------------------------------------------------- 1 | group 'org.jmqtt' 2 | version '1.0-SNAPSHOT' 3 | 4 | apply plugin: 'java' 5 | 6 | dependencies { 7 | compile "io.netty:netty-common:4.0.40.Final" 8 | compile "io.netty:netty-buffer:4.0.40.Final" 9 | compile "io.netty:netty-codec:4.0.40.Final" 10 | compile "org.slf4j:jcl-over-slf4j" 11 | compile "org.slf4j:jul-to-slf4j" 12 | compile "org.slf4j:slf4j-api" 13 | } 14 | -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/ConnAckDecoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/ConnAckDecoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/ConnAckEncoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/ConnAckEncoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/ConnectDecoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/ConnectDecoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/ConnectEncoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/ConnectEncoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/DemuxDecoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/DemuxDecoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/DemuxEncoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/DemuxEncoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/DisconnectDecoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/DisconnectDecoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/DisconnectEncoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/DisconnectEncoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/MQTTDecoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/MQTTDecoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/MQTTEncoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/MQTTEncoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/MessageIDDecoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/MessageIDDecoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/PingReqDecoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/PingReqDecoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/PingReqEncoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/PingReqEncoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/PingRespDecoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/PingRespDecoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/PingRespEncoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/PingRespEncoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/PubAckDecoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/PubAckDecoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/PubAckEncoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/PubAckEncoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/PubCompDecoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/PubCompDecoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/PubCompEncoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/PubCompEncoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/PubRecDecoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/PubRecDecoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/PubRecEncoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/PubRecEncoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/PubRelDecoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/PubRelDecoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/PubRelEncoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/PubRelEncoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/PublishDecoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/PublishDecoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/PublishEncoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/PublishEncoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/SubAckDecoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/SubAckDecoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/SubAckEncoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/SubAckEncoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/SubscribeDecoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/SubscribeDecoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/SubscribeEncoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/SubscribeEncoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/UnsubAckDecoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/UnsubAckDecoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/UnsubAckEncoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/UnsubAckEncoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/UnsubscribeDecoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/UnsubscribeDecoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/codec/UnsubscribeEncoder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/codec/UnsubscribeEncoder.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/constant/QosType$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/constant/QosType$1.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/constant/QosType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/constant/QosType.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/exception/MQTTException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/exception/MQTTException.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/packet/AbstractPacket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/packet/AbstractPacket.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/packet/ConnAckPacket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/packet/ConnAckPacket.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/packet/ConnectPacket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/packet/ConnectPacket.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/packet/DisconnectPacket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/packet/DisconnectPacket.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/packet/PacketIdPacket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/packet/PacketIdPacket.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/packet/PingReqPacket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/packet/PingReqPacket.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/packet/PingRespPacket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/packet/PingRespPacket.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/packet/PubAckPacket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/packet/PubAckPacket.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/packet/PubCompPacket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/packet/PubCompPacket.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/packet/PubRecPacket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/packet/PubRecPacket.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/packet/PubRelPacket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/packet/PubRelPacket.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/packet/PublishPacket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/packet/PublishPacket.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/packet/SubAckPacket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/packet/SubAckPacket.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/packet/SubscribePacket$Couple.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/packet/SubscribePacket$Couple.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/packet/SubscribePacket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/packet/SubscribePacket.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/packet/UnsubAckPacket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/packet/UnsubAckPacket.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/packet/UnsubscribePacket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/packet/UnsubscribePacket.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/packet/ZeroLengthPacket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/packet/ZeroLengthPacket.class -------------------------------------------------------------------------------- /core/build/classes/main/org/jmqtt/core/util/MqttUtils.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/classes/main/org/jmqtt/core/util/MqttUtils.class -------------------------------------------------------------------------------- /core/build/libs/core-1.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/core/build/libs/core-1.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /core/build/tmp/jar/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | 3 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/ConnAckDecoder.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.core.codec; 2 | 3 | import org.jmqtt.core.packet.ConnAckPacket; 4 | import io.netty.buffer.ByteBuf; 5 | import io.netty.util.AttributeMap; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author andrea 11 | */ 12 | class ConnAckDecoder extends DemuxDecoder { 13 | 14 | @Override 15 | void decode(AttributeMap ctx, ByteBuf in, List out) throws Exception { 16 | in.resetReaderIndex(); 17 | //Common decoding part 18 | ConnAckPacket message = new ConnAckPacket(); 19 | if (!decodeCommonHeader(message, 0x00, in)) { 20 | in.resetReaderIndex(); 21 | return; 22 | } 23 | //skip reserved byte 24 | in.skipBytes(1); 25 | 26 | //read return code 27 | message.setReturnCode(in.readByte()); 28 | out.add(message); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/ConnAckEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.channel.ChannelHandlerContext; 20 | import org.jmqtt.core.packet.AbstractPacket; 21 | import org.jmqtt.core.packet.ConnAckPacket; 22 | import org.jmqtt.core.util.MqttUtils; 23 | 24 | /** 25 | * @author andrea 26 | */ 27 | class ConnAckEncoder extends DemuxEncoder { 28 | 29 | @Override 30 | protected void encode(ChannelHandlerContext chc, ConnAckPacket message, ByteBuf out) { 31 | out.writeByte(AbstractPacket.CONNACK << 4); 32 | out.writeBytes(MqttUtils.encodeRemainingLength(2)); 33 | out.writeByte(message.isSessionPresent() ? 0x01 : 0x00); 34 | out.writeByte(message.getReturnCode()); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/DemuxDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.handler.codec.CorruptedFrameException; 20 | import io.netty.util.AttributeMap; 21 | import org.jmqtt.core.constant.QosType; 22 | import org.jmqtt.core.packet.AbstractPacket; 23 | import org.jmqtt.core.util.MqttUtils; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * @author andrea 29 | */ 30 | abstract class DemuxDecoder { 31 | abstract void decode(AttributeMap ctx, ByteBuf in, List out) throws Exception; 32 | 33 | /** 34 | * Decodes the first 2 bytes of the MQTT packet. 35 | * The first byte contain the packet operation code and the flags, 36 | * the second byte and more contains the overall packet length. 37 | */ 38 | protected boolean decodeCommonHeader(AbstractPacket message, ByteBuf in) { 39 | return genericDecodeCommonHeader(message, null, in); 40 | } 41 | 42 | /** 43 | * Do the same as the @see#decodeCommonHeader but having a strong validation on the flags values 44 | */ 45 | protected boolean decodeCommonHeader(AbstractPacket message, int expectedFlags, ByteBuf in) { 46 | return genericDecodeCommonHeader(message, expectedFlags, in); 47 | } 48 | 49 | 50 | private boolean genericDecodeCommonHeader(AbstractPacket message, Integer expectedFlagsOpt, ByteBuf in) { 51 | //Common decoding part 52 | if (in.readableBytes() < 2) { 53 | return false; 54 | } 55 | byte h1 = in.readByte(); 56 | byte messageType = (byte) ((h1 & 0x00F0) >> 4); 57 | 58 | byte flags = (byte) (h1 & 0x0F); 59 | if (expectedFlagsOpt != null) { 60 | int expectedFlags = expectedFlagsOpt; 61 | if ((byte) expectedFlags != flags) { 62 | String hexExpected = Integer.toHexString(expectedFlags); 63 | String hexReceived = Integer.toHexString(flags); 64 | throw new CorruptedFrameException(String.format("Received a message with fixed header flags (%s) != expected (%s)", hexReceived, hexExpected)); 65 | } 66 | } 67 | 68 | boolean dupFlag = ((byte) ((h1 & 0x0008) >> 3) == 1); 69 | byte qosLevel = (byte) ((h1 & 0x0006) >> 1); 70 | boolean retainFlag = ((byte) (h1 & 0x0001) == 1); 71 | int remainingLength = MqttUtils.decodeRemainingLenght(in); 72 | if (remainingLength == -1) { 73 | return false; 74 | } 75 | 76 | message.setMessageType(messageType); 77 | message.setDupFlag(dupFlag); 78 | try { 79 | message.setQos(QosType.valueOf(qosLevel)); 80 | } catch (IllegalArgumentException e) { 81 | throw new CorruptedFrameException(String.format("Received an invalid QOS: %s", e.getMessage()), e); 82 | } 83 | message.setRetainFlag(retainFlag); 84 | message.setRemainingLength(remainingLength); 85 | return true; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/DemuxEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import org.jmqtt.core.packet.AbstractPacket; 19 | import io.netty.buffer.ByteBuf; 20 | import io.netty.channel.ChannelHandlerContext; 21 | 22 | /** 23 | * @author andrea 24 | */ 25 | abstract class DemuxEncoder { 26 | abstract protected void encode(ChannelHandlerContext chc, T msg, ByteBuf bb); 27 | } 28 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/DisconnectDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import org.jmqtt.core.packet.DisconnectPacket; 19 | import io.netty.buffer.ByteBuf; 20 | import io.netty.util.AttributeMap; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * @author andrea 26 | */ 27 | class DisconnectDecoder extends DemuxDecoder { 28 | 29 | @Override 30 | void decode(AttributeMap ctx, ByteBuf in, List out) throws Exception { 31 | //Common decoding part 32 | in.resetReaderIndex(); 33 | DisconnectPacket message = new DisconnectPacket(); 34 | if (!decodeCommonHeader(message, 0x00, in)) { 35 | in.resetReaderIndex(); 36 | return; 37 | } 38 | out.add(message); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/DisconnectEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import org.jmqtt.core.packet.AbstractPacket; 19 | import org.jmqtt.core.packet.DisconnectPacket; 20 | import io.netty.buffer.ByteBuf; 21 | import io.netty.channel.ChannelHandlerContext; 22 | 23 | /** 24 | * @author andrea 25 | */ 26 | public class DisconnectEncoder extends DemuxEncoder { 27 | 28 | @Override 29 | protected void encode(ChannelHandlerContext chc, DisconnectPacket msg, ByteBuf out) { 30 | out.writeByte(AbstractPacket.DISCONNECT << 4).writeByte(0); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/MQTTDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.channel.ChannelHandlerContext; 20 | import io.netty.handler.codec.ByteToMessageDecoder; 21 | import io.netty.handler.codec.CorruptedFrameException; 22 | import io.netty.util.AttributeKey; 23 | import org.jmqtt.core.packet.AbstractPacket; 24 | import org.jmqtt.core.util.MqttUtils; 25 | 26 | import java.util.HashMap; 27 | import java.util.List; 28 | import java.util.Map; 29 | 30 | /** 31 | * @author andrea 32 | */ 33 | public class MQTTDecoder extends ByteToMessageDecoder { 34 | 35 | //3 = 3.1, 4 = 3.1.1 36 | public static final AttributeKey PROTOCOL_VERSION = AttributeKey.valueOf("version"); 37 | 38 | private final Map decoderMap = new HashMap<>(); 39 | 40 | public MQTTDecoder() { 41 | decoderMap.put(AbstractPacket.CONNECT, new ConnectDecoder()); 42 | decoderMap.put(AbstractPacket.CONNACK, new ConnAckDecoder()); 43 | decoderMap.put(AbstractPacket.PUBLISH, new PublishDecoder()); 44 | decoderMap.put(AbstractPacket.PUBACK, new PubAckDecoder()); 45 | decoderMap.put(AbstractPacket.SUBSCRIBE, new SubscribeDecoder()); 46 | decoderMap.put(AbstractPacket.SUBACK, new SubAckDecoder()); 47 | decoderMap.put(AbstractPacket.UNSUBSCRIBE, new UnsubscribeDecoder()); 48 | decoderMap.put(AbstractPacket.DISCONNECT, new DisconnectDecoder()); 49 | decoderMap.put(AbstractPacket.PINGREQ, new PingReqDecoder()); 50 | decoderMap.put(AbstractPacket.PINGRESP, new PingRespDecoder()); 51 | decoderMap.put(AbstractPacket.UNSUBACK, new UnsubAckDecoder()); 52 | decoderMap.put(AbstractPacket.PUBCOMP, new PubCompDecoder()); 53 | decoderMap.put(AbstractPacket.PUBREC, new PubRecDecoder()); 54 | decoderMap.put(AbstractPacket.PUBREL, new PubRelDecoder()); 55 | } 56 | 57 | @Override 58 | protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { 59 | in.markReaderIndex(); 60 | if (!MqttUtils.checkHeaderAvailability(in)) { 61 | in.resetReaderIndex(); 62 | return; 63 | } 64 | in.resetReaderIndex(); 65 | 66 | byte messageType = MqttUtils.readMessageType(in); 67 | 68 | DemuxDecoder decoder = decoderMap.get(messageType); 69 | if (decoder == null) { 70 | throw new CorruptedFrameException("Can't find any suitable decoder for message type: " + messageType); 71 | } 72 | decoder.decode(ctx, in, out); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/MQTTEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import org.jmqtt.core.packet.AbstractPacket; 19 | import io.netty.buffer.ByteBuf; 20 | import io.netty.channel.ChannelHandlerContext; 21 | import io.netty.handler.codec.CorruptedFrameException; 22 | import io.netty.handler.codec.MessageToByteEncoder; 23 | 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | /** 28 | * @author andrea 29 | */ 30 | public class MQTTEncoder extends MessageToByteEncoder { 31 | 32 | private Map m_encoderMap = new HashMap(); 33 | 34 | public MQTTEncoder() { 35 | m_encoderMap.put(AbstractPacket.CONNECT, new ConnectEncoder()); 36 | m_encoderMap.put(AbstractPacket.CONNACK, new ConnAckEncoder()); 37 | m_encoderMap.put(AbstractPacket.PUBLISH, new PublishEncoder()); 38 | m_encoderMap.put(AbstractPacket.PUBACK, new PubAckEncoder()); 39 | m_encoderMap.put(AbstractPacket.SUBSCRIBE, new SubscribeEncoder()); 40 | m_encoderMap.put(AbstractPacket.SUBACK, new SubAckEncoder()); 41 | m_encoderMap.put(AbstractPacket.UNSUBSCRIBE, new UnsubscribeEncoder()); 42 | m_encoderMap.put(AbstractPacket.DISCONNECT, new DisconnectEncoder()); 43 | m_encoderMap.put(AbstractPacket.PINGREQ, new PingReqEncoder()); 44 | m_encoderMap.put(AbstractPacket.PINGRESP, new PingRespEncoder()); 45 | m_encoderMap.put(AbstractPacket.UNSUBACK, new UnsubAckEncoder()); 46 | m_encoderMap.put(AbstractPacket.PUBCOMP, new PubCompEncoder()); 47 | m_encoderMap.put(AbstractPacket.PUBREC, new PubRecEncoder()); 48 | m_encoderMap.put(AbstractPacket.PUBREL, new PubRelEncoder()); 49 | } 50 | 51 | @Override 52 | protected void encode(ChannelHandlerContext chc, AbstractPacket msg, ByteBuf bb) throws Exception { 53 | DemuxEncoder encoder = m_encoderMap.get(msg.getMessageType()); 54 | if (encoder == null) { 55 | throw new CorruptedFrameException("Can't find any suitable decoder for message type: " + msg.getMessageType()); 56 | } 57 | encoder.encode(chc, msg, bb); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/MessageIDDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import org.jmqtt.core.packet.PacketIdPacket; 19 | import io.netty.buffer.ByteBuf; 20 | import io.netty.util.AttributeMap; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * @author andrea 26 | */ 27 | abstract class MessageIDDecoder extends DemuxDecoder { 28 | 29 | protected abstract PacketIdPacket createMessage(); 30 | 31 | @Override 32 | void decode(AttributeMap ctx, ByteBuf in, List out) throws Exception { 33 | in.resetReaderIndex(); 34 | //Common decoding part 35 | PacketIdPacket message = createMessage(); 36 | if (!decodeCommonHeader(message, 0x00, in)) { 37 | in.resetReaderIndex(); 38 | return; 39 | } 40 | 41 | //read messageIDs 42 | message.setPacketId(in.readUnsignedShort()); 43 | out.add(message); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/PingReqDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import org.jmqtt.core.packet.PingReqPacket; 19 | import io.netty.buffer.ByteBuf; 20 | import io.netty.util.AttributeMap; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * @author andrea 26 | */ 27 | class PingReqDecoder extends DemuxDecoder { 28 | 29 | @Override 30 | void decode(AttributeMap ctx, ByteBuf in, List out) throws Exception { 31 | //Common decoding part 32 | in.resetReaderIndex(); 33 | PingReqPacket message = new PingReqPacket(); 34 | if (!decodeCommonHeader(message, 0x00, in)) { 35 | in.resetReaderIndex(); 36 | return; 37 | } 38 | out.add(message); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/PingReqEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import org.jmqtt.core.packet.AbstractPacket; 19 | import org.jmqtt.core.packet.PingReqPacket; 20 | import io.netty.buffer.ByteBuf; 21 | import io.netty.channel.ChannelHandlerContext; 22 | 23 | /** 24 | * @author andrea 25 | */ 26 | class PingReqEncoder extends DemuxEncoder { 27 | 28 | @Override 29 | protected void encode(ChannelHandlerContext chc, PingReqPacket msg, ByteBuf out) { 30 | out.writeByte(AbstractPacket.PINGREQ << 4).writeByte(0); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/PingRespDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import org.jmqtt.core.packet.PingRespPacket; 19 | import io.netty.buffer.ByteBuf; 20 | import io.netty.util.AttributeMap; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * @author andrea 26 | */ 27 | class PingRespDecoder extends DemuxDecoder { 28 | 29 | @Override 30 | void decode(AttributeMap ctx, ByteBuf in, List out) throws Exception { 31 | //Common decoding part 32 | in.resetReaderIndex(); 33 | PingRespPacket message = new PingRespPacket(); 34 | if (!decodeCommonHeader(message, 0x00, in)) { 35 | in.resetReaderIndex(); 36 | return; 37 | } 38 | out.add(message); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/PingRespEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import org.jmqtt.core.packet.AbstractPacket; 19 | import org.jmqtt.core.packet.PingRespPacket; 20 | import io.netty.buffer.ByteBuf; 21 | import io.netty.channel.ChannelHandlerContext; 22 | 23 | /** 24 | * @author andrea 25 | */ 26 | class PingRespEncoder extends DemuxEncoder { 27 | 28 | @Override 29 | protected void encode(ChannelHandlerContext chc, PingRespPacket msg, ByteBuf out) { 30 | out.writeByte(AbstractPacket.PINGRESP << 4).writeByte(0); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/PubAckDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | 19 | import org.jmqtt.core.packet.PacketIdPacket; 20 | import org.jmqtt.core.packet.PubAckPacket; 21 | 22 | /** 23 | * @author andrea 24 | */ 25 | class PubAckDecoder extends MessageIDDecoder { 26 | 27 | @Override 28 | protected PacketIdPacket createMessage() { 29 | return new PubAckPacket(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/PubAckEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.channel.ChannelHandlerContext; 20 | import org.jmqtt.core.packet.AbstractPacket; 21 | import org.jmqtt.core.packet.PubAckPacket; 22 | import org.jmqtt.core.util.MqttUtils; 23 | 24 | /** 25 | * @author andrea 26 | */ 27 | class PubAckEncoder extends DemuxEncoder { 28 | 29 | @Override 30 | protected void encode(ChannelHandlerContext chc, PubAckPacket msg, ByteBuf out) { 31 | ByteBuf buff = chc.alloc().buffer(4); 32 | try { 33 | buff.writeByte(AbstractPacket.PUBACK << 4); 34 | buff.writeBytes(MqttUtils.encodeRemainingLength(2)); 35 | buff.writeShort(msg.getPacketId()); 36 | out.writeBytes(buff); 37 | } finally { 38 | buff.release(); 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/PubCompDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | 19 | import org.jmqtt.core.packet.PacketIdPacket; 20 | import org.jmqtt.core.packet.PubCompPacket; 21 | 22 | /** 23 | * @author andrea 24 | */ 25 | class PubCompDecoder extends MessageIDDecoder { 26 | 27 | @Override 28 | protected PacketIdPacket createMessage() { 29 | return new PubCompPacket(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/PubCompEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.channel.ChannelHandlerContext; 20 | import org.jmqtt.core.packet.AbstractPacket; 21 | import org.jmqtt.core.packet.PubCompPacket; 22 | import org.jmqtt.core.util.MqttUtils; 23 | 24 | /** 25 | * @author andrea 26 | */ 27 | class PubCompEncoder extends DemuxEncoder { 28 | 29 | @Override 30 | protected void encode(ChannelHandlerContext chc, PubCompPacket msg, ByteBuf out) { 31 | out.writeByte(AbstractPacket.PUBCOMP << 4); 32 | out.writeBytes(MqttUtils.encodeRemainingLength(2)); 33 | out.writeShort(msg.getPacketId()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/PubRecDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | 19 | import org.jmqtt.core.packet.PacketIdPacket; 20 | import org.jmqtt.core.packet.PubRecPacket; 21 | 22 | /** 23 | * @author andrea 24 | */ 25 | class PubRecDecoder extends MessageIDDecoder { 26 | 27 | @Override 28 | protected PacketIdPacket createMessage() { 29 | return new PubRecPacket(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/PubRecEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.channel.ChannelHandlerContext; 20 | import org.jmqtt.core.packet.AbstractPacket; 21 | import org.jmqtt.core.packet.PubRecPacket; 22 | import org.jmqtt.core.util.MqttUtils; 23 | 24 | /** 25 | * @author andrea 26 | */ 27 | class PubRecEncoder extends DemuxEncoder { 28 | 29 | @Override 30 | protected void encode(ChannelHandlerContext chc, PubRecPacket msg, ByteBuf out) { 31 | out.writeByte(AbstractPacket.PUBREC << 4); 32 | out.writeBytes(MqttUtils.encodeRemainingLength(2)); 33 | out.writeShort(msg.getPacketId()); 34 | } 35 | } -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/PubRelDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.util.AttributeMap; 20 | import org.jmqtt.core.packet.PacketIdPacket; 21 | import org.jmqtt.core.packet.PubRelPacket; 22 | 23 | import java.io.UnsupportedEncodingException; 24 | import java.util.List; 25 | 26 | /** 27 | * @author andrea 28 | */ 29 | class PubRelDecoder extends DemuxDecoder { 30 | 31 | @Override 32 | void decode(AttributeMap ctx, ByteBuf in, List out) throws UnsupportedEncodingException { 33 | in.resetReaderIndex(); 34 | //Common decoding part 35 | PacketIdPacket message = new PubRelPacket(); 36 | if (!decodeCommonHeader(message, 0x02, in)) { 37 | in.resetReaderIndex(); 38 | return; 39 | } 40 | 41 | //read messageIDs 42 | message.setPacketId(in.readUnsignedShort()); 43 | out.add(message); 44 | } 45 | 46 | } 47 | 48 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/PubRelEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.channel.ChannelHandlerContext; 20 | import org.jmqtt.core.packet.AbstractPacket; 21 | import org.jmqtt.core.packet.PubRelPacket; 22 | import org.jmqtt.core.util.MqttUtils; 23 | 24 | /** 25 | * @author andrea 26 | */ 27 | class PubRelEncoder extends DemuxEncoder { 28 | 29 | @Override 30 | protected void encode(ChannelHandlerContext chc, PubRelPacket msg, ByteBuf out) { 31 | out.writeByte(AbstractPacket.PUBREL << 4 | 0x02); 32 | out.writeBytes(MqttUtils.encodeRemainingLength(2)); 33 | out.writeShort(msg.getPacketId()); 34 | } 35 | } -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/PublishEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.channel.ChannelHandlerContext; 20 | import org.jmqtt.core.constant.QosType; 21 | import org.jmqtt.core.packet.AbstractPacket; 22 | import org.jmqtt.core.packet.PublishPacket; 23 | import org.jmqtt.core.util.MqttUtils; 24 | 25 | /** 26 | * @author andrea 27 | */ 28 | class PublishEncoder extends DemuxEncoder { 29 | 30 | @Override 31 | protected void encode(ChannelHandlerContext ctx, PublishPacket message, ByteBuf out) { 32 | if (message.getQos() == QosType.RESERVED) { 33 | throw new IllegalArgumentException("Found a message with RESERVED Qos"); 34 | } 35 | if (message.getTopicName() == null || message.getTopicName().isEmpty()) { 36 | throw new IllegalArgumentException("Found a message with empty or null topic name"); 37 | } 38 | 39 | ByteBuf variableHeaderBuff = ctx.alloc().buffer(2); 40 | ByteBuf buff = null; 41 | try { 42 | variableHeaderBuff.writeBytes(MqttUtils.encodeString(message.getTopicName())); 43 | if (message.getQos() == QosType.LEAST_ONE || 44 | message.getQos() == QosType.EXACTLY_ONCE) { 45 | if (message.getPacketId() == null) { 46 | throw new IllegalArgumentException("Found a message with QOS 1 or 2 and not MessageID setted"); 47 | } 48 | variableHeaderBuff.writeShort(message.getPacketId()); 49 | } 50 | variableHeaderBuff.writeBytes(message.getPayload()); 51 | int variableHeaderSize = variableHeaderBuff.readableBytes(); 52 | 53 | byte flags = MqttUtils.encodeFlags(message); 54 | 55 | buff = ctx.alloc().buffer(2 + variableHeaderSize); 56 | buff.writeByte(AbstractPacket.PUBLISH << 4 | flags); 57 | buff.writeBytes(MqttUtils.encodeRemainingLength(variableHeaderSize)); 58 | buff.writeBytes(variableHeaderBuff); 59 | out.writeBytes(buff); 60 | } finally { 61 | variableHeaderBuff.release(); 62 | if (buff != null) { 63 | buff.release(); 64 | } 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/SubAckDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.util.AttributeMap; 20 | import org.jmqtt.core.constant.QosType; 21 | import org.jmqtt.core.packet.SubAckPacket; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * @author andrea 27 | */ 28 | class SubAckDecoder extends DemuxDecoder { 29 | 30 | @Override 31 | void decode(AttributeMap ctx, ByteBuf in, List out) throws Exception { 32 | //Common decoding part 33 | in.resetReaderIndex(); 34 | SubAckPacket message = new SubAckPacket(); 35 | if (!decodeCommonHeader(message, 0x00, in)) { 36 | in.resetReaderIndex(); 37 | return; 38 | } 39 | int remainingLength = message.getRemainingLength(); 40 | 41 | //MessageID 42 | message.setPacketId(in.readUnsignedShort()); 43 | remainingLength -= 2; 44 | 45 | //Qos array 46 | if (in.readableBytes() < remainingLength) { 47 | in.resetReaderIndex(); 48 | return; 49 | } 50 | for (int i = 0; i < remainingLength; i++) { 51 | byte qos = in.readByte(); 52 | message.addType(QosType.valueOf(qos)); 53 | } 54 | 55 | out.add(message); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/SubAckEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.channel.ChannelHandlerContext; 20 | import org.jmqtt.core.constant.QosType; 21 | import org.jmqtt.core.packet.AbstractPacket; 22 | import org.jmqtt.core.packet.SubAckPacket; 23 | import org.jmqtt.core.util.MqttUtils; 24 | 25 | /** 26 | * @author andrea 27 | */ 28 | class SubAckEncoder extends DemuxEncoder { 29 | 30 | @Override 31 | protected void encode(ChannelHandlerContext chc, SubAckPacket message, ByteBuf out) { 32 | if (message.types().isEmpty()) { 33 | throw new IllegalArgumentException("Found a suback message with empty topics"); 34 | } 35 | 36 | int variableHeaderSize = 2 + message.types().size(); 37 | ByteBuf buff = chc.alloc().buffer(6 + variableHeaderSize); 38 | try { 39 | buff.writeByte(AbstractPacket.SUBACK << 4); 40 | buff.writeBytes(MqttUtils.encodeRemainingLength(variableHeaderSize)); 41 | buff.writeShort(message.getPacketId()); 42 | for (QosType c : message.types()) { 43 | buff.writeByte(c.byteValue()); 44 | } 45 | 46 | out.writeBytes(buff); 47 | } finally { 48 | buff.release(); 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/SubscribeDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.handler.codec.CorruptedFrameException; 20 | import io.netty.util.AttributeMap; 21 | import org.jmqtt.core.constant.QosType; 22 | import org.jmqtt.core.packet.SubscribePacket; 23 | import org.jmqtt.core.util.MqttUtils; 24 | 25 | import java.io.UnsupportedEncodingException; 26 | import java.util.List; 27 | 28 | /** 29 | * @author andrea 30 | */ 31 | class SubscribeDecoder extends DemuxDecoder { 32 | 33 | @Override 34 | void decode(AttributeMap ctx, ByteBuf in, List out) throws Exception { 35 | //Common decoding part 36 | SubscribePacket message = new SubscribePacket(); 37 | in.resetReaderIndex(); 38 | if (!decodeCommonHeader(message, 0x02, in)) { 39 | in.resetReaderIndex(); 40 | return; 41 | } 42 | 43 | //check qos level 44 | if (message.getQos() != QosType.LEAST_ONE) { 45 | throw new CorruptedFrameException("Received SUBSCRIBE message with QoS other than LEAST_ONE, was: " + message.getQos()); 46 | } 47 | 48 | int start = in.readerIndex(); 49 | //read messageIDs 50 | message.setPacketId(in.readUnsignedShort()); 51 | int read = in.readerIndex() - start; 52 | while (read < message.getRemainingLength()) { 53 | decodeSubscription(in, message); 54 | read = in.readerIndex() - start; 55 | } 56 | 57 | if (message.subscriptions().isEmpty()) { 58 | throw new CorruptedFrameException("subscribe MUST have got at least 1 couple topic/QoS"); 59 | } 60 | 61 | out.add(message); 62 | } 63 | 64 | /** 65 | * Populate the message with couple of Qos, topic 66 | */ 67 | private void decodeSubscription(ByteBuf in, SubscribePacket message) throws UnsupportedEncodingException { 68 | String topic = MqttUtils.decodeString(in); 69 | //check topic is at least one char [MQTT-4.7.3-1] 70 | if (topic.length() == 0) { 71 | throw new CorruptedFrameException("Received a SUBSCRIBE with empty topic filter"); 72 | } 73 | byte qosByte = in.readByte(); 74 | if ((qosByte & 0xFC) > 0) { //the first 6 bits is reserved => has to be 0 75 | throw new CorruptedFrameException("subscribe MUST have QoS byte with reserved buts to 0, found " + Integer.toHexString(qosByte)); 76 | } 77 | byte qos = (byte) (qosByte & 0x03); 78 | //TODO check qos id 000000xx 79 | message.addSubscription(new SubscribePacket.Couple(qos, topic)); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/SubscribeEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.channel.ChannelHandlerContext; 20 | import org.jmqtt.core.constant.QosType; 21 | import org.jmqtt.core.packet.AbstractPacket; 22 | import org.jmqtt.core.packet.SubscribePacket; 23 | import org.jmqtt.core.util.MqttUtils; 24 | 25 | /** 26 | * @author andrea 27 | */ 28 | class SubscribeEncoder extends DemuxEncoder { 29 | 30 | @Override 31 | protected void encode(ChannelHandlerContext chc, SubscribePacket message, ByteBuf out) { 32 | if (message.subscriptions().isEmpty()) { 33 | throw new IllegalArgumentException("Found a subscribe message with empty topics"); 34 | } 35 | 36 | if (message.getQos() != QosType.LEAST_ONE) { 37 | throw new IllegalArgumentException("Expected a message with QOS 1, found " + message.getQos()); 38 | } 39 | 40 | ByteBuf variableHeaderBuff = chc.alloc().buffer(4); 41 | ByteBuf buff = null; 42 | try { 43 | variableHeaderBuff.writeShort(message.getPacketId()); 44 | for (SubscribePacket.Couple c : message.subscriptions()) { 45 | variableHeaderBuff.writeBytes(MqttUtils.encodeString(c.topicFilter)); 46 | variableHeaderBuff.writeByte(c.qos); 47 | } 48 | 49 | int variableHeaderSize = variableHeaderBuff.readableBytes(); 50 | byte flags = MqttUtils.encodeFlags(message); 51 | buff = chc.alloc().buffer(2 + variableHeaderSize); 52 | 53 | buff.writeByte(AbstractPacket.SUBSCRIBE << 4 | flags); 54 | buff.writeBytes(MqttUtils.encodeRemainingLength(variableHeaderSize)); 55 | buff.writeBytes(variableHeaderBuff); 56 | 57 | out.writeBytes(buff); 58 | } finally { 59 | variableHeaderBuff.release(); 60 | buff.release(); 61 | } 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/UnsubAckDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | 19 | import org.jmqtt.core.packet.PacketIdPacket; 20 | import org.jmqtt.core.packet.UnsubAckPacket; 21 | 22 | /** 23 | * @author andrea 24 | */ 25 | class UnsubAckDecoder extends MessageIDDecoder { 26 | 27 | @Override 28 | protected PacketIdPacket createMessage() { 29 | return new UnsubAckPacket(); 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/UnsubAckEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.channel.ChannelHandlerContext; 20 | import org.jmqtt.core.packet.AbstractPacket; 21 | import org.jmqtt.core.packet.UnsubAckPacket; 22 | import org.jmqtt.core.util.MqttUtils; 23 | 24 | /** 25 | * @author andrea 26 | */ 27 | class UnsubAckEncoder extends DemuxEncoder { 28 | 29 | @Override 30 | protected void encode(ChannelHandlerContext chc, UnsubAckPacket msg, ByteBuf out) { 31 | out.writeByte(AbstractPacket.UNSUBACK << 4). 32 | writeBytes(MqttUtils.encodeRemainingLength(2)). 33 | writeShort(msg.getPacketId()); 34 | } 35 | } -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/UnsubscribeDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.handler.codec.CorruptedFrameException; 20 | import io.netty.util.AttributeMap; 21 | import org.jmqtt.core.constant.QosType; 22 | import org.jmqtt.core.packet.UnsubscribePacket; 23 | import org.jmqtt.core.util.MqttUtils; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * @author andrea 29 | */ 30 | class UnsubscribeDecoder extends DemuxDecoder { 31 | 32 | @Override 33 | void decode(AttributeMap ctx, ByteBuf in, List out) throws Exception { 34 | //Common decoding part 35 | in.resetReaderIndex(); 36 | UnsubscribePacket message = new UnsubscribePacket(); 37 | if (!decodeCommonHeader(message, 0x02, in)) { 38 | in.resetReaderIndex(); 39 | return; 40 | } 41 | 42 | //check qos level 43 | if (message.getQos() != QosType.LEAST_ONE) { 44 | throw new CorruptedFrameException("Found an Unsubscribe message with qos other than LEAST_ONE, was: " + message.getQos()); 45 | } 46 | 47 | int start = in.readerIndex(); 48 | //read messageIDs 49 | message.setPacketId(in.readUnsignedShort()); 50 | int read = in.readerIndex() - start; 51 | while (read < message.getRemainingLength()) { 52 | String topicFilter = MqttUtils.decodeString(in); 53 | //check topic is at least one char [MQTT-4.7.3-1] 54 | if (topicFilter.length() == 0) { 55 | throw new CorruptedFrameException("Received an UNSUBSCRIBE with empty topic filter"); 56 | } 57 | message.addTopicFilter(topicFilter); 58 | read = in.readerIndex() - start; 59 | } 60 | if (message.topicFilters().isEmpty()) { 61 | throw new CorruptedFrameException("unsubscribe MUST have got at least 1 topic"); 62 | } 63 | out.add(message); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/codec/UnsubscribeEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.codec; 17 | 18 | import io.netty.buffer.ByteBuf; 19 | import io.netty.channel.ChannelHandlerContext; 20 | import org.jmqtt.core.constant.QosType; 21 | import org.jmqtt.core.packet.AbstractPacket; 22 | import org.jmqtt.core.packet.UnsubscribePacket; 23 | import org.jmqtt.core.util.MqttUtils; 24 | 25 | 26 | /** 27 | * @author andrea 28 | */ 29 | class UnsubscribeEncoder extends DemuxEncoder { 30 | 31 | @Override 32 | protected void encode(ChannelHandlerContext chc, UnsubscribePacket message, ByteBuf out) { 33 | if (message.topicFilters().isEmpty()) { 34 | throw new IllegalArgumentException("Found an unsubscribe message with empty topics"); 35 | } 36 | 37 | if (message.getQos() != QosType.LEAST_ONE) { 38 | throw new IllegalArgumentException("Expected a message with QOS 1, found " + message.getQos()); 39 | } 40 | 41 | ByteBuf variableHeaderBuff = chc.alloc().buffer(4); 42 | ByteBuf buff = null; 43 | try { 44 | variableHeaderBuff.writeShort(message.getPacketId()); 45 | for (String topic : message.topicFilters()) { 46 | variableHeaderBuff.writeBytes(MqttUtils.encodeString(topic)); 47 | } 48 | 49 | int variableHeaderSize = variableHeaderBuff.readableBytes(); 50 | byte flags = MqttUtils.encodeFlags(message); 51 | buff = chc.alloc().buffer(2 + variableHeaderSize); 52 | 53 | buff.writeByte(AbstractPacket.UNSUBSCRIBE << 4 | flags); 54 | buff.writeBytes(MqttUtils.encodeRemainingLength(variableHeaderSize)); 55 | buff.writeBytes(variableHeaderBuff); 56 | 57 | out.writeBytes(buff); 58 | } finally { 59 | variableHeaderBuff.release(); 60 | buff.release(); 61 | } 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/constant/QosType.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.core.constant; 2 | 3 | /** 4 | * Created by gavin on 16/9/20. 5 | */ 6 | public enum QosType { 7 | MOST_ONE, LEAST_ONE, EXACTLY_ONCE, RESERVED, FAILURE; 8 | 9 | public static QosType valueOf(byte qos) { 10 | switch (qos) { 11 | case 0x00: 12 | return MOST_ONE; 13 | case 0x01: 14 | return LEAST_ONE; 15 | case 0x02: 16 | return EXACTLY_ONCE; 17 | case (byte) 0x80: 18 | return FAILURE; 19 | default: 20 | throw new IllegalArgumentException("Invalid QOS Type. Expected either 0, 1, 2, or 0x80. Given: " + qos); 21 | } 22 | } 23 | 24 | public byte byteValue() { 25 | switch (this) { 26 | case MOST_ONE: 27 | return 0; 28 | case LEAST_ONE: 29 | return 1; 30 | case EXACTLY_ONCE: 31 | return 2; 32 | case FAILURE: 33 | return (byte) 0x80; 34 | default: 35 | throw new IllegalArgumentException("Cannot give byteValue of QosType: " + this.name()); 36 | } 37 | } 38 | 39 | public static String formatQoS(QosType qos) { 40 | return String.format("%d - %s", qos.byteValue(), qos.name()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/exception/MQTTException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.exception; 17 | 18 | /** 19 | * @author andrea 20 | */ 21 | public class MQTTException extends RuntimeException { 22 | 23 | public MQTTException() { 24 | super(); 25 | } 26 | 27 | public MQTTException(String msg) { 28 | super(msg); 29 | } 30 | 31 | public MQTTException(Throwable cause) { 32 | super(cause); 33 | } 34 | 35 | public MQTTException(String msg, Throwable cause) { 36 | super(msg, cause); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/packet/AbstractPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.packet; 17 | 18 | import org.jmqtt.core.constant.QosType; 19 | 20 | /** 21 | * Basic abstract message for all MQTT protocol packets. 22 | * 23 | * @author andrea 24 | */ 25 | public abstract class AbstractPacket { 26 | 27 | public static final byte CONNECT = 1; // Client request to connect to Server 28 | public static final byte CONNACK = 2; // Connect Acknowledgment 29 | public static final byte PUBLISH = 3; // Publish message 30 | public static final byte PUBACK = 4; // Publish Acknowledgment 31 | public static final byte PUBREC = 5; //Publish Received (assured delivery part 1) 32 | public static final byte PUBREL = 6; // Publish Release (assured delivery part 2) 33 | public static final byte PUBCOMP = 7; //Publish Complete (assured delivery part 3) 34 | public static final byte SUBSCRIBE = 8; //Client Subscribe request 35 | public static final byte SUBACK = 9; // Subscribe Acknowledgment 36 | public static final byte UNSUBSCRIBE = 10; //Client Unsubscribe request 37 | public static final byte UNSUBACK = 11; // Unsubscribe Acknowledgment 38 | public static final byte PINGREQ = 12; //PING Request 39 | public static final byte PINGRESP = 13; //PING Response 40 | public static final byte DISCONNECT = 14; //Client is Disconnecting 41 | 42 | //type 43 | protected boolean dupFlag; 44 | protected QosType qos; 45 | protected boolean retainFlag; 46 | protected int remainingLength; 47 | protected byte messageType; 48 | 49 | public byte getMessageType() { 50 | return messageType; 51 | } 52 | 53 | public void setMessageType(byte messageType) { 54 | this.messageType = messageType; 55 | } 56 | 57 | public boolean isDupFlag() { 58 | return dupFlag; 59 | } 60 | 61 | public void setDupFlag(boolean dupFlag) { 62 | this.dupFlag = dupFlag; 63 | } 64 | 65 | public QosType getQos() { 66 | return qos; 67 | } 68 | 69 | public void setQos(QosType qos) { 70 | this.qos = qos; 71 | } 72 | 73 | public boolean isRetainFlag() { 74 | return retainFlag; 75 | } 76 | 77 | public void setRetainFlag(boolean retainFlag) { 78 | this.retainFlag = retainFlag; 79 | } 80 | 81 | /** 82 | * TOBE used only internally 83 | */ 84 | public int getRemainingLength() { 85 | return remainingLength; 86 | } 87 | 88 | /** 89 | * TOBE used only internally 90 | */ 91 | public void setRemainingLength(int remainingLength) { 92 | this.remainingLength = remainingLength; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/packet/ConnAckPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.packet; 17 | 18 | /** 19 | * The attributes Qos, Dup and Retain aren't used. 20 | * 21 | * @author andrea 22 | */ 23 | public class ConnAckPacket extends AbstractPacket { 24 | public static final byte CONNECTION_ACCEPTED = 0x00; 25 | public static final byte UNNACEPTABLE_PROTOCOL_VERSION = 0x01; 26 | public static final byte IDENTIFIER_REJECTED = 0x02; 27 | public static final byte SERVER_UNAVAILABLE = 0x03; 28 | public static final byte BAD_USERNAME_OR_PASSWORD = 0x04; 29 | public static final byte NOT_AUTHORIZED = 0x05; 30 | 31 | private byte returnCode; 32 | private boolean sessionPresent; 33 | 34 | public ConnAckPacket() { 35 | messageType = CONNACK; 36 | } 37 | 38 | public byte getReturnCode() { 39 | return returnCode; 40 | } 41 | 42 | public void setReturnCode(byte returnCode) { 43 | this.returnCode = returnCode; 44 | } 45 | 46 | public boolean isSessionPresent() { 47 | return this.sessionPresent; 48 | } 49 | 50 | public void setSessionPresent(boolean present) { 51 | this.sessionPresent = present; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/packet/DisconnectPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.packet; 17 | 18 | /** 19 | * Doesn't care DUP, QOS and RETAIN flags. 20 | * 21 | * @author andrea 22 | */ 23 | public class DisconnectPacket extends ZeroLengthPacket { 24 | 25 | public DisconnectPacket() { 26 | messageType = DISCONNECT; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/packet/PacketIdPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.packet; 17 | 18 | /** 19 | * Base class for alla the packets that carries only MessageID. (PUBACK, PUBREC, 20 | * PUBREL, PUBCOMP, UNSUBACK) 21 | *

22 | * The flags dup, QOS and Retained doesn't take care. 23 | * 24 | * @author andrea 25 | */ 26 | public abstract class PacketIdPacket extends AbstractPacket { 27 | protected Integer packetId; //could be null if Qos is == 0 28 | 29 | public Integer getPacketId() { 30 | return packetId; 31 | } 32 | 33 | public void setPacketId(Integer packetId) { 34 | this.packetId = packetId; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/packet/PingReqPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.packet; 17 | 18 | /** 19 | * Doesn't care DUP, QOS and RETAIN flags. 20 | * 21 | * @author andrea 22 | */ 23 | public class PingReqPacket extends ZeroLengthPacket { 24 | 25 | public PingReqPacket() { 26 | messageType = PINGREQ; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/packet/PingRespPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.packet; 17 | 18 | /** 19 | * Doesn't care DUP, QOS and RETAIN flags. 20 | * 21 | * @author andrea 22 | */ 23 | public class PingRespPacket extends ZeroLengthPacket { 24 | 25 | public PingRespPacket() { 26 | messageType = PINGRESP; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/packet/PubAckPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.packet; 17 | 18 | /** 19 | * Placeholder for PUBACK message. 20 | * 21 | * @author andrea 22 | */ 23 | public class PubAckPacket extends PacketIdPacket { 24 | 25 | public PubAckPacket() { 26 | messageType = PUBACK; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/packet/PubCompPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.packet; 17 | 18 | /** 19 | * @author andrea 20 | */ 21 | public class PubCompPacket extends PacketIdPacket { 22 | 23 | public PubCompPacket() { 24 | messageType = PUBCOMP; 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/packet/PubRecPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.packet; 17 | 18 | /** 19 | * Placeholder for PUBREC message. 20 | * 21 | * @author andrea 22 | */ 23 | public class PubRecPacket extends PacketIdPacket { 24 | 25 | public PubRecPacket() { 26 | messageType = PUBREC; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/packet/PubRelPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.packet; 17 | 18 | /** 19 | * @author andrea 20 | */ 21 | public class PubRelPacket extends PacketIdPacket { 22 | 23 | public PubRelPacket() { 24 | messageType = PUBREL; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/packet/PublishPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.packet; 17 | 18 | import java.nio.ByteBuffer; 19 | 20 | /** 21 | * @author andrea 22 | */ 23 | public class PublishPacket extends PacketIdPacket { 24 | 25 | private boolean local = true; 26 | private String clientId; 27 | 28 | protected String topicName; 29 | protected ByteBuffer payload; 30 | 31 | public PublishPacket() { 32 | messageType = AbstractPacket.PUBLISH; 33 | } 34 | 35 | public String getTopicName() { 36 | return topicName; 37 | } 38 | 39 | public void setTopicName(String topicName) { 40 | this.topicName = topicName; 41 | } 42 | 43 | public ByteBuffer getPayload() { 44 | return payload; 45 | } 46 | 47 | public void setPayload(ByteBuffer payload) { 48 | this.payload = payload; 49 | } 50 | 51 | public boolean isLocal() { 52 | return local; 53 | } 54 | 55 | public void setLocal(boolean local) { 56 | this.local = local; 57 | } 58 | 59 | public String getClientId() { 60 | return clientId; 61 | } 62 | 63 | public void setClientId(String clientId) { 64 | this.clientId = clientId; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/packet/SubAckPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.packet; 17 | 18 | import org.jmqtt.core.constant.QosType; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | /** 24 | * @author andrea 25 | */ 26 | public class SubAckPacket extends PacketIdPacket { 27 | 28 | List types = new ArrayList(); 29 | 30 | public SubAckPacket() { 31 | messageType = SUBACK; 32 | } 33 | 34 | public List types() { 35 | return types; 36 | } 37 | 38 | public void addType(QosType type) { 39 | types.add(type); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/packet/SubscribePacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.packet; 17 | 18 | import org.jmqtt.core.constant.QosType; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | /** 24 | * @author andrea 25 | */ 26 | public class SubscribePacket extends PacketIdPacket { 27 | 28 | public static class Couple { 29 | 30 | public final byte qos; 31 | public final String topicFilter; 32 | 33 | public Couple(byte qos, String topic) { 34 | this.qos = qos; 35 | this.topicFilter = topic; 36 | } 37 | 38 | } 39 | 40 | private List subscriptions = new ArrayList<>(); 41 | 42 | public SubscribePacket() { 43 | //Subscribe has always QoS 1 44 | messageType = AbstractPacket.SUBSCRIBE; 45 | qos = QosType.LEAST_ONE; 46 | } 47 | 48 | public List subscriptions() { 49 | return subscriptions; 50 | } 51 | 52 | public void addSubscription(Couple subscription) { 53 | subscriptions.add(subscription); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/packet/UnsubAckPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.packet; 17 | 18 | /** 19 | * @author andrea 20 | */ 21 | public class UnsubAckPacket extends PacketIdPacket { 22 | 23 | public UnsubAckPacket() { 24 | messageType = UNSUBACK; 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/packet/UnsubscribePacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.packet; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | /** 22 | * @author andrea 23 | */ 24 | public class UnsubscribePacket extends PacketIdPacket { 25 | List types = new ArrayList(); 26 | 27 | public UnsubscribePacket() { 28 | messageType = UNSUBSCRIBE; 29 | } 30 | 31 | public List topicFilters() { 32 | return types; 33 | } 34 | 35 | public void addTopicFilter(String type) { 36 | types.add(type); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /core/src/main/java/org/jmqtt/core/packet/ZeroLengthPacket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.core.packet; 17 | 18 | /** 19 | * @author andrea 20 | */ 21 | public abstract class ZeroLengthPacket extends AbstractPacket { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Sep 21 15:20:34 CST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /interception/build.gradle: -------------------------------------------------------------------------------- 1 | group 'org.jmqtt' 2 | version '1.0-SNAPSHOT' 3 | 4 | apply plugin: 'java' 5 | 6 | dependencies { 7 | compile project(":session") 8 | } 9 | -------------------------------------------------------------------------------- /interception/build/classes/main/org/jmqtt/interception/AbstractInterceptHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/interception/build/classes/main/org/jmqtt/interception/AbstractInterceptHandler.class -------------------------------------------------------------------------------- /interception/build/classes/main/org/jmqtt/interception/BrokerInterceptor$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/interception/build/classes/main/org/jmqtt/interception/BrokerInterceptor$1.class -------------------------------------------------------------------------------- /interception/build/classes/main/org/jmqtt/interception/BrokerInterceptor$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/interception/build/classes/main/org/jmqtt/interception/BrokerInterceptor$2.class -------------------------------------------------------------------------------- /interception/build/classes/main/org/jmqtt/interception/BrokerInterceptor$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/interception/build/classes/main/org/jmqtt/interception/BrokerInterceptor$3.class -------------------------------------------------------------------------------- /interception/build/classes/main/org/jmqtt/interception/BrokerInterceptor$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/interception/build/classes/main/org/jmqtt/interception/BrokerInterceptor$4.class -------------------------------------------------------------------------------- /interception/build/classes/main/org/jmqtt/interception/BrokerInterceptor$5.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/interception/build/classes/main/org/jmqtt/interception/BrokerInterceptor$5.class -------------------------------------------------------------------------------- /interception/build/classes/main/org/jmqtt/interception/BrokerInterceptor$6.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/interception/build/classes/main/org/jmqtt/interception/BrokerInterceptor$6.class -------------------------------------------------------------------------------- /interception/build/classes/main/org/jmqtt/interception/BrokerInterceptor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/interception/build/classes/main/org/jmqtt/interception/BrokerInterceptor.class -------------------------------------------------------------------------------- /interception/build/classes/main/org/jmqtt/interception/HazelcastMsg.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/interception/build/classes/main/org/jmqtt/interception/HazelcastMsg.class -------------------------------------------------------------------------------- /interception/build/classes/main/org/jmqtt/interception/InterceptHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/interception/build/classes/main/org/jmqtt/interception/InterceptHandler.class -------------------------------------------------------------------------------- /interception/build/classes/main/org/jmqtt/interception/Interceptor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/interception/build/classes/main/org/jmqtt/interception/Interceptor.class -------------------------------------------------------------------------------- /interception/build/classes/main/org/jmqtt/interception/messages/InterceptAbstractMessage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/interception/build/classes/main/org/jmqtt/interception/messages/InterceptAbstractMessage.class -------------------------------------------------------------------------------- /interception/build/classes/main/org/jmqtt/interception/messages/InterceptAcknowledgedMessage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/interception/build/classes/main/org/jmqtt/interception/messages/InterceptAcknowledgedMessage.class -------------------------------------------------------------------------------- /interception/build/classes/main/org/jmqtt/interception/messages/InterceptConnectMessage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/interception/build/classes/main/org/jmqtt/interception/messages/InterceptConnectMessage.class -------------------------------------------------------------------------------- /interception/build/classes/main/org/jmqtt/interception/messages/InterceptDisconnectMessage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/interception/build/classes/main/org/jmqtt/interception/messages/InterceptDisconnectMessage.class -------------------------------------------------------------------------------- /interception/build/classes/main/org/jmqtt/interception/messages/InterceptPublishMessage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/interception/build/classes/main/org/jmqtt/interception/messages/InterceptPublishMessage.class -------------------------------------------------------------------------------- /interception/build/classes/main/org/jmqtt/interception/messages/InterceptSubscribeMessage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/interception/build/classes/main/org/jmqtt/interception/messages/InterceptSubscribeMessage.class -------------------------------------------------------------------------------- /interception/build/classes/main/org/jmqtt/interception/messages/InterceptUnsubscribeMessage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/interception/build/classes/main/org/jmqtt/interception/messages/InterceptUnsubscribeMessage.class -------------------------------------------------------------------------------- /interception/build/libs/interception-1.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/interception/build/libs/interception-1.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /interception/build/tmp/jar/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | 3 | -------------------------------------------------------------------------------- /interception/src/main/java/org/jmqtt/interception/AbstractInterceptHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.interception; 17 | 18 | 19 | import org.jmqtt.interception.messages.*; 20 | 21 | /** 22 | * Basic abstract class usefull to avoid empty methods creation in subclasses. 23 | *

24 | * Created by andrea on 08/12/15. 25 | */ 26 | public abstract class AbstractInterceptHandler implements InterceptHandler { 27 | 28 | @Override 29 | public void onConnect(InterceptConnectMessage msg) { 30 | } 31 | 32 | @Override 33 | public void onDisconnect(InterceptDisconnectMessage msg) { 34 | } 35 | 36 | @Override 37 | public void onPublish(InterceptPublishMessage msg) { 38 | } 39 | 40 | @Override 41 | public void onSubscribe(InterceptSubscribeMessage msg) { 42 | } 43 | 44 | @Override 45 | public void onUnsubscribe(InterceptUnsubscribeMessage msg) { 46 | } 47 | 48 | @Override 49 | public void onMessageAcknowledged(InterceptAcknowledgedMessage msg) { 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /interception/src/main/java/org/jmqtt/interception/InterceptHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.interception; 17 | 18 | 19 | import org.jmqtt.core.packet.AbstractPacket; 20 | import org.jmqtt.interception.messages.*; 21 | 22 | /** 23 | * This interface is used to inject code for intercepting broker events. 24 | *

25 | * The events can act only as observers. 26 | *

27 | * Almost every method receives a subclass of {@link AbstractPacket}, except 28 | * onDisconnect that receives the client id string and 29 | * onSubscribe and onUnsubscribe 30 | * 31 | * @author Wagner Macedo 32 | */ 33 | public interface InterceptHandler { 34 | 35 | void onConnect(InterceptConnectMessage msg); 36 | 37 | void onDisconnect(InterceptDisconnectMessage msg); 38 | 39 | void onPublish(InterceptPublishMessage msg); 40 | 41 | void onSubscribe(InterceptSubscribeMessage msg); 42 | 43 | void onUnsubscribe(InterceptUnsubscribeMessage msg); 44 | 45 | void onMessageAcknowledged(InterceptAcknowledgedMessage msg); 46 | } 47 | -------------------------------------------------------------------------------- /interception/src/main/java/org/jmqtt/interception/Interceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.interception; 17 | 18 | 19 | import org.jmqtt.core.packet.ConnectPacket; 20 | import org.jmqtt.core.packet.PublishPacket; 21 | import org.jmqtt.interception.messages.InterceptAcknowledgedMessage; 22 | import org.jmqtt.session.model.Subscription; 23 | 24 | /** 25 | * This interface is to be used internally by the broker components. 26 | *

27 | * An interface is used instead of a class to allow more flexibility in changing 28 | * an implementation. 29 | *

30 | * Interceptor implementations forward notifications to a InterceptHandler, 31 | * that is normally a field. So, the implementations should act as a proxy to a custom 32 | * intercept handler. 33 | * 34 | * @author Wagner Macedo 35 | * @see InterceptHandler 36 | */ 37 | public interface Interceptor { 38 | 39 | void notifyClientConnected(ConnectPacket msg); 40 | 41 | void notifyClientDisconnected(String clientID, String username); 42 | 43 | void notifyTopicPublished(PublishPacket msg, String clientID, final String username); 44 | 45 | void notifyTopicSubscribed(Subscription sub, final String username); 46 | 47 | void notifyTopicUnsubscribed(String topic, String clientID, final String username); 48 | 49 | void notifyMessageAcknowledged(InterceptAcknowledgedMessage msg); 50 | 51 | boolean addInterceptHandler(InterceptHandler interceptHandler); 52 | 53 | boolean removeInterceptHandler(InterceptHandler interceptHandler); 54 | } 55 | -------------------------------------------------------------------------------- /interception/src/main/java/org/jmqtt/interception/messages/InterceptAbstractMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.interception.messages; 17 | 18 | 19 | import org.jmqtt.core.constant.QosType; 20 | import org.jmqtt.core.packet.AbstractPacket; 21 | 22 | /** 23 | * @author Wagner Macedo 24 | */ 25 | public abstract class InterceptAbstractMessage { 26 | private final AbstractPacket msg; 27 | 28 | InterceptAbstractMessage(AbstractPacket msg) { 29 | this.msg = msg; 30 | } 31 | 32 | public boolean isRetainFlag() { 33 | return msg.isRetainFlag(); 34 | } 35 | 36 | public boolean isDupFlag() { 37 | return msg.isDupFlag(); 38 | } 39 | 40 | public QosType getQos() { 41 | return msg.getQos(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /interception/src/main/java/org/jmqtt/interception/messages/InterceptAcknowledgedMessage.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.interception.messages; 2 | 3 | 4 | import org.jmqtt.session.model.Message; 5 | 6 | public class InterceptAcknowledgedMessage { 7 | final private Message msg; 8 | private final String username; 9 | private final String topic; 10 | 11 | public InterceptAcknowledgedMessage(final Message msg, final String topic, final String username) { 12 | this.msg = msg; 13 | this.username = username; 14 | this.topic = topic; 15 | } 16 | 17 | public Message getMsg() { 18 | return msg; 19 | } 20 | 21 | public String getUsername() { 22 | return username; 23 | } 24 | 25 | public String getTopic() { 26 | return topic; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /interception/src/main/java/org/jmqtt/interception/messages/InterceptConnectMessage.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.interception.messages; 2 | 3 | 4 | import org.jmqtt.core.packet.ConnectPacket; 5 | 6 | /** 7 | * @author Wagner Macedo 8 | */ 9 | public class InterceptConnectMessage extends InterceptAbstractMessage { 10 | private final ConnectPacket msg; 11 | 12 | public InterceptConnectMessage(ConnectPacket msg) { 13 | super(msg); 14 | this.msg = msg; 15 | } 16 | 17 | public String getClientID() { 18 | return msg.getClientId(); 19 | } 20 | 21 | public boolean isCleanSession() { 22 | return msg.isCleanSession(); 23 | } 24 | 25 | public int getKeepAlive() { 26 | return msg.getKeepAlive(); 27 | } 28 | 29 | public boolean isPasswordFlag() { 30 | return msg.isPasswordFlag(); 31 | } 32 | 33 | public byte getProtocolVersion() { 34 | return msg.getProtocolVersion(); 35 | } 36 | 37 | public String getProtocolName() { 38 | return msg.getProtocolName(); 39 | } 40 | 41 | public boolean isUserFlag() { 42 | return msg.isUserFlag(); 43 | } 44 | 45 | public boolean isWillFlag() { 46 | return msg.isWillFlag(); 47 | } 48 | 49 | public byte getWillQos() { 50 | return msg.getWillQos(); 51 | } 52 | 53 | public boolean isWillRetain() { 54 | return msg.isWillRetain(); 55 | } 56 | 57 | public String getUsername() { 58 | return msg.getUsername(); 59 | } 60 | 61 | public byte[] getPassword() { 62 | return msg.getPassword(); 63 | } 64 | 65 | public String getWillTopic() { 66 | return msg.getWillTopic(); 67 | } 68 | 69 | public byte[] getWillMessage() { 70 | return msg.getWillMessage(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /interception/src/main/java/org/jmqtt/interception/messages/InterceptDisconnectMessage.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.interception.messages; 2 | 3 | /** 4 | * @author Wagner Macedo 5 | */ 6 | public class InterceptDisconnectMessage { 7 | private final String clientID; 8 | private final String username; 9 | 10 | public InterceptDisconnectMessage(String clientID, String username) { 11 | this.clientID = clientID; 12 | this.username = username; 13 | } 14 | 15 | public String getClientID() { 16 | return clientID; 17 | } 18 | 19 | public String getUsername() { 20 | return username; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /interception/src/main/java/org/jmqtt/interception/messages/InterceptPublishMessage.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.interception.messages; 2 | 3 | 4 | import org.jmqtt.core.packet.PublishPacket; 5 | 6 | import java.nio.ByteBuffer; 7 | 8 | /** 9 | * @author Wagner Macedo 10 | */ 11 | public class InterceptPublishMessage extends InterceptAbstractMessage { 12 | private final PublishPacket msg; 13 | private final String clientID; 14 | private final String username; 15 | 16 | public InterceptPublishMessage(PublishPacket msg, String clientID, String username) { 17 | super(msg); 18 | this.msg = msg; 19 | this.clientID = clientID; 20 | this.username = username; 21 | } 22 | 23 | public String getTopicName() { 24 | return msg.getTopicName(); 25 | } 26 | 27 | public ByteBuffer getPayload() { 28 | return msg.getPayload(); 29 | } 30 | 31 | public String getClientID() { 32 | return clientID; 33 | } 34 | 35 | public String getUsername() { 36 | return username; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /interception/src/main/java/org/jmqtt/interception/messages/InterceptSubscribeMessage.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.interception.messages; 2 | 3 | 4 | import org.jmqtt.core.constant.QosType; 5 | import org.jmqtt.session.model.Subscription; 6 | 7 | /** 8 | * @author Wagner Macedo 9 | */ 10 | public class InterceptSubscribeMessage { 11 | private final Subscription subscription; 12 | private final String username; 13 | 14 | public InterceptSubscribeMessage(Subscription subscription, String username) { 15 | this.subscription = subscription; 16 | this.username = username; 17 | } 18 | 19 | public String getClientID() { 20 | return subscription.getClientId(); 21 | } 22 | 23 | public QosType getRequestedQos() { 24 | return subscription.getRequestedQos(); 25 | } 26 | 27 | public String getTopicFilter() { 28 | return subscription.getTopicFilter(); 29 | } 30 | 31 | public String getUsername() { 32 | return username; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /interception/src/main/java/org/jmqtt/interception/messages/InterceptUnsubscribeMessage.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.interception.messages; 2 | 3 | /** 4 | * @author Wagner Macedo 5 | */ 6 | public class InterceptUnsubscribeMessage { 7 | private final String topicFilter; 8 | private final String clientID; 9 | private final String username; 10 | 11 | public InterceptUnsubscribeMessage(String topicFilter, String clientID, String username) { 12 | this.topicFilter = topicFilter; 13 | this.clientID = clientID; 14 | this.username = username; 15 | } 16 | 17 | public String getTopicFilter() { 18 | return topicFilter; 19 | } 20 | 21 | public String getClientID() { 22 | return clientID; 23 | } 24 | 25 | public String getUsername() { 26 | return username; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /session-redisson/build.gradle: -------------------------------------------------------------------------------- 1 | group 'org.jmqtt' 2 | version '1.0-SNAPSHOT' 3 | 4 | apply plugin: 'java' 5 | 6 | dependencies { 7 | compile project(":session") 8 | compile "org.redisson:redisson:2.3.0" 9 | } 10 | -------------------------------------------------------------------------------- /session-redisson/build/classes/main/org/jmqtt/persistence/RedissonMessageStore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session-redisson/build/classes/main/org/jmqtt/persistence/RedissonMessageStore.class -------------------------------------------------------------------------------- /session-redisson/build/classes/main/org/jmqtt/persistence/RedissonPersistentStore$PersistentSession.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session-redisson/build/classes/main/org/jmqtt/persistence/RedissonPersistentStore$PersistentSession.class -------------------------------------------------------------------------------- /session-redisson/build/classes/main/org/jmqtt/persistence/RedissonPersistentStore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session-redisson/build/classes/main/org/jmqtt/persistence/RedissonPersistentStore.class -------------------------------------------------------------------------------- /session-redisson/build/classes/main/org/jmqtt/persistence/RedissonSessionsStore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session-redisson/build/classes/main/org/jmqtt/persistence/RedissonSessionsStore.class -------------------------------------------------------------------------------- /session-redisson/build/libs/persistence-1.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session-redisson/build/libs/persistence-1.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /session-redisson/build/tmp/jar/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | 3 | -------------------------------------------------------------------------------- /session-redisson/src/main/java/org/jmqtt/persistence/RedissonPersistentStore.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.persistence; 2 | 3 | import org.jmqtt.session.IMessagesStore; 4 | import org.jmqtt.session.ISessionsStore; 5 | import org.redisson.Redisson; 6 | import org.redisson.api.RedissonClient; 7 | import org.redisson.config.Config; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.util.Map; 12 | import java.util.concurrent.ConcurrentHashMap; 13 | 14 | /** 15 | * Created by gavin on 16/9/13. 16 | */ 17 | public class RedissonPersistentStore { 18 | 19 | public Map redissonCache = new ConcurrentHashMap<>(); 20 | 21 | private static final Logger LOG = LoggerFactory.getLogger(RedissonPersistentStore.class); 22 | 23 | private RedissonClient db; 24 | 25 | public RedissonPersistentStore(Config config) { 26 | db = Redisson.create(config); 27 | } 28 | 29 | /** 30 | * Factory method to create message store backed by MapDB 31 | */ 32 | public IMessagesStore messagesStore() { 33 | IMessagesStore msgStore = new RedissonMessageStore(db, redissonCache); 34 | msgStore.initStore(); 35 | return msgStore; 36 | } 37 | 38 | public ISessionsStore sessionsStore(IMessagesStore msgStore) { 39 | ISessionsStore sessionsStore = new RedissonSessionsStore(db, redissonCache, msgStore); 40 | sessionsStore.initStore(); 41 | return sessionsStore; 42 | } 43 | 44 | public void close() { 45 | db.shutdown(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /session/build.gradle: -------------------------------------------------------------------------------- 1 | group 'org.jmqtt' 2 | version '1.0-SNAPSHOT' 3 | 4 | apply plugin: 'java' 5 | 6 | dependencies { 7 | compile project(":core") 8 | } 9 | -------------------------------------------------------------------------------- /session/build/classes/main/org/jmqtt/session/ClientSession.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session/build/classes/main/org/jmqtt/session/ClientSession.class -------------------------------------------------------------------------------- /session/build/classes/main/org/jmqtt/session/IMatchingCondition.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session/build/classes/main/org/jmqtt/session/IMatchingCondition.class -------------------------------------------------------------------------------- /session/build/classes/main/org/jmqtt/session/IMessagesStore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session/build/classes/main/org/jmqtt/session/IMessagesStore.class -------------------------------------------------------------------------------- /session/build/classes/main/org/jmqtt/session/IPersistenceStore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session/build/classes/main/org/jmqtt/session/IPersistenceStore.class -------------------------------------------------------------------------------- /session/build/classes/main/org/jmqtt/session/ISessionsStore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session/build/classes/main/org/jmqtt/session/ISessionsStore.class -------------------------------------------------------------------------------- /session/build/classes/main/org/jmqtt/session/model/ClientTopicCouple.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session/build/classes/main/org/jmqtt/session/model/ClientTopicCouple.class -------------------------------------------------------------------------------- /session/build/classes/main/org/jmqtt/session/model/Message.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session/build/classes/main/org/jmqtt/session/model/Message.class -------------------------------------------------------------------------------- /session/build/classes/main/org/jmqtt/session/model/SessionStatus.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session/build/classes/main/org/jmqtt/session/model/SessionStatus.class -------------------------------------------------------------------------------- /session/build/classes/main/org/jmqtt/session/model/Subscription.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session/build/classes/main/org/jmqtt/session/model/Subscription.class -------------------------------------------------------------------------------- /session/build/classes/main/org/jmqtt/session/model/SubscriptionsStore$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session/build/classes/main/org/jmqtt/session/model/SubscriptionsStore$1.class -------------------------------------------------------------------------------- /session/build/classes/main/org/jmqtt/session/model/SubscriptionsStore$DumpTreeVisitor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session/build/classes/main/org/jmqtt/session/model/SubscriptionsStore$DumpTreeVisitor.class -------------------------------------------------------------------------------- /session/build/classes/main/org/jmqtt/session/model/SubscriptionsStore$IVisitor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session/build/classes/main/org/jmqtt/session/model/SubscriptionsStore$IVisitor.class -------------------------------------------------------------------------------- /session/build/classes/main/org/jmqtt/session/model/SubscriptionsStore$NodeCouple.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session/build/classes/main/org/jmqtt/session/model/SubscriptionsStore$NodeCouple.class -------------------------------------------------------------------------------- /session/build/classes/main/org/jmqtt/session/model/SubscriptionsStore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session/build/classes/main/org/jmqtt/session/model/SubscriptionsStore.class -------------------------------------------------------------------------------- /session/build/classes/main/org/jmqtt/session/model/Token.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session/build/classes/main/org/jmqtt/session/model/Token.class -------------------------------------------------------------------------------- /session/build/classes/main/org/jmqtt/session/model/TreeNode.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session/build/classes/main/org/jmqtt/session/model/TreeNode.class -------------------------------------------------------------------------------- /session/build/classes/main/org/jmqtt/session/model/WillMessage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session/build/classes/main/org/jmqtt/session/model/WillMessage.class -------------------------------------------------------------------------------- /session/build/libs/session-1.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/semicoder/jmqtt/1fc430209f907cbf6dd9b13ddfedc330f533993b/session/build/libs/session-1.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /session/build/tmp/jar/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | 3 | -------------------------------------------------------------------------------- /session/src/main/java/org/jmqtt/session/IMatchingCondition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.session; 17 | 18 | /** 19 | */ 20 | public interface IMatchingCondition { 21 | boolean match(String key); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /session/src/main/java/org/jmqtt/session/IMessagesStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.session; 17 | 18 | 19 | import org.jmqtt.session.model.Message; 20 | 21 | import java.util.Collection; 22 | import java.util.List; 23 | 24 | /** 25 | * Defines the SPI to be implemented by a StorageService that handle session of packets 26 | */ 27 | public interface IMessagesStore { 28 | 29 | /** 30 | * Used to initialize all persistent store structures 31 | */ 32 | void initStore(); 33 | 34 | /** 35 | * Persist the message. 36 | * If the message is empty then the topic is cleaned, else it's stored. 37 | */ 38 | void storeRetained(String topic, Message message); 39 | 40 | /** 41 | * Return a list of retained packets that satisfy the condition. 42 | */ 43 | Collection searchMatching(IMatchingCondition condition); 44 | 45 | /** 46 | * Persist the message. 47 | * 48 | * @return the unique id in the storage (msgId). 49 | */ 50 | void storePublishForFuture(Message evt); 51 | 52 | void removeStoredMessage(Message inflightMsg); 53 | 54 | void cacheForExactly(Message evt); 55 | 56 | void removeCacheExactlyMessage(Message message); 57 | 58 | /** 59 | * Return the list of persisted publishes for the given clientId. 60 | * For QoS1 and QoS2 with clean session flag, this method return the list of 61 | * missed publish events while the client was disconnected. 62 | */ 63 | List listMessagesInSession(String clientId, Collection guids); 64 | 65 | void dropMessagesInSession(String clientID); 66 | 67 | Message getMessageByGuid(String clientId, String guid); 68 | 69 | Message getCacheMessageByGuid(String clientId, String guid); 70 | 71 | void cleanRetained(String topic); 72 | } 73 | -------------------------------------------------------------------------------- /session/src/main/java/org/jmqtt/session/ISessionsStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.session; 17 | 18 | 19 | import org.jmqtt.session.model.ClientTopicCouple; 20 | import org.jmqtt.session.model.Message; 21 | import org.jmqtt.session.model.SessionStatus; 22 | import org.jmqtt.session.model.Subscription; 23 | 24 | import java.util.Collection; 25 | import java.util.List; 26 | 27 | /** 28 | * Store used to handle the session of the subscriptions tree. 29 | * 30 | * @author andrea 31 | */ 32 | public interface ISessionsStore { 33 | 34 | void initStore(); 35 | 36 | void updateStatus(String clientId, SessionStatus sessionStatus); 37 | 38 | /** 39 | * Add a new subscription to the session 40 | */ 41 | void addNewSubscription(Subscription newSubscription); 42 | 43 | /** 44 | * Removed a specific subscription 45 | */ 46 | void removeSubscription(String topic, String clientId); 47 | 48 | /** 49 | * Remove all the subscriptions of the session 50 | */ 51 | void wipeSubscriptions(String sessionId); 52 | 53 | /** 54 | * Return all topic filters to recreate the subscription tree. 55 | */ 56 | List listAllSubscriptions(); 57 | 58 | /** 59 | * @return the subscription stored by clientId and topicFilter, if any else null; 60 | */ 61 | Subscription getSubscription(ClientTopicCouple couple); 62 | 63 | /** 64 | * @return true if there are subscriptions persisted with clientId 65 | */ 66 | boolean contains(String clientId); 67 | 68 | ClientSession createNewSession(String clientId, boolean cleanSession); 69 | 70 | /** 71 | * @param clientId the client owning the session. 72 | * @return the session for the given clientId, null if not found. 73 | */ 74 | ClientSession sessionForClient(String clientId); 75 | 76 | void inFlightAck(String clientId, int packetId); 77 | 78 | /** 79 | * Save the binding packetId, clientId <-> guid 80 | */ 81 | void inFlight(String clientId, int packetId, String guid); 82 | 83 | /** 84 | * Return the next valid packetIdentifier for the given client session. 85 | */ 86 | int nextPacketId(String clientId); 87 | 88 | /** 89 | * Store the guid to be later published. 90 | */ 91 | void bindToDeliver(String guid, String clientId); 92 | 93 | /** 94 | * List the guids for retained packets for the session 95 | */ 96 | Collection enqueued(String clientId); 97 | 98 | /** 99 | * Remove form the queue of stored packets for session. 100 | */ 101 | void removeEnqueued(String clientId, String guid); 102 | 103 | void pubrelWaiting(String clientId, int packetId); 104 | 105 | /** 106 | * @return the guid of message just acked. 107 | */ 108 | String pubrelAcknowledged(String clientId, int packetId); 109 | 110 | String mapToGuid(String clientId, int packetId); 111 | 112 | Message getInflightMessage(String clientId, int packetId); 113 | 114 | } 115 | -------------------------------------------------------------------------------- /session/src/main/java/org/jmqtt/session/model/ClientTopicCouple.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.session.model; 2 | 3 | public class ClientTopicCouple { 4 | public final String topicFilter; 5 | public final String clientId; 6 | 7 | public ClientTopicCouple(String clientId, String topicFilter) { 8 | this.clientId = clientId; 9 | this.topicFilter = topicFilter; 10 | } 11 | 12 | @Override 13 | public boolean equals(Object o) { 14 | if (this == o) return true; 15 | if (o == null || getClass() != o.getClass()) return false; 16 | 17 | ClientTopicCouple that = (ClientTopicCouple) o; 18 | 19 | if (topicFilter != null ? !topicFilter.equals(that.topicFilter) : that.topicFilter != null) return false; 20 | return !(clientId != null ? !clientId.equals(that.clientId) : that.clientId != null); 21 | } 22 | 23 | @Override 24 | public int hashCode() { 25 | int result = topicFilter != null ? topicFilter.hashCode() : 0; 26 | result = 31 * result + (clientId != null ? clientId.hashCode() : 0); 27 | return result; 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return "ClientTopicCouple{" + 33 | "topicFilter='" + topicFilter + '\'' + 34 | ", clientId='" + clientId + '\'' + 35 | '}'; 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /session/src/main/java/org/jmqtt/session/model/Message.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.session.model; 2 | 3 | import org.jmqtt.core.constant.QosType; 4 | 5 | import java.io.Serializable; 6 | import java.nio.ByteBuffer; 7 | 8 | public class Message implements Serializable { 9 | private QosType qos; 10 | private byte[] payload; 11 | private String topic; 12 | private boolean retained; 13 | private String clientId; 14 | //Optional attribute, available only fo QoS 1 and 2 15 | private Integer packetId; 16 | private String msgId; 17 | 18 | public Message() { 19 | } 20 | 21 | public Message(byte[] message, QosType qos, String topic) { 22 | this.qos = qos; 23 | this.payload = message; 24 | this.topic = topic; 25 | } 26 | 27 | public QosType getQos() { 28 | return qos; 29 | } 30 | 31 | public ByteBuffer getPayloadBuffer() { 32 | return (ByteBuffer) ByteBuffer.allocate(payload.length).put(payload).flip(); 33 | } 34 | 35 | public String getTopic() { 36 | return topic; 37 | } 38 | 39 | public void setMsgId(String msgId) { 40 | this.msgId = msgId; 41 | } 42 | 43 | public String getMsgId() { 44 | return msgId; 45 | } 46 | 47 | public String getClientId() { 48 | return clientId; 49 | } 50 | 51 | public void setClientId(String m_clientID) { 52 | this.clientId = m_clientID; 53 | } 54 | 55 | public ByteBuffer getMessage() { 56 | return ByteBuffer.wrap(payload); 57 | } 58 | 59 | public void setRetained(boolean retained) { 60 | this.retained = retained; 61 | } 62 | 63 | public boolean isRetained() { 64 | return retained; 65 | } 66 | 67 | public void setQos(QosType qos) { 68 | this.qos = qos; 69 | } 70 | 71 | public void setPayload(byte[] payload) { 72 | this.payload = payload; 73 | } 74 | 75 | public byte[] getPayload() { 76 | return payload; 77 | } 78 | 79 | public void setTopic(String topic) { 80 | this.topic = topic; 81 | } 82 | 83 | public Integer getPacketId() { 84 | return packetId; 85 | } 86 | 87 | public void setPacketId(Integer packetId) { 88 | this.packetId = packetId; 89 | } 90 | 91 | @Override 92 | public String toString() { 93 | return "PublishEvent{" + 94 | "packetId=" + packetId + 95 | ", clientId='" + clientId + '\'' + 96 | ", m_retain=" + retained + 97 | ", qos=" + qos + 98 | ", topic='" + topic + '\'' + 99 | '}'; 100 | } 101 | } -------------------------------------------------------------------------------- /session/src/main/java/org/jmqtt/session/model/SessionStatus.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.session.model; 2 | 3 | import java.io.Serializable; 4 | 5 | public class SessionStatus implements Serializable { 6 | public boolean cleanSession; 7 | 8 | public boolean active; 9 | 10 | public SessionStatus() { 11 | } 12 | 13 | public SessionStatus(boolean cleanSession) { 14 | this.cleanSession = cleanSession; 15 | } 16 | 17 | public boolean isCleanSession() { 18 | return cleanSession; 19 | } 20 | 21 | public void setCleanSession(boolean cleanSession) { 22 | this.cleanSession = cleanSession; 23 | } 24 | 25 | public boolean isActive() { 26 | return active; 27 | } 28 | 29 | public void setActive(boolean active) { 30 | this.active = active; 31 | } 32 | } -------------------------------------------------------------------------------- /session/src/main/java/org/jmqtt/session/model/Subscription.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.session.model; 17 | 18 | 19 | import org.jmqtt.core.constant.QosType; 20 | 21 | import java.io.Serializable; 22 | 23 | /** 24 | * Maintain the information about which Topic a certain ClientID is subscribed 25 | * and at which QoS 26 | * 27 | * @author andrea 28 | */ 29 | public class Subscription implements Serializable { 30 | 31 | QosType requestedQos; //max QoS acceptable 32 | String clientId; 33 | String topicFilter; 34 | 35 | public Subscription() { 36 | } 37 | 38 | public Subscription(String clientId, String topicFilter, QosType requestedQos) { 39 | this.requestedQos = requestedQos; 40 | this.clientId = clientId; 41 | this.topicFilter = topicFilter; 42 | } 43 | 44 | public Subscription(Subscription orig) { 45 | this.requestedQos = orig.requestedQos; 46 | this.clientId = orig.clientId; 47 | this.topicFilter = orig.topicFilter; 48 | } 49 | 50 | public String getClientId() { 51 | return clientId; 52 | } 53 | 54 | public QosType getRequestedQos() { 55 | return requestedQos; 56 | } 57 | 58 | public String getTopicFilter() { 59 | return topicFilter; 60 | } 61 | 62 | public void setRequestedQos(QosType requestedQos) { 63 | this.requestedQos = requestedQos; 64 | } 65 | 66 | public void setClientId(String clientId) { 67 | this.clientId = clientId; 68 | } 69 | 70 | public void setTopicFilter(String topicFilter) { 71 | this.topicFilter = topicFilter; 72 | } 73 | 74 | @Override 75 | public boolean equals(Object o) { 76 | if (this == o) return true; 77 | if (o == null || getClass() != o.getClass()) return false; 78 | 79 | Subscription that = (Subscription) o; 80 | 81 | if (clientId != null ? !clientId.equals(that.clientId) : that.clientId != null) return false; 82 | return !(topicFilter != null ? !topicFilter.equals(that.topicFilter) : that.topicFilter != null); 83 | 84 | } 85 | 86 | @Override 87 | public int hashCode() { 88 | int result = clientId != null ? clientId.hashCode() : 0; 89 | result = 31 * result + (topicFilter != null ? topicFilter.hashCode() : 0); 90 | return result; 91 | } 92 | 93 | @Override 94 | public String toString() { 95 | return String.format("[filter:%s, cliID: %s, qos: %s, active: %s]", this.topicFilter, this.clientId, this.requestedQos); 96 | } 97 | 98 | @Override 99 | public Subscription clone() { 100 | try { 101 | return (Subscription) super.clone(); 102 | } catch (CloneNotSupportedException e) { 103 | return null; 104 | } 105 | } 106 | 107 | public ClientTopicCouple asClientTopicCouple() { 108 | return new ClientTopicCouple(this.clientId, this.topicFilter); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /session/src/main/java/org/jmqtt/session/model/Token.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2015 The original author or authors 3 | * ------------------------------------------------------ 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Apache License v2.0 which accompanies this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * 11 | * The Apache License v2.0 is available at 12 | * http://www.opensource.org/licenses/apache2.0.php 13 | * 14 | * You may elect to redistribute this code under either of these licenses. 15 | */ 16 | package org.jmqtt.session.model; 17 | 18 | /** 19 | * Internal use only class. 20 | */ 21 | public class Token { 22 | 23 | static final Token SYSTEM = new Token("$"); 24 | static final Token EMPTY = new Token(""); 25 | static final Token MULTI = new Token("#"); 26 | static final Token SINGLE = new Token("+"); 27 | final String name; 28 | 29 | protected Token(String s) { 30 | name = s; 31 | } 32 | 33 | protected String name() { 34 | return name; 35 | } 36 | 37 | protected boolean match(Token t) { 38 | if (t == MULTI || t == SINGLE) { 39 | return false; 40 | } 41 | 42 | if (this == MULTI || this == SINGLE) { 43 | return true; 44 | } 45 | 46 | return equals(t); 47 | } 48 | 49 | @Override 50 | public int hashCode() { 51 | int hash = 7; 52 | hash = 29 * hash + (this.name != null ? this.name.hashCode() : 0); 53 | return hash; 54 | } 55 | 56 | @Override 57 | public boolean equals(Object obj) { 58 | if (obj == null) { 59 | return false; 60 | } 61 | if (getClass() != obj.getClass()) { 62 | return false; 63 | } 64 | final Token other = (Token) obj; 65 | if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { 66 | return false; 67 | } 68 | return true; 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return name; 74 | } 75 | } -------------------------------------------------------------------------------- /session/src/main/java/org/jmqtt/session/model/WillMessage.java: -------------------------------------------------------------------------------- 1 | package org.jmqtt.session.model; 2 | 3 | import org.jmqtt.core.constant.QosType; 4 | 5 | import java.nio.ByteBuffer; 6 | 7 | public final class WillMessage { 8 | private final String topic; 9 | private final ByteBuffer payload; 10 | private final boolean retained; 11 | private final QosType qos; 12 | 13 | public WillMessage(String topic, ByteBuffer payload, boolean retained, QosType qos) { 14 | this.topic = topic; 15 | this.payload = payload; 16 | this.retained = retained; 17 | this.qos = qos; 18 | } 19 | 20 | public String getTopic() { 21 | return topic; 22 | } 23 | 24 | public ByteBuffer getPayload() { 25 | return payload; 26 | } 27 | 28 | public boolean isRetained() { 29 | return retained; 30 | } 31 | 32 | public QosType getQos() { 33 | return qos; 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'jmqtt' 2 | include 'core' 3 | include 'broker' 4 | include 'auth' 5 | include 'cluster' 6 | include 'session' 7 | include 'session-redisson' 8 | include 'interception' 9 | include 'auth-file' 10 | include 'auth-db' 11 | include 'auth-mongo' 12 | 13 | --------------------------------------------------------------------------------