Skip to content

Commit

Permalink
Update interface to use entity U
Browse files Browse the repository at this point in the history
Signed-off-by: Sooraj Sinha <[email protected]>
  • Loading branch information
soosinha committed May 29, 2024
1 parent 9b1cab6 commit 9aeea21
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @param <T> The entity which can be uploaded to / downloaded from blob store
* @param <U> The concrete class implementing {@link RemoteObject} which is used as a wrapper for T entity.
*/
public class AbstractRemoteBlobStore<T, U extends RemoteObject<T>> implements RemoteObjectStore<T, U> {
public class AbstractRemoteBlobStore<T, U extends AbstractRemoteBlobObject<T>> implements RemoteObjectStore<T, U> {

private final BlobStoreTransferService transferService;
private final BlobStoreRepository blobStoreRepository;
Expand All @@ -44,31 +44,27 @@ public AbstractRemoteBlobStore(BlobStoreTransferService blobStoreTransferService
}

@Override
public void writeAsync(RemoteObject<T> obj, ActionListener<Void> listener) {
assert obj instanceof AbstractRemoteBlobObject;
AbstractRemoteBlobObject<T> blobStoreObj = (AbstractRemoteBlobObject<T>) obj;
assert blobStoreObj.get() != null;
public void writeAsync(U obj, ActionListener<Void> listener) {
assert obj.get() != null;
try {
InputStream inputStream = obj.serialize();
BlobPath blobPath = getBlobPathForUpload(blobStoreObj);
blobStoreObj.setFullBlobName(blobPath);
transferService.uploadBlob(inputStream, getBlobPathForUpload(blobStoreObj), blobStoreObj.getBlobFileName(), WritePriority.URGENT, listener);
BlobPath blobPath = getBlobPathForUpload(obj);
obj.setFullBlobName(blobPath);
transferService.uploadBlob(inputStream, getBlobPathForUpload(obj), obj.getBlobFileName(), WritePriority.URGENT, listener);
} catch (Exception e) {
listener.onFailure(e);
}
}

@Override
public T read(RemoteObject<T> obj) throws IOException {
assert obj instanceof AbstractRemoteBlobObject;
AbstractRemoteBlobObject<T> blobStoreObj = (AbstractRemoteBlobObject<T>) obj;
assert blobStoreObj.getFullBlobName() != null;
return blobStoreObj.deserialize(
transferService.downloadBlob(getBlobPathForDownload(blobStoreObj), blobStoreObj.getBlobFileName()));
public T read(U obj) throws IOException {
assert obj.getFullBlobName() != null;
return obj.deserialize(
transferService.downloadBlob(getBlobPathForDownload(obj), obj.getBlobFileName()));
}

@Override
public void readAsync(RemoteObject<T> obj, ActionListener<T> listener) {
public void readAsync(U obj, ActionListener<T> listener) {
executorService.execute(() -> {
try {
listener.onResponse(read(obj));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
public interface RemoteObjectStore<T, U extends RemoteObject<T>> {

public void writeAsync(RemoteObject<T> obj, ActionListener<Void> listener);
public void writeAsync(U obj, ActionListener<Void> listener);

public T read(RemoteObject<T> obj) throws IOException;
public T read(U obj) throws IOException;

public void readAsync(RemoteObject<T> obj, ActionListener<T> listener);
public void readAsync(U obj, ActionListener<T> listener);
}

0 comments on commit 9aeea21

Please sign in to comment.