Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extensions to connectivity service
Signed-off-by: David Schwilk <david.schwilk@bosch.io>
- Loading branch information
1 parent
12bfbe0
commit caf8fc9
Showing
36 changed files
with
1,347 additions
and
595 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
76 changes: 76 additions & 0 deletions
76
.../src/main/java/org/eclipse/ditto/connectivity/service/CustomConnectivityRootExecutor.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,76 @@ | ||
/* | ||
* 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.connectivity.service; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.ditto.base.service.DittoExtensionPoint; | ||
import org.eclipse.ditto.connectivity.service.config.DittoConnectivityConfig; | ||
import org.eclipse.ditto.internal.utils.akka.AkkaClassLoader; | ||
import org.eclipse.ditto.internal.utils.config.DefaultScopedConfig; | ||
|
||
import akka.actor.AbstractExtensionId; | ||
import akka.actor.ActorContext; | ||
import akka.actor.ActorSystem; | ||
import akka.actor.ExtendedActorSystem; | ||
|
||
/** | ||
* Executor for custom code in connectivity root. Can be used i.e. to start custom actors. | ||
* | ||
* @since 3.0.0 | ||
*/ | ||
public abstract class CustomConnectivityRootExecutor implements DittoExtensionPoint { | ||
|
||
private static final ExtensionId EXTENSION_ID = new ExtensionId(); | ||
|
||
protected final ActorSystem actorSystem; | ||
|
||
/** | ||
* @param actorSystem the actor system in which to load the extension. | ||
*/ | ||
protected CustomConnectivityRootExecutor(final ActorSystem actorSystem) { | ||
this.actorSystem = actorSystem; | ||
} | ||
|
||
/** | ||
* Execute custom custom code. | ||
* @param actorContext the context of the {@code ConnectivityRootActor}. | ||
*/ | ||
public abstract void execute(ActorContext actorContext); | ||
|
||
/** | ||
* Loads the implementation of {@code CustomConnectivityRootExecutor} which is configured for the | ||
* {@code ActorSystem}. | ||
* | ||
* @param actorSystem the actorSystem in which the {@code CustomConnectivityRootExecutor} should be loaded. | ||
* @return the {@code CustomConnectivityRootExecutor} implementation. | ||
* @throws NullPointerException if {@code actorSystem} is {@code null}. | ||
*/ | ||
public static CustomConnectivityRootExecutor get(final ActorSystem actorSystem) { | ||
return EXTENSION_ID.get(actorSystem); | ||
} | ||
|
||
private static final class ExtensionId extends AbstractExtensionId<CustomConnectivityRootExecutor> { | ||
|
||
@Override | ||
public CustomConnectivityRootExecutor createExtension(final ExtendedActorSystem system) { | ||
final var implementation = DittoConnectivityConfig.of(DefaultScopedConfig.dittoScoped( | ||
system.settings().config())).getCustomRootExecutor(); | ||
|
||
return AkkaClassLoader.instantiate(system, CustomConnectivityRootExecutor.class, | ||
implementation, | ||
List.of(ActorSystem.class), | ||
List.of(system)); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...ce/src/main/java/org/eclipse/ditto/connectivity/service/NoOpConnectivityRootExecutor.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,34 @@ | ||
/* | ||
* 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.connectivity.service; | ||
|
||
import akka.actor.ActorContext; | ||
import akka.actor.ActorSystem; | ||
|
||
/** | ||
* Connectivity root executor that does purposefully nothing. | ||
*/ | ||
public class NoOpConnectivityRootExecutor extends CustomConnectivityRootExecutor{ | ||
|
||
/** | ||
* @param actorSystem the actor system in which to load the extension. | ||
*/ | ||
protected NoOpConnectivityRootExecutor(final ActorSystem actorSystem) { | ||
super(actorSystem); | ||
} | ||
|
||
@Override | ||
public void execute(final ActorContext actorContext) { | ||
// Do nothing. | ||
} | ||
} |
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
Oops, something went wrong.