Giter Site home page Giter Site logo

cuba-platform / global-events-addon Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 1.0 253 KB

Global Events add-on enables receiving Spring's application events on any application block of the distributed system

Java 93.67% HTML 6.33%
cuba-component cuba-platform websocket eventbus

global-events-addon's Introduction

Global Events Add-on

Overview

The standard CUBA Events interface allows you to publish events that can be received by subscribers within the same application block. So there are no built-in facilities for notifying clients from middleware or propagating events in the cluster.

The Global Events add-on enables receiving Spring's application events on any application block of the distributed system. In the simplest configuration with core and web blocks running in a single JVM, it allows you to send events from core to web to notify UI screens or managed beans. In a cluster environment, an event published inside a block, will be received on all other connected parts of the system: on all middleware blocks and on the clients: web and portal.

In case of the client is deployed in the same JVM as middleware and cuba.useLocalServiceInvocation application property is set to true, it registers a callback in the LocalRegistry class located in the shared-lib module which is accessible to both middleware and the client.

In a distributed environment, clients open WebSocket connections to the middleware blocks, and middleware exchange events in a usual way using the cluster communication mechanism.

Global Events

Installation

The add-on can be added to your project in one of the ways described below. Installation from the Marketplace is the simplest way. The last version of the add-on compatible with the used version of the platform will be installed. Also, you can install the add-on by coordinates choosing the required version of the add-on from the table.

In case you want to install the add-on by manual editing or by building from sources see the complete add-ons installation guide in CUBA Platform documentation.

From the Marketplace

  1. Open your application in CUBA Studio. Check the latest version of CUBA Studio on the CUBA Platform site.
  2. Go to CUBA -> Marketplace in the main menu.

marketplace

  1. Find the Global Events add-on there.

addons

  1. Click Install and apply the changes. The add-on corresponding to the used platform version will be installed.

By Coordinates

  1. Open your application in CUBA Studio. Check the latest version of CUBA Studio on the CUBA Platform site.
  2. Go to CUBA -> Marketplace in the main menu.
  3. Click the icon in the upper-right corner.

by-coordinates

  1. Paste the add-on coordinates in the corresponding field as follows:

com.haulmont.addon.globalevents:cubaglevt-global:<add-on version>

where <add-on version> is compatible with the used version of the CUBA platform.

Platform Version Add-on Version
7.2.x 0.6.1
7.1.x 0.5.1
7.0.x 0.4.2
6.10.x 0.3.1
6.9.x 0.2.1
6.8.x 0.1.2
  1. Click Install and apply the changes. The add-on will be installed to your project.

Usage

Your global event classes must be inherited from com.haulmont.addon.globalevents.GlobalApplicationEvent, for example:

package com.company.sample;

import com.haulmont.addon.globalevents.GlobalApplicationEvent;

public class MyGlobalEvent extends GlobalApplicationEvent {

    private String payload;

    public MyGlobalEvent(Object source, String payload) {
        super(source);
        this.payload = payload;
    }

    public String getPayload() {
        return payload;
    }
}

Make sure all fields of the event class are serializable! Also, do not ever use the source field to store and transfer any data, as it is transient and will not be preserved when the event is sent to another application block.

If you want to send event to Generic UI screens of connected web blocks, add the GlobalUiEvent marker interface to the event class:

package com.company.sample;

import com.haulmont.addon.globalevents.GlobalApplicationEvent;
import com.haulmont.addon.globalevents.GlobalUiEvent;

public class MyUiNotificationEvent extends GlobalApplicationEvent implements GlobalUiEvent {

    private String message;

    public MyUiNotificationEvent(Object source, String message) {
        super(source);
        this.message = message;
    }

    public String getMessage() {
        return message;
    }
}

Send global events using the standard Events.publish() method, and they will be received by subscribers running on all blocks of your distributed application.

In the distributed deployment, it is recommended to suppress DEBUG log messages from WebSocketDispatcherServlet by adding the following line to logback.xml:

<logger name="com.haulmont.addon.globalevents.core.WebSocketDispatcherServlet" level="INFO"/>

Features

  1. Events are delivered to other blocks asynchronously, including the local deployment.

  2. Ordering is accurate only within a block.

  3. Delivery in a distributed deployment is guaranteed "at most once", i.e. there is no retransmit, etc.

  4. In the distributed deployment, web client opens WebSocket connection to middleware on the first browser connection. So if some web bean is subscribed to a global event, it will start to receive notifications only after at least one user connects to it.

Testing

The global-events-demo project contains usage examples and automatic system tests.

Known Issues

  • If messages are not received and you see in the logs the message like this: The decoded text message was too big for the output buffer and the endpoint does not support partial messages, see this topic for the solution.

global-events-addon's People

Contributors

glebshalyganov avatar knstvk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

barser

global-events-addon's Issues

URISyntaxException in cluster mode

URISyntaxException is raised when working in cluster mode, URI is preped by whitespace character
java.lang.IllegalStateException: Could not create URI object: Illegal character in scheme name at index 0: %20http://vlt-app02:8080/quantum-core/cubaglevt-ws/handler

