├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── HEADER ├── LICENSE.txt ├── README.adoc ├── pom.xml └── src ├── main └── java │ └── com │ └── hivemq │ └── spi │ ├── HiveMQPluginModule.java │ ├── PluginEntryPoint.java │ ├── annotations │ ├── Experimental.java │ ├── Immutable.java │ ├── NotNull.java │ ├── Nullable.java │ ├── ReadOnly.java │ └── ThreadSafe.java │ ├── aop │ └── cache │ │ └── Cached.java │ ├── bridge │ ├── Address.java │ ├── Bridge.java │ ├── Notification.java │ ├── StartType.java │ ├── State.java │ ├── TLSVersion.java │ └── TopicPattern.java │ ├── callback │ ├── AsynchronousCallback.java │ ├── Callback.java │ ├── CallbackPriority.java │ ├── LowlevelCallback.java │ ├── SynchronousCallback.java │ ├── cluster │ │ ├── ClusterDiscoveryCallback.java │ │ └── ClusterNodeAddress.java │ ├── events │ │ ├── BeforePublishSendCallback.java │ │ ├── OnConnectCallback.java │ │ ├── OnDisconnectCallback.java │ │ ├── OnPublishReceivedCallback.java │ │ ├── OnPublishSend.java │ │ ├── OnSessionReadyCallback.java │ │ ├── OnSubscribeCallback.java │ │ ├── OnTopicSubscriptionCallback.java │ │ ├── OnUnsubscribeCallback.java │ │ └── broker │ │ │ ├── OnBrokerReady.java │ │ │ ├── OnBrokerStart.java │ │ │ └── OnBrokerStop.java │ ├── exception │ │ ├── AuthenticationException.java │ │ ├── BeforePublishSendException.java │ │ ├── BrokerUnableToStartException.java │ │ ├── IllegalBrokerStateException.java │ │ ├── InvalidSubscriptionException.java │ │ ├── InvalidTTLException.java │ │ ├── LimitExceededException.java │ │ ├── OnPublishReceivedException.java │ │ └── RefusedConnectionException.java │ ├── lowlevel │ │ ├── OnConnackSend.java │ │ ├── OnPingCallback.java │ │ ├── OnPubackReceived.java │ │ ├── OnPubackSend.java │ │ ├── OnPubcompReceived.java │ │ ├── OnPubcompSend.java │ │ ├── OnPubrecReceived.java │ │ ├── OnPubrecSend.java │ │ ├── OnPubrelReceived.java │ │ ├── OnPubrelSend.java │ │ ├── OnSubackSend.java │ │ └── OnUnsubackSend.java │ ├── registry │ │ └── CallbackRegistry.java │ ├── schedule │ │ ├── ScheduleExpressions.java │ │ └── ScheduledCallback.java │ ├── security │ │ ├── AfterLoginCallback.java │ │ ├── OnAuthenticationCallback.java │ │ ├── OnAuthorizationCallback.java │ │ ├── OnInsufficientPermissionDisconnect.java │ │ ├── RestrictionsAfterLoginCallback.java │ │ └── authorization │ │ │ ├── AuthorizationBehaviour.java │ │ │ └── AuthorizationResult.java │ └── webui │ │ └── WebUIAuthenticationCallback.java │ ├── config │ └── SystemInformation.java │ ├── exceptions │ ├── BridgeException.java │ └── UnrecoverableException.java │ ├── message │ ├── CONNACK.java │ ├── CONNECT.java │ ├── DISCONNECT.java │ ├── Message.java │ ├── MessageType.java │ ├── MessageWithID.java │ ├── ModifiablePUBLISH.java │ ├── PINGREQ.java │ ├── PINGRESP.java │ ├── PUBACK.java │ ├── PUBCOMP.java │ ├── PUBLISH.java │ ├── PUBREC.java │ ├── PUBREL.java │ ├── ProtocolVersion.java │ ├── QoS.java │ ├── REMOTE_PUBLISH.java │ ├── RetainedMessage.java │ ├── ReturnCode.java │ ├── SUBACK.java │ ├── SUBSCRIBE.java │ ├── SubackReturnCode.java │ ├── Topic.java │ ├── UNSUBACK.java │ └── UNSUBSCRIBE.java │ ├── metrics │ ├── HiveMQMetric.java │ ├── HiveMQMetrics.java │ └── annotations │ │ ├── Counted.java │ │ ├── ExceptionMetered.java │ │ ├── Metered.java │ │ └── Timed.java │ ├── plugin │ └── meta │ │ └── Information.java │ ├── security │ ├── AuthorizationEvaluator.java │ ├── ClientCredentialsData.java │ ├── ClientData.java │ ├── ProxyInformation.java │ ├── QueuedMessageStrategy.java │ ├── Restriction.java │ ├── RestrictionType.java │ └── SslClientCertificate.java │ ├── services │ ├── AsyncClientGroupService.java │ ├── AsyncClientService.java │ ├── AsyncMetricService.java │ ├── AsyncRetainedMessageStore.java │ ├── AsyncSessionAttributeStore.java │ ├── AsyncSubscriptionStore.java │ ├── BlockingClientGroupService.java │ ├── BlockingClientService.java │ ├── BlockingMetricService.java │ ├── BlockingRetainedMessageStore.java │ ├── BlockingSessionAttributeStore.java │ ├── BlockingSubscriptionStore.java │ ├── BridgeManagerService.java │ ├── ClientService.java │ ├── ConfigurationService.java │ ├── ConnectionAttributeStore.java │ ├── LogService.java │ ├── MetricService.java │ ├── OptionalAttribute.java │ ├── PluginExecutorService.java │ ├── PublishService.java │ ├── RetainedMessageStore.java │ ├── SYSTopicService.java │ ├── SharedSubscriptionService.java │ ├── SubscriptionStore.java │ ├── configuration │ │ ├── GeneralConfigurationService.java │ │ ├── MqttConfigurationService.java │ │ ├── ThrottlingConfigurationService.java │ │ ├── ValueChangedCallback.java │ │ ├── entity │ │ │ ├── ClientWriteBufferProperties.java │ │ │ ├── ConnectOverloadProtectionProperties.java │ │ │ ├── Listener.java │ │ │ ├── SocketOptionsProperties.java │ │ │ ├── TcpListener.java │ │ │ ├── Tls.java │ │ │ ├── TlsTcpListener.java │ │ │ ├── TlsWebsocketListener.java │ │ │ └── WebsocketListener.java │ │ ├── exception │ │ │ └── ConfigurationValidationException.java │ │ ├── listener │ │ │ └── ListenerConfigurationService.java │ │ └── validation │ │ │ ├── ValidationError.java │ │ │ ├── Validator.java │ │ │ ├── annotation │ │ │ └── Validate.java │ │ │ └── validators │ │ │ ├── ListenerValidator.java │ │ │ ├── MaxClientIdValidator.java │ │ │ ├── TtlValidator.java │ │ │ └── ZeroablePositiveNumber.java │ ├── exception │ │ ├── IncompatibleHiveMQVersionException.java │ │ ├── NoSuchClientIdException.java │ │ └── RateLimitExceededException.java │ └── rest │ │ ├── RESTService.java │ │ ├── listener │ │ ├── AbstractListener.java │ │ ├── HttpListener.java │ │ └── Listener.java │ │ └── servlet │ │ └── ServletFilter.java │ ├── topic │ ├── MqttTopicPermission.java │ ├── PermissionTopicMatcher.java │ ├── TopicMatcher.java │ ├── exception │ │ └── InvalidTopicException.java │ └── sys │ │ ├── SYSTopicEntry.java │ │ └── Type.java │ └── util │ ├── DefaultSslEngineUtil.java │ ├── Listeners.java │ ├── PathUtils.java │ └── SslException.java └── test └── java └── com └── hivemq └── spi ├── PluginEntryPointTest.java ├── bridge └── TLSVersionTest.java ├── callback └── schedule │ └── ScheduleExpressionsTest.java ├── message ├── CONNACKTest.java └── SubackReturnCodeTest.java ├── security ├── AuthorizationEvaluatorTest.java └── RestrictionTest.java ├── services ├── configuration │ ├── entity │ │ ├── ConnectOverloadProtectionPropertiesTest.java │ │ └── TcpListenerTest.java │ └── validation │ │ └── validators │ │ ├── ListenerValidatorTest.java │ │ ├── MaxClientIdValidatorTest.java │ │ ├── TtlValidatorTest.java │ │ └── ZeroablePositiveNumberTest.java └── rest │ ├── listener │ └── AbstractListenerTest.java │ └── servlet │ └── ServletFilterTest.java ├── topic ├── MqttTopicPermissionTest.java └── PermissionTopicMatcherTest.java └── util ├── DefaultSslEngineUtilTest.java └── ListenersTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /hivemq-spi.iml 3 | /.idea/ 4 | .DS_Store -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: trusty 2 | language: java 3 | 4 | jdk: 5 | - openjdk7 -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # HiveMQ Code of Conduct 2 | 3 | Please refer to our [HiveMQ Code of Conduct](https://github.com/hivemq/hivemq-community/blob/master/code-of-conduct.md). 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Welcome to the HiveMQ Community! Glad to see your interest in contributing to HiveMQ SPI. Please checkout our [Contribution Guide](https://github.com/hivemq/hivemq-community/blob/master/CONTRIBUTING.adoc) to make sure your contribution will be accepted by the HiveMQ team. 4 | 5 | For information on how the HiveMQ Community is organized and how contributions will be accepted please have a look at our [HiveMQ Community Repo](https://github.com/hivemq/hivemq-community). 6 | -------------------------------------------------------------------------------- /HEADER: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | :hivemq-github-link: https://github.com/hivemq 2 | :hivemq-link: http://www.hivemq.com 3 | :hivemq-plugin-docu-link: https://www.hivemq.com/docs/3.4/plugins/introduction.html 4 | :extension: https://github.com/hivemq/hivemq-extension-sdk 5 | 6 | == HiveMQ SDK 7 | 8 | NOTE: HiveMQ 4 uses a new extension system. This SDK is not compatible with HiveMQ 4. The new version can be found {extension}[here]. 9 | 10 | image:https://travis-ci.org/hivemq/hivemq-spi.png?branch=master["Build Status", link="https://travis-ci.org/hivemq/hivemq-spi"] 11 | 12 | The enterprise MQTT broker HiveMQ offers this free and open source plugin SDK with service provider interfaces. This allows everyone to extend HiveMQ and add custom functionality via plugins. 13 | 14 | With custom HiveMQ plugins, it's easy to add functionality like writing messages to databases, integrate with other service buses, collect statistics, add fine-grained security and virtually anything you else you can imagine. 15 | 16 | Plugin development for HiveMQ is as easy as writing a Java main method once you grasp the core concepts. 17 | 18 | === Using the SDK 19 | 20 | A extensive HiveMQ plugin documentation is available {hivemq-plugin-docu-link}[on the official HiveMQ website]. It covers the core concepts and shows how to set up your development environment. 21 | 22 | You can also clone our example open source HiveMQ plugins at {hivemq-github-link}[in our Github page]. 23 | 24 | 25 | === Maven Repository 26 | 27 | *Since version 2.0.0, the _hivemq-spi_ is available in Maven central, so no special configuration is needed*. 28 | 29 | 30 | === Using the SDK 31 | 32 | To use the SDK, add the following dependency to your Maven project: 33 | 34 | 35 | [source,xml] 36 | ---- 37 | 38 | com.hivemq 39 | hivemq-spi 40 | 3.4.4 41 | 42 | 43 | 44 | ---- 45 | 46 | === Plugin Development Documentation 47 | 48 | Please visit {hivemq-plugin-docu-link}[our website] for the documentation how to develop plugins. 49 | 50 | === Example plugins 51 | You can find many example plugins by browsing {hivemq-github-link}[here on Github]. 52 | 53 | = Contributing 54 | 55 | If you want to contribute to HiveMQ SPI, see the link:CONTRIBUTING.md[contribution guidelines]. 56 | 57 | = License 58 | 59 | HiveMQ SPI is licensed under the `APACHE LICENSE, VERSION 2.0`. A copy of the license can be found link:LICENSE.txt[here]. 60 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/HiveMQPluginModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi; 18 | 19 | import com.google.inject.AbstractModule; 20 | 21 | /** 22 | * The HiveMQ Plugin Guice Module class from which you should inherit when writing a HiveMQ plugin. 23 | *

24 | * The entryPointClass() must return a subclass of {@link PluginEntryPoint}. 25 | * It's possible to use Dependency Injection with Guice in this entry point 26 | * 27 | * @author Dominik Obermaier 28 | * @author Christoph Schäbel 29 | * @since 1.4 30 | */ 31 | public abstract class HiveMQPluginModule extends AbstractModule { 32 | 33 | /** 34 | * {@inheritDoc} 35 | */ 36 | @Override 37 | protected final void configure() { 38 | 39 | configurePlugin(); 40 | 41 | //Bind the main entry class and immediately start injection 42 | bind(entryPointClass()).asEagerSingleton(); 43 | } 44 | 45 | /** 46 | * This method should be used to configure the Guice Bindings and Guice Configurations. 47 | */ 48 | protected abstract void configurePlugin(); 49 | 50 | /** 51 | * Must return the main plugin class which is the "entry point" of the plugin. 52 | *

