Search in sources :

Example 21 with TaskJobExecutor

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

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

the class CopyDatabaseDialog method okPressed.

/**
	 * When ok button press,call this method
	 */
protected void okPressed() {
    if (!verify()) {
        return;
    }
    destDbName = destinationDBNameText.getText();
    if (!CommonUITool.openConfirmBox(parentComp.getShell(), Messages.warnYesNoCopyDb)) {
        return;
    }
    SocketTask checkTask = getCheckDirsTask();
    SocketTask copyTask = getCopyDbTask();
    TaskJobExecutor taskExec = new CommonTaskJobExec(this);
    taskExec.addTask(checkTask);
    taskExec.addTask(copyTask);
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    jobName = Messages.msgCopyDbRearJobName + " - " + dbName + "@" + serverName;
    taskExec.schedule(jobName, jobFamily, true, Job.SHORT);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) SocketTask(com.cubrid.cubridmanager.core.common.socket.SocketTask) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily)

Example 23 with TaskJobExecutor

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

the class UserEditor method loadData.

/**
	 * 
	 * Load data
	 * 
	 * @return <code>true</code> if it is successfully;<code>false</code>
	 *         otherwise
	 */
public boolean loadData() {
    final CommonQueryTask<DbUserInfoList> userTask = new CommonQueryTask<DbUserInfoList>(database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg(), new DbUserInfoList(), database.getDatabaseInfo().getCharSet());
    userTask.setDbName(database.getName());
    final GetAllClassListTask classInfoTask = new GetAllClassListTask(database.getDatabaseInfo());
    final GetAllPartitionClassTask partitionTask = new GetAllPartitionClassTask(database.getDatabaseInfo());
    TaskJobExecutor taskJobExecutor = new TaskJobExecutor() {

        @SuppressWarnings("unchecked")
        @Override
        public IStatus exec(IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return Status.CANCEL_STATUS;
            }
            for (ITask t : taskList) {
                if (t instanceof GetAllClassListTask) {
                    allClassInfoList = ((GetAllClassListTask) t).getAllClassInfoList();
                } else {
                    t.execute();
                }
                if (t instanceof CommonQueryTask) {
                    userListInfo = ((CommonQueryTask<DbUserInfoList>) t).getResultModel();
                }
                if (t instanceof GetAllPartitionClassTask) {
                    partitionClassMap = ((GetAllPartitionClassTask) t).getPartitionClassMap();
                }
                final String msg = t.getErrorMsg();
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
                if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                    return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
                }
                if (monitor.isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
            }
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    initial();
                }
            });
            return Status.OK_STATUS;
        }
    };
    taskJobExecutor.addTask(userTask);
    taskJobExecutor.addTask(classInfoTask);
    taskJobExecutor.addTask(partitionTask);
    String jobName = Messages.viewUserInfoJobName + " - " + userName + "@" + database.getName() + "@" + database.getServer().getName();
    taskJobExecutor.schedule(jobName, null, false, Job.SHORT);
    return true;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) GetAllPartitionClassTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllPartitionClassTask)

Example 24 with TaskJobExecutor

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

the class ServiceDashboardEditor method loadServerBrokerInfo.

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

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

        public IStatus postTaskFinished(ITask task) {
            return Status.OK_STATUS;
        }
    });
    taskJobExec.addTask(task);
    executeTask(taskJobExec, serverInfo.getServerName(), Messages.taskGetServerBrokerInfo);
}
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) BrokerInfos(com.cubrid.cubridmanager.core.broker.model.BrokerInfos) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask)

Example 25 with TaskJobExecutor

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

the class DBSpaceLabelProvider method loadVolumeData.

public void loadVolumeData() {
    //if no database on this server ,don't get volumn data
    if (serverInfo.getAllDatabaseList().size() == 0 || databaseInfoList == null) {
        return;
    }
    final List<CommonQueryTask<DbSpaceInfoList>> getVolumnTaskList = new ArrayList<CommonQueryTask<DbSpaceInfoList>>();
    if (serverInfo.getAllDatabaseList() != null) {
        for (String dbName : serverInfo.getAllDatabaseList()) {
            for (DatabaseInfo databaseInfo : databaseInfoList) {
                // only load start database volumn data
                if (dbName.equals(databaseInfo.getDbName()) && databaseInfo.getRunningType() == DbRunningType.CS) {
                    CommonQueryTask<DbSpaceInfoList> task = new CommonQueryTask<DbSpaceInfoList>(serverInfo, CommonSendMsg.getCommonDatabaseSendMsg(), new DbSpaceInfoList());
                    task.setDbName(dbName);
                    getVolumnTaskList.add(task);
                    break;
                }
            }
        }
    }
    //if no start database don't get volumn data
    if (getVolumnTaskList.size() == 0) {
        return;
    }
    TaskJobExecutor taskJobExec = new CommonTaskJobExec(new ITaskExecutorInterceptor() {

        public void completeAll() {
            List<DBVolumeSpaceInfo> dbVolumeSpaceInfoList = new ArrayList<DBVolumeSpaceInfo>();
            for (CommonQueryTask<DbSpaceInfoList> task : getVolumnTaskList) {
                DbSpaceInfoList dbSpaceInfoList = task.getResultModel();
                freespaceOnStorage = ((long) dbSpaceInfoList.getFreespace()) * 1024l * 1024l;
                DBVolumeSpaceInfo dbSpaceInfo = new DBVolumeSpaceInfo(dbSpaceInfoList.getDbname());
                dbSpaceInfo.setPageSize(dbSpaceInfoList.getPagesize());
                dbVolumeSpaceInfoList.add(dbSpaceInfo);
                if (dbSpaceInfoList != null) {
                    for (DbSpaceInfo spaceInfo : dbSpaceInfoList.getSpaceinfo()) {
                        dbSpaceInfo.addVolumeSpaceInfo(spaceInfo);
                    }
                }
            }
            setVolumeData(dbVolumeSpaceInfoList);
            finishedCount++;
            updateToolBar();
        }

        public IStatus postTaskFinished(ITask task) {
            return Status.OK_STATUS;
        }
    });
    for (CommonQueryTask<DbSpaceInfoList> task : getVolumnTaskList) {
        taskJobExec.addTask(task);
    }
    String serverName = serverInfo.getServerName();
    String jobName = Messages.taskGetVolumeInfo + serverName;
    JobFamily jobFamily = new JobFamily();
    jobFamily.setServerName(serverName);
    taskJobExec.schedule(jobName, jobFamily, false, Job.SHORT);
}
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) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ArrayList(java.util.ArrayList) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) DbSpaceInfoList(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList) DbSpaceInfo(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfo) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) 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)

Aggregations

TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)41 IStatus (org.eclipse.core.runtime.IStatus)29 ITask (com.cubrid.common.core.task.ITask)28 CommonTaskJobExec (com.cubrid.common.ui.spi.progress.CommonTaskJobExec)24 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)24 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)18 Status (org.eclipse.core.runtime.Status)15 ITaskExecutorInterceptor (com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor)12 ArrayList (java.util.ArrayList)12 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)11 DbSpaceInfoList (com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList)10 List (java.util.List)8 CheckDirTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask)6 CheckFileTask (com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask)6 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)6 BrokerInfoList (com.cubrid.cubridmanager.core.broker.model.BrokerInfoList)4 IEditorPart (org.eclipse.ui.IEditorPart)4 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)4 PartInitException (org.eclipse.ui.PartInitException)4 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)3