-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce extendable ThingEventObserver to allow custom processing of…
… thing events Signed-off-by: Dominik Guggemos <dominik.guggemos@bosch.io>
- Loading branch information
Showing
8 changed files
with
196 additions
and
30 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
26 changes: 26 additions & 0 deletions
26
.../java/org/eclipse/ditto/thingsearch/service/updater/actors/DefaultThingEventObserver.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,26 @@ | ||
/* | ||
* Copyright (c) 2021 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.thingsearch.service.updater.actors; | ||
|
||
import org.eclipse.ditto.things.model.signals.events.ThingEvent; | ||
|
||
/** | ||
* Default ThingEventObserver implementation. | ||
*/ | ||
public class DefaultThingEventObserver extends ThingEventObserver { | ||
|
||
@Override | ||
public void processThingEvent(final ThingEvent<?> event) { | ||
// noop | ||
} | ||
} |
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
72 changes: 72 additions & 0 deletions
72
...rc/main/java/org/eclipse/ditto/thingsearch/service/updater/actors/ThingEventObserver.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,72 @@ | ||
/* | ||
* Copyright (c) 2021 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.thingsearch.service.updater.actors; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.ditto.internal.utils.akka.AkkaClassLoader; | ||
import org.eclipse.ditto.internal.utils.config.DefaultScopedConfig; | ||
import org.eclipse.ditto.things.model.signals.events.ThingEvent; | ||
import org.eclipse.ditto.thingsearch.service.common.config.DittoSearchConfig; | ||
import org.eclipse.ditto.thingsearch.service.common.config.SearchConfig; | ||
|
||
import akka.actor.AbstractExtensionId; | ||
import akka.actor.ActorSystem; | ||
import akka.actor.ExtendedActorSystem; | ||
import akka.actor.Extension; | ||
|
||
/** | ||
* Thing event observer to be loaded by reflection. | ||
* Can be used as an extension point to use process thing events. | ||
* Implementations MUST have a public constructor taking an actorSystem as argument. | ||
* | ||
* @since 2.3.0 | ||
*/ | ||
public abstract class ThingEventObserver implements Extension { | ||
|
||
private static final ThingEventObserver.ExtensionId EXTENSION_ID = new ThingEventObserver.ExtensionId(); | ||
|
||
/** | ||
* Load a {@code ThingEventObserver} dynamically according to the search configuration. | ||
* | ||
* @param actorSystem The actor system in which to load the observer. | ||
* @return The thing event observer. | ||
*/ | ||
public static ThingEventObserver get(final ActorSystem actorSystem) { | ||
return EXTENSION_ID.get(actorSystem); | ||
} | ||
|
||
/** | ||
* Process the given {@code ThingEvent}. | ||
* | ||
* @param event the thing event | ||
*/ | ||
public abstract void processThingEvent(final ThingEvent<?> event); | ||
|
||
|
||
/** | ||
* ID of the actor system extension to validate the {@code ThingEventObserver}. | ||
*/ | ||
private static final class ExtensionId extends AbstractExtensionId<ThingEventObserver> { | ||
|
||
@Override | ||
public ThingEventObserver createExtension(final ExtendedActorSystem system) { | ||
final SearchConfig searchConfig = | ||
DittoSearchConfig.of(DefaultScopedConfig.dittoScoped(system.settings().config())); | ||
|
||
return AkkaClassLoader.instantiate(system, ThingEventObserver.class, | ||
searchConfig.getThingEventObserverImplementation(), List.of(ActorSystem.class), List.of(system)); | ||
} | ||
} | ||
|
||
} |
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.