fix:上位机

1.修改AgentSession的指令获取线程的退出循环逻辑
2.增加停止指令,用于部分线程停止。
master
李杰应 2024-07-24 18:50:41 +08:00
parent 47b6c0d728
commit 37be8c68ea
2 changed files with 57 additions and 4 deletions

View File

@ -1,10 +1,12 @@
package net.northking.cctp.upperComputer.driver.agent;
import cn.hutool.core.util.StrUtil;
import net.northking.cctp.upperComputer.driver.adb.Adb;
import net.northking.cctp.upperComputer.driver.adb.AdbDevice;
import net.northking.cctp.upperComputer.driver.adb.AdbTransport;
import net.northking.cctp.upperComputer.driver.agent.command.CloseSessionCommand;
import net.northking.cctp.upperComputer.driver.agent.command.StopCommand;
import net.northking.cctp.upperComputer.driver.agent.command.protocol.ProtocolCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -139,26 +141,43 @@ public class AndroidAgentSession {
*/
public void closeSilence() {
if (null != this.sendThread) {
this.sendThread.interrupt();
this.sendThread.setRunning(false);
this.sendQueue.clear();
StopCommand sc = new StopCommand();
this.sendQueue.add(sc); // 添加结束命令command
try {
this.sendThread.join();
} catch (InterruptedException e) {
logger.error("线程join失败", e);
}
}
state = false;
}
private class CommandSendThread extends Thread {
private volatile boolean running = true;
public void setRunning(boolean running) {
this.running = running;
}
@Override
public void run() {
while (!isInterrupted()) {
while (running) {
ProtocolCommand command;
try {
command = sendQueue.take();
logger.debug("获取到指令信息:{}", StrUtil.toString(command));
} catch (InterruptedException e) {
break;
}
try {
dataOutputStream.writeInt(command.getCommandId());
command.doSend(dataOutputStream);
if (command.getCommandId() != -999) {
dataOutputStream.writeInt(command.getCommandId());
command.doSend(dataOutputStream);
} else {
logger.debug("线程准备停止....");
}
} catch (IOException ignore) {
break;
}

View File

@ -0,0 +1,34 @@
package net.northking.cctp.upperComputer.driver.agent.command;
import net.northking.cctp.upperComputer.driver.agent.command.protocol.AbstractProtocolCommand;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class StopCommand extends AbstractProtocolCommand<String> {
/**
* id
*
* @return id
*/
@Override
public int getCommandId() {
return -999;
}
/**
* Session
*
* @param output
*/
@Override
public void doSend(DataOutput output) throws IOException {
}
@Override
public String buildReceive(DataInput input) throws IOException {
return null;
}
}