use of org.netxms.client.server.ServerJob in project netxms by netxms.
the class ServerJobManager method doJobAction.
/**
* Do job action: cancel, hold, unhold
*
* @param actionName
* @param actionId
*/
private void doJobAction(final String actionName, final String actionErrorName, final int actionId) {
final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
new ConsoleJob(String.format(Messages.get().ServerJobManager_ActionJobName, actionName), this, Activator.PLUGIN_ID, JOB_FAMILY) {
@SuppressWarnings("rawtypes")
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
Iterator it = selection.iterator();
while (it.hasNext()) {
Object object = it.next();
if (object instanceof ServerJob) {
final ServerJob jobObject = (ServerJob) object;
switch(actionId) {
case CANCEL_JOB:
session.cancelServerJob(jobObject.getId());
break;
case HOLD_JOB:
session.holdServerJob(jobObject.getId());
break;
case UNHOLD_JOB:
session.unholdServerJob(jobObject.getId());
break;
default:
throw new NXCException(RCC.INTERNAL_ERROR);
}
} else {
throw new NXCException(RCC.INTERNAL_ERROR);
}
}
}
@Override
protected String getErrorMessage() {
return String.format(Messages.get().ServerJobManager_ActionJobError, actionErrorName);
}
@Override
protected void jobFinalize() {
refreshJobList(false);
}
}.start();
}
use of org.netxms.client.server.ServerJob in project netxms by netxms.
the class NXCSession method getServerJobList.
/**
* Get list of server jobs
*
* @return list of server jobs
* @throws IOException if socket I/O error occurs
* @throws NXCException if NetXMS server returns an error or operation was timed out
*/
public ServerJob[] getServerJobList() throws IOException, NXCException {
NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_JOB_LIST);
sendMessage(msg);
final NXCPMessage response = waitForRCC(msg.getMessageId());
int count = response.getFieldAsInt32(NXCPCodes.VID_JOB_COUNT);
ServerJob[] jobList = new ServerJob[count];
long baseVarId = NXCPCodes.VID_JOB_LIST_BASE;
for (int i = 0; i < count; i++, baseVarId += 10) {
jobList[i] = new ServerJob(response, baseVarId);
}
return jobList;
}
use of org.netxms.client.server.ServerJob in project netxms by netxms.
the class ServerJobComparator method compare.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
int result;
switch(// $NON-NLS-1$
(Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
case ServerJobManager.COLUMN_STATUS:
result = ((ServerJob) e1).getStatus() - ((ServerJob) e2).getStatus();
break;
case ServerJobManager.COLUMN_NODE:
AbstractObject object1 = session.findObjectById(((ServerJob) e1).getNodeId());
AbstractObject object2 = session.findObjectById(((ServerJob) e2).getNodeId());
// $NON-NLS-1$
String name1 = (object1 != null) ? object1.getObjectName() : "<unknown>";
// $NON-NLS-1$
String name2 = (object2 != null) ? object2.getObjectName() : "<unknown>";
result = name1.compareToIgnoreCase(name2);
break;
case ServerJobManager.COLUMN_DESCRIPTION:
result = ((ServerJob) e1).getDescription().compareToIgnoreCase(((ServerJob) e2).getDescription());
break;
case ServerJobManager.COLUMN_MESSAGE:
result = ((ServerJob) e1).getFailureMessage().compareToIgnoreCase(((ServerJob) e2).getFailureMessage());
break;
default:
result = 0;
break;
}
return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
use of org.netxms.client.server.ServerJob in project netxms by netxms.
the class ServerJobManager method refreshJobList.
/**
* Refresh job list
*/
private void refreshJobList(boolean userInitiated) {
ConsoleJob job = new ConsoleJob(Messages.get(viewer.getControl().getDisplay()).ServerJobManager_RefreshJobName, this, Activator.PLUGIN_ID, JOB_FAMILY, viewer.getControl().getDisplay()) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final ServerJob[] jobList = session.getServerJobList();
runInUIThread(new Runnable() {
@Override
public void run() {
// Remember current selection
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
Object[] selectedObjects = selection.toArray();
viewer.setInput(jobList);
// Build new list of selected jobs - add object to selection if
// object with same id was selected before
List<ServerJob> selectedJobs = new ArrayList<ServerJob>(selectedObjects.length);
for (int i = 0; i < selectedObjects.length; i++) {
for (int j = 0; j < jobList.length; j++) {
if (((ServerJob) selectedObjects[i]).getId() == jobList[j].getId()) {
selectedJobs.add(jobList[j]);
break;
}
}
}
viewer.setSelection(new StructuredSelection(selectedJobs));
}
});
}
@Override
protected String getErrorMessage() {
return Messages.get().ServerJobManager_RefreshJobError;
}
};
job.setUser(userInitiated);
job.start();
}
Aggregations