/
WatchCrawler.js
234 lines (204 loc) · 7.79 KB
/
WatchCrawler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
DELETE_STRING="delete";
BAR_IMG1="/env/grafics/green-block.png";
BAR_IMG2="/env/grafics/red-block.png";
WORDCACHEBAR_LENGTH=1/4;
var statusRPC;
var queuesRPC;
var refreshInterval=5;
var wait=0;
var changing=false; //change the interval
refresh();
//loadInterval=window.setInterval("refresh()", refreshInterval*1000);
countInterval=window.setInterval("countdown()", 1000);
function changeInterval(){
if(!changing){
window.clearInterval(countInterval);
counter=document.getElementById("nextUpdate");
counter.innerHTML='<input type="text" id="newInterval" onblur="newInterval()" size="2" />';
document.getElementById("newInterval").focus();
changing=true;
}
}
function newInterval(){
refreshInterval=document.getElementById("newInterval").value;
refresh();
countInterval=window.setInterval("countdown()", 1000);
changing=false;
}
function countdown(){
document.getElementById("nextUpdate").innerHTML=wait;
wait--;
if(wait==0){
refresh()
}
}
function refresh(){
wait=refreshInterval;
requestStatus();
requestQueues();
}
function requestStatus(){
statusRPC=createRequestObject()
statusRPC.open('get', '/xml/status_p.xml');
statusRPC.onreadystatechange = handleStatus;
statusRPC.send(null)
}
function requestQueues(){
queuesRPC=createRequestObject()
queuesRPC.open('get', '/xml/queues_p.xml');
queuesRPC.onreadystatechange = handleQueues;
queuesRPC.send(null);
}
function handleStatus(){
if(statusRPC.readyState != 4){
return;
}
var statusResponse = statusRPC.responseXML;
statusTag=getFirstChild(statusResponse, "status")
ppm=getValue(getFirstChild(statusTag, "ppm"))
var ppmNum = document.getElementById("ppmNum");
removeAllChildren(ppmNum);
ppmNum.appendChild(document.createTextNode(ppm));
var ppmSpan = document.getElementById("ppmSpan");
removeAllChildren(ppmSpan);
for(i=0;i<ppm;i++){
img=document.createElement("img");
img.setAttribute("src", BAR_IMG1);
ppmSpan.appendChild(img);
}
// traffic output (no bar up to now)
traffic = getFirstChild(statusTag, "traffic");
trafficCrawler = getValue(getFirstChild(traffic, "crawler"));
trafCrawlerSpan = document.getElementById("trafficCrawler");
removeAllChildren(trafCrawlerSpan);
trafCrawlerSpan.appendChild(document.createTextNode(Math.round((trafficCrawler) / 1024 / 10.24) / 100));
var wordCache=getValue(getFirstChild(statusTag, "wordCacheWSize"));
var wordCacheMax=getValue(getFirstChild(statusTag, "wordCacheMaxCount"));
wordCacheNum=document.getElementById("wordcacheNum");
removeAllChildren(wordCacheNum);
wordCacheNum.appendChild(document.createTextNode(wordCache+"/"+wordCacheMax));
wordCacheSpan=document.getElementById("wordcacheSpan");
removeAllChildren(wordCacheSpan);
var img;
var percent=Math.round(wordCache/wordCacheMax*100);
for(i=0;i<percent*WORDCACHEBAR_LENGTH;i++){
img=document.createElement("img");
img.setAttribute("src", BAR_IMG2);
wordCacheSpan.appendChild(img);
}
for(i=0;i<(100-percent)*WORDCACHEBAR_LENGTH;i++){
img=document.createElement("img");
img.setAttribute("src", BAR_IMG1);
wordCacheSpan.appendChild(img);
}
}
function handleQueues(){
if(queuesRPC.readyState != 4){
return;
}
var queuesResponse = queuesRPC.responseXML;
xml=getFirstChild(queuesResponse);
if(queuesResponse != null){
clearTable(document.getElementById("queueTable"), 1);
indexingqueue=getFirstChild(xml, "indexingqueue");
updateTable(indexingqueue, "indexing");
indexingqueue_size=getValue(getFirstChild(indexingqueue, "size"));
indexingqueue_max=getValue(getFirstChild(indexingqueue, "max"));
document.getElementById("indexingqueuesize").firstChild.nodeValue=indexingqueue_size;
document.getElementById("indexingqueuemax").firstChild.nodeValue=indexingqueue_max;
dbsize=getFirstChild(xml, "dbsize");
urlpublictextSize=getValue(getFirstChild(dbsize, "urlpublictext"));
rwipublictextSize=getValue(getFirstChild(dbsize, "rwipublictext"));
document.getElementById("urldbsize").firstChild.nodeValue=urlpublictextSize;
document.getElementById("rwidbsize").firstChild.nodeValue=rwipublictextSize;
loaderqueue=getFirstChild(xml, "loaderqueue");
updateTable(loaderqueue, "loader");
loaderqueue_size=getValue(getFirstChild(loaderqueue, "size"));
loaderqueue_max=getValue(getFirstChild(loaderqueue, "max"));
document.getElementById("loaderqueuesize").firstChild.nodeValue=loaderqueue_size;
document.getElementById("loaderqueuemax").firstChild.nodeValue=loaderqueue_max;
localcrawlerqueue=getFirstChild(xml, "localcrawlerqueue");
localcrawlerqueue_size=getValue(getFirstChild(localcrawlerqueue, "size"));
localcrawlerqueue_state=getValue(getFirstChild(localcrawlerqueue, "state"));
document.getElementById("localcrawlerqueuesize").firstChild.nodeValue=localcrawlerqueue_size;
putQueueState("localcrawler", localcrawlerqueue_state);
updateTable(localcrawlerqueue, "local crawler");
remotecrawlerqueue=getFirstChild(xml, "remotecrawlerqueue");
updateTable(remotecrawlerqueue, "remoteCrawlerTable");
remotecrawlerqueue_size=getValue(getFirstChild(remotecrawlerqueue, "size"));
remotecrawlerqueue_state=getValue(getFirstChild(remotecrawlerqueue, "state"));
document.getElementById("remotecrawlerqueuesize").firstChild.nodeValue=remotecrawlerqueue_size;
putQueueState("remotecrawler", remotecrawlerqueue_state);
updateTable(remotecrawlerqueue, "remote crawler");
}
}
function putQueueState(queue, state) {
a = document.getElementById(queue + "stateA");
img = document.getElementById(queue + "stateIMG");
if (state == "paused") {
a.href = "WatchCrawler_p.html?continue=" + queue;
a.title = "Continue this queue";
img.src = "/env/grafics/start.gif";
img.alt = "Continue this queue";
} else {
a.href = "WatchCrawler_p.html?pause=" + queue;
a.title = "Pause this queue";
img.src = "/env/grafics/stop.gif";
img.alt = "Pause this queue";
}
}
function updateTable(indexingqueue, tablename){
indexingTable=document.getElementById("queueTable");
entries=indexingqueue.getElementsByTagName("entry");
dark=false;
for(i=0;i<entries.length;i++){
profile=getValue(getFirstChild(entries[i], "profile"));
initiator=getValue(getFirstChild(entries[i], "initiator"));
depth=getValue(getFirstChild(entries[i], "depth"));
modified=getValue(getFirstChild(entries[i], "modified"));
anchor=getValue(getFirstChild(entries[i], "anchor"));
url=getValue(getFirstChild(entries[i], "url"));
size=getValue(getFirstChild(entries[i], "size"));
hash=getValue(getFirstChild(entries[i], "hash"));
inProcess=false;
if(getValue(getFirstChild(entries[i], "inProcess"))=="true"){
inProcess=true;
}
if (tablename=="indexingTable")
deletebutton=createLinkCol("IndexCreateIndexingQueue_p.html?deleteEntry="+hash, DELETE_STRING);
else
deletebutton=createCol("");
row=createIndexingRow(tablename, profile, initiator, depth, modified, anchor, url, size, deletebutton);
//create row
if(inProcess){
row.setAttribute("class", "TableCellActive");
}else if(dark){
row.setAttribute("class", "TableCellDark");
}else{
row.setAttribute("class", "TableCellLight");
}
getFirstChild(indexingTable, "tbody").appendChild(row);
dark=!dark;
}
}
function shortenURL(url) {
if (url.length > 80) {
return url.substr(0, 80) + "...";
} else {
return url;
}
}
function createIndexingRow(queue, profile, initiator, depth, modified, anchor, url, size, deletebutton){
row=document.createElement("tr");
row.setAttribute("height", 10);
row.appendChild(createCol(queue));
row.appendChild(createCol(profile));
row.appendChild(createCol(initiator));
row.appendChild(createCol(depth));
row.appendChild(createCol(modified));
row.appendChild(createCol(anchor));
row.appendChild(createLinkCol(url, shortenURL(url)));
row.appendChild(createCol(size));
row.appendChild(deletebutton);
return row;
}