Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ public void removeEventHandler(@NotNull CBWebSessionEventHandler handler) {

public void migrateEventHandlersTo(@NotNull BaseWebSession target) {
synchronized (sessionEventHandlers) {
sessionEventHandlers.forEach(target::addEventHandler);
for (CBWebSessionEventHandler handler : sessionEventHandlers) {
handler.handleSessionRotation(target);
target.addEventHandler(handler);
}
sessionEventHandlers.clear();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
* Copyright (C) 2010-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,8 @@
*/
package io.cloudbeaver.websocket;

import io.cloudbeaver.model.session.BaseWebSession;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.websocket.event.WSEvent;

Expand All @@ -24,4 +26,5 @@ public interface CBWebSessionEventHandler {

void close();

void handleSessionRotation(@NotNull BaseWebSession newSession);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@

private static final Log log = Log.getLog(CBClientEventProcessor.class);

final BaseWebSession webSession;
private BaseWebSession webSession;

public CBClientEventProcessor(@NotNull BaseWebSession webSession) {
this.webSession = webSession;
}

public void setWebSession(BaseWebSession webSession) {

Check warning on line 42 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/websockets/CBClientEventProcessor.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Reference type 'BaseWebSession' is missing a nullability annotation. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/websockets/CBClientEventProcessor.java:42:31: warning: Reference type 'BaseWebSession' is missing a nullability annotation. (sh.adelessfox.checkstyle.checks.NullabilityAnnotationsCheck)
this.webSession = webSession;
}

public void process(@Nullable String message) {
if (CommonUtils.isEmpty(message)) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
* Copyright (C) 2010-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,9 +40,9 @@ public class CBEventsLongPolling implements CBWebSessionEventHandler {

private static final int QUEUE_CAPACITY = 1000;

private final BaseWebSession webSession;
private BaseWebSession webSession;
private final BlockingQueue<WSEvent> queue = new LinkedBlockingQueue<>(QUEUE_CAPACITY);
private final CBClientEventProcessor processor;
private CBClientEventProcessor processor;
private volatile long lastPoll;

public CBEventsLongPolling(@NotNull BaseWebSession webSession) {
Expand Down Expand Up @@ -100,6 +100,12 @@ public void onMessage(@Nullable String message) {
processor.process(message);
}

@Override
public void handleSessionRotation(@NotNull BaseWebSession newSession) {
this.webSession = newSession;
this.processor = new CBClientEventProcessor(this.webSession);
}

@Override
public void close() {
webSession.removeEventHandler(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
* Copyright (C) 2010-2026 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,9 +33,11 @@

@Nullable
private BaseWebSession webSession;
@Nullable
private FromUserEventHandler fromUserEventHandler;

@Override
public void onOpen(Session session, EndpointConfig config) {

Check warning on line 40 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/websockets/CBEventsWebSocket.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Reference type 'EndpointConfig' is missing a nullability annotation. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/websockets/CBEventsWebSocket.java:40:41: warning: Reference type 'EndpointConfig' is missing a nullability annotation. (sh.adelessfox.checkstyle.checks.NullabilityAnnotationsCheck)

Check warning on line 40 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/websockets/CBEventsWebSocket.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Reference type 'Session' is missing a nullability annotation. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/websockets/CBEventsWebSocket.java:40:24: warning: Reference type 'Session' is missing a nullability annotation. (sh.adelessfox.checkstyle.checks.NullabilityAnnotationsCheck)
super.onOpen(session, config);
if (session.getUserProperties().containsKey(CBWebSocketServerConfigurator.PROP_TOKEN_EXPIRED)) {
handleEvent(new WSAccessTokenExpiredEvent());
Expand All @@ -48,7 +50,8 @@
log.debug("EventWebSocket connected to the " + webSession.getSessionId() + " session");

session.setMaxIdleTimeout(Duration.ofMinutes(5).toMillis());
session.addMessageHandler(String.class, new FromUserEventHandler(webSession));
fromUserEventHandler = new FromUserEventHandler(webSession);
session.addMessageHandler(String.class, fromUserEventHandler);
session.addMessageHandler(PongMessage.class, new WebSocketPingPongCallback(webSession));

CBJettyWebSocketManager.registerWebSocket(webSession.getSessionId(), this);
Expand Down Expand Up @@ -76,8 +79,16 @@
}
}

@Override
public void handleSessionRotation(@NotNull BaseWebSession newSession) {
this.webSession = newSession;
if (fromUserEventHandler != null) {
fromUserEventHandler.setWebSession(newSession);
}
}

@Override
public void handleWebSessionEvent(WSEvent event) {

Check warning on line 91 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/websockets/CBEventsWebSocket.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 Reference type 'WSEvent' is missing a nullability annotation. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/websockets/CBEventsWebSocket.java:91:39: warning: Reference type 'WSEvent' is missing a nullability annotation. (sh.adelessfox.checkstyle.checks.NullabilityAnnotationsCheck)
super.handleEvent(event);
}

Expand Down
Loading