+ @SuppressWarnings("unchecked")
+ private T self() {
+ return (T) this;
+ }
+
+ public T id(ShardIdentifier id) {
+ checkSealed();
+ this.id = id;
+ return self();
+ }
+
+ public T peerAddresses(Map<String, String> peerAddresses) {
+ checkSealed();
+ this.peerAddresses = peerAddresses;
+ return self();
+ }
+
+ public T datastoreContext(DatastoreContext datastoreContext) {
+ checkSealed();
+ this.datastoreContext = datastoreContext;
+ return self();
+ }
+
+ public T schemaContext(SchemaContext schemaContext) {
+ checkSealed();
+ this.schemaContext = schemaContext;
+ return self();
+ }
+
+ public T restoreFromSnapshot(DatastoreSnapshot.ShardSnapshot restoreFromSnapshot) {
+ checkSealed();
+ this.restoreFromSnapshot = restoreFromSnapshot;
+ return self();
+ }
+
+ public ShardIdentifier getId() {
+ return id;
+ }
+
+ public Map<String, String> getPeerAddresses() {
+ return peerAddresses;
+ }
+
+ public DatastoreContext getDatastoreContext() {
+ return datastoreContext;
+ }
+
+ public SchemaContext getSchemaContext() {
+ return schemaContext;
+ }
+
+ public DatastoreSnapshot.ShardSnapshot getRestoreFromSnapshot() {
+ return restoreFromSnapshot;
+ }
+
+ public TreeType getTreeType() {
+ switch (datastoreContext.getLogicalStoreType()) {
+ case CONFIGURATION:
+ return TreeType.CONFIGURATION;
+ case OPERATIONAL:
+ return TreeType.OPERATIONAL;
+ }
+
+ throw new IllegalStateException("Unhandled logical store type " + datastoreContext.getLogicalStoreType());
+ }
+
+ protected void verify() {
+ Preconditions.checkNotNull(id, "id should not be null");
+ Preconditions.checkNotNull(peerAddresses, "peerAddresses should not be null");
+ Preconditions.checkNotNull(datastoreContext, "dataStoreContext should not be null");
+ Preconditions.checkNotNull(schemaContext, "schemaContext should not be null");
+ }
+
+ public Props props() {
+ sealed = true;
+ verify();
+ return Props.create(shardClass, this);
+ }