-
Notifications
You must be signed in to change notification settings - Fork 0
/
View.java
122 lines (90 loc) · 2.72 KB
/
View.java
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
package org.sakaiproject.logviewer.pages;
import java.io.File;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.basic.MultiLineLabel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.util.time.Duration;
/**
* Main page for LogViewerApplication
*
* @author Steve Swinsburg (steve.swinsburg@anu.edu.au)
*
*/
public class View extends BasePage {
private static final long serialVersionUID = 1L;
File logFile;
/**
* Render the View page
*/
public View() {
//disableLink(viewLink);
logFile = new File("/Users/erkel/dev/sakai/conf/trunk/sakai.properties");
}
@Override
public void onInitialize() {
super.onInitialize();
add(backFillLogData());
add(createNextLog());
}
/**
* Backfill existing data from the file
*
* @return a MultiLineLabel of data to be displayed
*/
private MultiLineLabel backFillLogData() {
MultiLineLabel label = new MultiLineLabel("logData");
label.setDefaultModel(new LoadableDetachableModel<Object>() {
private static final long serialVersionUID = 1L;
@Override
protected Object load() {
try{
//TODO improvement, get the last few lines from the file (as configured)
return "old log lines here";
//return FileUtils.readFileToString(logFile, "UTF-8");
}catch(Exception ex){}
return "";
}
});
label.setMarkupId("logData");
label.setOutputMarkupId(true);
return label;
}
/**
* Get the next portion of the log file and output it.
*
* @return a Label with the next part of the log
*/
private Label createNextLog() {
Label label = new Label("nextLog");
//if(listenerRunning) {
label.setDefaultModel(new LoadableDetachableModel<Object>() {
private static final long serialVersionUID = 1L;
@Override
protected Object load() {
//get the data from the tailer
return businessService.getLogLines();
}
});
label.add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(1)) {
private static final long serialVersionUID = 1L;
@Override
protected void onPostProcessTarget(AjaxRequestTarget target) {
if(label.getDefaultModel() != null) {
/*
* We are doing the following here:
* - append the content of "nextLog" to "logData"
* - remove "nextLog"
* - insert "nextLog" after "logData".
*/
target.appendJavaScript("doUpdate();");
}
}
});
//}
label.setMarkupId("nextLog");
label.setOutputMarkupId(true);
return label;
}
}