X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fentityownership%2Fselectionstrategy%2FEntityOwnerSelectionStrategyConfig.java;h=a5ffc49a0eb6d5341a374a3b1e7b91733c4ed301;hb=14f35cba90e93b69f038a243a6dd4eadac933a58;hp=c1ddab3c7d67aa351a38654351a93a34673e6d27;hpb=e4bf29ae5e97f128471cbe3e93f807721f944d83;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/EntityOwnerSelectionStrategyConfig.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/EntityOwnerSelectionStrategyConfig.java index c1ddab3c7d..a5ffc49a0e 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/EntityOwnerSelectionStrategyConfig.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/EntityOwnerSelectionStrategyConfig.java @@ -30,17 +30,18 @@ public final class EntityOwnerSelectionStrategyConfig { return entityTypeToStrategyInfo.get(entityType) != null; } - public EntityOwnerSelectionStrategy createStrategy(final String entityType) { + public EntityOwnerSelectionStrategy createStrategy(final String entityType, + final Map initialStatistics) { final EntityOwnerSelectionStrategy strategy; final EntityOwnerSelectionStrategy existingStrategy = entityTypeToOwnerSelectionStrategy.get(entityType); - if(existingStrategy != null){ + if (existingStrategy != null) { strategy = existingStrategy; } else { EntityOwnerSelectionStrategyConfig.StrategyInfo strategyInfo = entityTypeToStrategyInfo.get(entityType); - if(strategyInfo == null){ + if (strategyInfo == null) { strategy = FirstCandidateSelectionStrategy.INSTANCE; } else { - strategy = strategyInfo.createStrategy(); + strategy = strategyInfo.createStrategy(initialStatistics); } entityTypeToOwnerSelectionStrategy.put(entityType, strategy); } @@ -48,16 +49,19 @@ public final class EntityOwnerSelectionStrategyConfig { } /** - * @deprecated FIXME: THIS IS CONFIGURATION FOR A CUSTOM-LOADED CLASS CONSTRUCTOR - * * This class should not exist. It contains a single long, which is passed to the constructor (via reflection). * We are getting that information from a BundleContext. We are running in OSGi environment, hence this class * needs to be deployed in its own bundle, with its own configuration. - * * If this is used internally, it needs to be relocated into a separate package along with the implementation * using it. + * + * @deprecated FIXME: THIS IS CONFIGURATION FOR A CUSTOM-LOADED CLASS CONSTRUCTOR */ @Deprecated + public void clearStrategies() { + entityTypeToOwnerSelectionStrategy.clear(); + } + private static final class StrategyInfo { private final Class strategyClass; private final long delay; @@ -67,10 +71,12 @@ public final class EntityOwnerSelectionStrategyConfig { this.delay = delay; } - public EntityOwnerSelectionStrategy createStrategy() { + public EntityOwnerSelectionStrategy createStrategy(final Map initialStatistics) { try { - return strategyClass.getDeclaredConstructor(long.class).newInstance(delay); - } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + return strategyClass.getDeclaredConstructor(long.class, Map.class) + .newInstance(delay, initialStatistics); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException + | NoSuchMethodException e) { LOG.warn("could not create custom strategy", e); } return FirstCandidateSelectionStrategy.INSTANCE; @@ -81,19 +87,20 @@ public final class EntityOwnerSelectionStrategyConfig { return new Builder(new EntityOwnerSelectionStrategyConfig()); } - public static class Builder { + public static final class Builder { private final EntityOwnerSelectionStrategyConfig config; - private Builder(final EntityOwnerSelectionStrategyConfig config){ + Builder(final EntityOwnerSelectionStrategyConfig config) { this.config = config; } - public Builder addStrategy(final String entityType, final Class strategy, final long delay){ + public Builder addStrategy(final String entityType, + final Class strategy, final long delay) { config.entityTypeToStrategyInfo.put(entityType, new StrategyInfo(strategy, delay)); return this; } - public EntityOwnerSelectionStrategyConfig build(){ + public EntityOwnerSelectionStrategyConfig build() { return this.config; } }