Search in sources :

Example 1 with Connection

use of com.haulmont.cuba.desktop.Connection in project cuba by cuba-platform.

the class SessionMessagesNotifier method processServerMessage.

protected void processServerMessage(@Nullable String message) {
    if (message != null) {
        log.debug("Received session message");
        Connection connection = App.getInstance().getConnection();
        if (connection.isConnected() && timer != null && timer.isRunning()) {
            SessionMessageWindow dialog = new SessionMessageWindow(App.getInstance().getMainFrame());
            dialog.setMessage(message);
            dialog.setVisible(true);
        }
    }
}
Also used : Connection(com.haulmont.cuba.desktop.Connection)

Example 2 with Connection

use of com.haulmont.cuba.desktop.Connection in project cuba by cuba-platform.

the class SessionMessagesNotifier method syncMessages.

protected void syncMessages() {
    Connection connection = App.getInstance().getConnection();
    if (connection.isConnected()) {
        log.trace("Check session messages");
        asyncMessageLoader = new SwingWorker<String, Void>() {

            @Override
            protected String doInBackground() throws Exception {
                try {
                    UserSessionService uss = AppBeans.get(UserSessionService.NAME);
                    return uss.getMessages();
                } catch (NoUserSessionException e) {
                    log.warn("Unable to get messages for session, user session not found");
                } catch (Exception e) {
                    log.warn("Session messages exception: " + e.toString());
                }
                return null;
            }

            @Override
            protected void done() {
                try {
                    if (!isCancelled()) {
                        processServerMessage(get());
                    }
                } catch (InterruptedException | ExecutionException ignored) {
                // do nothing
                } finally {
                    asyncMessageLoader = null;
                }
            }
        };
        asyncMessageLoader.execute();
    }
}
Also used : UserSessionService(com.haulmont.cuba.security.app.UserSessionService) Connection(com.haulmont.cuba.desktop.Connection) NoUserSessionException(com.haulmont.cuba.security.global.NoUserSessionException) ExecutionException(java.util.concurrent.ExecutionException) NoUserSessionException(com.haulmont.cuba.security.global.NoUserSessionException)

Aggregations

Connection (com.haulmont.cuba.desktop.Connection)2 UserSessionService (com.haulmont.cuba.security.app.UserSessionService)1 NoUserSessionException (com.haulmont.cuba.security.global.NoUserSessionException)1 ExecutionException (java.util.concurrent.ExecutionException)1