This is a DTO-like class, not really a Builder with .build() method. Split it out
of its enclosing class and rename it to AbstractShardManagerCreator.
Change-Id: I891fc685c2d9776384294a708336b32eb34011b5
Signed-off-by: Robert Varga <rovarga@cisco.com>
import org.opendaylight.controller.cluster.datastore.jmx.mbeans.DatastoreConfigurationMXBeanImpl;
import org.opendaylight.controller.cluster.datastore.jmx.mbeans.DatastoreInfoMXBeanImpl;
import org.opendaylight.controller.cluster.datastore.messages.DatastoreSnapshot;
-import org.opendaylight.controller.cluster.datastore.shardmanager.ShardManager;
+import org.opendaylight.controller.cluster.datastore.shardmanager.ShardManagerCreator;
import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
import org.opendaylight.controller.cluster.datastore.utils.Dispatchers;
import org.opendaylight.controller.cluster.datastore.utils.PrimaryShardInfoFutureCache;
PrimaryShardInfoFutureCache primaryShardInfoCache = new PrimaryShardInfoFutureCache();
- ShardManager.Builder builder = ShardManager.builder().cluster(cluster).configuration(configuration).
+ ShardManagerCreator creator = new ShardManagerCreator().cluster(cluster).configuration(configuration).
datastoreContextFactory(datastoreContextFactory).waitTillReadyCountdownLatch(waitTillReadyCountDownLatch).
primaryShardInfoCache(primaryShardInfoCache).restoreFromSnapshot(restoreFromSnapshot);
- actorContext = new ActorContext(actorSystem, createShardManager(actorSystem, builder, shardDispatcher,
+ actorContext = new ActorContext(actorSystem, createShardManager(actorSystem, creator, shardDispatcher,
shardManagerId), cluster, configuration, datastoreContextFactory.getBaseDatastoreContext(), primaryShardInfoCache);
this.waitTillReadyTimeInMillis =
}
}
- private static ActorRef createShardManager(ActorSystem actorSystem, ShardManager.Builder builder,
+ private static ActorRef createShardManager(ActorSystem actorSystem, ShardManagerCreator creator,
String shardDispatcher, String shardManagerId) {
Exception lastException = null;
for(int i=0;i<100;i++) {
try {
- return actorSystem.actorOf(builder.props().withDispatcher(shardDispatcher).withMailbox(
+ return actorSystem.actorOf(creator.props().withDispatcher(shardDispatcher).withMailbox(
ActorContext.BOUNDED_MAILBOX), shardManagerId);
} catch (Exception e){
lastException = e;
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.cluster.datastore.shardmanager;
+
+import akka.actor.Props;
+import com.google.common.base.Preconditions;
+import java.util.concurrent.CountDownLatch;
+import org.opendaylight.controller.cluster.datastore.ClusterWrapper;
+import org.opendaylight.controller.cluster.datastore.DatastoreContextFactory;
+import org.opendaylight.controller.cluster.datastore.config.Configuration;
+import org.opendaylight.controller.cluster.datastore.messages.DatastoreSnapshot;
+import org.opendaylight.controller.cluster.datastore.utils.PrimaryShardInfoFutureCache;
+
+public abstract class AbstractShardManagerCreator<T extends AbstractShardManagerCreator<T>> {
+ private ClusterWrapper cluster;
+ private Configuration configuration;
+ private DatastoreContextFactory datastoreContextFactory;
+ private CountDownLatch waitTillReadyCountdownLatch;
+ private PrimaryShardInfoFutureCache primaryShardInfoCache;
+ private DatastoreSnapshot restoreFromSnapshot;
+ private volatile boolean sealed;
+
+ AbstractShardManagerCreator() {
+ // Prevent outside instantiation
+ }
+
+ @SuppressWarnings("unchecked")
+ private T self() {
+ return (T) this;
+ }
+
+ protected final void checkSealed() {
+ Preconditions.checkState(!sealed, "Builder is already sealed - further modifications are not allowed");
+ }
+
+ ClusterWrapper getCluster() {
+ return cluster;
+ }
+
+ public T cluster(ClusterWrapper cluster) {
+ checkSealed();
+ this.cluster = cluster;
+ return self();
+ }
+
+ Configuration getConfiguration() {
+ return configuration;
+ }
+
+ public T configuration(Configuration configuration) {
+ checkSealed();
+ this.configuration = configuration;
+ return self();
+ }
+
+ DatastoreContextFactory getDdatastoreContextFactory() {
+ return datastoreContextFactory;
+ }
+
+ public T datastoreContextFactory(DatastoreContextFactory datastoreContextFactory) {
+ checkSealed();
+ this.datastoreContextFactory = datastoreContextFactory;
+ return self();
+ }
+
+ CountDownLatch getWaitTillReadyCountdownLatch() {
+ return waitTillReadyCountdownLatch;
+ }
+
+ public T waitTillReadyCountdownLatch(CountDownLatch waitTillReadyCountdownLatch) {
+ checkSealed();
+ this.waitTillReadyCountdownLatch = waitTillReadyCountdownLatch;
+ return self();
+ }
+
+ PrimaryShardInfoFutureCache getPrimaryShardInfoCache() {
+ return primaryShardInfoCache;
+ }
+
+ public T primaryShardInfoCache(PrimaryShardInfoFutureCache primaryShardInfoCache) {
+ checkSealed();
+ this.primaryShardInfoCache = primaryShardInfoCache;
+ return self();
+ }
+
+ DatastoreSnapshot getRestoreFromSnapshot() {
+ return restoreFromSnapshot;
+ }
+
+ public T restoreFromSnapshot(DatastoreSnapshot restoreFromSnapshot) {
+ checkSealed();
+ this.restoreFromSnapshot = restoreFromSnapshot;
+ return self();
+ }
+
+ protected void verify() {
+ sealed = true;
+ Preconditions.checkNotNull(cluster, "cluster should not be null");
+ Preconditions.checkNotNull(configuration, "configuration should not be null");
+ Preconditions.checkNotNull(datastoreContextFactory, "datastoreContextFactory should not be null");
+ Preconditions.checkNotNull(waitTillReadyCountdownLatch, "waitTillReadyCountdownLatch should not be null");
+ Preconditions.checkNotNull(primaryShardInfoCache, "primaryShardInfoCache should not be null");
+ }
+
+ public Props props() {
+ verify();
+ return Props.create(ShardManager.class, this);
+ }
+}
\ No newline at end of file
* <li> Monitor the cluster members and store their addresses
* <ul>
*/
-public class ShardManager extends AbstractUntypedPersistentActorWithMetering {
+class ShardManager extends AbstractUntypedPersistentActorWithMetering {
private static final Logger LOG = LoggerFactory.getLogger(ShardManager.class);
private final String persistenceId;
- /**
- */
- protected ShardManager(AbstractBuilder<?> builder) {
-
- this.cluster = builder.cluster;
- this.configuration = builder.configuration;
- this.datastoreContextFactory = builder.datastoreContextFactory;
- this.type = builder.datastoreContextFactory.getBaseDatastoreContext().getDataStoreName();
+ ShardManager(AbstractShardManagerCreator<?> builder) {
+ this.cluster = builder.getCluster();
+ this.configuration = builder.getConfiguration();
+ this.datastoreContextFactory = builder.getDdatastoreContextFactory();
+ this.type = datastoreContextFactory.getBaseDatastoreContext().getDataStoreName();
this.shardDispatcherPath =
new Dispatchers(context().system().dispatchers()).getDispatcherPath(Dispatchers.DispatcherType.Shard);
- this.waitTillReadyCountdownLatch = builder.waitTillReadyCountdownLatch;
- this.primaryShardInfoCache = builder.primaryShardInfoCache;
- this.restoreFromSnapshot = builder.restoreFromSnapshot;
+ this.waitTillReadyCountdownLatch = builder.getWaitTillReadyCountdownLatch();
+ this.primaryShardInfoCache = builder.getPrimaryShardInfoCache();
+ this.restoreFromSnapshot = builder.getRestoreFromSnapshot();
String possiblePersistenceId = datastoreContextFactory.getBaseDatastoreContext().getShardManagerPersistenceId();
persistenceId = possiblePersistenceId != null ? possiblePersistenceId : "shard-manager-" + type;
}
}
- public static Builder builder() {
- return new Builder();
- }
-
- public static abstract class AbstractBuilder<T extends AbstractBuilder<T>> {
- private ClusterWrapper cluster;
- private Configuration configuration;
- private DatastoreContextFactory datastoreContextFactory;
- private CountDownLatch waitTillReadyCountdownLatch;
- private PrimaryShardInfoFutureCache primaryShardInfoCache;
- private DatastoreSnapshot restoreFromSnapshot;
- private volatile boolean sealed;
-
- @SuppressWarnings("unchecked")
- private T self() {
- return (T) this;
- }
-
- protected void checkSealed() {
- Preconditions.checkState(!sealed, "Builder is already sealed - further modifications are not allowed");
- }
-
- public T cluster(ClusterWrapper cluster) {
- checkSealed();
- this.cluster = cluster;
- return self();
- }
-
- public T configuration(Configuration configuration) {
- checkSealed();
- this.configuration = configuration;
- return self();
- }
-
- public T datastoreContextFactory(DatastoreContextFactory datastoreContextFactory) {
- checkSealed();
- this.datastoreContextFactory = datastoreContextFactory;
- return self();
- }
-
- public T waitTillReadyCountdownLatch(CountDownLatch waitTillReadyCountdownLatch) {
- checkSealed();
- this.waitTillReadyCountdownLatch = waitTillReadyCountdownLatch;
- return self();
- }
-
- public T primaryShardInfoCache(PrimaryShardInfoFutureCache primaryShardInfoCache) {
- checkSealed();
- this.primaryShardInfoCache = primaryShardInfoCache;
- return self();
- }
-
- public T restoreFromSnapshot(DatastoreSnapshot restoreFromSnapshot) {
- checkSealed();
- this.restoreFromSnapshot = restoreFromSnapshot;
- return self();
- }
-
- protected void verify() {
- sealed = true;
- Preconditions.checkNotNull(cluster, "cluster should not be null");
- Preconditions.checkNotNull(configuration, "configuration should not be null");
- Preconditions.checkNotNull(datastoreContextFactory, "datastoreContextFactory should not be null");
- Preconditions.checkNotNull(waitTillReadyCountdownLatch, "waitTillReadyCountdownLatch should not be null");
- Preconditions.checkNotNull(primaryShardInfoCache, "primaryShardInfoCache should not be null");
- }
-
- public Props props() {
- verify();
- return Props.create(ShardManager.class, this);
- }
- }
-
- public static class Builder extends AbstractBuilder<Builder> {
- }
-
private void findPrimary(final String shardName, final FindPrimaryResponseHandler handler) {
Timeout findPrimaryTimeout = new Timeout(datastoreContextFactory.getBaseDatastoreContext().
getShardInitializationTimeout().duration().$times(2));
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.cluster.datastore.shardmanager;
+
+public final class ShardManagerCreator extends AbstractShardManagerCreator<ShardManagerCreator> {
+
+}
final PrimaryShardInfoFutureCache primaryShardInfoCache = new PrimaryShardInfoFutureCache();
final CountDownLatch newShardActorLatch = new CountDownLatch(2);
class LocalShardManager extends ShardManager {
- public LocalShardManager(AbstractBuilder<?> builder) {
- super(builder);
+ public LocalShardManager(AbstractShardManagerCreator<?> creator) {
+ super(creator);
}
@Override
private static final long serialVersionUID = 1L;
@Override
public ShardManager create() throws Exception {
- return new LocalShardManager(new GenericBuilder<LocalShardManager>(LocalShardManager.class).
+ return new LocalShardManager(new GenericCreator<LocalShardManager>(LocalShardManager.class).
datastoreContextFactory(mockFactory).primaryShardInfoCache(primaryShardInfoCache).
configuration(mockConfig));
}
return new Builder(datastoreContextBuilder);
}
- private static class Builder extends AbstractGenericBuilder<Builder, TestShardManager> {
+ private static class Builder extends AbstractGenericCreator<Builder, TestShardManager> {
private ActorRef shardActor;
private final Map<String, ActorRef> shardActors = new HashMap<>();
}
}
- private static abstract class AbstractGenericBuilder<T extends AbstractGenericBuilder<T, ?>, C extends ShardManager>
- extends ShardManager.AbstractBuilder<T> {
+ private static abstract class AbstractGenericCreator<T extends AbstractGenericCreator<T, ?>, C extends ShardManager>
+ extends AbstractShardManagerCreator<T> {
private final Class<C> shardManagerClass;
- AbstractGenericBuilder(Class<C> shardManagerClass) {
+ AbstractGenericCreator(Class<C> shardManagerClass) {
this.shardManagerClass = shardManagerClass;
cluster(new MockClusterWrapper()).configuration(new MockConfiguration()).
waitTillReadyCountdownLatch(ready).primaryShardInfoCache(new PrimaryShardInfoFutureCache());
}
}
- private static class GenericBuilder<C extends ShardManager> extends AbstractGenericBuilder<GenericBuilder<C>, C> {
- GenericBuilder(Class<C> shardManagerClass) {
+ private static class GenericCreator<C extends ShardManager> extends AbstractGenericCreator<GenericCreator<C>, C> {
+ GenericCreator(Class<C> shardManagerClass) {
super(shardManagerClass);
}
}