Cuba v7.1.5 / Global events v0.5.1
Reproduces with Cuba v7.2.4 / Global events v0.6.0

In web-app.properties URL are configured as:
cuba.connectionUrlList=http://vlt-app01:8080/quantum-core,http://vlt-app02:8080/quantum-core

StackTrace:
java.lang.IllegalStateException: Could not create URI object: Illegal character in scheme name at index 0: %20http://vlt-app02:8080/quantum-core/cubaglevt-ws/handler
at org.springframework.web.util.HierarchicalUriComponents.toUri(HierarchicalUriComponents.java:526)
at org.springframework.web.socket.sockjs.client.SockJsClient.doHandshake(SockJsClient.java:241)
at com.haulmont.addon.globalevents.transport.AbstractWebSocketClient.tryConnect(AbstractWebSocketClient.java:141)
at com.haulmont.addon.globalevents.transport.AbstractWebSocketClient.connect(AbstractWebSocketClient.java:84)
at com.haulmont.addon.globalevents.web.WebRemoteClient.init(WebRemoteClient.java:67)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:305)
at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:190)
at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:153)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:403)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:360)
at com.haulmont.cuba.core.sys.EventsImpl.publish(EventsImpl.java:33)
at com.haulmont.cuba.web.sys.WebEvents.publish(WebEvents.java:36)
at com.haulmont.cuba.web.DefaultApp.publishAppStartedEvent(DefaultApp.java:321)
at com.haulmont.cuba.web.DefaultApp.loginOnStart(DefaultApp.java:308)
at com.haulmont.cuba.web.AppUI.setupUI(AppUI.java:522)
at com.haulmont.cuba.web.AppUI.init(AppUI.java:346)
at com.vaadin.ui.UI.doInit(UI.java:738)
at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:209)
at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:67)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1578)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:425)
at com.haulmont.cuba.web.sys.CubaApplicationServlet.serviceAppRequest(CubaApplicationServlet.java:329)
at com.haulmont.cuba.web.sys.CubaApplicationServlet.service(CubaApplicationServlet.java:215)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:763)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1631)
at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:226)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1618)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:549)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:602)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1610)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1363)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:489)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1580)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1278)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:221)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
at org.eclipse.jetty.server.Server.handle(Server.java:500)
at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)
at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129)
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:375)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.net.URISyntaxException: Illegal character in scheme name at index 0: %20http://vlt-app02:8080/quantum-core/cubaglevt-ws/handler
at java.base/java.net.URI$Parser.fail(URI.java:2913)
at java.base/java.net.URI$Parser.checkChars(URI.java:3084)
at java.base/java.net.URI$Parser.checkChar(URI.java:3094)
at java.base/java.net.URI$Parser.parse(URI.java:3109)
at java.base/java.net.URI.(URI.java:600)
at org.springframework.web.util.HierarchicalUriComponents.toUri(HierarchicalUriComponents.java:512)
... 68 more

Wrong classloader can be set in the current thread

See a topic on support forum: link

CUBA version: 7.0.6
Addon version: 0.4

Test case

  1. Create a global event to fire
  2. Create a service that will fire the event
  3. Extend main window and subscribe for the event
  4. Create any entity and open it in editor in event listener method
  5. Create scheduled task that will trigger the service

Stacktrace

10:06:23.746 ERROR com.haulmont.cuba.web.log.AppLog        - Exception: 
java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Can't find metaClass 'com.haulmont.cuba.security.entity.User'
	at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:1.8.0_121]
	at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[na:1.8.0_121]
	at com.vaadin.server.VaadinSession$FutureAccess.get(VaadinSession.java:102) ~[vaadin-server-8.6.4-11-cuba.jar:8.6.4-11-cuba]
	at com.vaadin.server.VaadinService.runPendingAccessTasks(VaadinService.java:2021) [vaadin-server-8.6.4-11-cuba.jar:8.6.4-11-cuba]
	at com.vaadin.server.VaadinSession.unlock(VaadinSession.java:1007) ~[vaadin-server-8.6.4-11-cuba.jar:8.6.4-11-cuba]
	at com.vaadin.server.VaadinService.ensureAccessQueuePurged(VaadinService.java:1983) [vaadin-server-8.6.4-11-cuba.jar:8.6.4-11-cuba]
	at com.vaadin.server.VaadinService.accessSession(VaadinService.java:1949) [vaadin-server-8.6.4-11-cuba.jar:8.6.4-11-cuba]
	at com.vaadin.server.VaadinSession.access(VaadinSession.java:1406) ~[vaadin-server-8.6.4-11-cuba.jar:8.6.4-11-cuba]
	at com.haulmont.addon.globalevents.web.GlobalUiEvents.publish(GlobalUiEvents.java:67) ~[na:na]
	at com.haulmont.addon.globalevents.web.WebLocalClient.lambda$onMessage$0(WebLocalClient.java:84) ~[na:na]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_121]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_121]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_121]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_121]
	at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_121]
