Eliminate tab character from datastore package
Change-Id: I6eea92ce72268c4ca90f1bd24bdccf7edf4cbb7f
diff --git a/src/main/java/net/onrc/onos/datastore/utils/KVObject.java b/src/main/java/net/onrc/onos/datastore/utils/KVObject.java
index 2aac0e3..b46c9f5 100644
--- a/src/main/java/net/onrc/onos/datastore/utils/KVObject.java
+++ b/src/main/java/net/onrc/onos/datastore/utils/KVObject.java
@@ -36,13 +36,13 @@
// each sub-class should prepare their own serializer, which has required
// objects registered for better performance.
private static final ThreadLocal<Kryo> defaultKryo = new ThreadLocal<Kryo>() {
- @Override
- protected Kryo initialValue() {
- Kryo kryo = new Kryo();
- // kryo.setRegistrationRequired(true);
- // kryo.setReferences(false);
- return kryo;
- }
+ @Override
+ protected Kryo initialValue() {
+ Kryo kryo = new Kryo();
+ // kryo.setRegistrationRequired(true);
+ // kryo.setReferences(false);
+ return kryo;
+ }
};
private final IKVTable table;
@@ -60,46 +60,46 @@
private Map<Object, Object> propertyMap;
public KVObject(final IKVTable table, final byte[] key) {
- this(table, key, null, table.VERSION_NONEXISTENT());
+ this(table, key, null, table.VERSION_NONEXISTENT());
}
public KVObject(final IKVTable table, final byte[] key, final byte[] value, final long version) {
- if (table == null) {
- throw new IllegalArgumentException("table cannot be null");
- }
- if (key == null) {
- throw new IllegalArgumentException("key cannot be null");
- }
- this.table = table;
- this.key = key;
- this.version = version;
- this.propertyMap = new HashMap<Object, Object>();
+ if (table == null) {
+ throw new IllegalArgumentException("table cannot be null");
+ }
+ if (key == null) {
+ throw new IllegalArgumentException("key cannot be null");
+ }
+ this.table = table;
+ this.key = key;
+ this.version = version;
+ this.propertyMap = new HashMap<Object, Object>();
- if (value != null) {
- deserialize(value);
- }
+ if (value != null) {
+ deserialize(value);
+ }
}
protected static KVObject createFromKey(final byte[] key) {
- // Equivalent of this method is expected to be implemented by SubClasses
- throw new UnsupportedOperationException(
- "createFromKey() is not expected to be called for RCObject");
+ // Equivalent of this method is expected to be implemented by SubClasses
+ throw new UnsupportedOperationException(
+ "createFromKey() is not expected to be called for RCObject");
}
public IKVTable getTable() {
- return table;
+ return table;
}
public IKVTableID getTableId() {
- return table.getTableId();
+ return table.getTableId();
}
public byte[] getKey() {
- return key;
+ return key;
}
public long getVersion() {
- return version;
+ return version;
}
/**
@@ -109,13 +109,13 @@
* @return Will return null, if never been set, or was not deserialized
*/
protected Map<Object, Object> getPropertyMap() {
- return this.propertyMap;
+ return this.propertyMap;
}
protected Map<Object, Object> replacePropertyMap(final Map<Object, Object> newMap) {
- Map<Object, Object> oldMap = this.propertyMap;
- this.propertyMap = newMap;
- return oldMap;
+ Map<Object, Object> oldMap = this.propertyMap;
+ this.propertyMap = newMap;
+ return oldMap;
}
/**
@@ -126,18 +126,18 @@
* @return serialized byte array
*/
public byte[] serialize() {
- return serializePropertyMap(defaultKryo.get(), this.propertyMap);
+ return serializePropertyMap(defaultKryo.get(), this.propertyMap);
}
protected byte[] serializePropertyMap(final Kryo kryo,
- final Map<Object, Object> propMap) {
+ final Map<Object, Object> propMap) {
- // value
- byte[] rcTemp = new byte[1024 * 1024];
- Output output = new Output(rcTemp);
- kryo.writeObject(output, propMap);
- return output.toBytes();
+ // value
+ byte[] rcTemp = new byte[1024 * 1024];
+ Output output = new Output(rcTemp);
+ kryo.writeObject(output, propMap);
+ return output.toBytes();
}
@@ -149,8 +149,8 @@
* @return true if success
*/
public boolean deserialize(final byte[] bytes, final long version) {
- this.version = version;
- return deserialize(bytes);
+ this.version = version;
+ return deserialize(bytes);
}
/**
@@ -162,8 +162,8 @@
* @return true if success
*/
protected boolean deserialize(final byte[] bytes) {
- deserializePropertyMap(defaultKryo.get(), bytes);
- return true;
+ deserializePropertyMap(defaultKryo.get(), bytes);
+ return true;
}
/**
@@ -173,26 +173,26 @@
* @return true if success
*/
protected boolean deserializePropertyMap(final Kryo kryo, final byte[] bytes) {
- @SuppressWarnings("unchecked")
- Map<Object, Object> map = deserializePropertyMap(kryo, bytes, HashMap.class);
- if (map == null) {
- map = new HashMap<>();
- }
- this.propertyMap = map;
- return true;
+ @SuppressWarnings("unchecked")
+ Map<Object, Object> map = deserializePropertyMap(kryo, bytes, HashMap.class);
+ if (map == null) {
+ map = new HashMap<>();
+ }
+ this.propertyMap = map;
+ return true;
}
protected <T extends Map<?, ?>> T deserializePropertyMap(final Kryo kryo,
- final byte[] bytes, final Class<T> type) {
+ final byte[] bytes, final Class<T> type) {
- if (bytes == null || bytes.length == 0) {
- return null;
- }
+ if (bytes == null || bytes.length == 0) {
+ return null;
+ }
- Input input = new Input(bytes);
- T map = kryo.readObject(input, type);
+ Input input = new Input(bytes);
+ T map = kryo.readObject(input, type);
- return map;
+ return map;
}
@@ -205,22 +205,22 @@
*/
public void create() throws ObjectExistsException {
- if (this.propertyMap == null) {
- log.warn("No object map was set. Setting empty Map.");
- replacePropertyMap(new HashMap<Object, Object>());
- }
+ if (this.propertyMap == null) {
+ log.warn("No object map was set. Setting empty Map.");
+ replacePropertyMap(new HashMap<Object, Object>());
+ }
- this.version = table.create(key, this.serialize());
+ this.version = table.create(key, this.serialize());
}
public void forceCreate() {
- if (this.propertyMap == null) {
- log.warn("No object map was set. Setting empty Map.");
- replacePropertyMap(new HashMap<Object, Object>());
- }
+ if (this.propertyMap == null) {
+ log.warn("No object map was set. Setting empty Map.");
+ replacePropertyMap(new HashMap<Object, Object>());
+ }
- this.version = table.forceCreate(key, this.serialize());
+ this.version = table.forceCreate(key, this.serialize());
}
/**
@@ -232,8 +232,8 @@
*
*/
public void read() throws ObjectDoesntExistException {
- IKVEntry e = table.read(key);
- deserialize(e.getValue(), e.getVersion());
+ IKVEntry e = table.read(key);
+ deserialize(e.getValue(), e.getVersion());
}
/**
@@ -246,11 +246,11 @@
*/
public void update() throws ObjectDoesntExistException,
WrongVersionException {
- if (this.propertyMap == null) {
- replacePropertyMap(new HashMap<Object, Object>());
- }
+ if (this.propertyMap == null) {
+ replacePropertyMap(new HashMap<Object, Object>());
+ }
- this.version = table.update(key, this.serialize(), version);
+ this.version = table.update(key, this.serialize(), version);
}
/**
@@ -263,36 +263,36 @@
*/
public void delete() throws ObjectDoesntExistException,
WrongVersionException {
- this.version = table.delete(key, this.version);
+ this.version = table.delete(key, this.version);
}
public void forceDelete() {
- this.version = table.forceDelete(key);
+ this.version = table.forceDelete(key);
}
public WriteOp forceCreateOp(IKVClient client) {
- return new WriteOp(client.forceCreateOp(getTableId(), getKey(), serialize()), this);
+ return new WriteOp(client.forceCreateOp(getTableId(), getKey(), serialize()), this);
}
public WriteOp createOp(IKVClient client) {
- return new WriteOp(client.createOp(getTableId(), getKey(), serialize()), this);
+ return new WriteOp(client.createOp(getTableId(), getKey(), serialize()), this);
}
// this might not be needed?
public WriteOp readOp(IKVClient client) {
- return new WriteOp(client.readOp(getTableId(), getKey()), this);
+ return new WriteOp(client.readOp(getTableId(), getKey()), this);
}
public WriteOp updateOp(IKVClient client) {
- return new WriteOp(client.updateOp(getTableId(), getKey(), serialize(), getVersion()), this);
+ return new WriteOp(client.updateOp(getTableId(), getKey(), serialize(), getVersion()), this);
}
public WriteOp deleteOp(IKVClient client) {
- return new WriteOp(client.deleteOp(getTableId(), getKey(), serialize(), getVersion()), this);
+ return new WriteOp(client.deleteOp(getTableId(), getKey(), serialize(), getVersion()), this);
}
public WriteOp forceDeleteOp(IKVClient client) {
- return new WriteOp(client.forceDeleteOp(getTableId(), getKey()), this);
+ return new WriteOp(client.forceDeleteOp(getTableId(), getKey()), this);
}
/**
@@ -306,32 +306,32 @@
*/
public static boolean multiRead(final List<? extends KVObject> objects) {
- final IKVClient client = DataStoreClient.getClient();
+ final IKVClient client = DataStoreClient.getClient();
- final ArrayList<IMultiEntryOperation> readOps = new ArrayList<>(objects.size());
- for (KVObject o : objects) {
- readOps.add(o.readOp(client));
- }
+ final ArrayList<IMultiEntryOperation> readOps = new ArrayList<>(objects.size());
+ for (KVObject o : objects) {
+ readOps.add(o.readOp(client));
+ }
- boolean failExists = client.multiRead(readOps);
+ boolean failExists = client.multiRead(readOps);
- for (int i = 0; i < readOps.size(); ++i) {
- KVObject obj = objects.get(i);
- IMultiEntryOperation entry = readOps.get(i);
- if ( entry.hasSucceeded() ) {
- if ( !obj.deserialize(entry.getValue(), entry.getVersion()) ) {
- //deserialize return true on success
- failExists = true;
- log.error("MultiRead error, failed to deserialize {}, {}", obj.getTable(), obj);
- }
- } else {
- log.error("MultiRead error, skipping {}, {}", obj.getTable(), obj);
- obj.version = obj.getTable().VERSION_NONEXISTENT();
- failExists = true;
- }
- }
+ for (int i = 0; i < readOps.size(); ++i) {
+ KVObject obj = objects.get(i);
+ IMultiEntryOperation entry = readOps.get(i);
+ if ( entry.hasSucceeded() ) {
+ if ( !obj.deserialize(entry.getValue(), entry.getVersion()) ) {
+ //deserialize return true on success
+ failExists = true;
+ log.error("MultiRead error, failed to deserialize {}, {}", obj.getTable(), obj);
+ }
+ } else {
+ log.error("MultiRead error, skipping {}, {}", obj.getTable(), obj);
+ obj.version = obj.getTable().VERSION_NONEXISTENT();
+ failExists = true;
+ }
+ }
- return failExists;
+ return failExists;
}
/**
@@ -339,131 +339,131 @@
*/
public static class WriteOp implements IMultiObjectOperation, IModifiableMultiEntryOperation {
- private final IModifiableMultiEntryOperation base;
- private final KVObject obj;
+ private final IModifiableMultiEntryOperation base;
+ private final KVObject obj;
- public WriteOp(IMultiEntryOperation base, final KVObject obj) {
- this.base = (IModifiableMultiEntryOperation) base;
- this.obj = obj;
+ public WriteOp(IMultiEntryOperation base, final KVObject obj) {
+ this.base = (IModifiableMultiEntryOperation) base;
+ this.obj = obj;
- // switch (base.getOperation()) {
- // case CREATE:
- // case FORCE_CREATE:
- // case UPDATE:
- // break;
- // default:
- // throw new UnsupportedOperationException("Unexpected OPERATION:"+base.getOperation());
- // }
- }
+ // switch (base.getOperation()) {
+ // case CREATE:
+ // case FORCE_CREATE:
+ // case UPDATE:
+ // break;
+ // default:
+ // throw new UnsupportedOperationException("Unexpected OPERATION:"+base.getOperation());
+ // }
+ }
- @Override
- public KVObject getObject() {
- return obj;
- }
+ @Override
+ public KVObject getObject() {
+ return obj;
+ }
- @Deprecated
- public OPERATION getOp() {
- return this.getOperation();
- }
+ @Deprecated
+ public OPERATION getOp() {
+ return this.getOperation();
+ }
- @Override
- public boolean hasSucceeded() {
- return base.hasSucceeded();
- }
+ @Override
+ public boolean hasSucceeded() {
+ return base.hasSucceeded();
+ }
- @Override
- public STATUS getStatus() {
- return base.getStatus();
- }
+ @Override
+ public STATUS getStatus() {
+ return base.getStatus();
+ }
- @Override
- public IKVTableID getTableId() {
- return base.getTableId();
- }
+ @Override
+ public IKVTableID getTableId() {
+ return base.getTableId();
+ }
- @Override
- public byte[] getKey() {
- return base.getKey();
- }
+ @Override
+ public byte[] getKey() {
+ return base.getKey();
+ }
- @Override
- public byte[] getValue() {
- return base.getValue();
- }
+ @Override
+ public byte[] getValue() {
+ return base.getValue();
+ }
- @Override
- public long getVersion() {
- return base.getVersion();
- }
+ @Override
+ public long getVersion() {
+ return base.getVersion();
+ }
- @Override
- public OPERATION getOperation() {
- return base.getOperation();
- }
+ @Override
+ public OPERATION getOperation() {
+ return base.getOperation();
+ }
- @Override
- public void setStatus(STATUS status) {
- base.setStatus(status);
- }
+ @Override
+ public void setStatus(STATUS status) {
+ base.setStatus(status);
+ }
- @Override
- public void setValue(byte[] value, long version) {
- base.setValue(value, version);
- }
+ @Override
+ public void setValue(byte[] value, long version) {
+ base.setValue(value, version);
+ }
- @Override
- public void setVersion(long version) {
- base.setVersion(version);
- this.obj.version = version;
- }
+ @Override
+ public void setVersion(long version) {
+ base.setVersion(version);
+ this.obj.version = version;
+ }
- @Override
- public IModifiableMultiEntryOperation getActualOperation() {
- return base;
- }
+ @Override
+ public IModifiableMultiEntryOperation getActualOperation() {
+ return base;
+ }
}
public static boolean multiWrite(final List<WriteOp> objects) {
- final IKVClient client = DataStoreClient.getClient();
+ final IKVClient client = DataStoreClient.getClient();
- final ArrayList<IMultiEntryOperation> writeOps = new ArrayList<>(objects.size());
- for (WriteOp o : objects) {
- writeOps.add(o);
- }
+ final ArrayList<IMultiEntryOperation> writeOps = new ArrayList<>(objects.size());
+ for (WriteOp o : objects) {
+ writeOps.add(o);
+ }
- return client.multiWrite(writeOps);
+ return client.multiWrite(writeOps);
}
public abstract static class AbstractObjectIterator<E extends KVObject> implements
Iterator<E> {
- protected Iterator<IKVEntry> enumerator;
+ protected Iterator<IKVEntry> enumerator;
- public AbstractObjectIterator(final IKVTable table) {
- this.enumerator = table.getAllEntries().iterator();
- }
+ public AbstractObjectIterator(final IKVTable table) {
+ this.enumerator = table.getAllEntries().iterator();
+ }
- @Override
- public boolean hasNext() {
- return enumerator.hasNext();
- }
+ @Override
+ public boolean hasNext() {
+ return enumerator.hasNext();
+ }
- // Implement something similar to below to realize Iterator
- // @Override
- // public E next() {
- // IKVTable.IKVEntry o = enumerator.next();
- // E obj = E.createFromKey(o.getKey());
- // obj.deserialize(o.getValue(), o.getVersion());
- // return obj;
- // }
+ // Implement something similar to below to realize Iterator
+ // @Override
+ // public E next() {
+ // IKVTable.IKVEntry o = enumerator.next();
+ // E obj = E.createFromKey(o.getKey());
+ // obj.deserialize(o.getValue(), o.getVersion());
+ // return obj;
+ // }
- @Deprecated
- @Override
- public void remove() {
- // TODO Not implemented, as I cannot find a use-case for it.
- throw new UnsupportedOperationException("Not implemented yet");
- }
+ @Deprecated
+ @Override
+ public void remove() {
+ // TODO Not implemented, as I cannot find a use-case for it.
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
}