Skip to content

Commit c69ae8b

Browse files
committed
optimize
1 parent 3b37dec commit c69ae8b

File tree

7 files changed

+56
-17
lines changed

7 files changed

+56
-17
lines changed

vjudge2016/src/applicationContext.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
</property>
127127
</bean>
128128

129+
129130

130131
<!-- 配置Service -->
131132
<bean id="baseService" class="judge.service.BaseService">
@@ -184,5 +185,6 @@
184185

185186
<bean id="remoteAccountTaskExecutor" factory-bean="remoteAccountTaskExecutorFactory" factory-method="create"
186187
init-method="init" />
187-
188+
189+
188190
</beans>

vjudge2016/src/judge/remote/provider/local/LOCALCrawler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public RemoteOjInfo getOjInfo() {
2424
}
2525

2626
private static final HttpHost HOSTS[] = new HttpHost[] {
27-
new HttpHost(LOCALInfo.DOMAIN)
27+
new HttpHost(LOCALInfo.domain)
2828
};
2929

3030
@Override
@@ -71,7 +71,7 @@ public RawProblemInfo crawl(String problemId) throws Exception {
7171
}
7272

7373
protected String getProblemUrl(HttpHost host, String problemId) {
74-
return host.toURI() + LOCALInfo.PATH+"/problem.php?id=" + problemId;
74+
return host.toURI() + LOCALInfo.path+"/problem.php?id=" + problemId;
7575
}
7676

