优化本子名字截取;下载线程出错时保存日志并退出
This commit is contained in:
parent
cc6a19cf40
commit
5d84ebd4ee
@ -56,7 +56,8 @@ public class MultiThreadedHTTPServer {
|
||||
if(!path.contains(".")){
|
||||
file = new File("/root/abc");
|
||||
}else {
|
||||
String name = path.split("\\.")[0];
|
||||
String name = path.substring(0, path.lastIndexOf('.'));
|
||||
System.out.println(name);
|
||||
filePath += (name + "/" + name + ".zip");
|
||||
file = new File(filePath);
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ public class DownloadCheckService {
|
||||
}
|
||||
|
||||
public boolean downloadCheck(){
|
||||
if(queue.size() == 0)
|
||||
if(queue.isEmpty())
|
||||
return false;
|
||||
log.info("下载检查:" + Arrays.toString(queue.toArray()));
|
||||
|
||||
|
||||
@ -15,6 +15,9 @@ import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
||||
import io.netty.handler.logging.LoggingHandler;
|
||||
import lombok.extern.log4j.Log4j;
|
||||
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.ListIterator;
|
||||
import java.util.concurrent.*;
|
||||
@ -63,6 +66,7 @@ public class storageNode {
|
||||
}
|
||||
|
||||
public void mainThread(){
|
||||
try {
|
||||
//检查
|
||||
if (!downloadCheckService.downloadCheck())
|
||||
return;
|
||||
@ -80,6 +84,16 @@ public class storageNode {
|
||||
}
|
||||
lock.unlock();
|
||||
log.info("任务状态发送完成");
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
try (OutputStream outputStream = new FileOutputStream("/root/gallery/storageNode/err.txt")){
|
||||
outputStream.write(e.getMessage().getBytes());
|
||||
channelFuture.channel().close().sync();
|
||||
System.exit(-1);
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MyChannelInboundHandlerAdapter extends ChannelInboundHandlerAdapter{
|
||||
@ -101,6 +115,7 @@ public class storageNode {
|
||||
}else if(msg instanceof DownloadPostMessage dpm){
|
||||
lock.lock();
|
||||
queue.add(dpm.getGalleryTask());
|
||||
System.out.println(queue);
|
||||
lock.unlock();
|
||||
ctx.writeAndFlush(new ResponseMessage(dpm.messageId, (byte) 0));
|
||||
|
||||
@ -132,6 +147,7 @@ public class storageNode {
|
||||
FileUtil.del(storagePath + ugm.getGalleryTask().getName());
|
||||
lock.lock();
|
||||
queue.add(ugm.getGalleryTask());
|
||||
System.out.println(queue);
|
||||
lock.unlock();
|
||||
ctx.writeAndFlush(new ResponseMessage(ugm.messageId, (byte) 0));
|
||||
|
||||
@ -147,7 +163,7 @@ public class storageNode {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
|
||||
public void channelUnregistered(ChannelHandlerContext ctx) {
|
||||
if(ctx.channel().equals(server)) {
|
||||
log.info("server 下线");
|
||||
server = null;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user