-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance Ditto java client with a "disconnection listener"
* called whenever the connection to the Ditto backend was disconnected * provides a context of who initiated the disconnection + an optional cause * provides means to e.g. close the client as a result or to perform a reconnect in addition: fixed executor service creation in Ditto: by default a ScheduledExecutorService with a high "corePoolSize" was configured as default * only use "scheduled" exector for schedluded tasks * provide Ditto client sessionId for thread factories (to append in thread names) * make it possible to configure user code provided "scheduled" executor Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
- Loading branch information
Showing
25 changed files
with
673 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
java/src/main/java/org/eclipse/ditto/client/configuration/DisconnectedContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.client.configuration; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Context provided to registered {@code disconnectedListener}s provided when building {@code MessagingConfiguration} | ||
* of a new Ditto client instance. | ||
* | ||
* @since 2.1.0 | ||
*/ | ||
public interface DisconnectedContext { | ||
|
||
/** | ||
* Returns the {@link Source} providing the source of the disconnect. | ||
* | ||
* @return the source of the disonnect. | ||
*/ | ||
Source getSource(); | ||
|
||
/** | ||
* Provides the optional cause (e.g. the last {@code DittoRuntimeException} or a websocket exception) before the | ||
* disconnect. | ||
* | ||
* @return the optional cause of the disconnect. | ||
*/ | ||
Optional<Throwable> getCause(); | ||
|
||
/** | ||
* Returns a {@link DisconnectionHandler} providing means to either destroy the client channel, prevent an automatic | ||
* reconnect or to explicitly perform a reconnect. | ||
* | ||
* @return the disconnection handler providing options how to handle the disconnect. | ||
*/ | ||
DisconnectionHandler handleDisconnect(); | ||
|
||
/** | ||
* An enumeration of the possible sources which initiated a disconnect. | ||
*/ | ||
enum Source { | ||
/** | ||
* The server closed the connection, potentially providing a cause before | ||
* (sent as {@code DittoRuntimeException} wrapped in an error {@code Adaptable} before). | ||
*/ | ||
SERVER, | ||
|
||
/** | ||
* The client closed the connection - without request by the user code. | ||
* This can e.g. happen if: | ||
* <ul> | ||
* <li>authentication at the Ditto backend failed</li> | ||
* <li>an initialization or network error occurred (e.g. unknown/unresolvable host, proxy problems)</li> | ||
* <li>the WebSocket handshake with the provided Ditto backend endpoint failed</li> | ||
* </ul> | ||
*/ | ||
CLIENT, | ||
|
||
/** | ||
* The user code explicitly disconnected. | ||
*/ | ||
USER_CODE | ||
} | ||
|
||
/** | ||
* A handler provided to the user code providing options to handle an encountered disconnect. | ||
*/ | ||
interface DisconnectionHandler { | ||
|
||
/** | ||
* Closes the underlying channel (e.g. twin, live or policies channel) including their | ||
* {@code MessagingProvider}. | ||
* | ||
* @return this instance for chaining. | ||
*/ | ||
DisconnectionHandler closeChannel(); | ||
|
||
/** | ||
* Prevents the client from doing a (configured) automatic reconnect upon disconnection. | ||
* | ||
* @param preventReconnect whether to prevent the automatic reconnect or not. | ||
* @return this instance for chaining. | ||
*/ | ||
DisconnectionHandler preventConfiguredReconnect(boolean preventReconnect); | ||
|
||
/** | ||
* Performs a reconnect independent from the configured automatic reconnect upon disconnection. | ||
* Can e.g. be used to perform a reconnect only for certain disconnection sources or causes. | ||
* | ||
* @return this instance for chaining. | ||
*/ | ||
DisconnectionHandler performReconnect(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...rc/main/java/org/eclipse/ditto/client/configuration/TokenAuthenticationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.client.configuration; | ||
|
||
import java.time.Duration; | ||
|
||
import org.eclipse.ditto.client.messaging.JsonWebTokenSupplier; | ||
|
||
/** | ||
* Additional JWT / Token specific configurations. | ||
* | ||
* @since 2.1.0 | ||
*/ | ||
public interface TokenAuthenticationConfiguration extends AuthenticationConfiguration { | ||
|
||
/** | ||
* Returns the access token supplier. | ||
* | ||
* @return the supplier. | ||
*/ | ||
JsonWebTokenSupplier getJsonWebTokenSupplier(); | ||
|
||
/** | ||
* Returns the grace period which will be subtracted from token expiry to trigger the configured token supplier. | ||
* | ||
* @return the grace period. | ||
*/ | ||
Duration getExpiryGracePeriod(); | ||
} |
Oops, something went wrong.