2024-01-12 20:48:35 +08:00
|
|
|
|
/*
|
|
|
|
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
|
|
|
|
* To change this template file, choose Tools | Templates
|
|
|
|
|
|
* and open the template in the editor.
|
|
|
|
|
|
*/
|
|
|
|
|
|
package data;
|
|
|
|
|
|
|
|
|
|
|
|
import gui.Control;
|
2024-03-26 22:38:33 +08:00
|
|
|
|
import static gui.Control.getJudgeInfoEditorPane;
|
2024-01-12 20:48:35 +08:00
|
|
|
|
import java.awt.EventQueue;
|
|
|
|
|
|
import java.net.URL;
|
2024-03-26 22:38:33 +08:00
|
|
|
|
import java.time.LocalTime;
|
2024-01-12 20:48:35 +08:00
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
import java.util.concurrent.locks.Lock;
|
2024-03-26 22:38:33 +08:00
|
|
|
|
import javax.swing.JEditorPane;
|
2024-01-12 20:48:35 +08:00
|
|
|
|
import myjdom.XmlToSolution;
|
|
|
|
|
|
import myjdom.model.Solution;
|
|
|
|
|
|
import myjdom.model.Solutions;
|
|
|
|
|
|
import myjdom.model.ProblemBean;
|
|
|
|
|
|
import persistence.oj_beans.ProblemTestCaseBean;
|
|
|
|
|
|
import web.Webservice;
|
2024-03-26 22:38:33 +08:00
|
|
|
|
import static web.Webservice.existDubbo;
|
2024-01-12 20:48:35 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* @author Administrator
|
|
|
|
|
|
*/
|
|
|
|
|
|
public class MainForNet extends Thread {
|
|
|
|
|
|
|
|
|
|
|
|
private List<ProblemTestCaseBean> testCaseBeans = null;
|
|
|
|
|
|
private Map<String, ProblemBean> problemBeanMap = null;
|
|
|
|
|
|
// private ProblemBean problemBean = null;
|
|
|
|
|
|
// private static String serverURL;
|
|
|
|
|
|
// private static IDistributorServer server;
|
|
|
|
|
|
private int previousSId = -1;
|
|
|
|
|
|
public Solutions solutions;
|
|
|
|
|
|
private Lock lock;
|
|
|
|
|
|
// private String ip = "127.0.0.1";
|
|
|
|
|
|
// private int port = 5000;
|
|
|
|
|
|
|
|
|
|
|
|
public MainForNet() {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void run() {
|
|
|
|
|
|
while (Control.threadCountsManager[0]) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
if (Control.queue.size() > 2) {
|
|
|
|
|
|
Thread.sleep(500);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
System.out.println("<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>ȡsolution");
|
2024-03-26 22:38:33 +08:00
|
|
|
|
|
2024-01-12 20:48:35 +08:00
|
|
|
|
List<Solution> list = getWebServiceSolutions();
|
|
|
|
|
|
System.out.println("<EFBFBD><EFBFBD>ȡslolutin<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"+list.size());
|
|
|
|
|
|
// getServerObject();
|
|
|
|
|
|
if (list.size() == 0) {
|
|
|
|
|
|
Thread.sleep(3000);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
System.out.println("solutionװ<EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
|
listToQueue(list);
|
|
|
|
|
|
System.out.println("solutionװ<EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
|
//Swing<6E><67><EFBFBD><EFBFBD><EFBFBD>̰߳<DFB3>ȫ<EFBFBD>ģ<EFBFBD>invoke<6B><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>run<75><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>첽ִ<ECB2BD><D6B4>
|
|
|
|
|
|
EventQueue.invokeLater(() -> {
|
|
|
|
|
|
Control.setGuiQueueSize("" + Control.queue.size());
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
// judge();
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
EventQueue.invokeLater(() -> {
|
|
|
|
|
|
Control.addExceptionInfo(0, ex.toString());
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Control.threadState[0] = false;
|
|
|
|
|
|
|
|
|
|
|
|
//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD>ȫֹͣ
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
synchronized (Control.threadCountsManager) {
|
|
|
|
|
|
for (; i <= 4; i++) {
|
|
|
|
|
|
if (Control.threadCountsManager[i] == true || Control.threadState[i] == true) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (i > 4) {
|
|
|
|
|
|
EventQueue.invokeLater(() -> {
|
|
|
|
|
|
Control.setStoptxt();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<Solution> getWebServiceSolutions() throws Exception {
|
|
|
|
|
|
Control.setWebService(new Webservice(new URL(Control.getUrl()), Control.getQname()));
|
2024-03-26 22:38:33 +08:00
|
|
|
|
|
2024-05-09 22:02:18 +08:00
|
|
|
|
String xml = null;
|
|
|
|
|
|
try{
|
|
|
|
|
|
xml=Control.getWebService().getSolutions(5);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch(Exception ex){
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
EventQueue.invokeLater(() -> {
|
|
|
|
|
|
Control.addExceptionInfo(0, ex.getStackTrace().toString());
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2024-01-12 20:48:35 +08:00
|
|
|
|
XmlToSolution xts = new XmlToSolution();
|
|
|
|
|
|
xts.readXmlString(xml);
|
|
|
|
|
|
|
2024-05-09 22:02:18 +08:00
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
|
this.solutions = xts.convertXML();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch(Exception ex){
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
EventQueue.invokeLater(() -> {
|
|
|
|
|
|
Control.addExceptionInfo(0, ex.getStackTrace().toString());
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2024-01-12 20:48:35 +08:00
|
|
|
|
// Control.addJudgeInfo(" get "+solutions.getSolution().size()+" solutioins ");
|
|
|
|
|
|
if (solutions.getSolution().size() != 0) {
|
|
|
|
|
|
//System.out.println("get " + solutions.getSolution().size() + " solution");
|
|
|
|
|
|
Control.addJudgeInfo(0, "get " + solutions.getSolution().size() + " solution");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
return solutions.getSolution();
|
|
|
|
|
|
}
|
|
|
|
|
|
//<2F><>list<73><74>Ԫ<EFBFBD>ذ<EFBFBD>list<73><74>˳<EFBFBD><CBB3><EFBFBD>Ž<EFBFBD><C5BD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
public void listToQueue(List<Solution> s) {
|
|
|
|
|
|
synchronized (Control.queue) {
|
|
|
|
|
|
Control.queue.addAll(s);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void getSolutionFromWeb() throws Exception {
|
|
|
|
|
|
|
|
|
|
|
|
List<Solution> s;
|
|
|
|
|
|
s = this.getWebServiceSolutions();
|
|
|
|
|
|
this.listToQueue(s);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// private void getServerObject() throws Exception{
|
|
|
|
|
|
// String serverURL = "jdbc://"+ip+":" + port + "/" + "gddoj";
|
|
|
|
|
|
// try {
|
|
|
|
|
|
// server = (IDistributorServer) Naming.lookup(serverURL);
|
|
|
|
|
|
// } catch (Exception ex) {
|
|
|
|
|
|
// ex.printStackTrace();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// private void getTestCaseBeans(SolutionBean sbean){
|
|
|
|
|
|
// Problem p = ProblemCacheManager.getOneProblem(sbean.getProblemId());
|
|
|
|
|
|
// ProblemBean problemBean = p.getPbean();
|
|
|
|
|
|
// testCaseBeans = p.getTestcases();
|
|
|
|
|
|
//
|
|
|
|
|
|
// }
|
|
|
|
|
|
// public void changeMessage(String message){
|
|
|
|
|
|
// Control.addJudgeInfo(message);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// public void submitAnswer(Answer answer){
|
|
|
|
|
|
// String xml = null;
|
|
|
|
|
|
// try {
|
|
|
|
|
|
// ResultBean rb = new ResultBean();
|
|
|
|
|
|
// rb.setSolutionId(answer.getSolutionId());
|
|
|
|
|
|
// rb.setProblemId(answer.getProblemId());
|
|
|
|
|
|
// rb.setStatus(answer.getStatus());
|
|
|
|
|
|
// rb.setCorrectCaseIds(answer.getCorrectCaseIds());
|
|
|
|
|
|
// rb.setRemark(answer.getRemark());
|
|
|
|
|
|
// rb.setLanguage(answer.getLanguage());
|
|
|
|
|
|
// rb.setSourceCode(answer.getSourceCode());
|
|
|
|
|
|
// List<ProblemTestCaseBean> wrongCase = new ArrayList<>();
|
|
|
|
|
|
// List<String> testCaseList = Arrays.asList(answer.getTestCaseId());
|
|
|
|
|
|
// List<String> correctList = Arrays.asList(answer.getCorrectCaseIds().split(","));
|
|
|
|
|
|
// for(int i=0;i<testCaseList.size();i++){
|
|
|
|
|
|
// if(!correctList.contains(testCaseList.get(i))){
|
|
|
|
|
|
// ProblemTestCaseBean testCase = new ProblemTestCaseBean();
|
|
|
|
|
|
// testCase.setId(Integer.parseInt(testCaseList.get(i)));
|
|
|
|
|
|
// testCase.setOutput(answer.getUsersOutput()[i]);
|
|
|
|
|
|
// wrongCase.add(testCase);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// rb.setWrongCase(wrongCase);
|
|
|
|
|
|
// AnswerToXml rtx = new AnswerToXml(rb);
|
|
|
|
|
|
// xml = rtx.convertXML();
|
|
|
|
|
|
// System.out.println(xml);
|
|
|
|
|
|
// String request = Control.getWebService().updateResult(xml);
|
|
|
|
|
|
// System.out.println(request);
|
|
|
|
|
|
// XmlToRequest xtr = new XmlToRequest();
|
|
|
|
|
|
// xtr.readXmlString(request);
|
|
|
|
|
|
// Request req = xtr.convertXML();
|
|
|
|
|
|
// Control.addJudgeInfo("server result:"+req.getRspMsg());
|
|
|
|
|
|
//// Control.addJudgeInfo("ok");
|
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// }
|
|
|
|
|
|
// public void judge() {
|
|
|
|
|
|
// while (true) {
|
|
|
|
|
|
// Integer sid = null;
|
|
|
|
|
|
// try {
|
|
|
|
|
|
//
|
|
|
|
|
|
// List<Solution> list = solutions.getSolution();
|
|
|
|
|
|
// for(Solution s:list){
|
|
|
|
|
|
// String problemId = s.getProblemId();
|
|
|
|
|
|
//
|
|
|
|
|
|
// String language = s.getLangeuage();
|
|
|
|
|
|
// String sourceCode = s.getCode();
|
|
|
|
|
|
//
|
|
|
|
|
|
//
|
|
|
|
|
|
// }
|
|
|
|
|
|
// sid = server.getOneSolutionId();
|
|
|
|
|
|
//
|
|
|
|
|
|
// new Process().Judge(langauge, sourceCode, timeOut, testCaseBeans);
|
|
|
|
|
|
// List<SolutionBean> slist=SolutionDAO.findMore("id=", sid, 1);
|
|
|
|
|
|
// if (slist.size() != 0) {
|
|
|
|
|
|
// SolutionBean sbean = slist.get(0);
|
|
|
|
|
|
// if ((sbean.getId() < previousSId) || !(sbean.getStatus().equals(Const.STATUS[Const.QUEUE]))) {
|
|
|
|
|
|
// Control.addExceptionInfo("previous SolutionId=" + previousSId + "---this SolutionId" + sid);
|
|
|
|
|
|
// Control.addExceptionInfo("thisSId < previousSId? " + (sbean.getId() < previousSId));
|
|
|
|
|
|
// Control.addExceptionInfo("sbean.status=" + sbean.getStatus());
|
|
|
|
|
|
// Control.addExceptionInfo("this status!=QUEUE? " + (!(sbean.getStatus().equals(Const.STATUS[Const.QUEUE]))));
|
|
|
|
|
|
// continue;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// previousSId = sbean.getId();
|
|
|
|
|
|
// getTestCaseBeans(sbean);
|
|
|
|
|
|
// new Process().Judge(sbean,testCaseBeans,problemBean);
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// TimeTool.sleep(2000);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if (this.stop) {
|
|
|
|
|
|
// break;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
|
// Control.addExceptionInfo("SID="+sid+" "+e.toString());
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
|