* @param instance GridNode instance
*/
private void registerHooks(GridNode instance) {
// Disconnection Hook
ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {
@Override
public void onServiceEvent(ServiceMessage message) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
updateGridInfo();
}
});
}
}, instance.getClusterId().toString(), ServiceMessageType.NODE_DISCONNECTED);
// Job Start Hook
ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {
@Override
public void onServiceEvent(ServiceMessage message) {
final String jobId = message.getMessage();
final String jobName = GridNode.getInstance()
.getJobExecutionService()
.getJobName(jobId);
activeJobId = jobId;
final long timeStart = System.currentTimeMillis();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
showBusyIcon();
setStatus("Executing Job");
((JLabel) getUIElement("general.stats.jobname"))
.setText(jobName);
((JLabel) getUIElement("general.stats.tasks")).setText("0");
((JLabel) getUIElement("general.stats.failures")).setText("0");
}
});
// Duration Update Thread
new Thread(new Runnable() {
@Override
public void run() {
while (jobId.equals(activeJobId)) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
((JLabel) getUIElement("general.stats.duration"))
.setText(TimeUtils.timeDifference(timeStart));
}
});
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
log.warn("Interrupted", e);
}
}
}
}).start();
// Job End Hook
ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {
@Override
public void onServiceEvent(ServiceMessage message) {
activeJobId = null;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
JLabel durationLabel = getUIElement("general.stats.duration");
JLabel jobnameLabel = getUIElement("general.stats.jobname");
JLabel tasksLabel = getUIElement("general.stats.tasks");
JLabel failuresLabel = getUIElement("general.stats.failures");
JLabel totalJobsLabel = getUIElement("general.stats.totaljobs");
int tasks = Integer.parseInt(tasksLabel.getText());
int failures = Integer.parseInt(failuresLabel.getText());
// Create and enter Job History Element
JobHistoryElement element =
new JobHistoryElement(jobName,
jobId,
TimeUtils.formatDate(timeStart),
durationLabel.getText(),
tasks,
failures);
historyList.addJobHistoryElement(element);
// Update Job Info Fields
durationLabel.setText("N/A");
jobnameLabel.setText("N/A");
tasksLabel.setText("N/A");
failuresLabel.setText("N/A");
// Update Total Jobs Count
int totalJobs = Integer.parseInt(totalJobsLabel.getText()) + 1;
totalJobsLabel.setText(String.valueOf(totalJobs));
showIdleIcon();
setStatus("Idle");
} catch (Exception e) {
log.warn("[UI] Exception ",e);
}
}
});
}
}, jobId, ServiceMessageType.LOCAL_JOBFINISHED);
}
}, ServiceMessageType.LOCAL_JOBSTARTED);
// Task Executed Hook
ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {
public void onServiceEvent(final ServiceMessage message) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
// Total Tasks
JLabel totalTasksLabel = getUIElement("general.stats.totaltasks");
int totalTasks = Integer.parseInt(totalTasksLabel.getText()) + 1;
totalTasksLabel.setText(String.valueOf(totalTasks));
// If active job, update task count
if (message.getMessage().equals(activeJobId)) {
JLabel tasksLabel = getUIElement("general.stats.tasks");
int tasks = Integer.parseInt(tasksLabel.getText()) + 1;
tasksLabel.setText(String.valueOf(tasks));
}
} catch (Exception e) {
log.warn("[UI] Exception ",e);
}
}
});
}
}, ServiceMessageType.LOCAL_TASKDONE);
// Task Failed Hook
ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {
public void onServiceEvent(final ServiceMessage message) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
// If active job, update task count
if (message.getMessage().equals(activeJobId)) {
JLabel failuresLabel = getUIElement("general.stats.failures");
int fails = Integer.parseInt(failuresLabel.getText()) + 1;
failuresLabel.setText(String.valueOf(fails));
}
} catch (Exception e) {
log.warn("[UI] Exception ",e);
}
}
});
}
}, ServiceMessageType.LOCAL_TASKFAILED);
// Task Execution Time Hook
ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {
public void onServiceEvent(final ServiceMessage message) {
try {
executionTime += Long.parseLong(message.getMessage());
} catch (Exception e) {
log.warn("[UI] Exception ",e);
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
updateExecutionTime();
}
});
}
}, ServiceMessageType.LOCAL_TASKEXEC);
// Node Banned Hook
ServiceEventsSupport.addServiceHook(new ServiceHookCallback() {
public void onServiceEvent(final ServiceMessage message) {
// If not relevant to node, ignore
if (!message.getMessage().startsWith(GridNode.getInstance().getId().toString())) {