Search in sources :

Example 6 with DBRProcessDescriptor

use of org.jkiss.dbeaver.model.runtime.DBRProcessDescriptor in project dbeaver by dbeaver.

the class DataSourceDescriptor method disconnect.

private boolean disconnect(final DBRProgressMonitor monitor, boolean reflect) {
    if (dataSource == null) {
        log.error("Datasource is not connected");
        return true;
    }
    if (connecting) {
        log.error("Connect/disconnect is in progress");
        return false;
    }
    connecting = true;
    try {
        releaseDataSourceUsers(monitor);
        monitor.beginTask("Disconnect from '" + getName() + "'", 5 + dataSource.getAvailableInstances().size());
        processEvents(monitor, DBPConnectionEventType.BEFORE_DISCONNECT);
        monitor.worked(1);
        // Close datasource
        monitor.subTask("Close connection");
        if (dataSource != null) {
            dataSource.shutdown(monitor);
        }
        monitor.worked(1);
        // Close tunnelHandler
        if (tunnelHandler != null) {
            monitor.subTask("Close tunnel");
            try {
                tunnelHandler.closeTunnel(monitor);
            } catch (Throwable e) {
                log.error("Error closing tunnel", e);
            }
        }
        monitor.worked(1);
        proxyHandler = null;
        processEvents(monitor, DBPConnectionEventType.AFTER_DISCONNECT);
        monitor.worked(1);
        monitor.done();
        // Terminate child processes
        synchronized (childProcesses) {
            for (Iterator<DBRProcessDescriptor> iter = childProcesses.iterator(); iter.hasNext(); ) {
                DBRProcessDescriptor process = iter.next();
                if (process.isRunning() && process.getCommand().isTerminateAtDisconnect()) {
                    process.terminate();
                }
                iter.remove();
            }
        }
        this.dataSource = null;
        this.resolvedConnectionInfo = null;
        this.connectTime = null;
        if (reflect) {
            // Reflect UI
            getRegistry().notifyDataSourceListeners(new DBPEvent(DBPEvent.Action.OBJECT_UPDATE, this, false));
        }
        return true;
    } finally {
        connecting = false;
        log.debug("Disconnected (" + getId() + ")");
    }
}
Also used : DBRProcessDescriptor(org.jkiss.dbeaver.model.runtime.DBRProcessDescriptor)

Aggregations

DBRProcessDescriptor (org.jkiss.dbeaver.model.runtime.DBRProcessDescriptor)6 DBException (org.jkiss.dbeaver.DBException)4 DBRShellCommand (org.jkiss.dbeaver.model.runtime.DBRShellCommand)4 IOException (java.io.IOException)2 DBCException (org.jkiss.dbeaver.model.exec.DBCException)2 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)2 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)2