Skip to content

Commit

Permalink
♻️ refactor: refactor codebase #4
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Aug 24, 2024
1 parent be3ae1b commit a6508bd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
2 changes: 2 additions & 0 deletions plugin/src/main/groovy/org/rmq4j/service/Rmq4jService.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public interface Rmq4jService {

Optional<Rmq4jProperties.Connection> getConnActivated(String key);

Map<String, Rmq4jProperties.Connection> getConnectionsActivated();

List<Rmq4jProperties.Config> getConfigsActivated();

Optional<ConnectionFactory> createFactory(Rmq4jProperties.Connection connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ public void snapIns() {
if (this.exists()) {
return;
}
for (Map.Entry<String, Rmq4jProperties.Connection> entry : rmq4jService.getConnections().entrySet()) {
if (!entry.getValue().isEnabled()) {
continue;
}
for (Map.Entry<String, Rmq4jProperties.Connection> entry : rmq4jService.getConnectionsActivated().entrySet()) {
Optional<CachingConnectionFactory> factory = rmq4jService.createCacheConnFactory(entry.getValue());
if (!factory.isPresent()) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
import org.unify4j.model.builder.HttpWrapBuilder;
import org.unify4j.model.enums.IconType;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;

@SuppressWarnings({"FieldCanBeLocal", "DuplicatedCode"})
Expand Down Expand Up @@ -115,6 +112,34 @@ public Optional<Rmq4jProperties.Connection> getConnActivated(String key) {
return cluster.get().isEnabled() ? cluster : Optional.empty();
}

/**
* Retrieves a map of all enabled RabbitMQ cluster configurations.
* <p>
* This method first checks if the RabbitMQ service is enabled by calling {@link #isEnabled()}.
* If the service is not enabled, it returns an empty map.
* If the service is enabled, it iterates through all the available cluster configurations retrieved via
* {@link #getConnections()}.
* For each configuration, it checks if the cluster is enabled.
* Only the enabled clusters added to a new map, which is then returned.
*
* @return A map containing the names and {@link Rmq4jProperties.Connection} objects of all enabled RabbitMQ clusters.
* If the service is not enabled or no clusters are enabled, an empty map is returned.
*/
@Override
public Map<String, Rmq4jProperties.Connection> getConnectionsActivated() {
if (!this.isEnabled()) {
return Collections.emptyMap();
}
Map<String, Rmq4jProperties.Connection> connections = new HashMap<>();
for (Map.Entry<String, Rmq4jProperties.Connection> entry : this.getConnections().entrySet()) {
if (!entry.getValue().isEnabled()) {
continue;
}
connections.put(entry.getKey(), entry.getValue());
}
return connections;
}

/**
* Retrieves a list of all enabled RabbitMQ configurations.
* <p>
Expand Down

0 comments on commit a6508bd

Please sign in to comment.