/** * @param destination */ public DwrMessageProducer(Destination destination, DwrConnection connection) { this.destination = destination; ServerContext serverContext = connection.getServerContext(); if (serverContext != null) { hub = HubFactory.get(serverContext); } else { hub = HubFactory.get(); } }
/** * Stop notifications of against a subscription id * @param subscriptionId The ID to pass back to link to client side data * @return true iff someone was unsubscribed */ @SuppressWarnings("unchecked") public boolean unsubscribe(String subscriptionId) { WebContext webContext = WebContextFactory.get(); Hub hub = HubFactory.get(); ScriptSession session = webContext.getScriptSession(); Map<String, BrowserMessageListener> subscriptions = (Map<String, BrowserMessageListener>) session.getAttribute(ATTRIBUTE_SUBSCRIPTIONS); BrowserMessageListener subscription = subscriptions.get(subscriptionId); return hub.unsubscribe(subscription.topic, subscription); }
/** * @see javax.jms.Session#createConsumer(Destination, String, boolean) */ public DwrMessageConsumer(DwrConnection connection, Destination destination, String messageSelector, boolean noLocal) throws JMSException { this.destination = destination; setMessageSelector(messageSelector); this.noLocal = noLocal; ServerContext serverContext = connection.getServerContext(); if (serverContext != null) { hub = HubFactory.get(serverContext); } else { hub = HubFactory.get(); } if (destination instanceof DwrTopic) { DwrTopic topic = (DwrTopic) destination; String topicName = topic.getTopicName(); hub.subscribe(topicName, new MessageListenerMessageListener()); } else { throw new IllegalStateException("Unsuported Destination type (" + destination.getClass().getCanonicalName() + "). Only Topics are currently supported."); } }
/** * Ensure that the clients know about server publishes * @param topic The topic being subscribed to * @param subscriptionId The ID to pass back to link to client side data */ @SuppressWarnings("unchecked") public void subscribe(String topic, String subscriptionId) { WebContext webContext = WebContextFactory.get(); Hub hub = HubFactory.get(); final ScriptSession session = webContext.getScriptSession(); // Create a subscription block BrowserMessageListener subscription = new BrowserMessageListener(session, topic, subscriptionId); Map<String, BrowserMessageListener> subscriptions = (Map<String, BrowserMessageListener>) session.getAttribute(ATTRIBUTE_SUBSCRIPTIONS); if (subscriptions == null) { subscriptions = new HashMap<String, BrowserMessageListener>(); } subscriptions.put(subscriptionId, subscription); session.setAttribute(ATTRIBUTE_SUBSCRIPTIONS, subscriptions); hub.subscribe(subscription.topic, subscription); }
/** * Something has published to the client side 'hub' and we're getting to * know about it. * @param topic The topic that has been published to * @param data The published data */ public void publish(String topic, RealRawData data) { WebContext webContext = WebContextFactory.get(); ConverterManager converterManager = webContext.getContainer().getBean(ConverterManager.class); Hub hub = HubFactory.get(); MessageEvent event = new DefaultMessageEvent(hub, converterManager, data); hub.publish(topic, event); }