Progress
This commit is contained in:
parent
6aeb893fbb
commit
961b355068
@ -1,7 +0,0 @@
|
||||
module org.warp.filesponge {
|
||||
exports org.warp.filesponge.api;
|
||||
exports org.warp.filesponge.extra.api;
|
||||
exports org.warp.filesponge.value;
|
||||
requires lombok;
|
||||
requires org.jetbrains.annotations;
|
||||
}
|
@ -23,9 +23,10 @@ import lombok.AllArgsConstructor;
|
||||
import org.warp.filesponge.api.FileSource;
|
||||
import org.warp.filesponge.value.MirrorURI;
|
||||
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@AllArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
public abstract class BaseMirrorFileSource implements FileSource {
|
||||
|
||||
private final MirrorURI mirrorURI;
|
||||
protected final ReceiverAvailabilityManager receiverAvailabilityManager;
|
||||
protected final MirrorURI mirrorURI;
|
||||
|
||||
}
|
||||
|
77
src/main/lombok/org/warp/filesponge/FileMirrorsManager.java
Normal file
77
src/main/lombok/org/warp/filesponge/FileMirrorsManager.java
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.warp.filesponge;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.warp.commonutils.type.MultiAssociation;
|
||||
import org.warp.filesponge.value.FileURI;
|
||||
import org.warp.filesponge.value.MirrorURI;
|
||||
|
||||
@AllArgsConstructor()
|
||||
public class FileMirrorsManager {
|
||||
|
||||
private final Set<MirrorURI> availableMirrors = new HashSet<>();
|
||||
/**
|
||||
* This map must be persistent
|
||||
*/
|
||||
private final MultiAssociation<FileURI, MirrorURI> fileMirrors;
|
||||
|
||||
public synchronized Set<MirrorURI> getAvailableMirrors(FileURI fileURI) {
|
||||
return fileMirrors
|
||||
.getLinks(fileURI)
|
||||
.stream()
|
||||
.filter(this::isMirrorAvailable)
|
||||
.collect(Collectors.toUnmodifiableSet());
|
||||
}
|
||||
|
||||
public synchronized boolean hasAnyAvailableReceiver(FileURI uri) {
|
||||
return fileMirrors.getLinks(uri).stream().anyMatch(this::isMirrorAvailable);
|
||||
}
|
||||
|
||||
public synchronized void addMirror(FileURI uri, MirrorURI mirrorURI) {
|
||||
fileMirrors.link(uri, mirrorURI);
|
||||
}
|
||||
|
||||
public synchronized void removeMirror(FileURI uri, MirrorURI mirrorURI) {
|
||||
fileMirrors.unlink(uri, mirrorURI);
|
||||
}
|
||||
|
||||
public synchronized void unsetAllFiles() {
|
||||
fileMirrors.clear();
|
||||
}
|
||||
|
||||
public synchronized void setAllMirrorsAsUnavailable() {
|
||||
availableMirrors.clear();
|
||||
}
|
||||
|
||||
public synchronized void setReceiverAvailability(MirrorURI mirrorURI, boolean available) {
|
||||
if (available) {
|
||||
availableMirrors.add(mirrorURI);
|
||||
} else {
|
||||
availableMirrors.remove(mirrorURI);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized boolean isMirrorAvailable(MirrorURI mirrorURI) {
|
||||
return this.availableMirrors.contains(mirrorURI);
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.warp.filesponge;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
@AllArgsConstructor(access = AccessLevel.PUBLIC)
|
||||
public class ReceiverAvailabilityManager {
|
||||
|
||||
private final FileMirrorsManager fileReceiversManager;
|
||||
}
|
@ -22,7 +22,6 @@ import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.warp.filesponge.api.FileAccessor;
|
||||
import org.warp.filesponge.value.FileContent;
|
||||
@ -34,7 +33,6 @@ import org.warp.filesponge.value.FileURI;
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
public class SecureFileAccessor implements FileAccessor {
|
||||
|
||||
private final FileAccessor fileAccessor;
|
||||
@ -53,4 +51,9 @@ public class SecureFileAccessor implements FileAccessor {
|
||||
public @NotNull FileStatus getStatus(@NotNull FileURI fileURI) {
|
||||
return fileAccessor.getStatus(fileURI);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return fileAccessor.toString();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user