I have 2 independent modules (Service and Web). The only thing they have in common is the database.
The Web module is connected to a client browser via a websocket connection. It can then send message at any time. But I want that client to get realtime logs about every database changes made by the Service layer.
___ Service Layer
/
DATABASE
\___ Web module <--> Client browser
I saw this solution but first, the beanManager
remains null
when using
@Inject
or
CDI.current().getBeanManager().fireEvent(new MenuChangeEvent(menu))
And second, in the code bellow, where should I call the function which @Observes
changes ?
@ServerEndpoint("/dashboard") // ws://localhost/app/dashboard
public class DashboardController extends EmptyInterceptor {
private static Set<Session> sessions = Collections.synchronizedSet(new HashSet<Session>());
@OnOpen
public void onOpen(Session session) {
sessions.add(session);
}
@OnClose
public void onClose(Session session) {
sessions.remove(session);
}
public void sendMessage(String message) {
for (Session session : sessions) {
session.getAsyncRemote().sendText(message);
}
}
}
Or do you guys have any other solutions ? (I want to avoid to use database triggers)