Skip to content

Commit

Permalink
Issue #106: Removed unused code and fixed some code smells.
Browse files Browse the repository at this point in the history
Signed-off-by: Juergen Fickel <juergen.fickel@bosch.io>
  • Loading branch information
Juergen Fickel committed Nov 12, 2021
1 parent 0d6fe6f commit bedc984
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;
import static org.eclipse.ditto.connectivity.api.ConnectivityMessagingConstants.CLUSTER_ROLE;

import java.text.MessageFormat;
import java.time.Duration;
import java.time.Instant;
import java.util.Collections;
Expand Down Expand Up @@ -115,7 +116,6 @@
import org.eclipse.ditto.thingsearch.model.signals.commands.subscription.CreateSubscription;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;

import akka.actor.ActorRef;
import akka.actor.Props;
Expand Down Expand Up @@ -662,13 +662,14 @@ private void startThingSearchSession(final CreateSubscription command) {
augmentWithPrefixAndForward(command, entity.getClientCount(), clientActorRouter);
}

private void augmentWithPrefixAndForward(final CreateSubscription createSubscription, final int clientCount,
private void augmentWithPrefixAndForward(final CreateSubscription createSubscription,
final int clientCount,
final ActorRef clientActorRouter) {

subscriptionCounter = (subscriptionCounter + 1) % Math.max(1, clientCount);
final int prefixLength = getSubscriptionPrefixLength(clientCount);
final String prefix = String.format("%0" + prefixLength + "X", subscriptionCounter);
final Optional<ActorRef> receiver = clientActorRefs.get(subscriptionCounter);
final CreateSubscription commandWithPrefix = createSubscription.setPrefix(prefix);
final var prefix = getPrefix(getSubscriptionPrefixLength(clientCount), subscriptionCounter);
final var receiver = clientActorRefs.get(subscriptionCounter);
final var commandWithPrefix = createSubscription.setPrefix(prefix);
if (clientCount == 1) {
clientActorRouter.tell(consistentHashableEnvelope(commandWithPrefix, prefix), ActorRef.noSender());
} else if (receiver.isPresent()) {
Expand All @@ -678,6 +679,11 @@ private void augmentWithPrefixAndForward(final CreateSubscription createSubscrip
}
}

private static String getPrefix(final int prefixLength, final int subscriptionCounter) {
final var prefixPattern = MessageFormat.format("%0{0,number}X", prefixLength);
return String.format(prefixPattern, subscriptionCounter);
}

private void checkLoggingEnabled(final Control message) {
final CheckConnectionLogsActive checkLoggingActive = CheckConnectionLogsActive.of(entityId, Instant.now());
broadcastToClientActorsIfStarted(checkLoggingActive, getSelf());
Expand Down Expand Up @@ -1139,15 +1145,6 @@ enum Control {
TRIGGER_UPDATE_PRIORITY
}

private static final class InitializationFailure {

private final Throwable cause;

private InitializationFailure(final Throwable cause) {
this.cause = cause;
}
}

/**
* Local message this actor may sent to itself in order to update the priority of the connection.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.eclipse.ditto.base.model.entity.id.NamespacedEntityId;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.base.model.headers.contenttype.ContentType;
import org.eclipse.ditto.connectivity.model.ConnectivityConstants;
import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.json.JsonPointer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import akka.actor.ActorRef;
import akka.japi.Pair;
import akka.pattern.Patterns;
import akka.stream.Attributes;
import akka.stream.javadsl.Source;

/**
Expand Down Expand Up @@ -102,7 +101,7 @@ public Source<Metadata, NotUsed> filterForInconsistencies(final Source<Metadata,
.flatMapConcat(this::filterForInconsistency);
}

private boolean isInsideToleranceWindow(final Metadata metadata, final Instant toleranceCutOff) {
private static boolean isInsideToleranceWindow(final Metadata metadata, final Instant toleranceCutOff) {
return metadata.getModified()
.map(modified -> modified.isAfter(toleranceCutOff))
.orElse(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,6 @@ public DittoMongoClient getUpdaterClient() {
return updaterClient;
}

@Nullable
private static CommandListener getCommandListenerOrNull(final MongoDbConfig.MonitoringConfig monitoringConfig,
final String prefix) {

return monitoringConfig.isCommandsEnabled() ? new KamonCommandListener(prefix) : null;
}

@Nullable
private static ConnectionPoolListener getConnectionPoolListenerOrNull(
final MongoDbConfig.MonitoringConfig monitoringConfig,
final String prefix) {

return monitoringConfig.isConnectionPoolEnabled()
? new KamonConnectionPoolListener(prefix)
: null;
}

private static final class Id extends AbstractExtensionId<MongoClientExtension> {

@Override
Expand All @@ -112,5 +95,22 @@ public MongoClientExtension createExtension(final ExtendedActorSystem system) {
.build();
return new MongoClientExtension(searchClient, updaterClient);
}

@Nullable
private static CommandListener getCommandListenerOrNull(final MongoDbConfig.MonitoringConfig monitoringConfig,
final String prefix) {

return monitoringConfig.isCommandsEnabled() ? new KamonCommandListener(prefix) : null;
}

@Nullable
private static ConnectionPoolListener getConnectionPoolListenerOrNull(
final MongoDbConfig.MonitoringConfig monitoringConfig,
final String prefix
) {
return monitoringConfig.isConnectionPoolEnabled() ? new KamonConnectionPoolListener(prefix) : null;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.eclipse.ditto.thingsearch.service.updater.actors.SearchUpdaterRootActor;

import akka.actor.ActorRef;
import akka.actor.ActorSelection;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.event.Logging;
Expand Down

0 comments on commit bedc984

Please sign in to comment.