1

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)

Community
  • 1
  • 1
David
  • 4,785
  • 7
  • 39
  • 63
  • It was suggested to manually grab an instance of `BeanManager` (through a JNDI look up) in the link you found, if it failed to work in some servers. – Tiny Mar 04 '16 at 06:29

0 Answers0