-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from scaleoutsoftware/br-dev
Adding shared data interface and workbench implementation
- Loading branch information
Showing
10 changed files
with
274 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
Core/src/main/java/com/scaleoutsoftware/digitaltwin/core/CacheOperationStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.scaleoutsoftware.digitaltwin.core; | ||
|
||
public enum CacheOperationStatus { | ||
|
||
/** | ||
* The object was successfully retrieved. | ||
*/ | ||
|
||
ObjectRetrieved, | ||
|
||
/** | ||
* The object was successfully added/updated. | ||
*/ | ||
ObjectPut, | ||
|
||
/** | ||
* The object could not be retrieved because it was not found. | ||
*/ | ||
ObjectDoesNotExist, | ||
|
||
/** | ||
* The object was removed successfully. | ||
*/ | ||
ObjectRemoved, | ||
|
||
/** | ||
* The cache was cleared successfully. | ||
*/ | ||
CacheCleared | ||
} |
24 changes: 24 additions & 0 deletions
24
Core/src/main/java/com/scaleoutsoftware/digitaltwin/core/CacheResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.scaleoutsoftware.digitaltwin.core; | ||
|
||
/** | ||
* Represents a response from a {@link SharedData} operation. | ||
*/ | ||
public interface CacheResult { | ||
/** | ||
* Gets the key or null to the object associated with the result. | ||
* @return the key or null. | ||
*/ | ||
public String getKey(); | ||
|
||
/** | ||
* Get the object returned from a Get operation. | ||
* @return the object or null. | ||
*/ | ||
public byte[] getValue(); | ||
|
||
/** | ||
* Gets the status of the cache operation. | ||
* @return the operation status. | ||
*/ | ||
CacheOperationStatus getStatus(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Core/src/main/java/com/scaleoutsoftware/digitaltwin/core/SharedData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.scaleoutsoftware.digitaltwin.core; | ||
|
||
public interface SharedData { | ||
/** | ||
* Retrieves an existing object from the cache. | ||
* @return A cache result. | ||
*/ | ||
public CacheResult get(String key); | ||
|
||
/** | ||
* Put a new key/value mapping into the cache. | ||
* @return a cache result. | ||
*/ | ||
public CacheResult put(String key, byte[] value); | ||
|
||
/** | ||
* Remove a key/value mapping from the cache. | ||
* @return a cache result. | ||
*/ | ||
public CacheResult remove(String key); | ||
|
||
/** | ||
* Clear the shared data cache. | ||
* @return a cache result. | ||
*/ | ||
public CacheResult clear(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...pment/src/main/java/com/scaleoutsoftware/digitaltwin/development/WorkbenchSharedData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.scaleoutsoftware.digitaltwin.development; | ||
|
||
import com.scaleoutsoftware.digitaltwin.core.CacheOperationStatus; | ||
import com.scaleoutsoftware.digitaltwin.core.CacheResult; | ||
import com.scaleoutsoftware.digitaltwin.core.SharedData; | ||
|
||
import java.util.HashMap; | ||
|
||
public class WorkbenchSharedData implements SharedData { | ||
private final HashMap<String, byte[]> data; | ||
|
||
public WorkbenchSharedData(HashMap<String, byte[]> shared) { | ||
data = shared; | ||
} | ||
@Override | ||
public CacheResult get(String s) { | ||
return new CacheResult() { | ||
@Override | ||
public String getKey() { | ||
return s; | ||
} | ||
|
||
@Override | ||
public byte[] getValue() { | ||
return data.getOrDefault(s, null); | ||
} | ||
|
||
@Override | ||
public CacheOperationStatus getStatus() { | ||
return data.containsKey(s) ? CacheOperationStatus.ObjectRetrieved : CacheOperationStatus.ObjectDoesNotExist; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public CacheResult put(String s, byte[] bytes) { | ||
data.put(s, bytes); | ||
return new CacheResult() { | ||
@Override | ||
public String getKey() { | ||
return s; | ||
} | ||
|
||
@Override | ||
public byte[] getValue() { | ||
return bytes; | ||
} | ||
|
||
@Override | ||
public CacheOperationStatus getStatus() { | ||
return CacheOperationStatus.ObjectPut; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public CacheResult remove(String s) { | ||
byte[] v = data.remove(s); | ||
return new CacheResult() { | ||
@Override | ||
public String getKey() { | ||
return s; | ||
} | ||
|
||
@Override | ||
public byte[] getValue() { | ||
return v; | ||
} | ||
|
||
@Override | ||
public CacheOperationStatus getStatus() { | ||
return v == null ? CacheOperationStatus.ObjectDoesNotExist : CacheOperationStatus.ObjectRemoved; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public CacheResult clear() { | ||
data.clear(); | ||
return new CacheResult() { | ||
@Override | ||
public String getKey() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public byte[] getValue() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public CacheOperationStatus getStatus() { | ||
return CacheOperationStatus.CacheCleared; | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters