├── .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 |
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 extends PluginEntryPoint> 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 | ListenableFuture12 | * 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 whentrue
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 beauthorizationResult
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 | Listnull
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 Listnull
.
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 null
42 | */
43 | @Nullable
44 | 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 null
.
55 | */
56 | @Nullable
57 | 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 null
43 | * @deprecated Use {@link BlockingMetricService} or {@link AsyncMetricService} instead.
44 | */
45 | @Nullable
46 | @Deprecated
47 | 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 ValueChangedCallbacktrue
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 | Suppliertrue
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