允许请求非webp图片;添加临时数组,防止下载线程与监听线程同时对任务数组进行操作
This commit is contained in:
parent
c2c5c50a48
commit
d49ba48f2e
@ -23,7 +23,7 @@ public class MultiThreadedHTTPServer {
|
|||||||
while (true) {
|
while (true) {
|
||||||
Socket clientSocket = serverSocket.accept();
|
Socket clientSocket = serverSocket.accept();
|
||||||
String ip = clientSocket.getInetAddress().getHostAddress();
|
String ip = clientSocket.getInetAddress().getHostAddress();
|
||||||
if(ip.equals("100.42.234.138")){
|
if(ip.equals("194.36.27.28")){
|
||||||
System.out.println("Client connected: " + ip);
|
System.out.println("Client connected: " + ip);
|
||||||
// 线程池处理下载请求
|
// 线程池处理下载请求
|
||||||
threadPool.submit(() -> handleClientRequest(clientSocket));
|
threadPool.submit(() -> handleClientRequest(clientSocket));
|
||||||
|
|||||||
@ -50,7 +50,7 @@ public class DeliveryService {
|
|||||||
return ErrorCode.FILE_NOT_FOUND;
|
return ErrorCode.FILE_NOT_FOUND;
|
||||||
|
|
||||||
singleThreadPool.submit(() -> {
|
singleThreadPool.submit(() -> {
|
||||||
try(SocketChannel socketChannel = SocketChannel.open(new InetSocketAddress("100.42.234.138", port));
|
try(SocketChannel socketChannel = SocketChannel.open(new InetSocketAddress("194.36.27.28", port));
|
||||||
FileChannel fileChannel = FileChannel.open(file.toPath(), StandardOpenOption.READ)) {
|
FileChannel fileChannel = FileChannel.open(file.toPath(), StandardOpenOption.READ)) {
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(1024);
|
ByteBuffer buffer = ByteBuffer.allocate(1024);
|
||||||
while (fileChannel.read(buffer)!=-1){
|
while (fileChannel.read(buffer)!=-1){
|
||||||
@ -86,7 +86,7 @@ public class DeliveryService {
|
|||||||
if(!directory.isDirectory())
|
if(!directory.isDirectory())
|
||||||
return ErrorCode.FILE_NOT_FOUND;
|
return ErrorCode.FILE_NOT_FOUND;
|
||||||
ArrayList<String> pageList = new ArrayList<>();
|
ArrayList<String> pageList = new ArrayList<>();
|
||||||
File[] files = directory.listFiles(((dir, name1) -> !name1.equals("galleryinfo.txt") && !name1.equals("thumbnail.webp")));
|
File[] files = directory.listFiles(((dir, name1) -> !name1.equals("galleryinfo.txt") && !name1.equals("thumbnail.webp") && !name1.endsWith(".zip")));
|
||||||
|
|
||||||
if(files == null)
|
if(files == null)
|
||||||
return ErrorCode.FILE_NOT_FOUND;
|
return ErrorCode.FILE_NOT_FOUND;
|
||||||
|
|||||||
@ -36,6 +36,8 @@ public class storageNode {
|
|||||||
|
|
||||||
ArrayList<GalleryTask> queue;
|
ArrayList<GalleryTask> queue;
|
||||||
|
|
||||||
|
ArrayList<GalleryTask> tempQueue;
|
||||||
|
|
||||||
ScheduledExecutorService checkThreadPool;
|
ScheduledExecutorService checkThreadPool;
|
||||||
|
|
||||||
|
|
||||||
@ -55,7 +57,7 @@ public class storageNode {
|
|||||||
channel.pipeline().addLast(new LengthFieldBasedFrameDecoder(100000000, 1, 4));
|
channel.pipeline().addLast(new LengthFieldBasedFrameDecoder(100000000, 1, 4));
|
||||||
channel.pipeline().addLast(new MessageCodec());
|
channel.pipeline().addLast(new MessageCodec());
|
||||||
channel.pipeline().addLast(new LoggingHandler());
|
channel.pipeline().addLast(new LoggingHandler());
|
||||||
channel.pipeline().addLast(new MyChannelInboundHandlerAdapter(queue));
|
channel.pipeline().addLast(new MyChannelInboundHandlerAdapter(tempQueue));
|
||||||
|
|
||||||
}
|
}
|
||||||
}).option(ChannelOption.SO_BACKLOG, 128)
|
}).option(ChannelOption.SO_BACKLOG, 128)
|
||||||
@ -64,7 +66,7 @@ public class storageNode {
|
|||||||
log.info("listen port:8080");
|
log.info("listen port:8080");
|
||||||
|
|
||||||
try(Socket socket = new Socket()) {
|
try(Socket socket = new Socket()) {
|
||||||
socket.connect(new InetSocketAddress("100.42.234.138", 26322));
|
socket.connect(new InetSocketAddress("194.36.27.28", 26322));
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {}
|
||||||
downloadCheckService = new DownloadCheckService(queue);
|
downloadCheckService = new DownloadCheckService(queue);
|
||||||
checkThreadPool = Executors.newScheduledThreadPool(1);
|
checkThreadPool = Executors.newScheduledThreadPool(1);
|
||||||
@ -88,6 +90,10 @@ public class storageNode {
|
|||||||
if (galleryTask.is_download_complete())
|
if (galleryTask.is_download_complete())
|
||||||
listIterator.remove();
|
listIterator.remove();
|
||||||
}
|
}
|
||||||
|
if(!tempQueue.isEmpty()){
|
||||||
|
queue.addAll(tempQueue);
|
||||||
|
tempQueue.clear();
|
||||||
|
}
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
log.info("任务状态发送完成");
|
log.info("任务状态发送完成");
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user