-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor GrpcConnector to use grpc builtin reconnection
Signed-off-by: Bernd Warmuth <[email protected]>
- Loading branch information
Showing
18 changed files
with
700 additions
and
1,158 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
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
113 changes: 83 additions & 30 deletions
113
...rc/main/java/dev/openfeature/contrib/providers/flagd/resolver/common/ConnectionEvent.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 |
---|---|---|
@@ -1,69 +1,122 @@ | ||
package dev.openfeature.contrib.providers.flagd.resolver.common; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import dev.openfeature.sdk.ImmutableStructure; | ||
import dev.openfeature.sdk.Structure; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Event payload for a | ||
* {@link dev.openfeature.contrib.providers.flagd.resolver.Resolver} connection | ||
* state change event. | ||
* Represents an event payload for a connection state change in a | ||
* {@link dev.openfeature.contrib.providers.flagd.resolver.Resolver}. | ||
* The event includes information about the connection status, any flags that have changed, | ||
* and metadata associated with the synchronization process. | ||
*/ | ||
@AllArgsConstructor | ||
public class ConnectionEvent { | ||
@Getter | ||
private final boolean connected; | ||
|
||
/** | ||
* The current state of the connection. | ||
*/ | ||
private final ConnectionState connected; | ||
|
||
/** | ||
* A list of flags that have changed due to this connection event. | ||
*/ | ||
private final List<String> flagsChanged; | ||
|
||
/** | ||
* Metadata associated with synchronization in this connection event. | ||
*/ | ||
private final Structure syncMetadata; | ||
|
||
/** | ||
* Construct a new ConnectionEvent. | ||
* | ||
* @param connected status of the connection | ||
* Constructs a new {@code ConnectionEvent} with the connection status only. | ||
* | ||
* @param connected {@code true} if the connection is established, otherwise {@code false}. | ||
*/ | ||
public ConnectionEvent(boolean connected) { | ||
this(connected ? ConnectionState.CONNECTED : ConnectionState.DISCONNECTED, Collections.emptyList(), | ||
new ImmutableStructure()); | ||
} | ||
|
||
/** | ||
* Constructs a new {@code ConnectionEvent} with the specified connection state. | ||
* | ||
* @param connected the connection state indicating if the connection is established or not. | ||
*/ | ||
public ConnectionEvent(ConnectionState connected) { | ||
this(connected, Collections.emptyList(), new ImmutableStructure()); | ||
} | ||
|
||
/** | ||
* Construct a new ConnectionEvent. | ||
* | ||
* @param connected status of the connection | ||
* @param flagsChanged list of flags changed | ||
* Constructs a new {@code ConnectionEvent} with the specified connection state and changed flags. | ||
* | ||
* @param connected the connection state indicating if the connection is established or not. | ||
* @param flagsChanged a list of flags that have changed due to this connection event. | ||
*/ | ||
public ConnectionEvent(boolean connected, List<String> flagsChanged) { | ||
public ConnectionEvent(ConnectionState connected, List<String> flagsChanged) { | ||
this(connected, flagsChanged, new ImmutableStructure()); | ||
} | ||
|
||
/** | ||
* Construct a new ConnectionEvent. | ||
* | ||
* @param connected status of the connection | ||
* @param syncMetadata sync.getMetadata | ||
* Constructs a new {@code ConnectionEvent} with the specified connection state and synchronization metadata. | ||
* | ||
* @param connected the connection state indicating if the connection is established or not. | ||
* @param syncMetadata metadata related to the synchronization process of this event. | ||
*/ | ||
public ConnectionEvent(boolean connected, Structure syncMetadata) { | ||
public ConnectionEvent(ConnectionState connected, Structure syncMetadata) { | ||
this(connected, Collections.emptyList(), new ImmutableStructure(syncMetadata.asMap())); | ||
} | ||
|
||
/** | ||
* Get changed flags. | ||
* | ||
* @return an unmodifiable view of the changed flags | ||
* Constructs a new {@code ConnectionEvent} with the specified connection state, changed flags, and | ||
* synchronization metadata. | ||
* | ||
* @param connectionState the state of the connection. | ||
* @param flagsChanged a list of flags that have changed due to this connection event. | ||
* @param syncMetadata metadata related to the synchronization process of this event. | ||
*/ | ||
public ConnectionEvent(ConnectionState connectionState, List<String> flagsChanged, Structure syncMetadata) { | ||
this.connected = connectionState; | ||
this.flagsChanged = flagsChanged != null ? flagsChanged : Collections.emptyList(); // Ensure non-null list | ||
this.syncMetadata = syncMetadata != null ? new ImmutableStructure(syncMetadata.asMap()) : | ||
new ImmutableStructure(); // Ensure valid syncMetadata | ||
} | ||
|
||
/** | ||
* Retrieves an unmodifiable view of the list of changed flags. | ||
* | ||
* @return an unmodifiable list of changed flags. | ||
*/ | ||
public List<String> getFlagsChanged() { | ||
return Collections.unmodifiableList(flagsChanged); | ||
} | ||
|
||
/** | ||
* Get changed sync metadata represented as SDK structure type. | ||
* | ||
* @return an unmodifiable view of the sync metadata | ||
* Retrieves the synchronization metadata represented as an immutable SDK structure type. | ||
* | ||
* @return an immutable structure containing the synchronization metadata. | ||
*/ | ||
public Structure getSyncMetadata() { | ||
return new ImmutableStructure(syncMetadata.asMap()); | ||
} | ||
|
||
/** | ||
* Indicates whether the current connection state is connected. | ||
* | ||
* @return {@code true} if connected, otherwise {@code false}. | ||
*/ | ||
public boolean isConnected() { | ||
return this.connected == ConnectionState.CONNECTED; | ||
} | ||
|
||
/** | ||
* Indicates | ||
* whether the current connection state is stale. | ||
* | ||
* @return {@code true} if stale, otherwise {@code false}. | ||
*/ | ||
public boolean isStale() { | ||
return this.connected == ConnectionState.STALE; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...rc/main/java/dev/openfeature/contrib/providers/flagd/resolver/common/ConnectionState.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,27 @@ | ||
package dev.openfeature.contrib.providers.flagd.resolver.common; | ||
|
||
/** | ||
* Represents the possible states of a connection. | ||
*/ | ||
public enum ConnectionState { | ||
|
||
/** | ||
* The connection is active and functioning as expected. | ||
*/ | ||
CONNECTED, | ||
|
||
/** | ||
* The connection is not active and has been fully disconnected. | ||
*/ | ||
DISCONNECTED, | ||
|
||
/** | ||
* The connection is inactive or degraded but may still recover. | ||
*/ | ||
STALE, | ||
|
||
/** | ||
* The connection has encountered an error and cannot function correctly. | ||
*/ | ||
ERROR, | ||
} |
Oops, something went wrong.