diff --git a/src/main/lombok/org/warp/filesponge/SecureFileAccessor.java b/src/main/lombok/org/warp/filesponge/SecureFileAccessor.java new file mode 100644 index 0000000..7b46f01 --- /dev/null +++ b/src/main/lombok/org/warp/filesponge/SecureFileAccessor.java @@ -0,0 +1,55 @@ +/* + * FileSponge + * Copyright (C) 2020 Andrea Cavalli + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.warp.filesponge; + +import java.util.Optional; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.jetbrains.annotations.NotNull; +import org.warp.filesponge.api.FileAccessor; +import org.warp.filesponge.api.FileContent; +import org.warp.filesponge.api.FileStatus; +import org.warp.filesponge.api.FileURI; + +/** + * Prevent access to other methods via casting + */ +@AllArgsConstructor +@EqualsAndHashCode +@ToString +public class SecureFileAccessor implements FileAccessor { + + private final FileAccessor fileAccessor; + + @Override + public void delete(@NotNull FileURI fileURI) { + fileAccessor.delete(fileURI); + } + + @Override + public Optional getContent(@NotNull FileURI fileURI, boolean offlineOnly) { + return fileAccessor.getContent(fileURI, offlineOnly); + } + + @Override + public @NotNull FileStatus getStatus(@NotNull FileURI fileURI) { + return fileAccessor.getStatus(fileURI); + } +} diff --git a/src/main/lombok/org/warp/filesponge/api/FileAccessor.java b/src/main/lombok/org/warp/filesponge/api/FileAccessor.java index f38f0ab..bff5261 100644 --- a/src/main/lombok/org/warp/filesponge/api/FileAccessor.java +++ b/src/main/lombok/org/warp/filesponge/api/FileAccessor.java @@ -21,6 +21,9 @@ package org.warp.filesponge.api; import java.util.Optional; import org.jetbrains.annotations.NotNull; +/** + * FileAccessor can be used to access files from the client side + */ public interface FileAccessor { void delete(@NotNull FileURI fileURI); diff --git a/src/main/lombok/org/warp/filesponge/api/FileActor.java b/src/main/lombok/org/warp/filesponge/api/FileActor.java index c92b1ee..f0e9141 100644 --- a/src/main/lombok/org/warp/filesponge/api/FileActor.java +++ b/src/main/lombok/org/warp/filesponge/api/FileActor.java @@ -18,4 +18,60 @@ package org.warp.filesponge.api; -public interface FileActor {} +import java.time.Duration; +import java.util.Optional; +import org.jetbrains.annotations.Nullable; + +/** + * FileActor sends signals to a mirror + */ +public interface FileActor { + + /** + * Send a "delete file" signal + * + * @param fileURI File URI + * @return true if the signal can be sent + */ + boolean deleteFile(FileURI fileURI); + + /** + * Send a "download file" signal + * + * @param fileURI File URI + * @return true if the signal can be sent + */ + boolean downloadFile(FileURI fileURI); + + /** + * Check if this actor can handle signals for this file + * + * @param fileURI File URI + * @return true if the actor can send signals related to this file + */ + boolean canHandleFile(FileURI fileURI); + + /** + * Send a "download file" signal + * + * @param fileURI File URI + * @param timeout if it's null the method will return immediately, + * if it's set the method will wait until a file download request has been found, + * or the timeout time elapsed + * @return empty if no pending download requests has been found, + * true if the signal can be sent, false otherwise + */ + Optional downloadNextFile(FileURI fileURI, @Nullable Duration timeout); + + /** + * Send a "delete file" signal + * + * @param fileURI File URI + * @param timeout if it's null the method will return immediately, + * if it's set the method will wait until a file delete request has been found, + * or the timeout time elapsed + * @return empty if no pending delete requests has been found, + * true if the signal can be sent, false otherwise + */ + Optional deleteNextFile(FileURI fileURI, @Nullable Duration timeout); +} diff --git a/src/main/lombok/org/warp/filesponge/api/FileSource.java b/src/main/lombok/org/warp/filesponge/api/FileSource.java index 79142ac..13ec1a3 100644 --- a/src/main/lombok/org/warp/filesponge/api/FileSource.java +++ b/src/main/lombok/org/warp/filesponge/api/FileSource.java @@ -21,6 +21,9 @@ package org.warp.filesponge.api; import java.nio.ByteBuffer; import org.jetbrains.annotations.NotNull; +/** + * FileSource receives requests from a mirror + */ public interface FileSource { void onAvailable(); diff --git a/src/main/lombok/org/warp/filesponge/api/FileSpongeClient.java b/src/main/lombok/org/warp/filesponge/api/FileSpongeClient.java new file mode 100644 index 0000000..2400ed2 --- /dev/null +++ b/src/main/lombok/org/warp/filesponge/api/FileSpongeClient.java @@ -0,0 +1,37 @@ +/* + * FileSponge + * Copyright (C) 2020 Andrea Cavalli + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.warp.filesponge.api; + +import org.warp.filesponge.SecureFileAccessor; + +/** + * FileAccessor can be used to manage FileSponge and access files from the client side + */ +public interface FileSpongeClient extends FileAccessor { + + void optimizeStorage(); + + /** + * Get this instance but without special methods + * @return a limited instance of itself + */ + default FileAccessor asFileAccessor() { + return new SecureFileAccessor(this); + } +}