parent
47b6c0d728
commit
37be8c68ea
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue