Skip to content

Commit

Permalink
Cb 4375 support idle connection closing (#2368)
Browse files Browse the repository at this point in the history
* CB-4365. Support idle connection closing

* CB-4375. Fix connection time

* CB-4375. Fixed checkstyle

* CB-4375. Refactor after review

* CB-4375. Refactor after review

* CB-4375. Refactor after review

* CB-4375. Refactor after review

* CB-4375. Refactor after review

* CB-4375. Refactor after review, change event type

* CB-4375. Refactor after review

---------

Co-authored-by: DenisSinelnikov <[email protected]>
Co-authored-by: Evgenia Bezborodova <[email protected]>
  • Loading branch information
3 people authored Feb 13, 2024
1 parent 9828b1d commit b62b8d1
Showing 1 changed file with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@
package io.cloudbeaver.server.jobs;

import io.cloudbeaver.model.session.BaseWebSession;
import io.cloudbeaver.model.session.WebSession;
import io.cloudbeaver.server.CBApplication;
import io.cloudbeaver.server.CBPlatform;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.app.DBPPlatform;
import org.jkiss.dbeaver.model.auth.SMSession;
import org.jkiss.dbeaver.model.websocket.event.WSEventType;
import org.jkiss.dbeaver.model.websocket.event.datasource.WSDataSourceEvent;
import org.jkiss.dbeaver.model.websocket.event.datasource.WSDataSourceProperty;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.runtime.jobs.DataSourceMonitorJob;

import java.util.Collection;
import java.util.List;

/**
* Web data source monitor job.
Expand All @@ -35,8 +45,23 @@ public WebDataSourceMonitorJob(DBPPlatform platform) {
@Override
protected void doJob() {
Collection<BaseWebSession> allSessions = CBPlatform.getInstance().getSessionManager().getAllActiveSessions();
allSessions.parallelStream().forEach(
s -> checkDataSourceAliveInWorkspace(s.getWorkspace())
);
allSessions.parallelStream().forEach(s -> {
checkDataSourceAliveInWorkspace(s.getWorkspace(), s::getLastAccessTimeMillis);
});

}

@Override
public void showNotification(DBPDataSource dataSource, DBPDataSourceContainer dsDescriptor, SMSession smSession) {
if (smSession instanceof WebSession webSession) {
webSession.addSessionEvent( //TODO: Add new event for disconnect datasource
WSDataSourceEvent.update(
webSession.getSessionId(),
webSession.getUserId(),
dsDescriptor.getProject().getId(),
List.of(dsDescriptor.getId()),
WSDataSourceProperty.CONFIGURATION)
);
}
}
}

0 comments on commit b62b8d1

Please sign in to comment.