e.printStackTrace();
}
TopicsContext topicsContext = TopicsContext.lookup();
Topic topic = topicsContext.getOrCreateTopic(new TopicKey("inmobles"));
topic.setMessageDataSerializer(DefaultMessageDataSerializer.instance());
topic.addTopicListener(new SessionTopicListener() {
public void processUnsubscriptionEvent(SessionUnsubscriptionEvent event) throws EventAbortedException {
TopicKey topicKey = event.getTopicKey();
Session session = event.getSession();
System.out.println(MessageFormat.format("Session {0} disconnected from {1}", session.getId(), topicKey.getTopicAddress()));
}
public void processSubscriptionEvent(SessionSubscriptionEvent event) throws EventAbortedException {
TopicKey topicKey = event.getTopicKey();
Session session = event.getSession();
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletRequest hsr = (HttpServletRequest) facesContext.getExternalContext().getRequest();
System.out.println(MessageFormat.format("Session {0} connected to {1} from {2}", session.getId(),
topicKey.getTopicAddress(), hsr.getRemoteAddr()));
}
public void processPreSubscriptionEvent(SessionPreSubscriptionEvent event) throws EventAbortedException {
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
ChatBean chatBean = (ChatBean) externalContext.getSessionMap().get("chatBean");