use of com.cubrid.common.ui.spi.progress.JobFamily in project cubrid-manager by CUBRID.
the class ApplicationWorkbenchWindowAdvisor method preWindowShellClose.
/**
* Performs arbitrary actions as the window's shell is being closed
* directly, and possibly veto the close.
*
* @return <code>true</code> to allow the window to close, and
* <code>false</code> to prevent the window from closing
* @see org.eclipse.ui.IWorkbenchWindow#close
* @see WorkbenchAdvisor#preShutdown()
*/
public boolean preWindowShellClose() {
Shell shell = getWindowConfigurer().getWindow().getShell();
GeneralPreference.setMaximizeWindowOnStartUp(shell.getMaximized());
if (timer != null) {
timer.cancel();
HeartBeatTaskManager.getInstance().cancel();
}
/*Close the information window*/
InfoWindowManager.dispose();
/*All opened queryEditor*/
List<QueryEditorPart> editorPartList = QueryEditorUtil.getAllQueryEditorPart();
boolean isNeedSaveQueryEditor = isNeedSaveQueryEditor(editorPartList);
boolean hasJobRunning = false;
final JobFamily jobFamily = new JobFamily();
jobFamily.setServerName(JobFamily.ALL_SERVER);
Job[] jobs = Job.getJobManager().find(jobFamily);
if (jobs.length > 0) {
hasJobRunning = true;
}
boolean isExit = false;
if (hasJobRunning) {
isExit = CommonUITool.openConfirmBox(getWindowConfigurer().getWindow().getShell(), Messages.msgExistConfirmWithJob);
if (isExit) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
try {
Job.getJobManager().cancel(jobFamily);
} catch (Exception e) {
LOGGER.error("Stopping background jobs was failed.", e);
}
}
});
if (isNeedSaveQueryEditor) {
processSaveQueryEditor();
}
}
} else {
if (isNeedSaveQueryEditor) {
processSaveQueryEditor();
return true;
} else {
if (GeneralPreference.isAlwaysExit()) {
return true;
}
MessageDialogWithToggle dialog = MessageDialogWithToggle.openOkCancelConfirm(getWindowConfigurer().getWindow().getShell(), com.cubrid.common.ui.common.Messages.titleExitConfirm, Messages.msgExistConfirm, com.cubrid.common.ui.common.Messages.msgToggleExitConfirm, false, CommonUIPlugin.getDefault().getPreferenceStore(), GeneralPreference.IS_ALWAYS_EXIT);
isExit = dialog.getReturnCode() == 0 ? true : false;
}
}
return isExit;
}
use of com.cubrid.common.ui.spi.progress.JobFamily in project cubrid-manager by CUBRID.
the class PstmtOneDataDialog method updateData.
/**
*
* Update the data
*
* @param parameterList List<PstmtParameter>
*/
private void updateData(List<PstmtParameter> parameterList) {
beginTimestamp = System.currentTimeMillis();
String jobName = Messages.executeSqlJobName;
JobFamily jobFamily = new JobFamily();
String serverName = database.getServer().getServerInfo().getServerName();
String dbName = database.getName();
jobFamily.setServerName(serverName);
jobFamily.setDbName(dbName);
TaskJobExecutor taskExec = new CommonTaskJobExec(this);
PstmtDataTask task = new PstmtDataTask(sqlTxt.getText(), database, parameterList, null);
taskExec.addTask(task);
taskExec.schedule(jobName, jobFamily, false, Job.SHORT);
}
use of com.cubrid.common.ui.spi.progress.JobFamily in project cubrid-manager by CUBRID.
the class ImportDataFromFileDialog method updateData.
/**
*
* Update data
*
* @param parameterList List<PstmtParameter>
*/
private void updateData(List<PstmtParameter> parameterList) {
taskList.clear();
String fileName = fileNameTxt.getText();
String charset = fileCharsetCombo.getText();
int threadCount = threadCountSpinner.getSelection();
int commitedLineOnce = commitLineSpinner.getSelection();
int totalLine = Integer.parseInt(totalLinesText.getText());
int threadLine = totalLine / threadCount;
int line = totalLine % threadCount;
int startRow = 0;
int totalProgress = 0;
boolean isIgnoreError = importErrorControl.isIgoreOrBreak();
if (isIgnoreError) {
errorLogDir = PstmtDataTask.makeErrorLogDir();
} else {
errorLogDir = null;
}
if (importFileHandler == null) {
importFileHandler = ImportFileHandlerFactory.getHandler(fileName, charset);
}
for (int i = 0; i < threadCount; i++) {
// FIXME move this logic to core module
int rowCount = threadLine;
if (i == threadCount - 1) {
rowCount = threadLine + line;
}
int commitCount = rowCount / commitedLineOnce + (rowCount % commitedLineOnce > 0 ? 1 : 0);
int taskProgress = commitCount * PstmtDataTask.PROGRESS_COMMIT + rowCount * PstmtDataTask.PROGRESS_ROW;
totalProgress = totalProgress + taskProgress + PstmtDataTask.PROGRESS_ROW;
PstmtDataTask task = new PstmtDataTask(sqlTxt.getText(), database, fileNameTxt.getText(), parameterList, startRow, rowCount, commitedLineOnce, charset, firstRowAsColumnBtn.getSelection(), isIgnoreError, errorLogDir, importFileHandler);
task.setTotalProgress(taskProgress);
taskList.add(task);
startRow += rowCount;
}
getShell().setVisible(false);
beginTimestamp = System.currentTimeMillis();
String jobName = Messages.executeSqlJobName;
JobFamily jobFamily = new JobFamily();
String serverName = database.getServer().getServerInfo().getServerName();
String dbName = database.getName();
jobFamily.setServerName(serverName);
jobFamily.setDbName(dbName);
final IProgressMonitor pmGroup = Job.getJobManager().createProgressGroup();
pmGroup.beginTask(jobName, totalProgress);
setStartShowResult(false);
final CountDownLatch cdl = new CountDownLatch(taskList.size());
final List<PstmtDataTask> threadTaskList = taskList;
for (PstmtDataTask task : taskList) {
TaskJobExecutor taskExec = new CommonTaskJobExec() {
public IStatus exec(IProgressMonitor monitor) {
IStatus status = super.exec(monitor);
if (Status.CANCEL_STATUS == status) {
return status;
}
return Status.OK_STATUS;
}
public void done(IJobChangeEvent event) {
if (event.getResult() == Status.CANCEL_STATUS) {
for (PstmtDataTask task : threadTaskList) {
if (!task.isCancel()) {
task.cancel();
}
}
}
countDownAndAwait(cdl);
Display.getDefault().syncExec(new Runnable() {
public void run() {
pmGroup.done();
finish();
}
});
}
};
taskExec.addTask(task);
TaskJob job = new TaskJob(jobName, taskExec);
if (jobFamily != null) {
job.setJobFamily(jobFamily);
}
job.setPriority(Job.LONG);
job.setUser(false);
job.setProgressGroup(pmGroup, task.getTotalProgress());
job.schedule();
try {
Thread.sleep(30);
} catch (InterruptedException e) {
}
pmGroup.worked(PstmtDataTask.PROGRESS_ROW);
}
}
use of com.cubrid.common.ui.spi.progress.JobFamily in project cubrid-manager by CUBRID.
the class ConnectionManager method connectDatabaseInJob.
/**
*
* Connect database
*
* @param dbNode The DatabaseNode
*/
public static void connectDatabaseInJob(DatabaseNode dbNode) {
HostNode hostNode = dbNode.getParent();
if (hostNode.isConnecting() || dbNode.isConnecting() || dbNode.isConnected()) {
return;
}
ServerInfo serverInfo = hostNode.getServerInfo();
if (serverInfo == null) {
serverInfo = new ServerInfo();
serverInfo.setServerName(hostNode.getIp());
serverInfo.setHostAddress(hostNode.getIp());
serverInfo.setHostMonPort(Integer.parseInt(hostNode.getPort()));
serverInfo.setHostJSPort(Integer.parseInt(hostNode.getPort()) + 1);
serverInfo.setUserName(hostNode.getUserName());
serverInfo.setUserPassword(hostNode.getPassword());
serverInfo.setJdbcDriverVersion(ServerJdbcVersionMapping.JDBC_SELF_ADAPTING_VERSION);
}
TaskJob job = new TaskJob(Messages.bind(Messages.jobConnectDatabase, dbNode.getDbName()));
if (!hostNode.isConnected()) {
hostNode.setConnecting(true);
ConnectHostJobExecutor connectHostJobExecutor = new ConnectHostJobExecutor(hostNode, serverInfo, false);
job.addTaskJobExecutor(connectHostJobExecutor);
}
dbNode.setConnecting(true);
ConnectDatabaseNodeJobExecutor dbJobExecutor = new ConnectDatabaseNodeJobExecutor(dbNode, serverInfo);
job.addTaskJobExecutor(dbJobExecutor);
JobFamily jobFamily = new JobFamily();
jobFamily.setServerName(serverInfo.getServerName());
jobFamily.setDbName(dbNode.getDbName());
job.setJobFamily(jobFamily);
job.setPriority(Job.SHORT);
job.setUser(false);
job.schedule();
}
use of com.cubrid.common.ui.spi.progress.JobFamily in project cubrid-manager by CUBRID.
the class ConnectionManager method connectHostInJob.
/**
*
* Connect Host
*
* @param hostNode The HostNode
* @param isConnectChild The boolean
* @param isPing The boolean
*/
public static void connectHostInJob(HostNode hostNode, boolean isConnectChild, boolean isPing) {
if (hostNode.isConnected() || hostNode.isConnecting()) {
return;
}
ServerInfo serverInfo = hostNode.getServerInfo();
if (serverInfo == null) {
serverInfo = new ServerInfo();
serverInfo.setServerName(hostNode.getIp());
serverInfo.setHostAddress(hostNode.getIp());
serverInfo.setHostMonPort(Integer.parseInt(hostNode.getPort()));
serverInfo.setHostJSPort(Integer.parseInt(hostNode.getPort()) + 1);
serverInfo.setUserName(hostNode.getUserName());
serverInfo.setUserPassword(hostNode.getPassword());
serverInfo.setJdbcDriverVersion(ServerJdbcVersionMapping.JDBC_SELF_ADAPTING_VERSION);
}
TaskJob job = new TaskJob(Messages.bind(Messages.jobConnectHost, serverInfo.getHostAddress()));
hostNode.setConnecting(true);
ConnectHostJobExecutor executor = new ConnectHostJobExecutor(hostNode, serverInfo, isPing);
job.addTaskJobExecutor(executor);
if (isConnectChild) {
List<DatabaseNode> dbNodeList = hostNode.getDbNodeList();
for (DatabaseNode dbNode : dbNodeList) {
if (dbNode.isConnecting() || dbNode.isConnected()) {
continue;
}
dbNode.setConnecting(true);
ConnectDatabaseNodeJobExecutor dbJobExecutor = new ConnectDatabaseNodeJobExecutor(dbNode, serverInfo);
job.addTaskJobExecutor(dbJobExecutor);
}
}
JobFamily jobFamily = new JobFamily();
jobFamily.setServerName(serverInfo.getServerName());
jobFamily.setDbName(JobFamily.ALL_DB);
job.setJobFamily(jobFamily);
job.setPriority(Job.SHORT);
job.setUser(false);
job.schedule();
}
Aggregations