Sho SHIMIZU
Committed by Gerrit Code Review

Refactor: add static factory method in BatchWrite, instead of in IntentStore

Change-Id: Ic0cecc4b3cc4facbc469d2eb87a36c4d5166a6f2
...@@ -24,7 +24,7 @@ import java.util.List; ...@@ -24,7 +24,7 @@ import java.util.List;
24 24
25 import static com.google.common.base.Preconditions.checkNotNull; 25 import static com.google.common.base.Preconditions.checkNotNull;
26 26
27 -public class BatchWrite { 27 +public final class BatchWrite {
28 28
29 public enum OpType { 29 public enum OpType {
30 CREATE_INTENT, 30 CREATE_INTENT,
...@@ -36,6 +36,17 @@ public class BatchWrite { ...@@ -36,6 +36,17 @@ public class BatchWrite {
36 36
37 List<Operation> operations = new ArrayList<>(); 37 List<Operation> operations = new ArrayList<>();
38 38
39 + private BatchWrite() {}
40 +
41 + /**
42 + * Returns a new empty batch write operation builder.
43 + *
44 + * @return BatchWrite
45 + */
46 + public static BatchWrite newInstance() {
47 + return new BatchWrite();
48 + }
49 +
39 public List<Operation> operations() { 50 public List<Operation> operations() {
40 return Collections.unmodifiableList(operations); 51 return Collections.unmodifiableList(operations);
41 } 52 }
......
...@@ -110,16 +110,6 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { ...@@ -110,16 +110,6 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> {
110 */ 110 */
111 void removeInstalledIntents(IntentId intentId); 111 void removeInstalledIntents(IntentId intentId);
112 112
113 -
114 - /**
115 - * Returns a new empty batch write operation buider.
116 - *
117 - * @return BatchWrite
118 - */
119 - default BatchWrite newBatchWrite() {
120 - return new BatchWrite();
121 - }
122 -
123 /** 113 /**
124 * Execute writes in a batch. 114 * Execute writes in a batch.
125 * 115 *
......
...@@ -768,7 +768,7 @@ public class IntentManager ...@@ -768,7 +768,7 @@ public class IntentManager
768 } 768 }
769 769
770 private void buildIntentUpdates() { 770 private void buildIntentUpdates() {
771 - BatchWrite batchWrite = store.newBatchWrite(); 771 + BatchWrite batchWrite = BatchWrite.newInstance();
772 772
773 // create context and record new request to store 773 // create context and record new request to store
774 for (IntentOperation op : ops.operations()) { 774 for (IntentOperation op : ops.operations()) {
...@@ -806,7 +806,7 @@ public class IntentManager ...@@ -806,7 +806,7 @@ public class IntentManager
806 return flowRuleService.applyBatch(batch); 806 return flowRuleService.applyBatch(batch);
807 } else { 807 } else {
808 // there are no flow rule batches; finalize the intent update 808 // there are no flow rule batches; finalize the intent update
809 - BatchWrite batchWrite = store.newBatchWrite(); 809 + BatchWrite batchWrite = BatchWrite.newInstance();
810 for (IntentUpdate update : intentUpdates) { 810 for (IntentUpdate update : intentUpdates) {
811 update.finalizeStates(batchWrite); 811 update.finalizeStates(batchWrite);
812 } 812 }
......