7777
protected void preValidate(String problemId) {
Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,53 @@
11
package judge.remote.provider.local;
22

3+
import java.util.ResourceBundle;
4+
35
import judge.remote.RemoteOj;
46
import judge.remote.RemoteOjInfo;
7+
import judge.tool.ApplicationConfigPopulator;
8+
import judge.tool.ApplicationContainer;
59

610
import org.apache.http.HttpHost;
711

812
public class LOCALInfo {
9-
public static final String DOMAIN="hustoj.com";
10-
public static final String PATH="/oj/";
11-
12-
public static final RemoteOjInfo INFO = new RemoteOjInfo( //
13+
public static String domain =java.util.ResourceBundle.getBundle("config").getString("hustoj.domain");
14+
15+
public static String path=java.util.ResourceBundle.getBundle("config").getString("hustoj.path");
16+
17+
18+
19+
20+
21+
public static String getDomain() {
22+
return domain;
23+
}
24+
25+
26+
public static void setDomain(String domain) {
27+
LOCALInfo.domain = domain;
28+
}
29+
30+
31+
public static String getPath() {
32+
return path;
33+
}
34+
35+
36+
public static void setPath(String path) {
37+
LOCALInfo.path = path;
38+
}
39+
40+
41+
public static final RemoteOjInfo INFO = new RemoteOjInfo( //
1342
RemoteOj.LOCAL, //
1443
"LOCAL", //
15-
new HttpHost(DOMAIN) //
44+
new HttpHost(domain) //
1645
);
1746

1847

1948
static {
2049
INFO.faviconUrl = "images/remote_oj/icon-icpc-small.gif";
2150
INFO._64IntIoFormat = "%lld & %llu";
22-
INFO.urlForIndexDisplay = "http://"+DOMAIN+PATH;
51+
INFO.urlForIndexDisplay = "http://"+domain+path;
2352
}
2453
}

vjudge2016/src/judge/remote/provider/local/LOCALLoginer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ public RemoteOjInfo getOjInfo() {
2222

2323
@Override
2424
protected void loginEnforce(RemoteAccount account, DedicatedHttpClient client) {
25-
if (client.get(LOCALInfo.PATH).getBody().contains("<a href=logout.php>")) {
25+
if (client.get(LOCALInfo.path).getBody().contains("<a href=logout.php>")) {
2626
return;
2727
}
2828

2929
HttpEntity entity = SimpleNameValueEntityFactory.create( //
3030
"user_id", account.getAccountId(), //
3131
"password", account.getPassword());
32-
client.get(LOCALInfo.PATH+"/setlang.php?lang=en");
33-
client.post(LOCALInfo.PATH+"/login.php", entity, new SimpleHttpResponseValidator() {
32+
client.get(LOCALInfo.path+"/setlang.php?lang=en");
33+
client.post(LOCALInfo.path+"/login.php", entity, new SimpleHttpResponseValidator() {
3434
@Override
3535
public void validate(SimpleHttpResponse response) throws Exception {
3636
Validate.isTrue(response.getBody().contains("history.go(-2)"));

vjudge2016/src/judge/remote/provider/local/LOCALQuerier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public RemoteOjInfo getOjInfo() {
2828
@Override
2929
protected SubmissionRemoteStatus query(SubmissionInfo info, RemoteAccount remoteAccount, DedicatedHttpClient client) {
3030
String html = client.get(
31-
LOCALInfo.PATH+"/status-ajax.php?solution_id=" + info.remoteRunId,
31+
LOCALInfo.path+"/status-ajax.php?solution_id=" + info.remoteRunId,
3232
new HttpBodyValidator("<title>Error</title>", true)).getBody();
3333
System.out.println(html);
3434
String[] s=html.split(",");
@@ -44,7 +44,7 @@ protected SubmissionRemoteStatus query(SubmissionInfo info, RemoteAccount remote
4444

4545
Validate.isTrue(result[Integer.parseInt(s[0])].contains("Compile Error"));
4646
status.compilationErrorInfo = client.get(
47-
LOCALInfo.PATH+"/ceinfo.php?sid=" + info.remoteRunId,
47+
LOCALInfo.path+"/ceinfo.php?sid=" + info.remoteRunId,
4848
new HttpBodyValidator("<title>Error</title>", true)).getBody().substring(3277);
4949
}
5050
}catch(Exception e){

vjudge2016/src/judge/remote/provider/local/LOCALSubmitter.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@ protected boolean needLogin() {
2929

3030
@Override
3131
protected Integer getMaxRunId(SubmissionInfo info, DedicatedHttpClient client, boolean submitted) {
32-
String html = client.get(LOCALInfo.PATH+"/status.php?user_id=" + info.remoteAccountId + "&problem_id=" + info.remoteProblemId).getBody();
33-
Matcher matcher = Pattern.compile("class='evenrow'><td> (\\d+)").matcher(html);
32+
try {
33+
Thread.sleep(3000);
34+
} catch (InterruptedException e) {
35+
// TODO Auto-generated catch block
36+
e.printStackTrace();
37+
}
38+
String html = client.get(LOCALInfo.path+"/status.php?user_id=" + info.remoteAccountId + "&problem_id=" + info.remoteProblemId+"&rand="+Math.random()).getBody();
39+
Matcher matcher = Pattern.compile("<tr class='evenrow'><td>(\\d+)</td>").matcher(html);
40+
// System.out.println(html);
3441
return matcher.find() ? Integer.parseInt(matcher.group(1)) : -1;
3542
}
3643

@@ -41,7 +48,7 @@ protected String submitCode(SubmissionInfo info, RemoteAccount remoteAccount, De
4148
"id", info.remoteProblemId, //
4249
"source", info.sourceCode //
4350
);
44-
client.post(LOCALInfo.PATH+"/submit.php", entity, HttpStatusValidator.SC_MOVED_TEMPORARILY);
51+
client.post(LOCALInfo.path+"/submit.php", entity, HttpStatusValidator.SC_MOVED_TEMPORARILY);
4552
return null;
4653
}
4754

vjudge2016/src/judge/remote/submitter/CanonicalSubmitter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ protected SubmissionReceipt call(RemoteAccount remoteAccount) throws Exception {
130130
if (errorStatus != null) {
131131
return new SubmissionReceipt(null, null, errorStatus);
132132
}
133+
Thread.sleep(2000);
133134

134135
Integer runIdAfter;
135136
long beginTime = System.currentTimeMillis();

0 commit comments

Comments
 (0)