Search in sources :

Example 16 with JobFamily

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;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) Job(org.eclipse.core.runtime.jobs.Job)

Example 17 with JobFamily

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);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily)

Example 18 with JobFamily

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);
    }
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) IStatus(org.eclipse.core.runtime.IStatus) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) CountDownLatch(java.util.concurrent.CountDownLatch) TaskJob(com.cubrid.common.ui.spi.progress.TaskJob) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec)

Example 19 with JobFamily

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();
}
Also used : ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) HostNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.HostNode) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) TaskJob(com.cubrid.common.ui.spi.progress.TaskJob)

Example 20 with JobFamily

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();
}
Also used : DatabaseNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) TaskJob(com.cubrid.common.ui.spi.progress.TaskJob)

Aggregations

JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)44 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)24 CommonTaskJobExec (com.cubrid.common.ui.spi.progress.CommonTaskJobExec)19 ITask (com.cubrid.common.core.task.ITask)14 Job (org.eclipse.core.runtime.jobs.Job)14 ArrayList (java.util.ArrayList)12 IStatus (org.eclipse.core.runtime.IStatus)12 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 ITaskExecutorInterceptor (com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor)7 List (java.util.List)7 CheckDirTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask)6 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)5 CommonUpdateTask (com.cubrid.cubridmanager.core.common.task.CommonUpdateTask)5 GetCubridConfParameterTask (com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask)5 DbSpaceInfoList (com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList)5 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)4 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)4 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)4 CheckFileTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask)4