-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extension to allow adding custom command forwarding
e.g. for commands issued by a route which is provided by a CustomApiRoutesProvider Signed-off-by: Yannic Klem <Yannic.Klem@bosch.io>
- Loading branch information
Showing
7 changed files
with
94 additions
and
2 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
59 changes: 59 additions & 0 deletions
59
...i/src/main/java/org/eclipse/ditto/edge/api/dispatching/EdgeCommandForwarderExtension.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,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.edge.api.dispatching; | ||
|
||
import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull; | ||
|
||
import org.eclipse.ditto.base.service.DittoExtensionPoint; | ||
|
||
import akka.actor.AbstractActor; | ||
import akka.actor.ActorSystem; | ||
|
||
/** | ||
* This extension allows to extend commands that are forwarded from the edges of ditto to other microservices by | ||
* handling them in the {@link AbstractActor.Receive} provided by {@link #getReceiveExtension(akka.actor.AbstractActor.ActorContext)}. | ||
*/ | ||
public interface EdgeCommandForwarderExtension extends DittoExtensionPoint { | ||
|
||
static EdgeCommandForwarderExtension get(final ActorSystem actorSystem) { | ||
checkNotNull(actorSystem, "actorSystem"); | ||
return ExtensionId.INSTANCE.get(actorSystem); | ||
} | ||
|
||
/** | ||
* Builds the receive extension to allow custom handling of messages. | ||
* This receive will be applied BEFORE the default receives of {@link EdgeCommandForwarderActor}, so it's possible | ||
* to overwrite the default handling. | ||
* | ||
* @param actorContext can be used for example to determine the original sender of a message. | ||
* @return The desired receive extension. | ||
*/ | ||
AbstractActor.Receive getReceiveExtension(AbstractActor.ActorContext actorContext); | ||
|
||
final class ExtensionId extends DittoExtensionPoint.ExtensionId<EdgeCommandForwarderExtension> { | ||
|
||
private static final String CONFIG_PATH = "ditto.edge-command-forwarder-extension"; | ||
private static final ExtensionId INSTANCE = new ExtensionId(EdgeCommandForwarderExtension.class); | ||
|
||
private ExtensionId(final Class<EdgeCommandForwarderExtension> parentClass) { | ||
super(parentClass); | ||
} | ||
|
||
@Override | ||
protected String getConfigPath() { | ||
return CONFIG_PATH; | ||
} | ||
|
||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...c/main/java/org/eclipse/ditto/edge/api/dispatching/NoOpEdgeCommandForwarderExtension.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,25 @@ | ||
/* | ||
* 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.edge.api.dispatching; | ||
|
||
import akka.actor.AbstractActor; | ||
import akka.japi.pf.ReceiveBuilder; | ||
|
||
final class NoOpEdgeCommandForwarderExtension implements EdgeCommandForwarderExtension{ | ||
|
||
@Override | ||
public AbstractActor.Receive getReceiveExtension(final AbstractActor.ActorContext actorContext) { | ||
return ReceiveBuilder.create().build(); | ||
} | ||
|
||
} |
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,2 @@ | ||
ditto.edge-command-forwarder-extension = org.eclipse.ditto.edge.api.dispatching.NoOpEdgeCommandForwarderExtension | ||
ditto.edge-command-forwarder-extension = ${?DITTO_EDGE_COMMAND_FORWARDER_EXTENSION} |
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