53 | * Note: This plugin class can use Dependency Injection via Guice 54 | * 55 | * @return the main entry class 56 | */ 57 | protected abstract Class entryPointClass(); 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/PluginEntryPoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi; 18 | 19 | import com.hivemq.spi.callback.registry.CallbackRegistry; 20 | 21 | import javax.inject.Inject; 22 | 23 | /** 24 | * The abstract class where all HiveMQ plugin Entry Points should extend from. 25 | *

26 | * You can use standard Guice injections like constructor injections. It is also possible to use LifeCycle 27 | * management annotations like {@link javax.annotation.PostConstruct} and {@link javax.annotation.PreDestroy} 28 | *

29 | * To get the global callback registry to register your own callbacks to HiveMQ, use getCallbackRegistry() 30 | * in your constructor or {@link javax.annotation.PostConstruct} annotated method 31 | * 32 | * @author Dominik Obermaier 33 | * @since 1.4 34 | */ 35 | public abstract class PluginEntryPoint { 36 | 37 | private CallbackRegistry callbackRegistry; 38 | 39 | /** 40 | * You should never call this method by your own except 41 | * for testing purposes. 42 | * 43 | * @param callbackRegistry the callback Registry object 44 | */ 45 | @Inject 46 | final void setCallbackRegistry(final CallbackRegistry callbackRegistry) { 47 | 48 | this.callbackRegistry = callbackRegistry; 49 | } 50 | 51 | /** 52 | * Returns global Callback registry 53 | * 54 | * @return the global Callback Registry 55 | */ 56 | public CallbackRegistry getCallbackRegistry() { 57 | return callbackRegistry; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/annotations/Experimental.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.annotations; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.Target; 22 | 23 | import static java.lang.annotation.ElementType.*; 24 | import static java.lang.annotation.RetentionPolicy.SOURCE; 25 | 26 | /** 27 | * This annotation indicates that an API is experimental an can be subject 28 | * to change in later versions. If you are relying on an experimental API, 29 | * it is possible that you have to modify your code after an upgrade. 30 | * 31 | * @author Dominik Obermaier 32 | * @since 2.0 33 | */ 34 | @Documented 35 | @Retention(SOURCE) 36 | @Target({METHOD, ANNOTATION_TYPE, TYPE, PACKAGE}) 37 | public @interface Experimental { 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/annotations/Immutable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.annotations; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.Target; 22 | 23 | import static java.lang.annotation.ElementType.*; 24 | import static java.lang.annotation.RetentionPolicy.SOURCE; 25 | 26 | /** 27 | * A marker annotation interface which marks a class as immutable. 28 | *

29 | * Convenient method to document the intended immutability of a class. 30 | * 31 | * @author Dominik Obermaier 32 | * @since 2.1 33 | */ 34 | @Documented 35 | @Retention(SOURCE) 36 | @Target({METHOD, ANNOTATION_TYPE, TYPE, PACKAGE}) 37 | public @interface Immutable { 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/annotations/NotNull.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.annotations; 18 | 19 | import java.lang.annotation.*; 20 | 21 | /** 22 | * An annotation which is used for indicating that something can not be null. 23 | * This is very useful for static code analysis to prevent bugs. 24 | * 25 | * @author Dominik Obermaier 26 | */ 27 | @Documented 28 | @Retention(RetentionPolicy.CLASS) 29 | @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE}) 30 | public @interface NotNull { 31 | String value() default ""; 32 | } -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/annotations/Nullable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.annotations; 18 | 19 | import java.lang.annotation.*; 20 | 21 | /** 22 | * An annotation which is used for indicating that something can be null. 23 | * This is very useful for static code analysis to prevent bugs. 24 | * 25 | * @author Dominik Obermaier 26 | */ 27 | @Documented 28 | @Retention(RetentionPolicy.CLASS) 29 | @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE}) 30 | public @interface Nullable { 31 | String value() default ""; 32 | } -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/annotations/ReadOnly.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.annotations; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.Target; 22 | 23 | import static java.lang.annotation.ElementType.METHOD; 24 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 25 | 26 | /** 27 | * This is an informal annotation which indicates that the method returns 28 | * a read-only type. 29 | *

30 | * If you encounter this on a method which returns a {@link java.util.Collection}, 31 | * this collection is expected to be immutable and must not be modified. 32 | * 33 | * @author Dominik Obermaier 34 | * @since 2.0 35 | */ 36 | @Documented 37 | @Retention(RUNTIME) 38 | @Target({METHOD}) 39 | public @interface ReadOnly { 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/annotations/ThreadSafe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.annotations; 18 | 19 | import java.lang.annotation.*; 20 | 21 | /** 22 | * An annotation which is used for indicating that a class or method is thread safe. 23 | * 24 | * @author Dominik Obermaier 25 | */ 26 | @Documented 27 | @Retention(RetentionPolicy.CLASS) 28 | @Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE}) 29 | public @interface ThreadSafe { 30 | String value() default ""; 31 | } -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/aop/cache/Cached.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.aop.cache; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.Target; 22 | import java.util.concurrent.TimeUnit; 23 | 24 | import static java.lang.annotation.ElementType.METHOD; 25 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 26 | 27 | 28 | /** 29 | * Caches the return value of a method for a specific time. It takes the parameters 30 | * of the method into account, when deciding if this method has already been cached. 31 | * Very useful for expensive methods 32 | * (like database lookups) which are called regularly. 33 | *

34 | * Only works on objects created by Guice. 35 | * 36 | * @author Christian Goetz 37 | * @since 1.4 38 | */ 39 | @Documented 40 | @Retention(RUNTIME) 41 | @Target(METHOD) 42 | public @interface Cached { 43 | 44 | /** 45 | * The total time how long the return value of this method should be cached 46 | */ 47 | long timeToLive(); 48 | 49 | /** 50 | * The {@link TimeUnit} for the timeToLive. Defaults to Milliseconds 51 | */ 52 | TimeUnit timeUnit() default TimeUnit.MILLISECONDS; 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/bridge/Notification.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.bridge; 18 | 19 | import com.hivemq.spi.message.QoS; 20 | 21 | /** 22 | * A concrete notification which consists of a topic and a quality of service level 23 | * 24 | * @author Dominik Obermaier 25 | * @since 2.0 26 | */ 27 | @Deprecated 28 | public class Notification { 29 | 30 | /** 31 | * The default notification topic on remote brokers: 32 | * $SYS/broker/connection/#{clientId}/state 33 | */ 34 | public final static String DEFAULT_NOTIFICATION_TOPIC = "$SYS/broker/connection/#{clientId}/state"; 35 | 36 | private String topic; 37 | 38 | private QoS qoS; 39 | 40 | public Notification(final String topic, final QoS qoS) { 41 | this.topic = topic; 42 | this.qoS = qoS; 43 | } 44 | 45 | public String getTopic() { 46 | return topic; 47 | } 48 | 49 | public void setTopic(final String topic) { 50 | this.topic = topic; 51 | } 52 | 53 | public QoS getQoS() { 54 | return qoS; 55 | } 56 | 57 | public void setQoS(final QoS qoS) { 58 | this.qoS = qoS; 59 | } 60 | 61 | @Override 62 | public boolean equals(final Object o) { 63 | if (this == o) return true; 64 | if (o == null || getClass() != o.getClass()) return false; 65 | 66 | final Notification that = (Notification) o; 67 | 68 | if (qoS != that.qoS) return false; 69 | if (topic != null ? !topic.equals(that.topic) : that.topic != null) return false; 70 | 71 | return true; 72 | } 73 | 74 | @Override 75 | public int hashCode() { 76 | int result = topic != null ? topic.hashCode() : 0; 77 | result = 31 * result + (qoS != null ? qoS.hashCode() : 0); 78 | return result; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/bridge/State.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.bridge; 18 | 19 | /** 20 | * The state of a bridge. 21 | *

22 | * The state machine is as follows: 23 | *

24 | * STOPPED -> STARTING -> RUNNING -> STOPPING -> STOPPED 25 | *

26 | * If something bad happens, the bridge can get in state FAILURE. 27 | * 28 | * @author Dominik Obermaier 29 | * @since 2.0 30 | */ 31 | @Deprecated 32 | public enum State { 33 | 34 | /** 35 | * The bridge is stopped at the moment 36 | */ 37 | STOPPED, 38 | /** 39 | * The bridge is starting and will be available soon 40 | */ 41 | STARTING, 42 | /** 43 | * The bridge is up and running 44 | */ 45 | RUNNING, 46 | /** 47 | * The bridge is in failure state. This is typically a fatal problem 48 | * and restarting could possibly be impossible. 49 | */ 50 | FAILURE, 51 | /** 52 | * The bridge is stopping at the moment and will be shutdown soon 53 | */ 54 | STOPPING 55 | } -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/bridge/TLSVersion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.bridge; 18 | 19 | /** 20 | * The TLS version for a bridge connection 21 | * 22 | * @author Dominik Obermaier 23 | * @since 2.0 24 | */ 25 | @Deprecated 26 | public enum TLSVersion { 27 | /** 28 | * SSLv3 29 | */ 30 | SSLv3("SSLv3"), 31 | /** 32 | * TLS 1.0 33 | */ 34 | TLS("TLS"), 35 | /** 36 | * TLS 1.0 37 | */ 38 | TLSv1("TLSv1"), 39 | /** 40 | * TLS 1.1 (may not be available with all Java versions) 41 | */ 42 | TLSv1_1("TLSv1.1"), 43 | /** 44 | * TLS 1.2 (may not be available with all Java versions) 45 | */ 46 | TLSv1_2("TLSv1.2"); 47 | 48 | private final String tlsVersion; 49 | 50 | TLSVersion(final String tlsVersion) { 51 | this.tlsVersion = tlsVersion; 52 | } 53 | 54 | public String getTlsVersion() { 55 | return tlsVersion; 56 | } 57 | 58 | /** 59 | * Returns the {@link TLSVersion} for this String. 60 | *

61 | * If the String is invalid, it will return null 62 | * 63 | * @param tlsVersion the TLS version string 64 | * @return the {@link TLSVersion} 65 | */ 66 | public static TLSVersion fromString(final String tlsVersion) { 67 | 68 | for (final TLSVersion version : TLSVersion.values()) { 69 | if (version.getTlsVersion().equals(tlsVersion)) { 70 | return version; 71 | } 72 | } 73 | return null; 74 | } 75 | 76 | } -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/AsynchronousCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback; 18 | 19 | /** 20 | * A callback which gets executed asynchronously. 21 | *

22 | * Asynchronous callbacks are executed at the same time. 23 | * Although the execution of the callbacks is asynchronous, 24 | * most callbacks get synchronized after executing to receive the results. 25 | *

26 | * Don't implement this interface on your own, use a more concrete interface when you want 27 | * to add a callback 28 | * 29 | * @author Christian Goetz 30 | * @since 1.4 31 | */ 32 | public interface AsynchronousCallback extends Callback { 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/Callback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback; 18 | 19 | /** 20 | * General marker interface for callbacks. 21 | *

22 | * Don't implement this interface on your own, use a more concrete interface when you want 23 | * to add a callback 24 | * 25 | * @author Dominik Obermaier 26 | * @since 1.4 27 | */ 28 | public interface Callback { 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/CallbackPriority.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback; 18 | 19 | /** 20 | * Useful constants for common priorities 21 | * 22 | * @author Christian Goetz 23 | * @since 1.4 24 | */ 25 | public class CallbackPriority { 26 | public static int CRITICAL = 1; 27 | public static int VERY_HIGH = 10; 28 | public static int HIGH = 50; 29 | public static int MEDIUM = 100; 30 | public static int LOW = 500; 31 | public static int VERY_LOW = 1000; 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/LowlevelCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback; 18 | 19 | /** 20 | * A marker interface for low level MQTT callbacks. 21 | *

22 | * Low level callbacks are callbacks which are notified on MQTT messages 23 | * which are typically not interesting for business logic but protocol flow. 24 | *

25 | * These callbacks are solely informational 26 | *

27 | * Don't implement this interface on your own, use a more concrete interface when you want 28 | * to add a callback 29 | * 30 | * @author Christian Goetz 31 | * @since 1.4 32 | */ 33 | public interface LowlevelCallback { 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/SynchronousCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback; 18 | 19 | /** 20 | * A callback which execution is synchronized. That means the callbacks 21 | * are executed in order of their priority. 22 | *

23 | * Don't implement this interface on your own, use a more concrete interface when you want 24 | * to add a callback 25 | * 26 | * @author Christian Goetz 27 | * @since 1.4 28 | */ 29 | public interface SynchronousCallback extends Callback { 30 | 31 | /** 32 | * @return a numerical priority. Lower numbers mean higher priority 33 | */ 34 | int priority(); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/cluster/ClusterDiscoveryCallback.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.callback.cluster; 2 | 3 | import com.google.common.util.concurrent.ListenableFuture; 4 | import com.hivemq.spi.callback.AsynchronousCallback; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * This callback is meant to regularly discover the addresses of all available HiveMQ cluster nodes. 10 | *

11 | * Notice: It is used only if cluster is enabled and discovery is set to "plugin" in the HiveMQ config file. 12 | * 13 | * @author Christoph Schäbel 14 | * @since 3.1 15 | */ 16 | public interface ClusterDiscoveryCallback extends AsynchronousCallback { 17 | 18 | /** 19 | * Gets called before the HiveMQ instance starts looking for other HiveMQ instances to form a cluster with. 20 | *

21 | * This method can be used to register this HiveMQ instance with some kind of central registry or save it to a 22 | * database or file server for example. 23 | * 24 | * @param clusterId this HiveMQ instance's unique cluster node ID 25 | * @param ownAddress this HiveMQ instance's address 26 | */ 27 | void init(String clusterId, ClusterNodeAddress ownAddress); 28 | 29 | /** 30 | * Gets called every X seconds by HiveMQ to discover all available cluster nodes. 31 | *

32 | * The interval at which this method is called can be configured in the HiveMQ config file. 33 | * 34 | * @return a list of all the cluster node's addresses 35 | */ 36 | ListenableFuture> getNodeAddresses(); 37 | 38 | /** 39 | * Gets called when the cluster is shut down. 40 | *

41 | * This method can be used to unregister this HiveMQ instance from a central registry. 42 | */ 43 | void destroy(); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/cluster/ClusterNodeAddress.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.callback.cluster; 2 | 3 | import com.hivemq.spi.annotations.Immutable; 4 | 5 | /** 6 | * Represents a cluster node's address 7 | * 8 | * @author Christoph Schäbel 9 | * @since 3.1 10 | */ 11 | @Immutable 12 | public class ClusterNodeAddress { 13 | 14 | private final String host; 15 | private final int port; 16 | 17 | /** 18 | * @param host the hostname or IP of the cluster node 19 | * @param port the cluster bind-port of the cluster node 20 | */ 21 | public ClusterNodeAddress(final String host, final int port) { 22 | this.host = host; 23 | this.port = port; 24 | } 25 | 26 | public String getHost() { 27 | return host; 28 | } 29 | 30 | public int getPort() { 31 | return port; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/events/BeforePublishSendCallback.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.callback.events; 2 | 3 | import com.hivemq.spi.callback.SynchronousCallback; 4 | import com.hivemq.spi.callback.exception.BeforePublishSendException; 5 | import com.hivemq.spi.message.ModifiablePUBLISH; 6 | import com.hivemq.spi.message.PUBLISH; 7 | import com.hivemq.spi.security.ClientData; 8 | 9 | /** 10 | * Gets called just before a {@link PUBLISH} message is sent to a client. 11 | *

12 | * This callback gets called very often, be sure to have a efficient implementation. 13 | *

14 | * This callback allows the modification of MQTT {@link PUBLISH} messages at the last moment before they are sent to the client. 15 | *

16 | * If more than one BeforePublishSendCallback is registered, they will get called ordered by decreasing {@link com.hivemq.spi.callback.CallbackPriority}. If an exception is thrown in a {@link BeforePublishSendCallback}, all pending callbacks will not be executed. 17 | * 18 | * @author Georg Held 19 | * @author Christoph Schaebel 20 | * @since 3.3 21 | */ 22 | public interface BeforePublishSendCallback extends SynchronousCallback { 23 | 24 | /** 25 | * @param publish A {@link ModifiablePUBLISH} that will be sent to the client or the result of BeforePublishSendCallbacks with higher {@link com.hivemq.spi.callback.CallbackPriority}. 26 | * @param clientData The client {@link ClientData} for the client, to which this {@link PUBLISH} will be sent to. 27 | * @throws BeforePublishSendException if the underlying PUBLISH should be dropped. All pending {@link BeforePublishSendCallback}s will not be executed. 28 | */ 29 | void beforePublishSend(ModifiablePUBLISH publish, ClientData clientData) throws BeforePublishSendException; 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/events/OnConnectCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.events; 18 | 19 | import com.hivemq.spi.callback.SynchronousCallback; 20 | import com.hivemq.spi.callback.exception.RefusedConnectionException; 21 | import com.hivemq.spi.message.CONNECT; 22 | import com.hivemq.spi.security.ClientData; 23 | import com.hivemq.spi.callback.security.OnAuthenticationCallback; 24 | import com.hivemq.spi.message.CONNACK; 25 | import com.hivemq.spi.message.ReturnCode; 26 | 27 | /** 28 | * This callback is called when a CONNECT MQTT message arrives. 29 | *

30 | * This callback is called after successful {@link OnAuthenticationCallback}s. 31 | * That means, when this callback gets executed, Authentication already took place 32 | *

33 | * This callback is not designed to be used for performing authentication. 34 | * Use {@link OnAuthenticationCallback} for this 35 | * purpose 36 | * 37 | * @author Dominik Obermaier 38 | * @author Christian Goetz 39 | * @since 1.4 40 | */ 41 | public interface OnConnectCallback extends SynchronousCallback { 42 | 43 | /** 44 | * This method gets called when a {@link CONNECT} message arrives. 45 | * 46 | * @param connect the {@link CONNECT} object which arrived 47 | * @param clientData information about the authenticated/anonymous client 48 | * @throws RefusedConnectionException if the client should be disconnected with a 49 | * {@link CONNACK} with a specific 50 | * {@link ReturnCode} 51 | */ 52 | void onConnect(CONNECT connect, ClientData clientData) throws RefusedConnectionException; 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/events/OnDisconnectCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.events; 18 | 19 | import com.hivemq.spi.callback.AsynchronousCallback; 20 | import com.hivemq.spi.message.DISCONNECT; 21 | import com.hivemq.spi.security.ClientData; 22 | 23 | /** 24 | * This callback gets called when a client disconnects gracefully with a 25 | * {@link DISCONNECT} message or when disconnects 26 | * abruptly by closing the TCP connection . 27 | * 28 | * @author Dominik Obermaier 29 | * @author Christian Goetz 30 | * @since 1.4 31 | */ 32 | public interface OnDisconnectCallback extends AsynchronousCallback { 33 | 34 | 35 | /** 36 | * @param clientData client information 37 | * @param abruptAbort when true the TCP connection was closed before 38 | * and no {@link DISCONNECT} 39 | * message was sent 40 | */ 41 | void onDisconnect(ClientData clientData, boolean abruptAbort); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/events/OnPublishSend.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.events; 18 | 19 | import com.hivemq.spi.callback.AsynchronousCallback; 20 | import com.hivemq.spi.message.PUBLISH; 21 | import com.hivemq.spi.security.ClientData; 22 | 23 | /** 24 | * Gets called when an outgoing PUBLISH message event occurs. 25 | * That means, the callback always gets called when a subscribing client is going 26 | * to receive a message 27 | *

28 | * This callback is called VERY often, so make sure you don't block and use proper caching 29 | * 30 | * @author Christian Goetz 31 | * @since 1.4 32 | */ 33 | public interface OnPublishSend extends AsynchronousCallback { 34 | 35 | /** 36 | * Gets called when a PUBLISH is sent by HiveMQ to a subscribing client. 37 | * 38 | * @param publish the PUBLISH message 39 | * @param clientData the information about the client 40 | */ 41 | void onPublishSend(PUBLISH publish, ClientData clientData); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/events/OnSessionReadyCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.events; 18 | 19 | import com.hivemq.spi.callback.SynchronousCallback; 20 | import com.hivemq.spi.security.ClientData; 21 | 22 | /** 23 | * This callback gets called once the MQTT Session is ready for a client. This callback gets called once the MQTT Session for the client is ready to be used. This is guaranteed to happen before the client receives a MQTT {@link com.hivemq.spi.message.CONNACK} message. 24 | *

25 | * It gets called for all clients regardless of the value of the clean-session flag or the existence of a previous session.. 26 | * 27 | * @author Georg Held 28 | * @since 3.3.0 29 | */ 30 | public interface OnSessionReadyCallback extends SynchronousCallback { 31 | 32 | /** 33 | * This method gets called once the MQTT Session for the client is ready to be used. 34 | * 35 | * @param clientData information about the client. 36 | */ 37 | public void onSessionReady(final ClientData clientData); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/events/OnSubscribeCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.events; 18 | 19 | import com.hivemq.spi.callback.SynchronousCallback; 20 | import com.hivemq.spi.callback.exception.InvalidSubscriptionException; 21 | import com.hivemq.spi.message.SUBSCRIBE; 22 | import com.hivemq.spi.security.ClientData; 23 | import com.hivemq.spi.callback.security.OnAuthorizationCallback; 24 | 25 | /** 26 | * Gets called when a {@link SUBSCRIBE} message arrives 27 | *

28 | * When a subscription was invalid it's possible to throw a 29 | * {@link InvalidSubscriptionException}. 30 | *

31 | * Please note that the recommended way to handle Topic Permissions is 32 | * to use the {@link OnAuthorizationCallback}. 33 | * 34 | * @author Dominik Obermaier 35 | * @since 1.4 36 | */ 37 | public interface OnSubscribeCallback extends SynchronousCallback { 38 | 39 | 40 | /** 41 | * Called when a {@link SUBSCRIBE} message arrives. 42 | * 43 | * @param message the SUBSCRIBE message 44 | * @param clientData the information about the client 45 | * @throws InvalidSubscriptionException when a subscription was invalid 46 | */ 47 | void onSubscribe(SUBSCRIBE message, ClientData clientData) throws InvalidSubscriptionException; 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/events/OnTopicSubscriptionCallback.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.callback.events; 2 | 3 | import com.hivemq.spi.callback.SynchronousCallback; 4 | import com.hivemq.spi.message.SubackReturnCode; 5 | import com.hivemq.spi.message.Topic; 6 | import com.hivemq.spi.security.ClientData; 7 | 8 | /** 9 | * This callback returns the {@link SubackReturnCode} for a {@link Topic} and a {@link ClientData}. 10 | *

11 | * This callback is called after the {@link com.hivemq.spi.callback.security.OnAuthorizationCallback} but before the {@link OnSubscribeCallback}. 12 | * When more {@link OnTopicSubscriptionCallback}s are added the one that fires last (with the least priority) 13 | * has the final say. 14 | * It is possible to override the MQTT specification 15 | * for SUBACK payloads with this callback. 16 | *

17 | * This callback is called once for every topic for every SUBSCRIBE, 18 | * it is highly recommended to make the implementation as efficient as possible. 19 | * 20 | * @author Georg Held 21 | * @since 3.2 22 | */ 23 | public interface OnTopicSubscriptionCallback extends SynchronousCallback { 24 | 25 | /** 26 | * Returns a {@link SubackReturnCode} for a {@link Topic}, a previous {@link SubackReturnCode} and a {@link ClientData}. 27 | * 28 | * @param topic the topic to which the client wants to subscribe 29 | * @param authorizationResult the result of a {@link OnTopicSubscriptionCallback} with higher priority if available, 30 | * or of the {@link com.hivemq.spi.callback.security.OnAuthorizationCallback}s if available, 31 | * or the QoS the client requested. 32 | * @param clientData information about the client 33 | * @return the {@link SubackReturnCode} that corresponds to the topic in the {@link com.hivemq.spi.message.SUBACK} to be sent to the client, 34 | * a good default would be authorizationResult 35 | */ 36 | SubackReturnCode getSubackReturnCodeForClient(final Topic topic, final SubackReturnCode authorizationResult, final ClientData clientData); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/events/OnUnsubscribeCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.events; 18 | 19 | import com.hivemq.spi.callback.AsynchronousCallback; 20 | import com.hivemq.spi.message.UNSUBSCRIBE; 21 | import com.hivemq.spi.security.ClientData; 22 | 23 | /** 24 | * A callback which gets called when an UNSUBSCRIBE MQTT message arrives. 25 | * 26 | * @author Dominik Obermaier 27 | * @since 1.4 28 | */ 29 | public interface OnUnsubscribeCallback extends AsynchronousCallback { 30 | 31 | 32 | /** 33 | * Gets called when an UNSUBSCRIBE MQTT message arrives 34 | * 35 | * @param message the {@link UNSUBSCRIBE} message 36 | * @param clientData information about the client 37 | */ 38 | void onUnsubscribe(UNSUBSCRIBE message, ClientData clientData); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/events/broker/OnBrokerReady.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.callback.events.broker; 2 | 3 | import com.hivemq.spi.callback.SynchronousCallback; 4 | import com.hivemq.spi.callback.exception.IllegalBrokerStateException; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * *This callback gets called once the broker is started, after network interfaces are bound 10 | * and after a possible cluster join was executed. 11 | *

12 | * The broker will suspend all incoming client connections until the last executed OnBrokerReady callback returns. 13 | *

14 | * To signal HiveMQ, that a immediate shutdown is necessary, throw a {@link IllegalBrokerStateException} 15 | * 16 | * @author Georg Held 17 | * @since 3.3 18 | */ 19 | public interface OnBrokerReady extends SynchronousCallback { 20 | 21 | /** 22 | * Called, once the broker is ready 23 | * 24 | * @throws IllegalBrokerStateException if the broker is in a non recoverable state 25 | */ 26 | public void onBrokerReady() throws IllegalBrokerStateException; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/events/broker/OnBrokerStart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.events.broker; 18 | 19 | import com.hivemq.spi.callback.SynchronousCallback; 20 | import com.hivemq.spi.callback.exception.BrokerUnableToStartException; 21 | 22 | /** 23 | * This callback gets called when the broker starts but before network interfaces are bound 24 | * and before other bootstrapping actions take place. 25 | *

26 | * To prevent HiveMQ from starting, throw a {@link BrokerUnableToStartException} 27 | * 28 | * @author Dominik Obermaier 29 | * @since 1.4 30 | */ 31 | public interface OnBrokerStart extends SynchronousCallback { 32 | 33 | /** 34 | * Called when the broker starts up 35 | * 36 | * @throws BrokerUnableToStartException when the broker must not be started 37 | * because some preconditions are not satisfied 38 | */ 39 | void onBrokerStart() throws BrokerUnableToStartException; 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/events/broker/OnBrokerStop.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.events.broker; 18 | 19 | import com.hivemq.spi.callback.SynchronousCallback; 20 | 21 | /** 22 | * This callback gets executed when the broker shuts down. 23 | * At the time this callback gets executed, all connections are already closed 24 | * and there is no way to prevent HiveMQ from shutting down. 25 | *

26 | * It is recommended to do blocking actions in this callback because the VM 27 | * could quit before your asynchronous actions are finished 28 | * 29 | * @author Dominik Obermaier 30 | * @since 1.4 31 | */ 32 | public interface OnBrokerStop extends SynchronousCallback { 33 | 34 | /** 35 | * Called when the broker shuts down 36 | *

37 | * You can use blocking actions in this callback. 38 | */ 39 | void onBrokerStop(); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/exception/AuthenticationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.exception; 18 | 19 | import com.hivemq.spi.message.ReturnCode; 20 | import com.hivemq.spi.callback.security.OnAuthenticationCallback; 21 | 22 | /** 23 | * Indicates that the authentication of a certain client failed. 24 | * As a consequence the client gets disconnected from the broker. 25 | * The return code, which is sent back to the client, signals what 26 | * the cause of the failed authentication is. For a complete list of 27 | * return codes see {@link ReturnCode}. 28 | *

29 | * This exception should be used in an implementation of 30 | * {@link OnAuthenticationCallback} 31 | * 32 | * @author Christian Goetz 33 | * @since 1.4 34 | */ 35 | public class AuthenticationException extends Exception { 36 | 37 | private ReturnCode returnCode; 38 | 39 | public AuthenticationException(final ReturnCode returnCode) { 40 | super(); 41 | this.returnCode = returnCode; 42 | } 43 | 44 | public AuthenticationException(final String message, final ReturnCode returnCode) { 45 | super(message); 46 | this.returnCode = returnCode; 47 | } 48 | 49 | public ReturnCode getReturnCode() { 50 | return returnCode; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/exception/BeforePublishSendException.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.callback.exception; 2 | 3 | /** 4 | * This exception is used to signal in the {@link com.hivemq.spi.callback.events.BeforePublishSendCallback} that the PUBLISH should not be sent. 5 | * 6 | * @author Georg Held 7 | * @since 3.3 8 | */ 9 | public class BeforePublishSendException extends Exception { 10 | 11 | /** 12 | * This is a helper constant for a {@link BeforePublishSendException}. 13 | */ 14 | private static BeforePublishSendException INSTANCE = new BeforePublishSendException(); 15 | 16 | /** 17 | * Use this method if you need a {@link BeforePublishSendException}, it is more performant than the usage of a Constructor. 18 | * 19 | * @return a singleton {@link BeforePublishSendException} exception 20 | */ 21 | public static BeforePublishSendException getInstance() { 22 | return INSTANCE; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/exception/BrokerUnableToStartException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.exception; 18 | 19 | import com.hivemq.spi.callback.events.broker.OnBrokerStart; 20 | 21 | /** 22 | * Indicates that the broker is unable to start because some preconditions 23 | * for a safe startup are not satisfied. 24 | *

25 | * This exception should be used in an implementation of 26 | * {@link OnBrokerStart} 27 | * 28 | * @author Dominik Obermaier 29 | * @since 1.4 30 | */ 31 | public class BrokerUnableToStartException extends Exception { 32 | 33 | public BrokerUnableToStartException() { 34 | super(); 35 | } 36 | 37 | public BrokerUnableToStartException(final String message) { 38 | super(message); 39 | } 40 | 41 | public BrokerUnableToStartException(final String message, final Throwable cause) { 42 | super(message, cause); 43 | } 44 | 45 | public BrokerUnableToStartException(final Throwable cause) { 46 | super(cause); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/exception/IllegalBrokerStateException.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.callback.exception; 2 | 3 | /** 4 | * Indicates that the broker should stop immediately because something in its current 5 | * state prevents a safe operation. 6 | *

7 | * This exception should be used in an implementation of 8 | * {@link com.hivemq.spi.callback.events.broker.OnBrokerReady} 9 | * 10 | * @author Georg Held 11 | * @since 3.3 12 | */ 13 | public class IllegalBrokerStateException extends Exception { 14 | 15 | public IllegalBrokerStateException() { 16 | } 17 | 18 | public IllegalBrokerStateException(final String message) { 19 | super(message); 20 | } 21 | 22 | public IllegalBrokerStateException(final String message, final Throwable cause) { 23 | super(message, cause); 24 | } 25 | 26 | public IllegalBrokerStateException(final Throwable cause) { 27 | super(cause); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/exception/InvalidSubscriptionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.exception; 18 | 19 | import com.hivemq.spi.message.SUBSCRIBE; 20 | 21 | /** 22 | * An exception which can be thrown when one or more subscriptions 23 | * in the {@link SUBSCRIBE} message was invalid 24 | * 25 | * @author Dominik Obermaier 26 | * @since 1.4 27 | */ 28 | public class InvalidSubscriptionException extends Exception { 29 | 30 | public InvalidSubscriptionException() { 31 | super(); 32 | } 33 | 34 | public InvalidSubscriptionException(final String message) { 35 | super(message); 36 | } 37 | 38 | public InvalidSubscriptionException(final String message, final Throwable cause) { 39 | super(message, cause); 40 | } 41 | 42 | public InvalidSubscriptionException(final Throwable cause) { 43 | super(cause); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/exception/InvalidTTLException.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.callback.exception; 2 | 3 | 4 | /** 5 | * An exception which is thrown when the time to live was invalid (< -1). 6 | * 7 | * @author Waldemar Ruck 8 | * @since 3.4 9 | */ 10 | public class InvalidTTLException extends RuntimeException { 11 | 12 | public InvalidTTLException() { 13 | super(); 14 | } 15 | 16 | public InvalidTTLException(final String message) { 17 | super(message); 18 | } 19 | 20 | public InvalidTTLException(final String message, final Throwable cause) { 21 | super(message, cause); 22 | } 23 | 24 | public InvalidTTLException(final Throwable cause) { 25 | super(cause); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/exception/LimitExceededException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.exception; 18 | 19 | /** 20 | * Unchecked Exception which is thrown when a limit is exceeded by a passed parameter 21 | * 22 | * @author Christoph Schäbel 23 | * @since 3.3 24 | */ 25 | public class LimitExceededException extends RuntimeException { 26 | 27 | public LimitExceededException() { 28 | } 29 | 30 | public LimitExceededException(final String message) { 31 | super(message); 32 | } 33 | 34 | public LimitExceededException(final String message, final Throwable cause) { 35 | super(message, cause); 36 | } 37 | 38 | public LimitExceededException(final Throwable cause) { 39 | super(cause); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/exception/OnPublishReceivedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.exception; 18 | 19 | /** 20 | * This exception can be thrown when a PUBLISH arrives but the PUBLISH is invalid. 21 | *

22 | * It's possible to disconnect the client when passing true as parameter. 23 | * 24 | * @author Dominik Obermaier 25 | * @since 1.4 26 | */ 27 | public class OnPublishReceivedException extends Exception { 28 | 29 | private final boolean disconnectClient; 30 | 31 | public OnPublishReceivedException(final boolean disconnectClient) { 32 | super(); 33 | this.disconnectClient = disconnectClient; 34 | } 35 | 36 | public OnPublishReceivedException(final String message, final boolean disconnectClient) { 37 | super(message); 38 | this.disconnectClient = disconnectClient; 39 | } 40 | 41 | public OnPublishReceivedException(final String message, final Throwable cause, final boolean disconnectClient) { 42 | super(message, cause); 43 | this.disconnectClient = disconnectClient; 44 | } 45 | 46 | public OnPublishReceivedException(final Throwable cause, final boolean disconnectClient) { 47 | super(cause); 48 | this.disconnectClient = disconnectClient; 49 | } 50 | 51 | /** 52 | * @return if the client should be disconnected 53 | */ 54 | public boolean getDisconnectClient() { 55 | return disconnectClient; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/exception/RefusedConnectionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.exception; 18 | 19 | import com.hivemq.spi.message.ReturnCode; 20 | import com.hivemq.spi.message.CONNACK; 21 | import com.hivemq.spi.message.CONNECT; 22 | 23 | /** 24 | * An exception which can be used to refuse a {@link CONNECT} 25 | * MQTT message and send (+ disconnect) the client with a {@link CONNACK} 26 | * including a specific {@link ReturnCode} 27 | * 28 | * @author Dominik Obermaier 29 | * @since 1.4 30 | */ 31 | public class RefusedConnectionException extends Exception { 32 | 33 | private ReturnCode returnCode; 34 | 35 | public RefusedConnectionException(final ReturnCode returnCode) { 36 | super(); 37 | this.returnCode = returnCode; 38 | } 39 | 40 | public RefusedConnectionException(final String message, final ReturnCode returnCode) { 41 | super(message); 42 | this.returnCode = returnCode; 43 | } 44 | 45 | public RefusedConnectionException(final String message, final ReturnCode returnCode, final Throwable cause) { 46 | super(message, cause); 47 | this.returnCode = returnCode; 48 | } 49 | 50 | public RefusedConnectionException(final ReturnCode returnCode, final Throwable cause) { 51 | super(cause); 52 | this.returnCode = returnCode; 53 | } 54 | 55 | public ReturnCode getReturnCode() { 56 | return returnCode; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "RefusedConnectionException{" + 62 | "returnCode=" + returnCode + 63 | '}'; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/lowlevel/OnConnackSend.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.lowlevel; 18 | 19 | import com.hivemq.spi.callback.AsynchronousCallback; 20 | import com.hivemq.spi.callback.LowlevelCallback; 21 | import com.hivemq.spi.message.CONNACK; 22 | import com.hivemq.spi.security.ClientData; 23 | 24 | /** 25 | * The OnConnackSend Callback gets called when the broker sent 26 | * a CONNACK message to a client 27 | * 28 | * @author Christian Goetz 29 | * @since 1.4 30 | */ 31 | public interface OnConnackSend extends AsynchronousCallback, LowlevelCallback { 32 | 33 | /** 34 | * This method gets called after a CONNACK message was sent to the client. 35 | *

36 | * This method does not allow to interfere with the CONNACK message and is just 37 | * for information that this CONNACK message was sent. 38 | * 39 | * @param connack the CONNACK message 40 | * @param clientData the clientData 41 | */ 42 | void onConnackSend(CONNACK connack, ClientData clientData); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/lowlevel/OnPingCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.lowlevel; 18 | 19 | import com.hivemq.spi.callback.AsynchronousCallback; 20 | import com.hivemq.spi.callback.LowlevelCallback; 21 | import com.hivemq.spi.security.ClientData; 22 | 23 | /** 24 | * The OnPingCallback which gets called after a client sent a PINGREQ message 25 | * 26 | * @author Christian Goetz 27 | * @since 1.4 28 | */ 29 | public interface OnPingCallback extends AsynchronousCallback, LowlevelCallback { 30 | 31 | /** 32 | * This method gets called after the broker received a PINGREQ message from a client. 33 | *

34 | * This callback does not allow to interfere with the heartbeat mechanism and is for information 35 | * purposes only. 36 | * 37 | * @param clientData the ClientData of the client which sent the PINGREQ message 38 | */ 39 | void onPingReceived(ClientData clientData); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/lowlevel/OnPubackReceived.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.lowlevel; 18 | 19 | import com.hivemq.spi.callback.AsynchronousCallback; 20 | import com.hivemq.spi.callback.LowlevelCallback; 21 | import com.hivemq.spi.message.PUBACK; 22 | import com.hivemq.spi.security.ClientData; 23 | 24 | /** 25 | * This callback gets called after a PUBACK message was received from a client 26 | * 27 | * @author Christian Goetz 28 | * @since 1.4 29 | */ 30 | public interface OnPubackReceived extends AsynchronousCallback, LowlevelCallback { 31 | 32 | /** 33 | * This method gets called every time a client sent a PUBACK message. This callback does not allow 34 | * to interfere with HiveMQ and is for information purposes only 35 | * 36 | * @param puback the PUBACK message which was received by HiveMQ 37 | * @param clientData the ClientData of the client which sent the PUBACK message 38 | */ 39 | void onPubackReceived(PUBACK puback, ClientData clientData); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/lowlevel/OnPubackSend.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.lowlevel; 18 | 19 | import com.hivemq.spi.callback.AsynchronousCallback; 20 | import com.hivemq.spi.callback.LowlevelCallback; 21 | import com.hivemq.spi.message.PUBACK; 22 | import com.hivemq.spi.security.ClientData; 23 | 24 | /** 25 | * The OnPubackSend callback gets called after HiveMQ sent a PUBACK message to a client 26 | * 27 | * @author Christian Goetz 28 | * @since 1.4 29 | */ 30 | public interface OnPubackSend extends AsynchronousCallback, LowlevelCallback { 31 | 32 | /** 33 | * This method gets called after HiveMQ sent a PUBACK message to a client. This callback does not allow 34 | * to interfere with HiveMQ and is for information purposes only. 35 | * 36 | * @param puback the PUBACK message sent by HiveMQ 37 | * @param clientData the ClientData of the client HiveMQ sent the PUBACK to 38 | */ 39 | void onPubackSend(PUBACK puback, ClientData clientData); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/lowlevel/OnPubcompReceived.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.lowlevel; 18 | 19 | import com.hivemq.spi.callback.AsynchronousCallback; 20 | import com.hivemq.spi.callback.LowlevelCallback; 21 | import com.hivemq.spi.message.PUBCOMP; 22 | import com.hivemq.spi.security.ClientData; 23 | 24 | /** 25 | * The OnPubcompReceived Callback gets called after HiveMQ receives a PUBCOMP 26 | * message from a client. 27 | * 28 | * @author Christian Goetz 29 | * @since 1.4 30 | */ 31 | public interface OnPubcompReceived extends AsynchronousCallback, LowlevelCallback { 32 | 33 | /** 34 | * This method gets called when a PUBCOMP message is received from a client. It's not possible 35 | * to interfere with HiveMQ and this callback is for information purposes 36 | * 37 | * @param pubcomp the PUBCOMP message which was received by HiveMQ 38 | * @param clientData the ClientData for the client which sent the PUBCOMP message 39 | */ 40 | void onPubcompReceived(PUBCOMP pubcomp, ClientData clientData); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/lowlevel/OnPubcompSend.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.lowlevel; 18 | 19 | import com.hivemq.spi.callback.AsynchronousCallback; 20 | import com.hivemq.spi.callback.LowlevelCallback; 21 | import com.hivemq.spi.message.PUBCOMP; 22 | import com.hivemq.spi.security.ClientData; 23 | 24 | /** 25 | * The OnPubcompSend callback gets executed after a PUBCOMP message was sent by HiveMQ 26 | * to a client. 27 | * 28 | * @author Christian Goetz 29 | * @since 1.4 30 | */ 31 | public interface OnPubcompSend extends AsynchronousCallback, LowlevelCallback { 32 | 33 | /** 34 | * This method gets called when HiveMQ sends a PUBCOMP message to a client. It's not possible to interfere 35 | * with HiveMQ in this callback and this callback is for information purposes only 36 | * 37 | * @param pubcomp the PUBCOMP message HiveMQ sends to a client 38 | * @param clientData the ClientData for the client HiveMQ sends the PUBCOMP message to 39 | */ 40 | void onPubcompSend(PUBCOMP pubcomp, ClientData clientData); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/lowlevel/OnPubrecReceived.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.lowlevel; 18 | 19 | import com.hivemq.spi.callback.AsynchronousCallback; 20 | import com.hivemq.spi.callback.LowlevelCallback; 21 | import com.hivemq.spi.message.PUBREC; 22 | import com.hivemq.spi.security.ClientData; 23 | 24 | /** 25 | * The OnPubrecReceived Callback gets called after HiveMQ receives a PUBREC 26 | * message from a client. 27 | * 28 | * @author Christian Goetz 29 | * @since 1.4 30 | */ 31 | public interface OnPubrecReceived extends AsynchronousCallback, LowlevelCallback { 32 | 33 | /** 34 | * This method gets called when a PUBREC message is received from a client. It's not possible 35 | * to interfere with HiveMQ and this callback is for information purposes 36 | * 37 | * @param pubrec the PUBREC message which was received by HiveMQ 38 | * @param clientData the ClientData for the client which sent the PUBREC message 39 | */ 40 | void onPubrecReceived(PUBREC pubrec, ClientData clientData); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/lowlevel/OnPubrecSend.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.lowlevel; 18 | 19 | import com.hivemq.spi.callback.AsynchronousCallback; 20 | import com.hivemq.spi.callback.LowlevelCallback; 21 | import com.hivemq.spi.message.PUBREC; 22 | import com.hivemq.spi.security.ClientData; 23 | 24 | /** 25 | * The OnPubrecSend callback gets executed after a PUBREC message was sent by HiveMQ 26 | * to a client. 27 | * 28 | * @author Christian Goetz 29 | * @since 1.4 30 | */ 31 | public interface OnPubrecSend extends AsynchronousCallback, LowlevelCallback { 32 | 33 | /** 34 | * This method gets called when HiveMQ sends a PUBREC message to a client. It's not possible to interfere 35 | * with HiveMQ in this callback and this callback is for information purposes only 36 | * 37 | * @param pubrec the PUBREC message HiveMQ sends to a client 38 | * @param clientData the ClientData for the client HiveMQ sends the PUBREC message to 39 | */ 40 | void onPubrecSend(PUBREC pubrec, ClientData clientData); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/lowlevel/OnPubrelReceived.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.lowlevel; 18 | 19 | import com.hivemq.spi.callback.AsynchronousCallback; 20 | import com.hivemq.spi.callback.LowlevelCallback; 21 | import com.hivemq.spi.message.PUBREL; 22 | import com.hivemq.spi.security.ClientData; 23 | 24 | /** 25 | * The OnPubrelReceived Callback gets called after HiveMQ receives a PUBREL 26 | * message from a client. 27 | * 28 | * @author Christian Goetz 29 | * @since 1.4 30 | */ 31 | public interface OnPubrelReceived extends AsynchronousCallback, LowlevelCallback { 32 | 33 | /** 34 | * This method gets called when a PUBREL message is received from a client. It's not possible 35 | * to interfere with HiveMQ and this callback is for information purposes 36 | * 37 | * @param pubrel the PUBREL message which was received by HiveMQ 38 | * @param clientData the ClientData for the client which sent the PUBREL message 39 | */ 40 | void onPubrelReceived(PUBREL pubrel, ClientData clientData); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/lowlevel/OnPubrelSend.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.lowlevel; 18 | 19 | import com.hivemq.spi.callback.AsynchronousCallback; 20 | import com.hivemq.spi.callback.LowlevelCallback; 21 | import com.hivemq.spi.message.PUBREL; 22 | import com.hivemq.spi.security.ClientData; 23 | 24 | /** 25 | * The OnPubrelSend callback gets executed after a PUBREL message was sent by HiveMQ 26 | * to a client. 27 | * 28 | * @author Christian Goetz 29 | * @since 1.4 30 | */ 31 | public interface OnPubrelSend extends AsynchronousCallback, LowlevelCallback { 32 | 33 | /** 34 | * This method gets called when HiveMQ sends a PUBREL message to a client. It's not possible to interfere 35 | * with HiveMQ in this callback and this callback is for information purposes only 36 | * 37 | * @param pubrel the PUBREL message HiveMQ sends to a client 38 | * @param clientData the ClientData for the client HiveMQ sends the PUBREL message to 39 | */ 40 | void onPubrelSend(PUBREL pubrel, ClientData clientData); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/lowlevel/OnSubackSend.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.lowlevel; 18 | 19 | import com.hivemq.spi.callback.AsynchronousCallback; 20 | import com.hivemq.spi.callback.LowlevelCallback; 21 | import com.hivemq.spi.message.SUBACK; 22 | import com.hivemq.spi.security.ClientData; 23 | 24 | /** 25 | * The OnSubackSend callback gets called after HiveMQ sends a SUBACK message to a client. It's not possible to interfere 26 | * with HiveMQ in this callback and this callback is for information purposes only 27 | * 28 | * @author Christian Goetz 29 | * @since 1.4 30 | */ 31 | public interface OnSubackSend extends AsynchronousCallback, LowlevelCallback { 32 | 33 | /** 34 | * This method is called after HiveMQ sends a SUBACK message to a client. It's not possible to interfere with HiveMQ 35 | * in this callback and this callback is for information purposes only 36 | * 37 | * @param suback the SUBACK message HiveMQ sends to the client 38 | * @param clientData the ClientData of the client HiveMQ sends the message to 39 | */ 40 | void onSubackSend(SUBACK suback, ClientData clientData); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/lowlevel/OnUnsubackSend.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.lowlevel; 18 | 19 | import com.hivemq.spi.callback.AsynchronousCallback; 20 | import com.hivemq.spi.callback.LowlevelCallback; 21 | import com.hivemq.spi.message.UNSUBACK; 22 | import com.hivemq.spi.security.ClientData; 23 | 24 | /** 25 | * The OnUnsubackSend callback gets called after HiveMQ sends a UNSUBACK message to a client. It's not possible to interfere 26 | * with HiveMQ in this callback and this callback is for information purposes only 27 | * 28 | * @author Christian Goetz 29 | * @since 1.4 30 | */ 31 | public interface OnUnsubackSend extends AsynchronousCallback, LowlevelCallback { 32 | 33 | /** 34 | * This method is called after HiveMQ sends a UNSUBACK message to a client. It's not possible to interfere with HiveMQ 35 | * in this callback and this callback is for information purposes only 36 | * 37 | * @param unsuback the UNSUBACK message HiveMQ sends to the client 38 | * @param clientData the ClientData of the client HiveMQ sends the message to 39 | */ 40 | void onUnsubackSend(UNSUBACK unsuback, ClientData clientData); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/schedule/ScheduleExpressions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.schedule; 18 | 19 | import static com.google.common.base.Preconditions.checkArgument; 20 | import static java.text.MessageFormat.format; 21 | 22 | /** 23 | * This utility class has several methods and constants for working with quartz-style cron expressions. 24 | * 25 | * @author Dominik Obermaier 26 | */ 27 | public class ScheduleExpressions { 28 | 29 | /** 30 | * Returns the a Schedule Expression which schedules to the beginning of every minute 31 | */ 32 | public static final String ONCE_A_MINUTE = "0 0/1 * * * ?"; 33 | 34 | /** 35 | * Returns a quartz-style cron expression which is used to schedule something every X minutes. 36 | *

37 | * This is useful if you want to run a scheduled callback e.g. every 10 minutes. 38 | *

39 | * 40 | * @param minutes the minutes 41 | * @return the quartz-style cron expression for the number of minutes passed 42 | * @throws IllegalArgumentException if the number of minutes is < 1 43 | */ 44 | public static String everyMinutes(final int minutes) { 45 | final String minutePattern = "0 0/{0,number,#} * * * ?"; 46 | checkArgument(minutes > 0, "Only a number of minutes > 0 can be used for scheduling. %s was provided.", minutes); 47 | 48 | return format(minutePattern, minutes); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/schedule/ScheduledCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.schedule; 18 | 19 | 20 | import com.hivemq.spi.callback.AsynchronousCallback; 21 | import com.hivemq.spi.callback.registry.CallbackRegistry; 22 | 23 | /** 24 | * This callback gets called periodically based on the value provided in the 25 | * {@link ScheduledCallback#cronExpression()} method. 26 | *

27 | * This callback is especially useful for recurring tasks like maintenance tasks. 28 | * 29 | * @author Dominik Obermaier 30 | * @since 2.0 31 | */ 32 | public interface ScheduledCallback extends AsynchronousCallback { 33 | 34 | 35 | /** 36 | * This method gets executed on the given schedules 37 | */ 38 | void execute(); 39 | 40 | /** 41 | * This method returns the quartz-like cron expression for the callback. 42 | *

43 | * Note that this method only gets called once when adding the callback to the 44 | * {@link CallbackRegistry}. If you have dynamic 45 | * cron expressions in this method, you must manually call the 46 | * {@link CallbackRegistry#reloadScheduledCallbackExpression(ScheduledCallback)} 47 | * method in order to reload the expression 48 | * 49 | * @return a String which contains the quartz-like cron expressions. 50 | * @see 51 | * Documentation for quartz cron expressions 52 | */ 53 | String cronExpression(); 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/security/AfterLoginCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.security; 18 | 19 | import com.hivemq.spi.callback.AsynchronousCallback; 20 | import com.hivemq.spi.callback.exception.AuthenticationException; 21 | import com.hivemq.spi.security.ClientData; 22 | 23 | /** 24 | * The methods of this callback get called when a login attempt was made. Potential use cases for this callback are: 25 | *

26 | * - You want to log when someone tries to log in. 27 | * - Execute custom logic which should occur after a login attempt 28 | *

29 | * No authentication and authorization logic should be implemented here, 30 | * please use {@link OnAuthenticationCallback} or {@link OnAuthorizationCallback} for that purpose. 31 | * 32 | * @author Dominik Obermaier 33 | * @author Christian Goetz 34 | * @since 1.4 35 | */ 36 | public interface AfterLoginCallback extends AsynchronousCallback { 37 | 38 | /** 39 | * Called after a client was granted authentication 40 | * 41 | * @param clientData the information about the client 42 | */ 43 | void afterSuccessfulLogin(final ClientData clientData); 44 | 45 | /** 46 | * Called after a client was denied authentication 47 | * The client will be disconnected after calling this method. 48 | * 49 | * @param exception the exception which has details why the client had an unsuccessful login attempt or null if no exception was thrown. 50 | * @param clientData information about the client 51 | */ 52 | void afterFailedLogin(AuthenticationException exception, final ClientData clientData); 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/security/OnAuthenticationCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.security; 18 | 19 | import com.hivemq.spi.callback.SynchronousCallback; 20 | import com.hivemq.spi.callback.exception.AuthenticationException; 21 | import com.hivemq.spi.security.ClientCredentialsData; 22 | 23 | /** 24 | * This callback gets called when a CONNECT message arrives and is meant to 25 | * perform the authentication of a client. 26 | *

27 | * When more OnAuthenticationCallbacks are added only one must return 28 | * a positive result to successfully authenticate the client. 29 | *

30 | * If an {@link AuthenticationException} is thrown, no additional 31 | * credentials checks in other plugins are made and the client is 32 | * disconnected immediately with an CONNACK with the given return code. 33 | *

34 | * Note: It's your responsibility to use proper caching in the checkCredentials method 35 | * 36 | * @author Christian Goetz 37 | * @since 1.4 38 | */ 39 | public interface OnAuthenticationCallback extends SynchronousCallback { 40 | 41 | /** 42 | * Checks the credentials after a CONNECT message arrives. 43 | *

44 | * return true when the authentication with the credentials was successful, false otherwise 45 | * 46 | * @param clientData the client credentials 47 | * @return true when the authentication was successful 48 | * @throws AuthenticationException when you want the client to disconnect immediately with a given return code 49 | */ 50 | Boolean checkCredentials(ClientCredentialsData clientData) throws AuthenticationException; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/security/OnAuthorizationCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.security; 18 | 19 | import com.hivemq.spi.callback.SynchronousCallback; 20 | import com.hivemq.spi.callback.security.authorization.AuthorizationBehaviour; 21 | import com.hivemq.spi.security.ClientData; 22 | import com.hivemq.spi.topic.MqttTopicPermission; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * This callback returns a list of {@link MqttTopicPermission}s. 28 | *

29 | * When more OnAuthorizationCallbacks are added only one must return 30 | * a permission, which matches the required permission to successfully 31 | * authorize the client action. 32 | *

33 | * It is highly recommended to use proper caching as this callback is 34 | * called every time HiveMQ asks for the client permissions. 35 | * 36 | * @author Christian Goetz 37 | * @author Christoph Schäbel 38 | * @since 1.4 39 | */ 40 | public interface OnAuthorizationCallback extends SynchronousCallback { 41 | 42 | /** 43 | * Returns a list of {@link MqttTopicPermission}s for this client. 44 | *

45 | * Make sure you use proper caching of the returned values as this method will be called very often 46 | * 47 | * @param clientData information about the client 48 | * @return a list of {@link MqttTopicPermission}s for the given client 49 | */ 50 | List getPermissionsForClient(ClientData clientData); 51 | 52 | /** 53 | * Declares the default behaviour to use if none of the {@link MqttTopicPermission}s returned by getPermissionForClient matches an activity. 54 | * The default behaviour should be {@link AuthorizationBehaviour}.NEXT in most cases. 55 | * 56 | * @return the default behaviour to use if none of the {@link MqttTopicPermission}s matches an activity. 57 | */ 58 | AuthorizationBehaviour getDefaultBehaviour(); 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/security/OnInsufficientPermissionDisconnect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.security; 18 | 19 | import com.hivemq.spi.callback.AsynchronousCallback; 20 | import com.hivemq.spi.message.QoS; 21 | import com.hivemq.spi.security.ClientData; 22 | 23 | /** 24 | * This callback gets executed after a client was disconnected due to insufficient permissions. 25 | * 26 | * @author Dominik Obermaier 27 | * @author Christian Goetz 28 | * @since 1.4 29 | */ 30 | public interface OnInsufficientPermissionDisconnect extends AsynchronousCallback { 31 | 32 | /** 33 | * Gets executed after a client was disconnected due to insufficient permissions when publishing 34 | * 35 | * @param clientData information about the client 36 | * @param topic the topic the client wanted to publish to 37 | * @param qoS the quality of service the client wanted to publish with 38 | */ 39 | void onPublishDisconnect(ClientData clientData, String topic, QoS qoS); 40 | 41 | /** 42 | * Gets executed after a client was disconnected due to insufficient permissions when subscribing 43 | * 44 | * @param clientData information about the client 45 | * @param topic the topic the client wanted to publish to 46 | * @param qoS the quality of service the client wanted to publish with 47 | */ 48 | void onSubscribeDisconnect(ClientData clientData, String topic, QoS qoS); 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/security/RestrictionsAfterLoginCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.security; 18 | 19 | import com.hivemq.spi.callback.AsynchronousCallback; 20 | import com.hivemq.spi.security.ClientData; 21 | import com.hivemq.spi.security.Restriction; 22 | 23 | import java.util.Set; 24 | 25 | /** 26 | * This callback gets executed after a CONNECT message arrived and 27 | * the client was authenticated successfully. 28 | *

29 | * This callback provides {@link Restriction}s for a given client 30 | * which allows e.g. throttling. 31 | *

32 | * This callback is only executed once after a login 33 | * 34 | * @author Dominik Obermaier 35 | * @author Chrisitan Goetz 36 | * @author Christoph Schaebel 37 | * @since 1.4 38 | */ 39 | public interface RestrictionsAfterLoginCallback extends AsynchronousCallback { 40 | 41 | /** 42 | * Gets called after a successful login of a client. 43 | *

44 | * Provides {@link Restriction}s which allow e.g. throttling of a client 45 | * 46 | * @param clientData information about the client 47 | * @return a set of restrictions for the client 48 | */ 49 | Set getRestrictions(ClientData clientData); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/security/authorization/AuthorizationBehaviour.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.callback.security.authorization; 2 | 3 | /** 4 | * The Authorization behaviour which defines if 5 | * an authorization was granted, denied or if 6 | * another callback should be called 7 | * 8 | * @author Christoph Schäbel 9 | * @since 3.0 10 | */ 11 | public enum AuthorizationBehaviour { 12 | 13 | ACCEPT, 14 | DENY, 15 | NEXT 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/security/authorization/AuthorizationResult.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.callback.security.authorization; 2 | 3 | import com.hivemq.spi.annotations.NotNull; 4 | import com.hivemq.spi.topic.MqttTopicPermission; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * The Result of one OnAuthorizationCallback call 10 | * 11 | * @author Christoph Schäbel 12 | */ 13 | public interface AuthorizationResult { 14 | 15 | /** 16 | * A list of all topic permissions which are granted 17 | * 18 | * @return a list of topic permission 19 | */ 20 | List getMqttTopicPermissions(); 21 | 22 | /** 23 | * The default {@link AuthorizationBehaviour} if the getMqttTopicPermissions() method returns 24 | * an empty list. 25 | * 26 | * @return the deafult authorization behaviour 27 | */ 28 | @NotNull 29 | AuthorizationBehaviour getDefaultBehaviour(); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/callback/webui/WebUIAuthenticationCallback.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.callback.webui; 2 | 3 | import com.hivemq.spi.annotations.NotNull; 4 | import com.hivemq.spi.callback.Callback; 5 | import com.hivemq.spi.callback.SynchronousCallback; 6 | import com.hivemq.spi.callback.registry.CallbackRegistry; 7 | 8 | /** 9 | * This callback is called, when a web ui user is trying to log in. 10 | * 11 | * Use the {@link CallbackRegistry#addCallback(Callback)} method to add a WebUIAuthenticationCallback to HiveMQ. 12 | * 13 | * If multiple callbacks are registered, only the one with the highest priority is used. 14 | * 15 | * If no callback is registered, the credentials are validated against HiveMQ's config.xml 16 | * 17 | * @author Florian Limpöck 18 | * 19 | * @since 3.4.2 20 | */ 21 | public interface WebUIAuthenticationCallback extends SynchronousCallback { 22 | 23 | /** 24 | * Checks the credentials for a WebUI login. 25 | * 26 | * return {@link AuthenticationState#SUCCESS} when the authentication with the credentials was successful, 27 | * {@link AuthenticationState#FAILED} otherwise. 28 | * 29 | * @param username the username to check 30 | * @param password the password to check 31 | * 32 | **/ 33 | @NotNull AuthenticationState checkCredentials(final @NotNull String username, final @NotNull String password); 34 | 35 | enum AuthenticationState{ 36 | 37 | SUCCESS(0), FAILED(1); 38 | 39 | final int code; 40 | 41 | AuthenticationState(final int code) { 42 | this.code = code; 43 | } 44 | 45 | public AuthenticationState fromCode(final int code){ 46 | for (AuthenticationState value : values()) { 47 | if(value.code == code){ 48 | return value; 49 | } 50 | } 51 | throw new IllegalArgumentException("There is no AuthenticationState available for code: " + code); 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/config/SystemInformation.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.config; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * Useful information about HiveMQ and the underlying system 7 | * 8 | * @author Christoph Schäbel 9 | * @since 3.0 10 | */ 11 | public interface SystemInformation { 12 | 13 | /** 14 | * @return the version string of HiveMQ 15 | */ 16 | String getHiveMQVersion(); 17 | 18 | /** 19 | * @return the home folder of HiveMQ 20 | */ 21 | File getHiveMQHomeFolder(); 22 | 23 | /** 24 | * @return the plugin folder of HiveMQ 25 | */ 26 | File getPluginFolder(); 27 | 28 | /** 29 | * @return the config folder of HiveMQ 30 | */ 31 | File getConfigFolder(); 32 | 33 | /** 34 | * @return the log folder of HiveMQ 35 | */ 36 | File getLogFolder(); 37 | 38 | /** 39 | * @return the license folder of HiveMQ 40 | */ 41 | File getLicenseFolder(); 42 | 43 | /** 44 | * @return the data folder of HiveMQ 45 | */ 46 | File getDataFolder(); 47 | 48 | /** 49 | * @return the backup folder of HiveMQ 50 | */ 51 | File getBackupFolder(); 52 | 53 | /** 54 | * @return the timestamp of HiveMQ start 55 | */ 56 | long getRunningSince(); 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/exceptions/BridgeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.exceptions; 18 | 19 | /** 20 | * An exception which indicates that a bridge error occurred or a bridge configuration 21 | * was invalid 22 | * 23 | * @author Dominik Obermaier 24 | * @since 2.0 25 | */ 26 | public class BridgeException extends RuntimeException { 27 | public BridgeException(final String message) { 28 | super(message); 29 | } 30 | 31 | public BridgeException(final String message, final Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public BridgeException(Throwable cause) { 36 | super(cause); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/exceptions/UnrecoverableException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.exceptions; 18 | 19 | /** 20 | * An exception which indicates an unrecoverable state. 21 | *

22 | * HiveMQ will shut down gracefully when this exception is thrown 23 | * 24 | * @author Dominik Obermaier 25 | */ 26 | public class UnrecoverableException extends RuntimeException { 27 | 28 | private final boolean showException; 29 | 30 | 31 | public UnrecoverableException() { 32 | this(true); 33 | } 34 | 35 | public UnrecoverableException(boolean showException) { 36 | 37 | this.showException = showException; 38 | } 39 | 40 | public boolean isShowException() { 41 | return showException; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/DISCONNECT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.message; 18 | 19 | /** 20 | * @author Dominik Obermaier 21 | * @since 1.4 22 | */ 23 | public class DISCONNECT implements Message { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/Message.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.message; 18 | 19 | import java.io.Serializable; 20 | 21 | /** 22 | * @author Dominik Obermaier 23 | * @since 1.4 24 | */ 25 | public interface Message extends Serializable { 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/MessageType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.message; 18 | 19 | /** 20 | * @author Dominik Obermaier 21 | * @since 1.4 22 | */ 23 | public enum MessageType { 24 | RESERVED_ZERO(0), 25 | CONNECT(1), 26 | CONNACK(2), 27 | PUBLISH(3), 28 | PUBACK(4), 29 | PUBREC(5), 30 | PUBREL(6), 31 | PUBCOMP(7), 32 | SUBSCRIBE(8), 33 | SUBACK(9), 34 | UNSUBSCRIBE(10), 35 | UNSUBACK(11), 36 | PINGREQ(12), 37 | PINGRESP(13), 38 | DISCONNECT(14), 39 | RESERVED_15(15); 40 | 41 | private final int type; 42 | 43 | private MessageType(final int type) { 44 | 45 | this.type = type; 46 | } 47 | 48 | public static MessageType valueOf(final int i) { 49 | 50 | for (final MessageType messageType : MessageType.values()) { 51 | if (messageType.type == i) { 52 | return messageType; 53 | } 54 | } 55 | throw new IllegalArgumentException("Invalid Message Type: " + i); 56 | } 57 | 58 | public int getType() { 59 | return type; 60 | } 61 | } -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/MessageWithID.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.message; 18 | 19 | /** 20 | * @author Dominik Obermaier 21 | * @since 1.4 22 | */ 23 | public class MessageWithID implements Message { 24 | 25 | protected int messageId; 26 | 27 | public MessageWithID() { 28 | } 29 | 30 | MessageWithID(final int messageId) { 31 | this.messageId = messageId; 32 | } 33 | 34 | public int getMessageId() { 35 | return messageId; 36 | } 37 | 38 | public void setMessageId(final int messageId) { 39 | this.messageId = messageId; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/PINGREQ.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.message; 18 | 19 | /** 20 | * The MQTT PINGREQ message 21 | * 22 | * @author Dominik Obermaier 23 | * @since 1.4 24 | */ 25 | public class PINGREQ implements Message { 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/PINGRESP.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.message; 18 | 19 | /** 20 | * The MQTT PINGRESP message 21 | * 22 | * @author Dominik Obermaier 23 | * @since 1.4 24 | */ 25 | public class PINGRESP implements Message { 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/PUBACK.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.message; 18 | 19 | /** 20 | * The MQTT PUBACK message 21 | * 22 | * @author Dominik Obermaier 23 | * @since 1.4 24 | */ 25 | public class PUBACK extends MessageWithID { 26 | 27 | public PUBACK(final int messageId) { 28 | super(messageId); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/PUBCOMP.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.message; 18 | 19 | /** 20 | * The MQTT PUBCOMP message 21 | * 22 | * @author Dominik Obermaier 23 | * @since 1.4 24 | */ 25 | public class PUBCOMP extends MessageWithID { 26 | 27 | 28 | public PUBCOMP(final int messageId) { 29 | super(messageId); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/PUBREC.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.message; 18 | 19 | /** 20 | * The MQTT PUBREC message 21 | * 22 | * @author Dominik Obermaier 23 | * @since 1.4 24 | */ 25 | public class PUBREC extends MessageWithID { 26 | 27 | 28 | public PUBREC(final int messageId) { 29 | super(messageId); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/PUBREL.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.message; 18 | 19 | /** 20 | * The MQTT PUBREL message 21 | * @author Dominik Obermaier 22 | * @since 1.4 23 | */ 24 | public class PUBREL extends MessageWithID { 25 | 26 | 27 | public PUBREL(final int messageId) { 28 | super(messageId); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/ProtocolVersion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.message; 18 | 19 | /** 20 | * @author Dominik Obermaier 21 | */ 22 | public enum ProtocolVersion { 23 | 24 | /** 25 | * The protocol version which indicates a MQTT 3.1 connection 26 | */ 27 | MQTTv3_1, 28 | /** 29 | * The protocol version which indicates a MQTT 3.1.1 connection 30 | */ 31 | MQTTv3_1_1 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/QoS.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.message; 18 | 19 | import com.hivemq.spi.annotations.Nullable; 20 | 21 | /** 22 | * The Quality of Service level 23 | * 24 | * @author Dominik Obermaier 25 | * @since 1.4 26 | */ 27 | public enum QoS { 28 | 29 | /** 30 | * At most once delivery. The message will be delivered once or never (best effort delivery) 31 | */ 32 | AT_MOST_ONCE(0), 33 | /** 34 | * At least once delivery. The message will be delivered once or multiple times 35 | */ 36 | AT_LEAST_ONCE(1), 37 | /** 38 | * At exactly once delivery. The message will be delivered once and only once 39 | */ 40 | EXACTLY_ONCE(2); 41 | private final int qosNumber; 42 | 43 | QoS(final int qosNumber) { 44 | 45 | this.qosNumber = qosNumber; 46 | } 47 | 48 | /** 49 | * @return the integer value of the QoS. Can be 0, 1 or 2 50 | */ 51 | public int getQosNumber() { 52 | return qosNumber; 53 | } 54 | 55 | /** 56 | * Creates a QoS level enum from an integer 57 | * 58 | * @param i the QoS level as integer (0,1,2) 59 | * @return the QoS level or null if an invalid QoS level was passed 60 | */ 61 | @Nullable 62 | public static QoS valueOf(final int i) { 63 | 64 | for (final QoS qoS : QoS.values()) { 65 | if (qoS.getQosNumber() == i) { 66 | return qoS; 67 | } 68 | } 69 | return null; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/REMOTE_PUBLISH.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.message; 18 | 19 | /** 20 | * A publish object received from the cluster 21 | * 22 | * @deprecated use {@link PUBLISH} instead 23 | * @author Dominik Obermaier 24 | * @since 1.4 25 | */ 26 | @Deprecated 27 | public class REMOTE_PUBLISH extends PUBLISH { 28 | 29 | private final PUBLISH original; 30 | 31 | public REMOTE_PUBLISH(final PUBLISH original) { 32 | 33 | this.original = original; 34 | } 35 | 36 | @Override 37 | public byte[] getPayload() { 38 | return original.getPayload(); 39 | } 40 | 41 | @Override 42 | public String getTopic() { 43 | return original.getTopic(); 44 | } 45 | 46 | @Override 47 | public int getMessageId() { 48 | return original.getMessageId(); 49 | } 50 | 51 | @Override 52 | public QoS getQoS() { 53 | return original.getQoS(); 54 | } 55 | 56 | @Override 57 | public boolean isRetain() { 58 | return original.isRetain(); 59 | } 60 | 61 | @Override 62 | public boolean isDuplicateDelivery() { 63 | return original.isDuplicateDelivery(); 64 | } 65 | 66 | @Override 67 | public boolean equals(final Object o) { 68 | return original.equals(o); 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | return original.hashCode(); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/RetainedMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.message; 18 | 19 | /** 20 | * A retained message 21 | * 22 | * @author Lukas Brandl 23 | */ 24 | public class RetainedMessage { 25 | private String topic; 26 | private byte[] message; 27 | private QoS qoS; 28 | 29 | public RetainedMessage(String topic, byte[] message, QoS qoS) { 30 | this.topic = topic; 31 | this.message = message; 32 | this.qoS = qoS; 33 | } 34 | 35 | 36 | public String getTopic() { 37 | return topic; 38 | } 39 | 40 | public void setTopic(String topic) { 41 | this.topic = topic; 42 | } 43 | 44 | public byte[] getMessage() { 45 | return message; 46 | } 47 | 48 | public void setMessage(byte[] message) { 49 | this.message = message; 50 | } 51 | 52 | public QoS getQoS() { 53 | return qoS; 54 | } 55 | 56 | public void setQoS(QoS qoS) { 57 | this.qoS = qoS; 58 | } 59 | 60 | @Override 61 | public boolean equals(Object o) { 62 | if (this == o) return true; 63 | if (o == null || getClass() != o.getClass()) return false; 64 | 65 | RetainedMessage that = (RetainedMessage) o; 66 | 67 | if (topic != null ? !topic.equals(that.topic) : that.topic != null) return false; 68 | 69 | return true; 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | return topic != null ? topic.hashCode() : 0; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/ReturnCode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.message; 18 | 19 | /** 20 | * The return code of a {@link CONNACK} message. 21 | * 22 | * @author Dominik Obermaier 23 | * @author Christian Goetz 24 | * @since 1.4 25 | */ 26 | public enum ReturnCode { 27 | ACCEPTED(0), 28 | REFUSED_UNACCEPTABLE_PROTOCOL_VERSION(1), 29 | REFUSED_IDENTIFIER_REJECTED(2), 30 | REFUSED_SERVER_UNAVAILABLE(3), 31 | REFUSED_BAD_USERNAME_OR_PASSWORD(4), 32 | REFUSED_NOT_AUTHORIZED(5); 33 | 34 | private final int code; 35 | 36 | ReturnCode(int code) { 37 | 38 | this.code = code; 39 | } 40 | 41 | public int getCode() { 42 | return code; 43 | } 44 | 45 | public static ReturnCode with(final int code) { 46 | for (ReturnCode returnCode : ReturnCode.values()) { 47 | if (returnCode.code == code) { 48 | return returnCode; 49 | } 50 | } 51 | throw new IllegalArgumentException("No Return code with value " + code + " defined"); 52 | } 53 | } -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/SUBACK.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.message; 18 | 19 | import com.google.common.base.Preconditions; 20 | 21 | import java.util.Arrays; 22 | import java.util.List; 23 | 24 | /** 25 | * The MQTT SUBACK message 26 | * 27 | * @author Dominik Obermaier 28 | * @since 1.4 29 | */ 30 | public class SUBACK extends MessageWithID { 31 | 32 | public static final byte QoS_0 = 0x00; 33 | public static final byte QoS_1 = 0x01; 34 | public static final byte QoS_2 = 0x02; 35 | public static final byte FAILURE = (byte) 0x80; 36 | 37 | 38 | private List grantedQos; 39 | 40 | 41 | public SUBACK(final int messageId, final Byte... entries) { 42 | this(messageId, Arrays.asList(entries)); 43 | } 44 | 45 | public SUBACK(final int messageId, final List grantedQos) { 46 | super(messageId); 47 | Preconditions.checkArgument(messageId > 0 && messageId <= 65535); 48 | this.grantedQos = grantedQos; 49 | } 50 | 51 | public List getGrantedQos() { 52 | return grantedQos; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/SUBSCRIBE.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.message; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | /** 23 | * The MQTT SUBSCRIBE message 24 | * 25 | * @author Dominik Obermaier 26 | * @since 1.4 27 | */ 28 | public class SUBSCRIBE implements Message { 29 | 30 | private int messageId; 31 | 32 | private List topics; 33 | 34 | /** 35 | * Creates a new MQTT SUBSCRIBE message 36 | */ 37 | public SUBSCRIBE() { 38 | topics = new ArrayList<>(); 39 | } 40 | 41 | /** 42 | * @return the message id of the SUBSCRIBE message 43 | */ 44 | public int getMessageId() { 45 | return messageId; 46 | } 47 | 48 | public void setMessageId(final int messageId) { 49 | this.messageId = messageId; 50 | } 51 | 52 | /** 53 | * @return a List of topics and their corresponding QoS the SUBSCRIBE message contains 54 | */ 55 | public List getTopics() { 56 | return topics; 57 | } 58 | 59 | public void setTopics(final List topics) { 60 | this.topics = topics; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/SubackReturnCode.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.message; 2 | 3 | /** 4 | * The return code of a {@link SUBACK} message. 5 | * 6 | * @author Georg Held 7 | */ 8 | public enum SubackReturnCode { 9 | SUCCESS_QOS_0((byte) 0x00), 10 | SUCCESS_QOS_1((byte) 0x01), 11 | SUCCESS_QOS_2((byte) 0x02), 12 | FAILURE((byte) 0x80); 13 | 14 | private final byte code; 15 | 16 | SubackReturnCode(final byte code) { 17 | this.code = code; 18 | } 19 | 20 | public byte getCode() { 21 | return code; 22 | } 23 | 24 | public static SubackReturnCode valueOf(final byte code) { 25 | 26 | for (final SubackReturnCode subackReturnCode : SubackReturnCode.values()) { 27 | if (subackReturnCode.getCode() == code) { 28 | return subackReturnCode; 29 | } 30 | } 31 | throw new IllegalArgumentException("Unknown SUBACK return code: " + code); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/UNSUBACK.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.message; 18 | 19 | /** 20 | * The MQTT UNSUBACK message 21 | * 22 | * @author Dominik Obermaier 23 | * @since 1.4 24 | */ 25 | public class UNSUBACK extends MessageWithID { 26 | 27 | 28 | public UNSUBACK(final int messageId) { 29 | 30 | super(messageId); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/message/UNSUBSCRIBE.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.message; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | /** 23 | * The MQTT UNSUBSCRIBE message 24 | * 25 | * @author Dominik Obermaier 26 | * @since 1.4 27 | */ 28 | public class UNSUBSCRIBE extends MessageWithID { 29 | 30 | 31 | private List topics; 32 | 33 | public UNSUBSCRIBE() { 34 | super(0); 35 | topics = new ArrayList<>(); 36 | } 37 | 38 | /** 39 | * @return a list of topic the client wants to unsubscribe to 40 | */ 41 | public List getTopics() { 42 | return topics; 43 | } 44 | 45 | public void setTopics(final List topics) { 46 | this.topics = topics; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/metrics/HiveMQMetric.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.metrics; 2 | 3 | import com.codahale.metrics.Gauge; 4 | import com.codahale.metrics.Metric; 5 | 6 | import static com.google.common.base.Preconditions.checkNotNull; 7 | 8 | /** 9 | * A convenience class to specify constant names and types of the internal HiveMQ metrics 10 | * 11 | * @author Christoph Schäbel 12 | */ 13 | public class HiveMQMetric { 14 | 15 | private final String name; 16 | private final Class clazz; 17 | 18 | 19 | private HiveMQMetric(final String name, final Class clazz) { 20 | this.name = name; 21 | this.clazz = clazz; 22 | } 23 | 24 | public static HiveMQMetric valueOf(String name, Class metricClass) { 25 | checkNotNull(name, "Name cannot be null"); 26 | 27 | return new HiveMQMetric<>(name, metricClass); 28 | } 29 | 30 | public static HiveMQMetric> gaugeValue(String name) { 31 | checkNotNull(name, "Name cannot be null"); 32 | 33 | return new HiveMQMetric<>(name, Gauge.class); 34 | } 35 | 36 | public String name() { 37 | return name; 38 | } 39 | 40 | public Class getClazz() { 41 | return clazz; 42 | } 43 | } -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/metrics/annotations/Counted.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.metrics.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Methods annotated with this annotation are added to the HiveMQ {@link com.codahale.metrics.MetricRegistry} 10 | * automatically as Counters. The invocation of the annotated methods are counted 11 | * 12 | * @author Christoph Schäbel 13 | */ 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE}) 16 | public @interface Counted { 17 | 18 | /** 19 | * @return The name of this metric. When left empty, the canonical name of the class and method will be used. 20 | */ 21 | String name() default ""; 22 | 23 | 24 | /** 25 | * @return If {@code false} the counter is decremented when the annotated 26 | * method returns, counting current invocations of the annotated method. 27 | * If {@code true} (default) the counter increases monotonically, counting total 28 | * invocations of the annotated method. 29 | */ 30 | boolean monotonic() default true; 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/metrics/annotations/ExceptionMetered.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.metrics.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Methods annotated with this annotation are added to the HiveMQ {@link com.codahale.metrics.MetricRegistry} 10 | * automatically as Meters. The exceptions thrown by the annotated method are counted 11 | * 12 | * @author Christoph Schäbel 13 | */ 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE}) 16 | public @interface ExceptionMetered { 17 | 18 | /** 19 | * @return The name of this metric. When left emtpy the canonical name of the class and method will be used. 20 | */ 21 | String name() default ""; 22 | 23 | /** 24 | * @return The type of exceptions that the meter will catch and count. 25 | */ 26 | Class cause() default Exception.class; 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/metrics/annotations/Metered.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.metrics.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Methods annotated with this annotation are added to the HiveMQ {@link com.codahale.metrics.MetricRegistry} 10 | * automatically as Meters. The methods annotated with this Annotation get instrumented as Meters. 11 | * 12 | * @author Christoph Schäbel 13 | */ 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE}) 16 | public @interface Metered { 17 | 18 | /** 19 | * @return The name of this metric. When left empty the canonical name of the class and method will be used. 20 | */ 21 | String name() default ""; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/metrics/annotations/Timed.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.metrics.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Methods annotated with this annotation are added to the HiveMQ {@link com.codahale.metrics.MetricRegistry} 10 | * automatically as Timers. The invocation times of the methods annotated with this Annotation are captured automatically. 11 | * 12 | * @author Christoph Schäbel 13 | */ 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE}) 16 | public @interface Timed { 17 | 18 | /** 19 | * @return The name of this metric. When left emtpy the canonical name of the class and method will be used. 20 | */ 21 | String name() default ""; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/plugin/meta/Information.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.plugin.meta; 18 | 19 | import com.hivemq.spi.HiveMQPluginModule; 20 | 21 | import java.lang.annotation.Documented; 22 | import java.lang.annotation.ElementType; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.Target; 25 | 26 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 27 | 28 | /** 29 | * A annotation which can be used on {@link HiveMQPluginModule}s 30 | * to set metadata about the project and the author. 31 | * 32 | * @author Dominik Obermaier 33 | * @since 1.4 34 | */ 35 | @Target({ElementType.TYPE}) 36 | @Retention(RUNTIME) 37 | @Documented 38 | public @interface Information { 39 | 40 | /** 41 | * The name of the plugin 42 | */ 43 | String name(); 44 | 45 | /** 46 | * The author(s) of the plugin. 47 | */ 48 | String author() default "no author defined"; 49 | 50 | /** 51 | * The version of the plugin 52 | */ 53 | String version(); 54 | 55 | /** 56 | * Additional description about the plugin 57 | */ 58 | String description() default ""; 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/security/ClientCredentialsData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.security; 18 | 19 | import com.google.common.base.Optional; 20 | import com.hivemq.spi.message.CONNECT; 21 | 22 | import java.net.InetAddress; 23 | 24 | /** 25 | * An extended version of {@link ClientData} which also contains 26 | * the password the client used in the {@link CONNECT} 27 | * message 28 | * 29 | * @author Christian Goetz 30 | * @since 1.4 31 | */ 32 | public interface ClientCredentialsData extends ClientData { 33 | /** 34 | * Returns an {@link Optional} of the clear text password the client used encoded 35 | * as UTF-8. 36 | *

37 | * Consider using the {@link #getPasswordBytes()} method instead, since passwords 38 | * are not required to be human readable and can be any arbitrary byte array 39 | * 40 | * @return the password, if present 41 | */ 42 | Optional getPassword(); 43 | 44 | 45 | /** 46 | * Returns an {@link Optional} of the text password the client used 47 | * 48 | * @return the password, if present 49 | * @since 3.0.0 50 | */ 51 | Optional getPasswordBytes(); 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/security/QueuedMessageStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.security; 18 | 19 | /** 20 | * @author Lukas Brandl 21 | */ 22 | public class QueuedMessageStrategy { 23 | 24 | public static final long DISCARD = 0; 25 | 26 | public static final long DISCARD_OLDEST = 1; 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/security/Restriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.security; 18 | 19 | import java.io.Serializable; 20 | 21 | /** 22 | * A restriction is essentially a permission with a numerical value. 23 | * 24 | * @author Dominik Obermaier 25 | * @since 1.4 26 | */ 27 | public class Restriction implements Serializable { 28 | 29 | private RestrictionType type; 30 | 31 | private Long value; 32 | 33 | public Restriction(final RestrictionType type, final Long value) { 34 | this.type = type; 35 | this.value = value; 36 | } 37 | 38 | /** 39 | * @return the numerical value for this restriction 40 | */ 41 | public Long getValue() { 42 | return value; 43 | } 44 | 45 | /** 46 | * @return the type of this restriction 47 | */ 48 | public RestrictionType getType() { 49 | return type; 50 | } 51 | 52 | @Override 53 | public boolean equals(Object o) { 54 | if (this == o) return true; 55 | if (o == null || getClass() != o.getClass()) return false; 56 | 57 | Restriction that = (Restriction) o; 58 | 59 | if (type != that.type) return false; 60 | if (value != null ? !value.equals(that.value) : that.value != null) return false; 61 | 62 | return true; 63 | } 64 | 65 | @Override 66 | public int hashCode() { 67 | int result = type != null ? type.hashCode() : 0; 68 | result = 31 * result + (value != null ? value.hashCode() : 0); 69 | return result; 70 | } 71 | 72 | @Override 73 | public String toString() { 74 | return "Restriction{" + 75 | "type=" + type + 76 | ", value=" + value + 77 | '}'; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/security/SslClientCertificate.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.security; 2 | 3 | import java.security.cert.Certificate; 4 | 5 | /** 6 | * Represents information of a X509 client certificate. 7 | * 8 | * @author Christoph Schäbel 9 | * @since 3.0 10 | */ 11 | public interface SslClientCertificate { 12 | 13 | /** 14 | * @return the last certificate in the chain 15 | */ 16 | Certificate certificate(); 17 | 18 | /** 19 | * @return the whole certificate chain 20 | */ 21 | Certificate[] certificateChain(); 22 | 23 | /** 24 | * @return the commonName from the last certificate in the chain 25 | */ 26 | String commonName(); 27 | 28 | /** 29 | * @return the organization from the last certificate in the chain 30 | */ 31 | String organization(); 32 | 33 | /** 34 | * @return the organizational unit from the last certificate in the chain 35 | */ 36 | String organizationalUnit(); 37 | 38 | /** 39 | * @return the title from the last certificate in the chain 40 | */ 41 | String title(); 42 | 43 | /** 44 | * @return the serial number from the last certificate in the chain 45 | */ 46 | String serial(); 47 | 48 | /** 49 | * @return the country code from the last certificate in the chain 50 | */ 51 | String country(); 52 | 53 | /** 54 | * @return the locality from the last certificate in the chain 55 | */ 56 | String locality(); 57 | 58 | /** 59 | * @return the state from the last certificate in the chain 60 | */ 61 | String state(); 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/BlockingMetricService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.services; 18 | 19 | import com.codahale.metrics.Metric; 20 | import com.codahale.metrics.MetricRegistry; 21 | import com.hivemq.spi.annotations.Nullable; 22 | import com.hivemq.spi.metrics.HiveMQMetric; 23 | 24 | import java.util.Map; 25 | 26 | /** 27 | * This service allows plugins to get or add global HiveMQ metrics. 28 | * 29 | * @author Lukas Brandl 30 | */ 31 | public interface BlockingMetricService { 32 | 33 | /** 34 | * Returns a specific HiveMQ metric. If the metric does not exist, this method will return 35 | * null. 36 | *

37 | * For a list of all available metrics, refer to the {@link com.hivemq.spi.metrics.HiveMQMetrics} constant class. 38 | * 39 | * @param metric the metric 40 | * @param the metric type 41 | * @return the metric (if available) or null 42 | */ 43 | @Nullable 44 | T getHiveMQMetric(HiveMQMetric metric); 45 | 46 | /** 47 | * Returns a map which contains an entry for every node in the cluster with the given HiveMQ metric. An entry represents the name of the node (key) and the associated metric for the node (value). 48 | * If the metric does not exist, this method will return null. 49 | *

50 | * For a list of all available metrics, refer to the {@link com.hivemq.spi.metrics.HiveMQMetrics} constant class. 51 | * 52 | * @param metric the metric 53 | * @param the metric type 54 | * @return a map with node names and their sought-after metrics or null. 55 | */ 56 | @Nullable 57 | Map getClusterMetric(HiveMQMetric metric); 58 | 59 | /** 60 | * Returns the metric registry of HiveMQ. 61 | * 62 | * @return the metric registry 63 | */ 64 | MetricRegistry getMetricRegistry(); 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/ConfigurationService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.services; 18 | 19 | import com.hivemq.spi.services.configuration.GeneralConfigurationService; 20 | import com.hivemq.spi.services.configuration.MqttConfigurationService; 21 | import com.hivemq.spi.services.configuration.ThrottlingConfigurationService; 22 | import com.hivemq.spi.services.configuration.listener.ListenerConfigurationService; 23 | 24 | /** 25 | * The Configuration Service interface which allows to change HiveMQ configuration 26 | * programmatically. 27 | *

28 | * Runtime configuration changes via plugins are possible for most of the configuration subsystem services. 29 | * 30 | * @author Dominik Obermaier 31 | * @since 3.0 32 | */ 33 | 34 | public interface ConfigurationService { 35 | 36 | /** 37 | * Returns the configuration service for general HiveMQ configuration 38 | * 39 | * @return the general HiveMQ configuration service 40 | */ 41 | GeneralConfigurationService generalConfiguration(); 42 | 43 | /** 44 | * Returns the configuration service which allows to add and inspect listeners add runtime. 45 | * 46 | * @return the listener configuration service 47 | */ 48 | ListenerConfigurationService listenerConfiguration(); 49 | 50 | /** 51 | * Returns the configuration service for MQTT configuration 52 | * 53 | * @return the mqtt configuration service 54 | */ 55 | MqttConfigurationService mqttConfiguration(); 56 | 57 | /** 58 | * Returns the throttling configuration service for global throttling 59 | * 60 | * @return the global throttling service 61 | */ 62 | ThrottlingConfigurationService throttlingConfiguration(); 63 | 64 | } 65 | 66 | 67 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/LogService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.services; 18 | 19 | 20 | import com.hivemq.spi.annotations.NotNull; 21 | 22 | /** 23 | * The logservice which allows to change the internal logger 24 | * of HiveMQ at runtime programmatically 25 | * 26 | * @author Dominik Obermaier 27 | * @since 3.0 28 | */ 29 | public interface LogService { 30 | 31 | /** 32 | * The loglevels HiveMQ supports 33 | */ 34 | enum LogLevel { 35 | 36 | /** 37 | * The TRACE log level for finest HiveMQ logging 38 | */ 39 | TRACE, 40 | /** 41 | * The DEBUG log level for fine HiveMQ logging 42 | */ 43 | DEBUG, 44 | /** 45 | * The INFO log level. INFO logging is the default HiveMQ log behaviour 46 | */ 47 | INFO, 48 | /** 49 | * The WARN log level which only logs warnings 50 | */ 51 | WARN, 52 | /** 53 | * The ERROR log level which only logs severe HiveMQ errors 54 | */ 55 | ERROR 56 | 57 | } 58 | 59 | /** 60 | * Changes the log level of the internal HiveMQ logger 61 | *

62 | * This does not support null parameters. If you pass 63 | * null, this method is lenient and will ignore the parameter 64 | * 65 | * @param logLevel the new loglevel 66 | */ 67 | void setLogLevel(@NotNull LogLevel logLevel); 68 | 69 | /** 70 | * Returns the current log level of the internal HiveMQ logger 71 | * 72 | * @return the current log level of the internal HiveMQ logger 73 | */ 74 | LogLevel getLogLevel(); 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/MetricService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.hivemq.spi.services; 17 | 18 | 19 | import com.codahale.metrics.Metric; 20 | import com.codahale.metrics.MetricRegistry; 21 | import com.hivemq.spi.annotations.Nullable; 22 | import com.hivemq.spi.metrics.HiveMQMetric; 23 | 24 | /** 25 | * This service allows plugins to get or add global HiveMQ metrics. 26 | * 27 | * @author Christoph Schäbel 28 | * @since 3.0 29 | * @deprecated Use {@link BlockingMetricService} or {@link AsyncMetricService} instead. 30 | */ 31 | @Deprecated 32 | public interface MetricService { 33 | 34 | /** 35 | * Returns a specific HiveMQ metric. If the metric does not exist, this method will return 36 | * null. 37 | *

38 | * For a list of all available metrics, refer to the {@link com.hivemq.spi.metrics.HiveMQMetrics} constant class. 39 | * 40 | * @param metric the metric 41 | * @param the metric type 42 | * @return the metric (if available) or null 43 | * @deprecated Use {@link BlockingMetricService} or {@link AsyncMetricService} instead. 44 | */ 45 | @Nullable 46 | @Deprecated 47 | T getHiveMQMetric(HiveMQMetric metric); 48 | 49 | /** 50 | * Returns the metric registry of HiveMQ. 51 | * 52 | * @return the metric registry 53 | * @deprecated Use {@link BlockingMetricService} or {@link AsyncMetricService} instead. 54 | */ 55 | @Deprecated 56 | MetricRegistry getMetricRegistry(); 57 | 58 | } -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/OptionalAttribute.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.services; 2 | 3 | import com.hivemq.spi.annotations.Nullable; 4 | 5 | /** 6 | * @author Florian Limpöck 7 | */ 8 | public class OptionalAttribute { 9 | 10 | /** 11 | * the replaced value. 12 | * may be if no value was replaced. 13 | */ 14 | private final byte[] value; 15 | 16 | /** 17 | * true if a value was replaced, else false. 18 | */ 19 | private final boolean replaced; 20 | 21 | public OptionalAttribute(@Nullable byte[] value, boolean replaced) { 22 | this.value = value; 23 | this.replaced = replaced; 24 | } 25 | 26 | public byte[] getValue() { 27 | return value; 28 | } 29 | 30 | public boolean isReplaced() { 31 | return replaced; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/PluginExecutorService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.services; 18 | 19 | import com.google.common.util.concurrent.ListeningScheduledExecutorService; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * A shared thread pool executor which is a {@link ListeningScheduledExecutorService}. 25 | * It is recommended to use this instead of creating your own thread(-pool) in your plugin. 26 | *

27 | * Use this class for all concurrent code. 28 | * 29 | * @author Christoph Schäbel 30 | */ 31 | public interface PluginExecutorService extends ListeningScheduledExecutorService { 32 | 33 | /** 34 | * DO NOT CALL THIS METHOD! 35 | *

36 | * The Plugin Executor Service is automatically shut down when HiveMQ is shut down. 37 | *

38 | * Manual calls to this method from the plugin system are not supported. 39 | * 40 | * @throws {@link UnsupportedOperationException} always 41 | */ 42 | @Override 43 | void shutdown(); 44 | 45 | /** 46 | * DO NOT CALL THIS METHOD! 47 | *

48 | * The Plugin Executor Service is automatically shut down when HiveMQ shuts down. 49 | *

50 | * Manual calls to this method from the plugin system are not supported. 51 | * 52 | * @throws {@link UnsupportedOperationException} always 53 | */ 54 | @Override 55 | List shutdownNow(); 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/PublishService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.services; 18 | 19 | import com.hivemq.spi.annotations.NotNull; 20 | import com.hivemq.spi.message.PUBLISH; 21 | 22 | /** 23 | * This service allows plugins to publish new MQTT messages programmatically 24 | * 25 | * @author Lukas Brandl 26 | * @since 1.5 27 | */ 28 | public interface PublishService { 29 | 30 | /** 31 | * Publishes a new MQTT {@link PUBLISH} message. The standard MQTT topic matching mechanism of HiveMQ will apply. 32 | *

33 | * If the given {@link PUBLISH} or any of its information (topic,qos,message) is null, a {@link NullPointerException} 34 | * will be thrown 35 | * 36 | * @param publish object with topic, QoS and message, which should be published to all subscribed clients 37 | * @throws NullPointerException if the given object is null or any relevant information like topic, qos 38 | * or message is null 39 | */ 40 | void publish(@NotNull PUBLISH publish); 41 | 42 | 43 | /** 44 | * Publishes a new MQTT {@link PUBLISH} message. 45 | * The PUBLISH will only be delivered to the client with the specified client identifier. 46 | * Also the client needs to be subscribed on the topic of the PUBLISH in order to receive it. 47 | *

48 | * If the given {@link PUBLISH} or any of its information (topic,qos,message) is null, a {@link NullPointerException} 49 | * will be thrown 50 | * 51 | * @param publish object with topic, QoS and message, which should be published to all subscribed clients 52 | * @throws NullPointerException if the given object is null or any relevant information like topic, qos 53 | * or message is null 54 | */ 55 | void publishtoClient(@NotNull PUBLISH publish, @NotNull String clientId); 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/configuration/GeneralConfigurationService.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.services.configuration; 2 | 3 | /** 4 | * A Configuration service which allows to get information about the current General configuration 5 | * and allows to change the global General configuration of HiveMQ at runtime. 6 | * 7 | * @author Christoph Schäbel 8 | * @since 3.0 9 | */ 10 | public interface GeneralConfigurationService { 11 | 12 | /** 13 | * @return true if the update check is enabled, false otherwise 14 | */ 15 | boolean updateCheckEnabled(); 16 | 17 | void setUpdateCheckEnabled(boolean updateCheckEnabled); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/configuration/ValueChangedCallback.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.services.configuration; 2 | 3 | 4 | /** 5 | * A callback which is executed when a value for a configuration changes 6 | * at runtime 7 | * 8 | * @author Christoph Schäbel 9 | * @since 3.0 10 | */ 11 | public interface ValueChangedCallback { 12 | 13 | /** 14 | * This method gets executed when the valuef or a configuration changes 15 | * 16 | * @param newValue the new value 17 | */ 18 | void valueChanged(T newValue); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/configuration/entity/ClientWriteBufferProperties.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.services.configuration.entity; 2 | 3 | import com.hivemq.spi.annotations.Immutable; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | /** 8 | * Allows the customization of write buffer behaviour. 9 | * 10 | * @author Georg Held 11 | * @since 3.3 12 | */ 13 | @Immutable 14 | public class ClientWriteBufferProperties { 15 | 16 | private final int highThreshold; 17 | private final int lowThreshold; 18 | 19 | /** 20 | * @param highThreshold If the write buffer for a client reaches a size in bytes that is greater than {@code highThreshold} no more data will be written to the write buffer. 21 | * @param lowThreshold If the write buffer for a client exceeded the highThreshold in the past, writing to the buffer will be resumed once the fill state of the buffer drops below the {@code lowThreshold}. 22 | */ 23 | public ClientWriteBufferProperties(final int highThreshold, final int lowThreshold) { 24 | this.highThreshold = highThreshold; 25 | this.lowThreshold = lowThreshold; 26 | } 27 | 28 | public int getHighThreshold() { 29 | return highThreshold; 30 | } 31 | 32 | public int getLowThreshold() { 33 | return lowThreshold; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/configuration/entity/ConnectOverloadProtectionProperties.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.services.configuration.entity; 2 | 3 | import com.hivemq.spi.annotations.Immutable; 4 | 5 | /** 6 | * Enables the overload protection for MQTT CONNECT messages processed by HiveMQ. 7 | * 8 | * @author Georg Held 9 | * @since 3.3 10 | */ 11 | @Immutable 12 | public class ConnectOverloadProtectionProperties { 13 | 14 | private final double connectRate; 15 | private final long connectBurstSize; 16 | 17 | /** 18 | * @param connectRate the maximum sustained rate by which CONNECT messages shall be processed by the listener in CONNECT/seconds 19 | * @param connectBurstSize maximum amount of CONNECT messages that the listener shall handle at any time 20 | */ 21 | public ConnectOverloadProtectionProperties(final double connectRate, 22 | final long connectBurstSize) { 23 | this.connectRate = connectRate; 24 | this.connectBurstSize = connectBurstSize; 25 | } 26 | 27 | /** 28 | * @param connectRate the maximum sustained rate by which CONNECT messages shall be processed by the listener in CONNECT/seconds 29 | */ 30 | public ConnectOverloadProtectionProperties(final double connectRate) { 31 | this.connectRate = connectRate; 32 | this.connectBurstSize = (long) (connectRate * 2); 33 | } 34 | 35 | public double getConnectRate() { 36 | return connectRate; 37 | } 38 | 39 | public long getConnectBurstSize() { 40 | return connectBurstSize; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/configuration/entity/Listener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.services.configuration.entity; 18 | 19 | import com.google.common.base.Optional; 20 | 21 | /** 22 | * A marker interface for a listener. Any listener implementation must 23 | * implement this interface. 24 | * 25 | * @author Dominik Obermaier 26 | * @author Christoph Schaebel 27 | * @author Georg Held 28 | * @see TcpListener 29 | * @see TlsTcpListener 30 | * @see WebsocketListener 31 | * @see TlsWebsocketListener 32 | */ 33 | public interface Listener { 34 | 35 | /** 36 | * @return the port of the listener 37 | */ 38 | int getPort(); 39 | 40 | /** 41 | * @return the bind address of a listener 42 | */ 43 | String getBindAddress(); 44 | 45 | /** 46 | * @return the human readable, name of the listener 47 | */ 48 | String readableName(); 49 | 50 | /** 51 | * @return if the PROXY protocol is supported by this listener 52 | * @since 3.2 53 | */ 54 | boolean isProxyProtocolSupported(); 55 | 56 | /** 57 | * @return an {@link Optional} of {@link SocketOptionsProperties} of this listener 58 | */ 59 | Optional getSocketOptionsProperties(); 60 | 61 | /** 62 | * @return an {@link Optional} of {@link ConnectOverloadProtectionProperties} of this listener 63 | */ 64 | Optional getConnectOverloadProtectionProperties(); 65 | 66 | /** 67 | * @return an {@link Optional} of {@link ClientWriteBufferProperties} of this listener 68 | */ 69 | Optional getClientWriteBufferProperties(); 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/configuration/exception/ConfigurationValidationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.services.configuration.exception; 18 | 19 | import com.google.common.collect.ImmutableList; 20 | import com.hivemq.spi.services.configuration.validation.ValidationError; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * This exception indicates that a configuration was no successful 26 | * 27 | * @author Dominik Obermaier 28 | * @since 3.0 29 | */ 30 | public class ConfigurationValidationException extends RuntimeException { 31 | 32 | private final List validationErrors; 33 | 34 | public ConfigurationValidationException(final List validationErrors) { 35 | this.validationErrors = ImmutableList.copyOf(validationErrors); 36 | } 37 | 38 | /** 39 | * @return a list of all Validation errors 40 | */ 41 | public List getValidationErrors() { 42 | return validationErrors; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/configuration/validation/ValidationError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.services.configuration.validation; 18 | 19 | import com.hivemq.spi.annotations.Immutable; 20 | 21 | /** 22 | * A concrete validation erro 23 | * 24 | * @author Dominik Obermaier 25 | */ 26 | @Immutable 27 | public class ValidationError { 28 | 29 | private final String message; 30 | 31 | public ValidationError(final String message, final Object... args) { 32 | 33 | this.message = String.format(message, args); 34 | } 35 | 36 | public String getMessage() { 37 | return message; 38 | } 39 | 40 | @Override 41 | public boolean equals(final Object o) { 42 | if (this == o) return true; 43 | if (o == null || getClass() != o.getClass()) return false; 44 | 45 | final ValidationError that = (ValidationError) o; 46 | 47 | if (message != null ? !message.equals(that.message) : that.message != null) return false; 48 | 49 | return true; 50 | } 51 | 52 | @Override 53 | public int hashCode() { 54 | return message != null ? message.hashCode() : 0; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/configuration/validation/Validator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.services.configuration.validation; 18 | 19 | import java.util.List; 20 | 21 | /** 22 | * The configuration validator 23 | * 24 | * @author Dominik Obermaier 25 | * @since 3.0 26 | */ 27 | public interface Validator { 28 | 29 | List validate(final T parameter, final String name); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/configuration/validation/annotation/Validate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.services.configuration.validation.annotation; 18 | 19 | import com.hivemq.spi.services.configuration.validation.Validator; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * This annotation indicates that a method must be validated 28 | * 29 | * @author Dominik Obermaier 30 | * @since 3.0 31 | */ 32 | @Retention(RetentionPolicy.RUNTIME) 33 | @Target(ElementType.METHOD) 34 | public @interface Validate { 35 | 36 | Class value(); 37 | 38 | String name() default ""; 39 | } -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/configuration/validation/validators/MaxClientIdValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.services.configuration.validation.validators; 18 | 19 | import com.google.common.collect.ImmutableList; 20 | import com.hivemq.spi.services.configuration.validation.ValidationError; 21 | import com.hivemq.spi.services.configuration.validation.Validator; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * A validator which validates the maximum client length parameter 27 | * 28 | * @author Dominik Obermaier 29 | * @since 3.0 30 | */ 31 | public class MaxClientIdValidator implements Validator { 32 | 33 | @Override 34 | public List validate(final Integer clientIdLength, final String name) { 35 | 36 | final ImmutableList.Builder validationErrors = ImmutableList.builder(); 37 | if (clientIdLength < 1 || clientIdLength > 65535) { 38 | validationErrors.add(new ValidationError("%d is an invalid client identifier length. A valid client identifier length must have a value between 1 and 65535.", clientIdLength)); 39 | } 40 | return validationErrors.build(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/configuration/validation/validators/TtlValidator.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.services.configuration.validation.validators; 2 | 3 | import com.google.common.collect.ImmutableList; 4 | import com.hivemq.spi.services.configuration.validation.ValidationError; 5 | import com.hivemq.spi.services.configuration.validation.Validator; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author Lukas Brandl 11 | */ 12 | public class TtlValidator implements Validator { 13 | 14 | @Override 15 | public List validate(final Integer clientSessionTtl, final String name) { 16 | 17 | final ImmutableList.Builder validationErrors = ImmutableList.builder(); 18 | if (clientSessionTtl < 1 && clientSessionTtl != -1) { 19 | validationErrors.add(new ValidationError("%d is an invalid time to live. A valid ttl must be -1 or more than 1.", clientSessionTtl)); 20 | } 21 | return validationErrors.build(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/configuration/validation/validators/ZeroablePositiveNumber.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.services.configuration.validation.validators; 18 | 19 | import com.google.common.collect.ImmutableList; 20 | import com.hivemq.spi.services.configuration.validation.ValidationError; 21 | import com.hivemq.spi.services.configuration.validation.Validator; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * A validator which validates that a parameter is higher or equal to 0 27 | * 28 | * @author Dominik Obermaier 29 | * @since 3.0 30 | */ 31 | public class ZeroablePositiveNumber implements Validator { 32 | 33 | @Override 34 | public List validate(final Number number, final String name) { 35 | 36 | final ImmutableList.Builder validationErrors = ImmutableList.builder(); 37 | if (number.intValue() < 0) { 38 | validationErrors.add(new ValidationError("Validation failed for %s. The number must be 0 or higher but was %d", name, number)); 39 | } 40 | return validationErrors.build(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/exception/NoSuchClientIdException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.services.exception; 18 | 19 | /** 20 | * This exception is used to signal that a given MQTT ClientId is unknown to the broker in the given context. 21 | * 22 | * @author Georg Held 23 | * @since 3.3.0 24 | */ 25 | public class NoSuchClientIdException extends Exception { 26 | 27 | private final String clientId; 28 | private final boolean fillInStacktrace; 29 | 30 | /** 31 | * Creates a new NoSuchClientException. 32 | * 33 | * @param clientId the not available MQTT ClientId. 34 | * @param fillInStacktrace whether the created exception should fill in a stacktrace. 35 | */ 36 | public NoSuchClientIdException(final String clientId, final boolean fillInStacktrace) { 37 | this.clientId = clientId; 38 | this.fillInStacktrace = fillInStacktrace; 39 | } 40 | 41 | /** 42 | * Creates a new NoSuchClientException that will not contain a stacktrace. 43 | * 44 | * @param clientId the not available MQTT ClientId. 45 | */ 46 | public NoSuchClientIdException(final String clientId) { 47 | this(clientId, false); 48 | } 49 | 50 | @Override 51 | public synchronized Throwable fillInStackTrace() { 52 | if (fillInStacktrace) { 53 | return super.fillInStackTrace(); 54 | } 55 | return this; 56 | } 57 | 58 | /** 59 | * Returns the unknown MQTT ClientId. 60 | * 61 | * @return the not available MQTT ClientId. 62 | */ 63 | public String getClientId() { 64 | return clientId; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/exception/RateLimitExceededException.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.services.exception; 2 | 3 | /** 4 | * This exception is used to signal that the configured plugin service rate limit has been exceeded 5 | * 6 | * @author Lukas Brandl 7 | */ 8 | public class RateLimitExceededException extends RuntimeException { 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/rest/listener/AbstractListener.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.services.rest.listener; 2 | 3 | import com.hivemq.spi.annotations.NotNull; 4 | 5 | import static com.google.common.base.Preconditions.checkArgument; 6 | import static com.google.common.base.Preconditions.checkNotNull; 7 | 8 | /** 9 | * A base implementation for listeners with common listener 10 | * base properties 11 | * 12 | * @author Dominik Obermaier 13 | */ 14 | abstract class AbstractListener implements Listener { 15 | 16 | private final String name; 17 | private final String bindAddress; 18 | private final int port; 19 | 20 | 21 | AbstractListener(@NotNull final String name, @NotNull final String bindAddress, final int port) { 22 | checkNotNull(name, "Name of the listener must not be null"); 23 | checkNotNull(bindAddress, "Bind address of the listener must not be null"); 24 | checkArgument(port <= 65535 && port > 0, " The port %s is not a valid port. Valid ports are between 1 and 65535", port); 25 | this.name = name; 26 | this.bindAddress = bindAddress; 27 | this.port = port; 28 | } 29 | 30 | 31 | /** 32 | * Returns the unique name of the listener 33 | * 34 | * @return the unique name of the listener 35 | */ 36 | public String getName() { 37 | return name; 38 | } 39 | 40 | /** 41 | * Returns the bind address the listener is bound to 42 | * 43 | * @return the the bind address 44 | */ 45 | public String getBindAddress() { 46 | return bindAddress; 47 | } 48 | 49 | /** 50 | * Returns the port the listener is bound to 51 | * 52 | * @return the port of the listener 53 | */ 54 | public int getPort() { 55 | return port; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/rest/listener/HttpListener.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.services.rest.listener; 2 | 3 | import com.hivemq.spi.annotations.Immutable; 4 | import com.hivemq.spi.annotations.NotNull; 5 | 6 | /** 7 | * A HTTP listener which is bound to a specific host and port. 8 | * 9 | * @author Dominik Obermaier 10 | */ 11 | @Immutable 12 | public class HttpListener extends AbstractListener { 13 | 14 | 15 | /** 16 | * Creates a new HTTP listener. 17 | *

18 | * In order to bind the HTTP listener to all interfaces use the host '0.0.0.0' 19 | * 20 | * @param name The unique identifier of the listener. 21 | * @param bindAddress the bind address the listener should be bound to. Must be a valid IP or hostname. 22 | * @param port the port the listener should be bound to. Must be between 1 and 65535. 23 | * @throws NullPointerException if name or host are null 24 | * @throws IllegalArgumentException if the port is not valid 25 | */ 26 | public HttpListener(@NotNull final String name, @NotNull final String bindAddress, final int port) { 27 | super(name, bindAddress, port); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/services/rest/listener/Listener.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.services.rest.listener; 2 | 3 | /** 4 | * This interface marks all HiveMQ REST Service Listener implementations. 5 | * 6 | * @author Dominik Obermaier 7 | */ 8 | public interface Listener { 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/topic/TopicMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.topic; 18 | 19 | import com.hivemq.spi.topic.exception.InvalidTopicException; 20 | 21 | /** 22 | * A topic matcher which is useful if you want to match topics manually if they match to specific wildcard topics 23 | * 24 | * @author Dominik Obermaier 25 | * @since 1.4 26 | */ 27 | public interface TopicMatcher { 28 | 29 | /** 30 | * Evaluates if a topic matches a specific topic which also can contain wildcards. All MQTT topic matching rules 31 | * apply 32 | * 33 | * @param topicSubscription the subscription. May contain wildcards 34 | * @param actualTopic the actual topic. Must not contain wildcards 35 | * @return true if a topic matches a specific subscription, false otherwise 36 | * @throws InvalidTopicException if the topic was invalid 37 | */ 38 | boolean matches(final String topicSubscription, final String actualTopic) throws InvalidTopicException; 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/topic/exception/InvalidTopicException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.topic.exception; 18 | 19 | /** 20 | * Indicates that a provided topic is not compliant with the definition of a topic in the mqtt specification. 21 | *

22 | * Please note that since HiveMQ 3.0 this is a {@link RuntimeException}. Prior to HiveMQ 3.0 23 | * this was a checked Exception. 24 | * 25 | * @author Dominik Obermaier 26 | * @since 1.4 27 | */ 28 | public class InvalidTopicException extends RuntimeException { 29 | 30 | public InvalidTopicException() { 31 | } 32 | 33 | public InvalidTopicException(final String message) { 34 | super(message); 35 | } 36 | 37 | public InvalidTopicException(final String message, final Throwable cause) { 38 | super(message, cause); 39 | } 40 | 41 | public InvalidTopicException(final Throwable cause) { 42 | super(cause); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/topic/sys/SYSTopicEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.topic.sys; 18 | 19 | import com.google.common.base.Supplier; 20 | import com.hivemq.spi.services.SYSTopicService; 21 | 22 | /** 23 | * An implementation of this interface representa a concrete $SYS topic entry 24 | * which can be added to the {@link SYSTopicService}. 25 | * 26 | * @author Dominik Obermaier 27 | * @since 2.0 28 | */ 29 | public interface SYSTopicEntry { 30 | 31 | 32 | /** 33 | * Returns the topic of the $SYS Topic Entry. 34 | *

35 | * Must start with '$SYS/' 36 | * 37 | * @return the topic of the entry 38 | */ 39 | String topic(); 40 | 41 | /** 42 | * Returns a {@link Supplier} for the payload of this $SYS topic. The supplier will be called 43 | * every time the broker publishes on the $SYS topics. 44 | *

45 | * If the payload is static or if you need to cache, you can consider using the utility methods in the 46 | * {@link com.google.common.base.Suppliers} util class. 47 | * 48 | * @return a supplier for the payload of this $SYS topic 49 | */ 50 | Supplier payload(); 51 | 52 | /** 53 | * Returns the Type of this $SYS topic 54 | * 55 | * @return the {@link Type} of this $SYS topics 56 | */ 57 | Type type(); 58 | 59 | /** 60 | * Returns a description of this $SYS topic 61 | * 62 | * @return a textual description of this $SYS topic 63 | */ 64 | String description(); 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/topic/sys/Type.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.topic.sys; 18 | 19 | /** 20 | * An enumeration of all available types for HiveMQ $SYS Topics 21 | * 22 | * @author Dominik Obermaier 23 | * @since 2.0 24 | */ 25 | public enum Type { 26 | /** 27 | * A static $SYS topic is a $SYS topic which will be published on the initial $SYS subscription of a client. 28 | * Typically static $SYS topic values don't change over time. 29 | */ 30 | STATIC, 31 | 32 | /** 33 | * A standard $SYS topic which will be published every time the $SYS topic publishing job 34 | * is running. 35 | */ 36 | STANDARD 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/util/Listeners.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.util; 2 | 3 | import com.hivemq.spi.services.configuration.entity.Listener; 4 | import com.hivemq.spi.services.configuration.entity.TlsTcpListener; 5 | import com.hivemq.spi.services.configuration.entity.TlsWebsocketListener; 6 | import com.hivemq.spi.services.configuration.entity.WebsocketListener; 7 | 8 | /** 9 | * Utilities for working with {@link com.hivemq.spi.services.configuration.entity.Listener}s 10 | * 11 | * @author Dominik Obermaier 12 | */ 13 | public class Listeners { 14 | 15 | private Listeners() { 16 | //Util, don't instantiate 17 | } 18 | 19 | /** 20 | * Checks if a given {@link Listener} uses TLS. 21 | * 22 | * @param listener the listener 23 | * @return true if the listener is a {@link TlsTcpListener} or a {@link TlsWebsocketListener} 24 | */ 25 | public static boolean isSecure(final Listener listener) { 26 | return listener instanceof TlsTcpListener || 27 | listener instanceof TlsWebsocketListener; 28 | } 29 | 30 | /** 31 | * Checks if a given {@link Listener} is a websocket listener 32 | * 33 | * @param listener the listener 34 | * @return true if the listener is a websocket listener 35 | */ 36 | public static boolean isWebsocket(final Listener listener) { 37 | return listener instanceof TlsWebsocketListener || 38 | listener instanceof WebsocketListener; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/hivemq/spi/util/SslException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.util; 18 | 19 | /** 20 | * @author Christoph Schäbel 21 | */ 22 | public class SslException extends RuntimeException { 23 | 24 | public SslException() { 25 | } 26 | 27 | public SslException(String message) { 28 | super(message); 29 | } 30 | 31 | public SslException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public SslException(Throwable cause) { 36 | super(cause); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/hivemq/spi/bridge/TLSVersionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.bridge; 18 | 19 | import org.junit.Test; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | 23 | /** 24 | * @author Dominik Obermaier 25 | */ 26 | public class TLSVersionTest { 27 | 28 | @Test 29 | public void test_fromString() throws Exception { 30 | final TLSVersion tlsVersion1 = TLSVersion.fromString("TLSv1.1"); 31 | assertEquals(TLSVersion.TLSv1_1, tlsVersion1); 32 | 33 | final TLSVersion tlsVersion2 = TLSVersion.fromString("TLS"); 34 | assertEquals(TLSVersion.TLS, tlsVersion2); 35 | 36 | final TLSVersion tlsVersion3 = TLSVersion.fromString("SSLv3"); 37 | assertEquals(TLSVersion.SSLv3, tlsVersion3); 38 | 39 | final TLSVersion tlsVersion4 = TLSVersion.fromString("TLSv1"); 40 | assertEquals(TLSVersion.TLSv1, tlsVersion4); 41 | 42 | final TLSVersion tlsVersion5 = TLSVersion.fromString("TLSv1.2"); 43 | assertEquals(TLSVersion.TLSv1_2, tlsVersion5); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/com/hivemq/spi/callback/schedule/ScheduleExpressionsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.callback.schedule; 18 | 19 | import org.junit.Assert; 20 | import org.junit.Test; 21 | 22 | import static org.junit.Assert.assertEquals; 23 | 24 | /** 25 | * Common schedule expressions which can be used with the {@link ScheduledCallback} 26 | * 27 | * @author Dominik Obermaier 28 | */ 29 | public class ScheduleExpressionsTest { 30 | 31 | 32 | @Test(expected = IllegalArgumentException.class) 33 | public void test_every_minutes_invalid_argument_zero() throws Exception { 34 | ScheduleExpressions.everyMinutes(0); 35 | } 36 | 37 | @Test(expected = IllegalArgumentException.class) 38 | public void test_every_minutes_invalid_argument_minus() throws Exception { 39 | ScheduleExpressions.everyMinutes(-1); 40 | } 41 | 42 | @Test 43 | public void test_every_five_minutes() throws Exception { 44 | 45 | Assert.assertEquals("0 0/5 * * * ?", ScheduleExpressions.everyMinutes(5)); 46 | } 47 | 48 | @Test 49 | public void test_every_MAX_INT_minutes() throws Exception { 50 | 51 | Assert.assertEquals("0 0/" + Integer.MAX_VALUE + " * * * ?", ScheduleExpressions.everyMinutes(Integer.MAX_VALUE)); 52 | } 53 | 54 | @Test 55 | public void test_every_minute() throws Exception { 56 | Assert.assertEquals(ScheduleExpressions.ONCE_A_MINUTE, ScheduleExpressions.everyMinutes(1)); 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/com/hivemq/spi/message/CONNACKTest.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.message; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | /** 8 | * @author Dominik Obermaier 9 | */ 10 | public class CONNACKTest { 11 | 12 | @Test(expected = IllegalArgumentException.class) 13 | public void test_throw_illegal_argument_if_session_present_on_non_accepted_return_code() throws Exception { 14 | new CONNACK(ReturnCode.REFUSED_NOT_AUTHORIZED, true); 15 | } 16 | 17 | @Test 18 | public void test_session_present_non_accepted_return_code() throws Exception { 19 | final CONNACK connack = new CONNACK(ReturnCode.ACCEPTED, true); 20 | 21 | assertEquals(true, connack.isSessionPresent()); 22 | assertEquals(ReturnCode.ACCEPTED, connack.getReturnCode()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/hivemq/spi/message/SubackReturnCodeTest.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.message; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | 7 | /** 8 | * @author Georg Held 9 | */ 10 | public class SubackReturnCodeTest { 11 | @Test(expected = IllegalArgumentException.class) 12 | public void test_throw_illegal_argument_exception() throws Exception { 13 | SubackReturnCode.valueOf((byte) 3); 14 | } 15 | 16 | @Test 17 | public void test_suback_codes() throws Exception { 18 | assertEquals(SubackReturnCode.FAILURE, SubackReturnCode.valueOf((byte) 128)); 19 | assertEquals(SubackReturnCode.SUCCESS_QOS_0, SubackReturnCode.valueOf((byte) 0)); 20 | assertEquals(SubackReturnCode.SUCCESS_QOS_1, SubackReturnCode.valueOf((byte) 1)); 21 | assertEquals(SubackReturnCode.SUCCESS_QOS_2, SubackReturnCode.valueOf((byte) 2)); 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /src/test/java/com/hivemq/spi/security/RestrictionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.security; 18 | 19 | import org.junit.Before; 20 | import org.junit.Test; 21 | 22 | import static org.junit.Assert.assertEquals; 23 | import static org.junit.Assert.assertTrue; 24 | 25 | /** 26 | * @author Christian Goetz 27 | */ 28 | public class RestrictionTest { 29 | 30 | private Restriction restriction; 31 | private Long expectedValue; 32 | private RestrictionType expectedType; 33 | 34 | @Before 35 | public void setUp() throws Exception { 36 | expectedValue = 123l; 37 | expectedType = RestrictionType.MAX_INCOMING_BYTES; 38 | restriction = new Restriction(expectedType, expectedValue); 39 | 40 | 41 | } 42 | 43 | @Test 44 | public void testGetValue() throws Exception { 45 | assertEquals(restriction.getValue(), expectedValue); 46 | } 47 | 48 | @Test 49 | public void testGetType() throws Exception { 50 | assertEquals(restriction.getType(),expectedType); 51 | } 52 | 53 | @Test 54 | public void testEquals() throws Exception { 55 | Restriction restriction1 = new Restriction(RestrictionType.MAX_INCOMING_BYTES,123l); 56 | assertTrue(restriction1.equals(restriction)); 57 | } 58 | 59 | @Test 60 | public void testHashCode() throws Exception { 61 | Restriction restriction1 = new Restriction(RestrictionType.MAX_INCOMING_BYTES,123l); 62 | assertEquals(restriction1.hashCode(), restriction.hashCode()); 63 | } 64 | 65 | @Test 66 | public void testToString() throws Exception { 67 | String expectedToString = "Restriction{type=MAX_INCOMING_BYTES, value=123}"; 68 | assertEquals(restriction.toString(), expectedToString); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/com/hivemq/spi/services/configuration/entity/ConnectOverloadProtectionPropertiesTest.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.services.configuration.entity; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | public class ConnectOverloadProtectionPropertiesTest { 8 | 9 | @Test(timeout = 5000) 10 | public void test_default_burst_size_is_set() throws Exception { 11 | final ConnectOverloadProtectionProperties connectOverloadProtectionProperties = new ConnectOverloadProtectionProperties(500.25); 12 | assertEquals(1000, connectOverloadProtectionProperties.getConnectBurstSize()); 13 | } 14 | 15 | @Test(timeout = 5000) 16 | public void test_default_burst_size_is_overridden() throws Exception { 17 | final ConnectOverloadProtectionProperties connectOverloadProtectionProperties = new ConnectOverloadProtectionProperties(500.25, 750); 18 | assertEquals(750, connectOverloadProtectionProperties.getConnectBurstSize()); 19 | } 20 | } -------------------------------------------------------------------------------- /src/test/java/com/hivemq/spi/services/configuration/entity/TcpListenerTest.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.services.configuration.entity; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | public class TcpListenerTest { 8 | 9 | @Test(timeout = 5000, expected = NullPointerException.class) 10 | public void test_bind_address_must_not_be_null() throws Exception { 11 | new TcpListener(1883, null); 12 | } 13 | 14 | @Test(timeout = 5000) 15 | public void test_smallest_constructor_disables_options() throws Exception { 16 | final TcpListener tcpListener = new TcpListener(1883, "127.0.0.1"); 17 | 18 | assertFalse(tcpListener.isProxyProtocolSupported()); 19 | assertFalse(tcpListener.getSocketOptionsProperties().isPresent()); 20 | assertFalse(tcpListener.getConnectOverloadProtectionProperties().isPresent()); 21 | assertFalse(tcpListener.getClientWriteBufferProperties().isPresent()); 22 | } 23 | } -------------------------------------------------------------------------------- /src/test/java/com/hivemq/spi/services/configuration/validation/validators/MaxClientIdValidatorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.services.configuration.validation.validators; 18 | 19 | import org.junit.Before; 20 | import org.junit.Test; 21 | 22 | import static org.junit.Assert.assertEquals; 23 | 24 | public class MaxClientIdValidatorTest { 25 | 26 | private MaxClientIdValidator maxClientIdValidator; 27 | 28 | @Before 29 | public void setUp() throws Exception { 30 | maxClientIdValidator = new MaxClientIdValidator(); 31 | } 32 | 33 | @Test 34 | public void test_valid_client_identifiers() throws Exception { 35 | 36 | for (int i = 1; i <= 65535; i++) { 37 | assertEquals(true, maxClientIdValidator.validate(i, "").isEmpty()); 38 | } 39 | } 40 | 41 | @Test 42 | public void test_zero_client_identifier() throws Exception { 43 | assertEquals(1, maxClientIdValidator.validate(0, "").size()); 44 | } 45 | 46 | @Test 47 | public void test_negative_client_identifier() throws Exception { 48 | assertEquals(1, maxClientIdValidator.validate(-1, "").size()); 49 | } 50 | 51 | @Test 52 | public void test_client_identifier_higher_65535() throws Exception { 53 | assertEquals(1, maxClientIdValidator.validate(65536, "").size()); 54 | } 55 | } -------------------------------------------------------------------------------- /src/test/java/com/hivemq/spi/services/configuration/validation/validators/TtlValidatorTest.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.services.configuration.validation.validators; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | 6 | import static org.junit.Assert.assertEquals; 7 | 8 | /** 9 | * @author Lukas Brandl 10 | */ 11 | public class TtlValidatorTest { 12 | 13 | private TtlValidator ttlValidator; 14 | 15 | @Before 16 | public void setUp() throws Exception { 17 | ttlValidator = new TtlValidator(); 18 | } 19 | 20 | @Test 21 | public void test_valid_client_identifiers() throws Exception { 22 | assertEquals(true, ttlValidator.validate(100, "").isEmpty()); 23 | } 24 | 25 | @Test 26 | public void test_ttl_disabled() throws Exception { 27 | assertEquals(true, ttlValidator.validate(-1, "").isEmpty()); 28 | } 29 | 30 | @Test 31 | public void test_zero_ttl() throws Exception { 32 | assertEquals(1, ttlValidator.validate(0, "").size()); 33 | } 34 | 35 | @Test 36 | public void test_negative_ttl() throws Exception { 37 | assertEquals(1, ttlValidator.validate(-2, "").size()); 38 | } 39 | } -------------------------------------------------------------------------------- /src/test/java/com/hivemq/spi/services/configuration/validation/validators/ZeroablePositiveNumberTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 dc-square GmbH 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.hivemq.spi.services.configuration.validation.validators; 18 | 19 | import com.hivemq.spi.services.configuration.validation.ValidationError; 20 | import org.junit.Test; 21 | 22 | import java.util.List; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | 26 | public class ZeroablePositiveNumberTest { 27 | 28 | @Test 29 | public void test_zero_valid() throws Exception { 30 | final ZeroablePositiveNumber zeroablePositiveNumber = new ZeroablePositiveNumber(); 31 | final List validationErrors = zeroablePositiveNumber.validate(0, "test"); 32 | 33 | assertEquals(true, validationErrors.isEmpty()); 34 | } 35 | 36 | @Test 37 | public void test_positive_number_valid() throws Exception { 38 | final ZeroablePositiveNumber zeroablePositiveNumber = new ZeroablePositiveNumber(); 39 | final List validationErrors = zeroablePositiveNumber.validate(1, "test"); 40 | 41 | assertEquals(true, validationErrors.isEmpty()); 42 | } 43 | 44 | @Test 45 | public void test_negative_number_invalid() throws Exception { 46 | final ZeroablePositiveNumber zeroablePositiveNumber = new ZeroablePositiveNumber(); 47 | final List validationErrors = zeroablePositiveNumber.validate(-1, "test"); 48 | 49 | assertEquals(1, validationErrors.size()); 50 | System.out.println(validationErrors.get(0).getMessage()); 51 | } 52 | } -------------------------------------------------------------------------------- /src/test/java/com/hivemq/spi/services/rest/listener/AbstractListenerTest.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.services.rest.listener; 2 | 3 | import org.junit.Test; 4 | 5 | /** 6 | * @author Dominik Obermaier 7 | */ 8 | public class AbstractListenerTest { 9 | 10 | 11 | @Test(expected = NullPointerException.class) 12 | public void test_name_null() throws Exception { 13 | new AbstractListener(null, "host", 123) { 14 | }; 15 | 16 | } 17 | 18 | @Test(expected = NullPointerException.class) 19 | public void test_host_null() throws Exception { 20 | new AbstractListener("name", null, 123) { 21 | }; 22 | 23 | } 24 | 25 | @Test(expected = IllegalArgumentException.class) 26 | public void test_port_too_small() throws Exception { 27 | new AbstractListener("name", "host", 0) { 28 | }; 29 | 30 | } 31 | 32 | @Test(expected = IllegalArgumentException.class) 33 | public void test_port_too_high() throws Exception { 34 | new AbstractListener("name", "host", 65536) { 35 | }; 36 | 37 | } 38 | } -------------------------------------------------------------------------------- /src/test/java/com/hivemq/spi/util/ListenersTest.java: -------------------------------------------------------------------------------- 1 | package com.hivemq.spi.util; 2 | 3 | import com.hivemq.spi.services.configuration.entity.TcpListener; 4 | import com.hivemq.spi.services.configuration.entity.TlsTcpListener; 5 | import com.hivemq.spi.services.configuration.entity.TlsWebsocketListener; 6 | import com.hivemq.spi.services.configuration.entity.WebsocketListener; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import org.mockito.Mock; 10 | import org.mockito.MockitoAnnotations; 11 | 12 | import static org.junit.Assert.assertFalse; 13 | import static org.junit.Assert.assertTrue; 14 | 15 | /** 16 | * @author Dominik Obermaier 17 | */ 18 | public class ListenersTest { 19 | 20 | 21 | @Mock 22 | TcpListener tcpListener; 23 | 24 | @Mock 25 | TlsTcpListener tlsTcpListener; 26 | 27 | @Mock 28 | TlsWebsocketListener tlsWebsocketListener; 29 | 30 | @Mock 31 | WebsocketListener websocketListener; 32 | 33 | @Before 34 | public void setUp() throws Exception { 35 | MockitoAnnotations.initMocks(this); 36 | } 37 | 38 | @Test 39 | public void test_is_websocket_listener() throws Exception { 40 | 41 | assertTrue(Listeners.isWebsocket(tlsWebsocketListener)); 42 | assertTrue(Listeners.isWebsocket(websocketListener)); 43 | assertFalse(Listeners.isWebsocket(tcpListener)); 44 | assertFalse(Listeners.isWebsocket(tlsTcpListener)); 45 | } 46 | 47 | @Test 48 | public void test_is_secure_listener() throws Exception { 49 | 50 | assertTrue(Listeners.isSecure(tlsWebsocketListener)); 51 | assertFalse(Listeners.isSecure(websocketListener)); 52 | assertFalse(Listeners.isSecure(tcpListener)); 53 | assertTrue(Listeners.isSecure(tlsTcpListener)); 54 | 55 | } 56 | } --------------------------------------------------------------------------------