Skip to content

Commit

Permalink
Add VariableDependency.lock()
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kielbus committed Jun 11, 2014
1 parent 7e4ea2c commit 43811d7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private static List<Lock> orderedLocks(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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@

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>> {

Variable<VALUE> variable();

DependencyType type();

Lock lock();
}

0 comments on commit 43811d7

Please sign in to comment.