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() + ")");
}
}
Aggregations