Caused by: java.lang.IllegalStateException: Can't find metaClass 'com.haulmont.cuba.security.entity.User'
	at com.haulmont.cuba.gui.xml.data.DsContextLoader.loadMetaClass(DsContextLoader.java:354) ~[na:na]
	at com.haulmont.cuba.gui.xml.data.DsContextLoader.initDatasourceAttributes(DsContextLoader.java:240) ~[na:na]
	at com.haulmont.cuba.gui.xml.data.DsContextLoader.loadDatasource(DsContextLoader.java:220) ~[na:na]
	at com.haulmont.cuba.gui.xml.data.DsContextLoader.loadDatasources(DsContextLoader.java:94) ~[na:na]
	at com.haulmont.cuba.web.sys.WebScreens.loadDsContext(WebScreens.java:380) ~[na:na]
	at com.haulmont.cuba.web.sys.WebScreens.initDsContext(WebScreens.java:358) ~[na:na]
	at com.haulmont.cuba.web.sys.WebScreens.loadWindowFromXml(WebScreens.java:346) ~[na:na]
	at com.haulmont.cuba.web.sys.WebScreens.createScreen(WebScreens.java:227) ~[na:na]
	at com.haulmont.cuba.web.sys.WebScreens.openEditor(WebScreens.java:1158) ~[na:na]
	at com.haulmont.cuba.gui.components.HasWindowManager.openEditor(HasWindowManager.java:82) ~[na:na]
	at com.company.sample.web.screens.ExtAppMainWindow.onAlarm(ExtAppMainWindow.java:25) ~[na:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
	at com.haulmont.cuba.gui.events.sys.UiEventListenerMethodAdapter.doInvoke(UiEventListenerMethodAdapter.java:224) ~[na:na]
	at com.haulmont.cuba.gui.events.sys.UiEventListenerMethodAdapter.processEvent(UiEventListenerMethodAdapter.java:150) ~[na:na]
	at com.haulmont.cuba.gui.events.sys.UiEventListenerMethodAdapter.onApplicationEvent(UiEventListenerMethodAdapter.java:109) ~[na:na]
	at com.haulmont.cuba.gui.events.sys.UiEventsMulticasterImpl.invokeListener(UiEventsMulticasterImpl.java:73) ~[na:na]
	at com.haulmont.cuba.gui.events.sys.UiEventsMulticasterImpl.multicastEvent(UiEventsMulticasterImpl.java:66) ~[na:na]
	at com.haulmont.addon.globalevents.web.GlobalUiEvents.lambda$null$0(GlobalUiEvents.java:78) ~[na:na]
	at com.vaadin.ui.UI.accessSynchronously(UI.java:1468) ~[vaadin-server-8.6.4-11-cuba.jar:8.6.4-11-cuba]
	at com.haulmont.addon.globalevents.web.GlobalUiEvents.lambda$publish$1(GlobalUiEvents.java:77) ~[na:na]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_121]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_121]
	at com.vaadin.server.VaadinService.runPendingAccessTasks(VaadinService.java:2018) [vaadin-server-8.6.4-11-cuba.jar:8.6.4-11-cuba]
	... 11 common frames omitted

Test project

gl-ev-test.zip

Nullpointer with open screen

I think this happens when I have a window open where @eventlistener is registered but in the browser the main tab becomes different. Or when the browser is generally minimized or is under other windows.

Cuba-platform version: 7.0.9
Addon version: 0.4.1

17:36:00.132 ERROR com.haulmont.cuba.web.log.AppLog        - Exception: 
java.util.concurrent.ExecutionException: java.lang.NullPointerException
	at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:na]
	at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191) ~[na:na]
	at com.vaadin.server.VaadinSession$FutureAccess.get(VaadinSession.java:102) ~[vaadin-server-8.6.4-17-cuba.jar:8.6.4-17-cuba]
	at com.vaadin.server.VaadinService.runPendingAccessTasks(VaadinService.java:2021) ~[vaadin-server-8.6.4-17-cuba.jar:8.6.4-17-cuba]
	at com.vaadin.server.VaadinSession.unlock(VaadinSession.java:1007) ~[vaadin-server-8.6.4-17-cuba.jar:8.6.4-17-cuba]
	at com.vaadin.server.VaadinService.ensureAccessQueuePurged(VaadinService.java:1983) ~[vaadin-server-8.6.4-17-cuba.jar:8.6.4-17-cuba]
	at com.vaadin.server.VaadinService.accessSession(VaadinService.java:1949) ~[vaadin-server-8.6.4-17-cuba.jar:8.6.4-17-cuba]
	at com.vaadin.server.VaadinSession.access(VaadinSession.java:1406) ~[vaadin-server-8.6.4-17-cuba.jar:8.6.4-17-cuba]
	at com.haulmont.addon.globalevents.web.GlobalUiEvents.publish(GlobalUiEvents.java:67) ~[cubaglevt-web-0.4.1.jar:na]
	at com.haulmont.addon.globalevents.web.WebLocalClient.lambda$onMessage$0(WebLocalClient.java:88) ~[cubaglevt-web-0.4.1.jar:na]
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na]
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
	at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
Caused by: java.lang.NullPointerException: null

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.