Skip to content

Commit

Permalink
Adjust extensions in things-search
Browse files Browse the repository at this point in the history
Additionally, change existing RootActorStarter to be RootChildActorStarter and add new RootActorStarter for starting additional root actors outside BaseRootActor

Signed-off-by: David Schwilk <david.schwilk@bosch.io>
  • Loading branch information
DerSchwilk committed May 17, 2022
1 parent 62cbbd9 commit 2e2676a
Show file tree
Hide file tree
Showing 18 changed files with 157 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@
import java.lang.management.ManagementFactory;
import java.text.MessageFormat;
import java.time.Duration;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;

import org.eclipse.ditto.base.model.common.DittoSystemProperties;
Expand Down Expand Up @@ -80,8 +77,6 @@
* <ol>
* <li>{@link #getMainRootActorProps(org.eclipse.ditto.base.service.config.ServiceSpecificConfig, akka.actor.ActorRef)},</li>
* <li>{@link #startMainRootActor(akka.actor.ActorSystem, akka.actor.Props)},</li>
* <li>{@link #getAdditionalRootActorsInformation(org.eclipse.ditto.base.service.config.ServiceSpecificConfig, akka.actor.ActorSystem)} and</li>
* <li>{@link #startAdditionalRootActors(akka.actor.ActorSystem, Iterable)}.</li>
* </ol>
* </li>
* </ol>
Expand Down Expand Up @@ -391,8 +386,6 @@ protected void startDevOpsCommandsActor(final ActorSystem actorSystem) {
* <ul>
* <li>{@link #getMainRootActorProps(org.eclipse.ditto.base.service.config.ServiceSpecificConfig, akka.actor.ActorRef)},</li>
* <li>{@link #startMainRootActor(akka.actor.ActorSystem, akka.actor.Props)},</li>
* <li>{@link #getAdditionalRootActorsInformation(org.eclipse.ditto.base.service.config.ServiceSpecificConfig, akka.actor.ActorSystem)} and</li>
* <li>{@link #startAdditionalRootActors(akka.actor.ActorSystem, Iterable)}.</li>
* </ul>
*
* @param actorSystem Akka actor system for starting actors.
Expand All @@ -409,8 +402,7 @@ protected void startServiceRootActors(final ActorSystem actorSystem, final C ser
injectSystemPropertiesLimits(serviceSpecificConfig);

startMainRootActor(actorSystem, getMainRootActorProps(serviceSpecificConfig, pubSubMediator));
startAdditionalRootActors(actorSystem, getAdditionalRootActorsInformation(serviceSpecificConfig,
actorSystem));
RootActorStarter.get(actorSystem).execute();
});
}

Expand Down Expand Up @@ -459,34 +451,6 @@ protected ActorRef startMainRootActor(final ActorSystem actorSystem, final Props
return startActor(actorSystem, mainRootActorProps, rootActorName);
}

/**
* May be overridden to return information of additional root actors of this service.
* <em>The base implementation returns an empty collection.</em>
*
* @param serviceSpecificConfig the specific configuration of this service.
* @param actorSystem the actor system.
* @return the additional root actors information.
*/
protected Collection<RootActorInformation> getAdditionalRootActorsInformation(final C serviceSpecificConfig,
final ActorSystem actorSystem) {
return Collections.emptyList();
}

/**
* Starts additional root actors of this service. May be overridden to change the way how additional root actors
* will be started.
*
* @param actorSystem Akka actor system for starting actors.
* @param additionalRootActorsInformation information of additional root actors to be started.
*/
protected void startAdditionalRootActors(final ActorSystem actorSystem,
final Iterable<RootActorInformation> additionalRootActorsInformation) {

for (final RootActorInformation rootActorInformation : additionalRootActorsInformation) {
startActor(actorSystem, rootActorInformation.props, rootActorInformation.name);
}
}

private void setUpCoordinatedShutdown(final ActorSystem actorSystem) {
final var coordinatedShutdown = CoordinatedShutdown.get(actorSystem);

Expand All @@ -512,36 +476,4 @@ private void setUpCoordinatedShutdown(final ActorSystem actorSystem) {
});
}

/**
* This class bundles meta information of this service's root actor.
*/
@Immutable
public static final class RootActorInformation {

private final Props props;
private final String name;

private RootActorInformation(final Props theProps, final String theName) {
props = theProps;
name = theName;
}

/**
* Returns an instance of {@code RootActorInformation}.
*
* @param props the Props of the root actor.
* @param name the name of the root actor.
* @return the instance.
* @throws NullPointerException if any argument is {@code null}.
* @throws IllegalArgumentException if {@code name} is empty.
*/
public static RootActorInformation getInstance(final Props props, final String name) {
checkNotNull(props, "root actor props");
argumentNotEmpty(name, "root actor name");

return new RootActorInformation(props, name);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
package org.eclipse.ditto.base.service;

import akka.actor.ActorContext;
import akka.actor.ActorSystem;

/**
Expand All @@ -28,8 +27,9 @@ public NoOpRootActorStarter(final ActorSystem actorSystem) {
}

@Override
public void execute(final ActorContext actorContext) {
public void execute() {
// Do nothing.
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2022 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.base.service;

import akka.actor.ActorContext;
import akka.actor.ActorSystem;

/**
* Root actor child starter that does purposefully nothing.
*/
public final class NoOpRootChildActorStarter implements RootChildActorStarter {

/**
* @param actorSystem the actor system in which to load the extension.
*/
public NoOpRootChildActorStarter(final ActorSystem actorSystem) {
//No-Op because extensions need a constructor accepting an actorSystem
}

@Override
public void execute(final ActorContext actorContext) {
// Do nothing.
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
import org.eclipse.ditto.internal.utils.akka.AkkaClassLoader;
import org.eclipse.ditto.internal.utils.config.DefaultScopedConfig;

import akka.actor.ActorContext;
import akka.actor.ActorSystem;

/**
* Extension to start custom child actors in root actor.
* Extension to start custom root actors in service.
*
* @since 3.0.0
*/
Expand All @@ -33,10 +32,8 @@ public interface RootActorStarter extends DittoExtensionPoint {

/**
* Execute custom custom code.
*
* @param actorContext the context of the {@code GatewayRootActor}.
*/
void execute(ActorContext actorContext);
void execute();

/**
* Loads the implementation of {@code RootActorStarter} which is configured for the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2022 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.base.service;

import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;

import java.util.List;

import org.eclipse.ditto.internal.utils.akka.AkkaClassLoader;
import org.eclipse.ditto.internal.utils.config.DefaultScopedConfig;

import akka.actor.ActorContext;
import akka.actor.ActorSystem;

/**
* Extension to start custom child actors in root actor.
*
* @since 3.0.0
*/
public interface RootChildActorStarter extends DittoExtensionPoint {

static final String CONFIG_PATH = "root-child-actor-starter";

/**
* Execute custom custom code.
*
* @param actorContext the context of the {@code RootActor}.
*/
void execute(ActorContext actorContext);

/**
* Loads the implementation of {@code RootChildActorStarter} which is configured for the
* {@code ActorSystem}.
*
* @param actorSystem the actorSystem in which the {@code RootChildActorStarter} should be loaded.
* @return the {@code RootChildActorStarter} implementation.
* @throws NullPointerException if {@code actorSystem} is {@code null}.
*/
static RootChildActorStarter get(final ActorSystem actorSystem) {
checkNotNull(actorSystem, "actorSystem");
final DefaultScopedConfig dittoScoped = DefaultScopedConfig.dittoScoped(actorSystem.settings().config());
final var implementation = dittoScoped.getString(CONFIG_PATH);

return AkkaClassLoader.instantiate(actorSystem, RootChildActorStarter.class,
implementation,
List.of(ActorSystem.class),
List.of(actorSystem));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import javax.jms.JMSRuntimeException;
import javax.naming.NamingException;

import org.eclipse.ditto.base.service.RootActorStarter;
import org.eclipse.ditto.base.service.RootChildActorStarter;
import org.eclipse.ditto.base.service.actors.DittoRootActor;
import org.eclipse.ditto.connectivity.api.ConnectivityMessagingConstants;
import org.eclipse.ditto.connectivity.service.config.ConnectionIdsRetrievalConfig;
Expand Down Expand Up @@ -112,7 +112,7 @@ private ConnectivityRootActor(final ConnectivityConfig connectivityConfig,
ConnectionPersistenceOperationsActor.props(pubSubMediator, connectivityConfig.getMongoDbConfig(),
actorSystem.settings().config(), connectivityConfig.getPersistenceOperationsConfig()));

RootActorStarter.get(actorSystem).execute(getContext());
RootChildActorStarter.get(actorSystem).execute(getContext());

final var cleanupConfig = connectivityConfig.getConnectionConfig().getCleanupConfig();
final var cleanupActorProps = PersistenceCleanupActor.props(cleanupConfig, mongoReadJournal, CLUSTER_ROLE);
Expand Down
3 changes: 2 additions & 1 deletion connectivity/service/src/main/resources/connectivity.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
ditto {
service-name = "connectivity"
signal-transformer = "org.eclipse.ditto.edge.api.dispatching.NoOpSignalTransformer"
root-actor-starter= "org.eclipse.ditto.base.service.NoOpRootActorStarter"
root-child-actor-starter = "org.eclipse.ditto.base.service.NoOpRootChildActorStarter"
root-actor-starter = "org.eclipse.ditto.base.service.NoOpRootActorStarter"

mongodb {
database = "connectivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.eclipse.ditto.base.model.headers.DittoHeadersSizeChecker;
import org.eclipse.ditto.base.model.headers.translator.HeaderTranslator;
import org.eclipse.ditto.base.service.RootActorStarter;
import org.eclipse.ditto.base.service.RootChildActorStarter;
import org.eclipse.ditto.base.service.actors.DittoRootActor;
import org.eclipse.ditto.base.service.config.limits.LimitsConfig;
import org.eclipse.ditto.connectivity.api.ConnectivityMessagingConstants;
Expand Down Expand Up @@ -149,7 +149,7 @@ private GatewayRootActor(final GatewayConfig gatewayConfig, final ActorRef pubSu
pubSubMediator,
conciergeForwarder));

RootActorStarter.get(actorSystem).execute(getContext());
RootChildActorStarter.get(actorSystem).execute(getContext());

final ActorRef healthCheckActor = createHealthCheckActor(healthCheckConfig);
final var hostname = getHostname(httpConfig);
Expand Down
3 changes: 2 additions & 1 deletion gateway/service/src/main/resources/gateway.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
ditto {
service-name = "gateway"
signal-transformer = "org.eclipse.ditto.edge.api.dispatching.NoOpSignalTransformer"
root-actor-starter= "org.eclipse.ditto.base.service.NoOpRootActorStarter"
root-child-actor-starter = "org.eclipse.ditto.base.service.NoOpRootChildActorStarter"
root-actor-starter = "org.eclipse.ditto.base.service.NoOpRootActorStarter"
mapping-strategy.implementation = "org.eclipse.ditto.gateway.service.util.GatewayMappingStrategies"

signal-enrichment {
Expand Down
2 changes: 2 additions & 0 deletions policies/service/src/main/resources/policies.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ditto {
service-name = "policies"
mapping-strategy.implementation = "org.eclipse.ditto.policies.api.PoliciesMappingStrategies"
root-child-actor-starter = "org.eclipse.ditto.base.service.NoOpRootChildActorStarter"
root-actor-starter = "org.eclipse.ditto.base.service.NoOpRootActorStarter"

mongodb {
database = "policies"
Expand Down
3 changes: 2 additions & 1 deletion things/service/src/main/resources/things.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
ditto {
service-name = "things"
mapping-strategy.implementation = "org.eclipse.ditto.things.api.ThingsMappingStrategies"

root-child-actor-starter = "org.eclipse.ditto.base.service.NoOpRootChildActorStarter"
root-actor-starter = "org.eclipse.ditto.base.service.NoOpRootActorStarter"
persistence.operations.delay-after-persistence-actor-shutdown = 5s
persistence.operations.delay-after-persistence-actor-shutdown = ${?DELAY_AFTER_PERSISTENCE_ACTOR_SHUTDOWN}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@
* Default {@link QueryCriteriaValidator},
* who parses QueryCriteria without additional validation.
*/
public final class DefaultQueryCriteriaValidator extends QueryCriteriaValidator {
public final class DefaultQueryCriteriaValidator implements QueryCriteriaValidator {

/**
* Instantiate this provider. Called by reflection.
*/
public DefaultQueryCriteriaValidator(final ActorSystem actorSystem) {
super(actorSystem);
// Nothing to initialize.
}

Expand Down
Loading

0 comments on commit 2e2676a

Please sign in to comment.