Search in sources :

Example 11 with CommonTaskJobExec

use of com.cubrid.common.ui.spi.progress.CommonTaskJobExec in project cubrid-manager by CUBRID.

the class ServiceDashboardEditor method loadServerDbInfo.

/**
	 * Load Server Database Info
	 */
private void loadServerDbInfo(final ServerInfo serverInfo, final String key) {
    if (serverInfo.isConnected() == false) {
        return;
    }
    final GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(serverInfo);
    TaskJobExecutor taskJobExec = new CommonTaskJobExec(new ITaskExecutorInterceptor() {

        public void completeAll() {
            Object input = serviceTreeViewer.getInput();
            ServiceDashboardInfo sDashInfo = getSelectedDashInfo(input, serverInfo.getServerName(), key);
            List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
            setDbData(sDashInfo, databaseInfoList);
            serviceTreeViewer.refresh(input);
        }

        public IStatus postTaskFinished(ITask task) {
            return Status.OK_STATUS;
        }
    });
    taskJobExec.addTask(getDatabaseListTask);
    executeTask(taskJobExec, serverInfo.getServerName(), Messages.taskGetServerDbInfo);
}
Also used : GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITaskExecutorInterceptor(com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor) ITask(com.cubrid.common.core.task.ITask) IStatus(org.eclipse.core.runtime.IStatus) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) BrokerInfoList(com.cubrid.cubridmanager.core.broker.model.BrokerInfoList) List(java.util.List) ArrayList(java.util.ArrayList) DbSpaceInfoList(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList)

Example 12 with CommonTaskJobExec

use of com.cubrid.common.ui.spi.progress.CommonTaskJobExec in project cubrid-manager by CUBRID.

the class ServiceDashboardEditor method loadServerVolumeData.

/**
	 * Load Server Volume Info
	 */
private void loadServerVolumeData(final ServerInfo serverInfo, final String key) {
    List<String> dbList = serverInfo.getAllDatabaseList();
    if (dbList == null || dbList.size() == 0) {
        return;
    }
    final List<CommonQueryTask<DbSpaceInfoList>> getVolumnTaskList = new ArrayList<CommonQueryTask<DbSpaceInfoList>>();
    for (String dbname : dbList) {
        CommonQueryTask<DbSpaceInfoList> task = new CommonQueryTask<DbSpaceInfoList>(serverInfo, CommonSendMsg.getCommonDatabaseSendMsg(), new DbSpaceInfoList());
        task.setDbName(dbname);
        getVolumnTaskList.add(task);
    }
    TaskJobExecutor taskJobExec = new CommonTaskJobExec(new ITaskExecutorInterceptor() {

        public void completeAll() {
            Object input = serviceTreeViewer.getInput();
            ServiceDashboardInfo sDashInfo = getSelectedDashInfo(input, serverInfo.getServerName(), key);
            setVolumeData(sDashInfo, getVolumnTaskList);
            serviceTreeViewer.refresh(input);
        }

        public IStatus postTaskFinished(ITask task) {
            return Status.OK_STATUS;
        }
    });
    for (CommonQueryTask<DbSpaceInfoList> task : getVolumnTaskList) {
        taskJobExec.addTask(task);
    }
    executeTask(taskJobExec, serverInfo.getServerName(), Messages.taskGetServerVolumeInfo);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITaskExecutorInterceptor(com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor) ITask(com.cubrid.common.core.task.ITask) IStatus(org.eclipse.core.runtime.IStatus) ArrayList(java.util.ArrayList) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) DbSpaceInfoList(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask)

Example 13 with CommonTaskJobExec

use of com.cubrid.common.ui.spi.progress.CommonTaskJobExec in project cubrid-manager by CUBRID.

the class ServiceDashboardEditor method loadServerHostInfo.

/**
	 * Load Server Host Info
	 */
private void loadServerHostInfo(final ServerInfo serverInfo, final String key) {
    final CommonQueryTask<HostStatData> task = new CommonQueryTask<HostStatData>(serverInfo, CommonSendMsg.getCommonSimpleSendMsg(), new HostStatData());
    TaskJobExecutor taskJobExec = new CommonTaskJobExec(new ITaskExecutorInterceptor() {

        public void completeAll() {
            Object input = serviceTreeViewer.getInput();
            ServiceDashboardInfo sDashInfo = getSelectedDashInfo(input, serverInfo.getServerName(), key);
            HostStatData hostInfo = task.getResultModel();
            setHostData(sDashInfo, hostInfo);
            serviceTreeViewer.refresh(input);
        }

        public IStatus postTaskFinished(ITask task) {
            return Status.OK_STATUS;
        }
    });
    taskJobExec.addTask(task);
    executeTask(taskJobExec, serverInfo.getServerName(), Messages.taskGetServerHostInfo);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITaskExecutorInterceptor(com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor) ITask(com.cubrid.common.core.task.ITask) IStatus(org.eclipse.core.runtime.IStatus) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) HostStatData(com.cubrid.cubridmanager.core.monitoring.model.HostStatData)

Example 14 with CommonTaskJobExec

use of com.cubrid.common.ui.spi.progress.CommonTaskJobExec 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 15 with CommonTaskJobExec

use of com.cubrid.common.ui.spi.progress.CommonTaskJobExec 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)

Aggregations

CommonTaskJobExec (com.cubrid.common.ui.spi.progress.CommonTaskJobExec)25 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)24 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)19 IStatus (org.eclipse.core.runtime.IStatus)14 ITask (com.cubrid.common.core.task.ITask)12 ITaskExecutorInterceptor (com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor)12 ArrayList (java.util.ArrayList)9 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)7 DbSpaceInfoList (com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList)6 List (java.util.List)6 BrokerInfoList (com.cubrid.cubridmanager.core.broker.model.BrokerInfoList)4 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)3 TaskJob (com.cubrid.common.ui.spi.progress.TaskJob)2 BrokerInfos (com.cubrid.cubridmanager.core.broker.model.BrokerInfos)2 EnvInfo (com.cubrid.cubridmanager.core.common.model.EnvInfo)2 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)2 CommonUpdateTask (com.cubrid.cubridmanager.core.common.task.CommonUpdateTask)2 GetEnvInfoTask (com.cubrid.cubridmanager.core.common.task.GetEnvInfoTask)2 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)2 CheckDirTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask)2