From d49ba48f2edfa5aeb0ca1ef0ba9ddb62fe289976 Mon Sep 17 00:00:00 2001 From: chuzhongzai Date: Sun, 27 Aug 2023 16:17:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=81=E8=AE=B8=E8=AF=B7=E6=B1=82=E9=9D=9Ewe?= =?UTF-8?q?bp=E5=9B=BE=E7=89=87;=E6=B7=BB=E5=8A=A0=E4=B8=B4=E6=97=B6?= =?UTF-8?q?=E6=95=B0=E7=BB=84=EF=BC=8C=E9=98=B2=E6=AD=A2=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E4=B8=8E=E7=9B=91=E5=90=AC=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E5=AF=B9=E4=BB=BB=E5=8A=A1=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lion/MultiThreadedHTTPServer.java | 2 +- src/main/java/lion/Service/DeliveryService.java | 4 ++-- src/main/java/lion/storageNode.java | 10 ++++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/lion/MultiThreadedHTTPServer.java b/src/main/java/lion/MultiThreadedHTTPServer.java index 274d1a3..c3ab722 100644 --- a/src/main/java/lion/MultiThreadedHTTPServer.java +++ b/src/main/java/lion/MultiThreadedHTTPServer.java @@ -23,7 +23,7 @@ public class MultiThreadedHTTPServer { while (true) { Socket clientSocket = serverSocket.accept(); 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); // 线程池处理下载请求 threadPool.submit(() -> handleClientRequest(clientSocket)); diff --git a/src/main/java/lion/Service/DeliveryService.java b/src/main/java/lion/Service/DeliveryService.java index 25827d4..93b784f 100644 --- a/src/main/java/lion/Service/DeliveryService.java +++ b/src/main/java/lion/Service/DeliveryService.java @@ -50,7 +50,7 @@ public class DeliveryService { return ErrorCode.FILE_NOT_FOUND; 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)) { ByteBuffer buffer = ByteBuffer.allocate(1024); while (fileChannel.read(buffer)!=-1){ @@ -86,7 +86,7 @@ public class DeliveryService { if(!directory.isDirectory()) return ErrorCode.FILE_NOT_FOUND; ArrayList 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) return ErrorCode.FILE_NOT_FOUND; diff --git a/src/main/java/lion/storageNode.java b/src/main/java/lion/storageNode.java index 93b29cb..dbf514a 100644 --- a/src/main/java/lion/storageNode.java +++ b/src/main/java/lion/storageNode.java @@ -36,6 +36,8 @@ public class storageNode { ArrayList queue; + ArrayList tempQueue; + ScheduledExecutorService checkThreadPool; @@ -55,7 +57,7 @@ public class storageNode { channel.pipeline().addLast(new LengthFieldBasedFrameDecoder(100000000, 1, 4)); channel.pipeline().addLast(new MessageCodec()); channel.pipeline().addLast(new LoggingHandler()); - channel.pipeline().addLast(new MyChannelInboundHandlerAdapter(queue)); + channel.pipeline().addLast(new MyChannelInboundHandlerAdapter(tempQueue)); } }).option(ChannelOption.SO_BACKLOG, 128) @@ -64,7 +66,7 @@ public class storageNode { log.info("listen port:8080"); 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) {} downloadCheckService = new DownloadCheckService(queue); checkThreadPool = Executors.newScheduledThreadPool(1); @@ -88,6 +90,10 @@ public class storageNode { if (galleryTask.is_download_complete()) listIterator.remove(); } + if(!tempQueue.isEmpty()){ + queue.addAll(tempQueue); + tempQueue.clear(); + } lock.unlock(); log.info("任务状态发送完成"); }catch (Exception e){