What you're trying to implement is like a Notification system where the server can actively send data to the client without any kind of triggers on the client side (eg. click button, open page).
If that's the case, PrimeFaces Push is definitely a solution. I am using the it to implement the Notification system in my application. Regarding the performance, you can try googling about the Atmosphere Framework, which is used for PrimeFaces Push.
UPDATE:
One important thing to note is that for PrimeFaces Push to work, your service needs to have access to the context of the web application. In other words, the implementation must be done inside the WAR
project. Otherwise, the PushContext
will be null
if you try to get it inside, say, an EJB
project. My NotificationServices
looks like the following:
@WebService(serviceName = "NotificationServices")
@Named(value="notificator")
public class NotificationServices {
private final PushContext pushContext = PushContextFactory.getDefault().getPushContext();
/**
* Push a notification to a user
*/
@WebMethod(operationName = "pushNotification")
public void pushNotification(@WebParam(name = "username") String username,
@WebParam(name = "message") String message) {
pushContext.push("/notification/" + username, message);
}
}
So, the remaining task is to connect users to their own channel after they've logged in. In my application, I used username
as the unique key for each channel. Then, you can use @WebServiceRef
to inject the above web service into any other services in your back-end implementation. At this point, you can simply invoke the pushNotification
method if you want to push any messages to the front end.
Since the service is also annotated with @Named
, you can also inject it in any front-end code using @Inject
if necessary.