Madan Jampani

Fixed checkstyle issues

......@@ -8,63 +8,63 @@ import com.google.common.collect.Lists;
/**
* Collection of read requests to be submitted as one batch.
*/
public class BatchReadRequest {
public final class BatchReadRequest {
private final List<ReadRequest> readRequests;
private final List<ReadRequest> readRequests;
/**
* Creates a new BatchReadRequest object from the specified list of read requests.
* @param readRequests read requests.
* @return BatchReadRequest object.
*/
public static BatchReadRequest create(List<ReadRequest> readRequests) {
return new BatchReadRequest(readRequests);
}
/**
* Creates a new BatchReadRequest object from the specified list of read requests.
* @param readRequests read requests.
* @return BatchReadRequest object.
*/
public static BatchReadRequest create(List<ReadRequest> readRequests) {
return new BatchReadRequest(readRequests);
}
private BatchReadRequest(List<ReadRequest> readRequests) {
this.readRequests = Collections.unmodifiableList(readRequests);
}
private BatchReadRequest(List<ReadRequest> readRequests) {
this.readRequests = Collections.unmodifiableList(readRequests);
}
/**
* Returns the number of requests in this batch.
* @return size of request batch.
*/
public int batchSize() {
return readRequests.size();
}
/**
* Returns the number of requests in this batch.
* @return size of request batch.
*/
public int batchSize() {
return readRequests.size();
}
/**
* Returns the requests in this batch as a list.
* @return list of read requests
*/
public List<ReadRequest> getAsList() {
return readRequests;
}
/**
* Returns the requests in this batch as a list.
* @return list of read requests
*/
public List<ReadRequest> getAsList() {
return readRequests;
}
/**
* Builder for BatchReadRequest.
*/
public static class Builder {
/**
* Builder for BatchReadRequest.
*/
public static class Builder {
private final List<ReadRequest> readRequests = Lists.newLinkedList();
private final List<ReadRequest> readRequests = Lists.newLinkedList();
/**
* Append a get request.
* @param tableName table name
* @param key key to fetch.
* @return this Builder
*/
public Builder get(String tableName, String key) {
readRequests.add(new ReadRequest(tableName, key));
return this;
}
/**
* Append a get request.
* @param tableName table name
* @param key key to fetch.
* @return this Builder
*/
public Builder get(String tableName, String key) {
readRequests.add(new ReadRequest(tableName, key));
return this;
}
/**
* Builds a BatchReadRequest
* @return BatchReadRequest
*/
public BatchReadRequest build() {
return new BatchReadRequest(readRequests);
}
}
}
\ No newline at end of file
/**
* Builds a BatchReadRequest.
* @return BatchReadRequest
*/
public BatchReadRequest build() {
return new BatchReadRequest(readRequests);
}
}
}
......
......@@ -3,19 +3,30 @@ package org.onlab.onos.store.service;
import java.util.Collections;
import java.util.List;
/**
* Result of a batch read operation.
*/
public class BatchReadResult {
private final List<ReadResult> readResults;
public BatchReadResult(List<ReadResult> readResults) {
this.readResults = Collections.unmodifiableList(readResults);
}
public List<ReadResult> getAsList() {
return readResults;
}
public int batchSize() {
return readResults.size();
}
}
\ No newline at end of file
private final List<ReadResult> readResults;
public BatchReadResult(List<ReadResult> readResults) {
this.readResults = Collections.unmodifiableList(readResults);
}
/**
* Returns the results as a list.
* @return list of results
*/
public List<ReadResult> getAsList() {
return readResults;
}
/**
* Returns the batch size.
* @return batch size
*/
public int batchSize() {
return readResults.size();
}
}
......
......@@ -8,83 +8,83 @@ import com.google.common.collect.Lists;
/**
* Collection of write requests to be submitted as one batch.
*/
public class BatchWriteRequest {
private final List<WriteRequest> writeRequests;
/**
* Creates a new BatchWriteRequest object from the specified list of write requests.
* @param writeRequests write requests.
* @return BatchWriteRequest object.
*/
public static BatchWriteRequest create(List<WriteRequest> writeRequests) {
return new BatchWriteRequest(writeRequests);
}
private BatchWriteRequest(List<WriteRequest> writeRequests) {
this.writeRequests = Collections.unmodifiableList(writeRequests);
}
/**
* Returns the requests in this batch as a list.
* @return list of write requests
*/
public List<WriteRequest> getAsList() {
return writeRequests;
}
/**
* Returns the number of requests in this batch.
* @return size of request batch.
*/
public int batchSize() {
return writeRequests.size();
}
/**
* Builder for BatchWriteRequest.
*/
public static class Builder {
private final List<WriteRequest> writeRequests = Lists.newLinkedList();
public Builder put(String tableName, String key, byte[] value) {
writeRequests.add(WriteRequest.put(tableName, key, value));
return this;
}
public Builder putIfAbsent(String tableName, String key, byte[] value) {
writeRequests.add(WriteRequest.putIfAbsent(tableName, key, value));
return this;
}
public Builder putIfValueMatches(String tableName, String key, byte[] oldValue, byte[] newValue) {
writeRequests.add(WriteRequest.putIfValueMatches(tableName, key, oldValue, newValue));
return this;
}
public Builder putIfVersionMatches(String tableName, String key, byte[] value, long version) {
writeRequests.add(WriteRequest.putIfVersionMatches(tableName, key, value, version));
return this;
}
public Builder remove(String tableName, String key) {
writeRequests.add(WriteRequest.remove(tableName, key));
return this;
}
public Builder removeIfVersionMatches(String tableName, String key, long version) {
writeRequests.add(WriteRequest.removeIfVersionMatches(tableName, key, version));
return this;
}
public Builder removeIfValueMatches(String tableName, String key, byte[] value) {
writeRequests.add(WriteRequest.removeIfValueMatches(tableName, key, value));
return this;
}
public BatchWriteRequest build() {
return new BatchWriteRequest(writeRequests);
}
}
}
\ No newline at end of file
public final class BatchWriteRequest {
private final List<WriteRequest> writeRequests;
/**
* Creates a new BatchWriteRequest object from the specified list of write requests.
* @param writeRequests write requests.
* @return BatchWriteRequest object.
*/
public static BatchWriteRequest create(List<WriteRequest> writeRequests) {
return new BatchWriteRequest(writeRequests);
}
private BatchWriteRequest(List<WriteRequest> writeRequests) {
this.writeRequests = Collections.unmodifiableList(writeRequests);
}
/**
* Returns the requests in this batch as a list.
* @return list of write requests
*/
public List<WriteRequest> getAsList() {
return writeRequests;
}
/**
* Returns the number of requests in this batch.
* @return size of request batch.
*/
public int batchSize() {
return writeRequests.size();
}
/**
* Builder for BatchWriteRequest.
*/
public static class Builder {
private final List<WriteRequest> writeRequests = Lists.newLinkedList();
public Builder put(String tableName, String key, byte[] value) {
writeRequests.add(WriteRequest.put(tableName, key, value));
return this;
}
public Builder putIfAbsent(String tableName, String key, byte[] value) {
writeRequests.add(WriteRequest.putIfAbsent(tableName, key, value));
return this;
}
public Builder putIfValueMatches(String tableName, String key, byte[] oldValue, byte[] newValue) {
writeRequests.add(WriteRequest.putIfValueMatches(tableName, key, oldValue, newValue));
return this;
}
public Builder putIfVersionMatches(String tableName, String key, byte[] value, long version) {
writeRequests.add(WriteRequest.putIfVersionMatches(tableName, key, value, version));
return this;
}
public Builder remove(String tableName, String key) {
writeRequests.add(WriteRequest.remove(tableName, key));
return this;
}
public Builder removeIfVersionMatches(String tableName, String key, long version) {
writeRequests.add(WriteRequest.removeIfVersionMatches(tableName, key, version));
return this;
}
public Builder removeIfValueMatches(String tableName, String key, byte[] value) {
writeRequests.add(WriteRequest.removeIfValueMatches(tableName, key, value));
return this;
}
public BatchWriteRequest build() {
return new BatchWriteRequest(writeRequests);
}
}
}
......
......@@ -3,28 +3,43 @@ package org.onlab.onos.store.service;
import java.util.Collections;
import java.util.List;
/**
* Result of a batch write operation.
*/
public class BatchWriteResult {
private final List<WriteResult> writeResults;
public BatchWriteResult(List<WriteResult> writeResults) {
this.writeResults = Collections.unmodifiableList(writeResults);
}
public boolean isSuccessful() {
for (WriteResult result : writeResults) {
if (result.status() != WriteStatus.OK) {
return false;
}
}
return true;
}
public List<WriteResult> getAsList() {
return this.writeResults;
}
public int batchSize() {
return writeResults.size();
}
}
\ No newline at end of file
private final List<WriteResult> writeResults;
public BatchWriteResult(List<WriteResult> writeResults) {
this.writeResults = Collections.unmodifiableList(writeResults);
}
/**
* Returns true if this batch write operation was successful.
* @return true if successful, false otherwise.
*/
public boolean isSuccessful() {
for (WriteResult result : writeResults) {
if (result.status() != WriteStatus.OK) {
return false;
}
}
return true;
}
/**
* Returns the results as a List.
* @return list of batch results.
*/
public List<WriteResult> getAsList() {
return this.writeResults;
}
/**
* Returns the size of this batch.
* @return batch size.
*/
public int batchSize() {
return writeResults.size();
}
}
......
......@@ -13,7 +13,7 @@ public interface DatabaseService {
* @returns value (and version) associated with this key. This calls returns null if the key does not exist.
*/
VersionedValue get(String tableName, String key);
/**
* Associate the key with a value.
* @param tableName table name in which this key/value resides.
......@@ -22,7 +22,7 @@ public interface DatabaseService {
* @return the previous value associated with the specified key, or null if there was no mapping for the key.
*/
VersionedValue put(String tableName, String key, byte[] value);
/**
* If the specified key is not already associated with a value, associate it with the given value.
* @param tableName table name in which this key/value resides.
......@@ -31,7 +31,7 @@ public interface DatabaseService {
* @return true if put was successful, false if there is already a value associated with this key
*/
boolean putIfAbsent(String tableName, String key, byte[] value);
/**
* Sets the key to the specified value if the version in the database (for that key)
* matches the specified version.
......@@ -42,7 +42,7 @@ public interface DatabaseService {
* @return true if put was successful, false if there version in database is different from what is specified.
*/
boolean putIfVersionMatches(String tableName, String key, byte[] value, long version);
/**
* Replaces the entry for a key only if currently mapped to a given value.
* @param tableName name of table associated with this operation.
......@@ -52,7 +52,7 @@ public interface DatabaseService {
* @return true if put was successful, false if there version in database is different from what is specified.
*/
boolean putIfValueMatches(String tableName, String key, byte[] oldValue, byte[] newValue);
/**
* Removes the key (and associated value).
* @param tableName name of table associated with this operation.
......@@ -60,7 +60,7 @@ public interface DatabaseService {
* @return value previously associated with the key. This call returns null if the key does not exist.
*/
VersionedValue remove(String tableName, String key);
/**
* Removes the key (and associated value) if the version in the database matches specified version.
* @param tableName name of table associated with this operation.
......@@ -69,7 +69,7 @@ public interface DatabaseService {
* @return true if remove was successful, false if there version in database is different from what is specified.
*/
boolean removeIfVersionMatches(String tableName, String key, long version);
/**
* Removes the key (and associated value) if the value in the database matches specified value.
* @param tableName name of table associated with this operation.
......@@ -78,14 +78,14 @@ public interface DatabaseService {
* @return true if remove was successful, false if there value in database is different from what is specified.
*/
boolean removeIfValueMatches(String tableName, String key, byte[] value);
/**
* Performs a batch read operation and returns the results.
* @param batchRequest batch request.
* @return result of the batch operation.
*/
BatchReadResult batchRead(BatchReadRequest batchRequest);
/**
* Performs a batch write operation and returns the results.
* This method provides transactional semantics. Either all writes succeed or none do.
......@@ -96,4 +96,4 @@ public interface DatabaseService {
* @return result of the batch operation.
*/
BatchWriteResult batchWrite(BatchWriteRequest batchRequest);
}
\ No newline at end of file
}
......
......@@ -9,11 +9,11 @@ package org.onlab.onos.store.service;
*/
public interface Lock {
/**
* Returns the path this lock will be used to guard from concurrent access.
* @return path.
*/
String path();
/**
* Returns the path this lock will be used to guard from concurrent access.
* @return path.
*/
String path();
/**
* Acquires the lock.
......@@ -79,4 +79,4 @@ public interface Lock {
* extend expiration fails or if the path is currently not locked by this instance.
*/
boolean extendExpiration(int leaseDurationMillis);
}
\ No newline at end of file
}
......
......@@ -14,17 +14,17 @@ public class ReadResult {
private final ReadStatus status;
public ReadResult(ReadStatus status, String tableName, String key, VersionedValue value) {
this.status = status;
this.status = status;
this.tableName = tableName;
this.key = key;
this.value = value;
}
/**
* Returns the status of the read operation.
*/
public ReadStatus status() {
return status;
return status;
}
/**
......
package org.onlab.onos.store.service;
public enum ReadStatus {
OK,
NO_SUCH_TABLE
OK,
NO_SUCH_TABLE
}
......
......@@ -7,27 +7,27 @@ import com.google.common.base.MoreObjects;
* Database write result.
*/
public class WriteResult {
private final WriteStatus status;
private final VersionedValue previousValue;
public WriteResult(WriteStatus status, VersionedValue previousValue) {
this.status = status;
this.status = status;
this.previousValue = previousValue;
}
public VersionedValue previousValue() {
return previousValue;
}
public WriteStatus status() {
return status;
return status;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("status", status)
.add("status", status)
.add("previousValue", previousValue)
.toString();
}
......
package org.onlab.onos.store.service;
public enum WriteStatus {
OK,
ABORTED,
PRECONDITION_VIOLATION,
NO_SUCH_TABLE,
OK,
ABORTED,
PRECONDITION_VIOLATION,
NO_SUCH_TABLE,
}
......