Skip to content
Browse files

Add VariableDependency.lock()

  • Loading branch information...
1 parent 7e4ea2c commit 43811d7f5aac9dbfd85d65ca18e72fc7a9b9861e @thomas-kielbus thomas-kielbus committed
View
2 ...k-core/src/main/java/com/liveramp/megadesk/base/transaction/BaseTransactionExecution.java
@@ -110,7 +110,7 @@ private void lock(Dependency dependency) {
Collections.sort(all);
List<Lock> result = Lists.newArrayList();
for (VariableDependency variableDependency : all) {
- result.add(DependencyType.lock(variableDependency));
+ result.add(variableDependency.lock());
}
return result;
}
View
13 ...esk-core/src/main/java/com/liveramp/megadesk/base/transaction/BaseVariableDependency.java
@@ -18,6 +18,7 @@
import org.apache.commons.lang.builder.CompareToBuilder;
+import com.liveramp.megadesk.core.state.Lock;
import com.liveramp.megadesk.core.state.Variable;
import com.liveramp.megadesk.core.transaction.DependencyType;
import com.liveramp.megadesk.core.transaction.VariableDependency;
@@ -42,6 +43,18 @@ public DependencyType type() {
return type;
}
+ @Override
+ public Lock lock() {
+ switch (type) {
+ case READ:
+ return variable.driver().lock().readLock();
+ case WRITE:
+ return variable.driver().lock().writeLock();
+ default:
+ throw new IllegalStateException(); // TODO: message
+ }
+ }
+
public static <VALUE> BaseVariableDependency<VALUE> build(Variable<VALUE> variable, DependencyType type) {
return new BaseVariableDependency<VALUE>(variable, type);
}
View
15 megadesk-core/src/main/java/com/liveramp/megadesk/core/transaction/DependencyType.java
@@ -16,20 +16,7 @@
package com.liveramp.megadesk.core.transaction;
-import com.liveramp.megadesk.core.state.Lock;
-
public enum DependencyType {
READ,
- WRITE;
-
- public static Lock lock(VariableDependency variableDependency) {
- switch (variableDependency.type()) {
- case READ:
- return variableDependency.variable().driver().lock().readLock();
- case WRITE:
- return variableDependency.variable().driver().lock().writeLock();
- default:
- throw new IllegalStateException(); // TODO: message
- }
- }
+ WRITE
}
View
3 megadesk-core/src/main/java/com/liveramp/megadesk/core/transaction/VariableDependency.java
@@ -16,6 +16,7 @@
package com.liveramp.megadesk.core.transaction;
+import com.liveramp.megadesk.core.state.Lock;
import com.liveramp.megadesk.core.state.Variable;
public interface VariableDependency<VALUE> extends Comparable<VariableDependency<VALUE>> {
@@ -23,4 +24,6 @@
Variable<VALUE> variable();
DependencyType type();
+
+ Lock lock();
}

0 comments on commit 43811d7

Please sign in to comment.
Something went wrong with that request. Please try again.