-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide mechanism to configure each extension on a separate level
Signed-off-by: Yannic Klem <yannic.klem@bosch.io>
- Loading branch information
Showing
2 changed files
with
104 additions
and
7 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
base/service/src/main/java/org/eclipse/ditto/base/service/DittoExtensionIds.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,63 @@ | ||
/* | ||
* 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 java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
import org.eclipse.ditto.base.service.DittoExtensionPoint.ExtensionId.ExtensionIdConfig; | ||
import org.eclipse.ditto.internal.utils.akka.AkkaClassLoader; | ||
|
||
import akka.actor.AbstractExtensionId; | ||
import akka.actor.ActorSystem; | ||
import akka.actor.ExtendedActorSystem; | ||
import akka.actor.Extension; | ||
|
||
public final class DittoExtensionIds implements Extension { | ||
|
||
static final ExtensionId INSTANCE = new ExtensionId(); | ||
private final Map<ExtensionIdConfig<?>, DittoExtensionPoint.ExtensionId<?>> extensionIds = new HashMap<>(); | ||
|
||
public <T extends Extension> DittoExtensionPoint.ExtensionId<T> computeIfAbsent( | ||
final ExtensionIdConfig<T> extensionIdConfig, | ||
final Function<ExtensionIdConfig<T>, DittoExtensionPoint.ExtensionId<T>> extensionIdCreator) { | ||
final DittoExtensionPoint.ExtensionId<T> extensionId = | ||
(DittoExtensionPoint.ExtensionId<T>) extensionIds.get(extensionIdConfig); | ||
if (extensionId == null) { | ||
final DittoExtensionPoint.ExtensionId<T> newExtensionId = extensionIdCreator.apply(extensionIdConfig); | ||
extensionIds.put(extensionIdConfig, newExtensionId); | ||
return newExtensionId; | ||
} else { | ||
return extensionId; | ||
} | ||
} | ||
|
||
public static DittoExtensionIds get(final ActorSystem actorSystem) { | ||
return INSTANCE.get(actorSystem); | ||
} | ||
|
||
static final class ExtensionId extends AbstractExtensionId<DittoExtensionIds> { | ||
|
||
@Override | ||
public DittoExtensionIds createExtension(final ExtendedActorSystem system) { | ||
|
||
return AkkaClassLoader.instantiate(system, DittoExtensionIds.class, | ||
DittoExtensionIds.class.getCanonicalName(), | ||
List.of(), | ||
List.of()); | ||
} | ||
} | ||
|
||
} |
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