Author: jjamrich
Date: 2011-12-07 06:25:47 -0500 (Wed, 07 Dec 2011)
New Revision: 23057
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/AbstractCapabilityInitializer.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/AbstractMessageProducerInitializer.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/CapabilityInitializer.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/JMSInitializer.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/JMSMessageProducer.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/JMSMessageProducerInitializer.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/MessageProducer.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/MessageProducerRunnable.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/PushConfiguration.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsContextMessageProducer.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsContextMessageProducerInitializer.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsInitializer.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/AS6MessagingProviderManagement.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/AS7MessagingProviderManagement.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/CustomMessagingServerManagement.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/InitializationFailedException.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/MessagingProviderManagement.java
Removed:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/listener/HornetQInitializer.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/listener/TopicsInitializer.java
Modified:
modules/tests/metamer/trunk/application/pom.xml
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/a4j/A4JPushBean.java
modules/tests/metamer/trunk/application/src/main/webapp/WEB-INF/faces-config.xml
modules/tests/metamer/trunk/application/src/main/webapp/WEB-INF/web.xml
Log:
RFPL-1572: add JMS initialization mechanism from showcase
This is initial commit.
List of changed files and short description:
modified: application/pom.xml: hornetq version change
modified: application/src/main/webapp/WEB-INF/faces-config.xml: replaced legacy
startup listeners by listeners from showcase
modified: application/src/main/webapp/WEB-INF/web.xml: removed deprecated
PushServlet declaration
Import from showcase: files for JMS and Topic initialization:
new file: application/src/main/java/org/richfaces/demo/push/*
new file: application/src/main/java/org/richfaces/demo/push/provider/*
Removed legacy listeners (replaced by ones from showcase
deleted:
application/src/main/java/org/richfaces/tests/metamer/listener/{HornetQ,Topics}Initializer.java
Modified: modules/tests/metamer/trunk/application/pom.xml
===================================================================
--- modules/tests/metamer/trunk/application/pom.xml 2011-12-07 11:05:52 UTC (rev 23056)
+++ modules/tests/metamer/trunk/application/pom.xml 2011-12-07 11:25:47 UTC (rev 23057)
@@ -43,7 +43,7 @@
<properties>
<jetty.port>8080</jetty.port>
- <hornetq.version>2.1.2.Final</hornetq.version>
+ <hornetq.version>2.2.6.Final</hornetq.version>
</properties>
<dependencies>
@@ -197,7 +197,7 @@
<SCM-Revision>${buildNumber}</SCM-Revision>
<SCM-Timestamp>${timestamp}</SCM-Timestamp>
<!-- define SLF4J dependency in JBoss AS 7 -->
-
<Dependencies>org.slf4j,org.jboss.as.process-controller,org.jboss.as.controller-client</Dependencies>
+
<Dependencies>org.slf4j,org.jboss.as.process-controller,org.jboss.as.controller-client,org.jboss.dmr</Dependencies>
</manifestEntries>
</archive>
</configuration>
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/AbstractCapabilityInitializer.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/AbstractCapabilityInitializer.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/AbstractCapabilityInitializer.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -0,0 +1,129 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.demo.push;
+
+import javax.faces.application.Application;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.PostConstructApplicationEvent;
+import javax.faces.event.PreDestroyApplicationEvent;
+import javax.faces.event.SystemEvent;
+import javax.faces.event.SystemEventListener;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+/**
+ * <p>
+ * Abstract initializater and finalizer listening for JSF PostConstructApplicationEvent
(needs to be registered explicitly in
+ * faces-config.xml).
+ * </p>
+ *
+ * <p>
+ * After observing PostConstructApplicationEvent, it registers to
PreDestroyApplicationEvent to observe finalization phase.
+ * </p>
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ */
+public abstract class AbstractCapabilityInitializer implements CapabilityInitializer,
SystemEventListener,
+ ServletContextListener {
+
+ private boolean correctlyInitialized = false;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.event.SystemEventListener#processEvent(javax.faces.event.
SystemEvent)
+ */
+ public void processEvent(SystemEvent event) throws AbortProcessingException {
+ if (isCapabilityEnabled()) {
+ if (event instanceof PostConstructApplicationEvent) {
+ Application application =
FacesContext.getCurrentInstance().getApplication();
+ application.subscribeToEvent(PreDestroyApplicationEvent.class, this);
+
+ try {
+ initializeCapability();
+ correctlyInitialized = true;
+ } catch (Exception e) {
+ throw new RuntimeException("Capability " +
this.getClass().getName() + " was not correctly initialized", e);
+ }
+ } else {
+ try {
+ finalizeCapability();
+ } catch (Exception e) {
+ throw new RuntimeException("Capability " +
this.getClass().getName() + " was not correctly finalized", e);
+ }
+ }
+ }
+ }
+
+ public void contextInitialized(ServletContextEvent sce) {
+ try {
+ initializeCapability();
+ correctlyInitialized = true;
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public void contextDestroyed(ServletContextEvent sce) {
+ try {
+ finalizeCapability();
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Returns true if initialization method has been processed without errors.
+ *
+ * @return true if initialization method has been processed without errors.
+ */
+ protected boolean isCorrentlyInitialized() {
+ return correctlyInitialized;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.event.SystemEventListener#isListenerForSource(java.lang.Object )
+ */
+ public boolean isListenerForSource(Object source) {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.demo.push.Initializer#unload()
+ */
+ public void finalizeCapability() throws Exception {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.demo.push.CapabilityInitializer#isCapabilityEnabled()
+ */
+ public boolean isCapabilityEnabled() {
+ return true;
+ }
+}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/AbstractMessageProducerInitializer.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/AbstractMessageProducerInitializer.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/AbstractMessageProducerInitializer.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.demo.push;
+
+/**
+ * Initializer which manages start of associated MessageProducer.
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ *
+ */
+public abstract class AbstractMessageProducerInitializer extends
AbstractCapabilityInitializer {
+
+ private Thread messageProducerThread;
+ private MessageProducer messageProducer;
+ private MessageProducerRunnable messageProducerRunnable;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.demo.push.Initializer#initialize()
+ */
+ public void initializeCapability() throws Exception {
+ messageProducer = createMessageProducer();
+ messageProducerRunnable = new MessageProducerRunnable(messageProducer);
+ messageProducerThread = new Thread(messageProducerRunnable,
"MessageProducerThread");
+ messageProducerThread.setDaemon(false);
+ messageProducerThread.start();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.demo.push.Initializer#unload()
+ */
+ @Override
+ public void finalizeCapability() throws Exception {
+ if (messageProducer != null) {
+ messageProducer.finalizeProducer();
+ }
+ if (messageProducerRunnable != null) {
+ messageProducerRunnable.stop();
+ }
+ if (messageProducerThread != null) {
+ messageProducerThread.interrupt();
+ }
+ }
+
+ public abstract MessageProducer createMessageProducer();
+}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/CapabilityInitializer.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/CapabilityInitializer.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/CapabilityInitializer.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.demo.push;
+
+/**
+ * Initialize and finalize capability.
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ */
+public interface CapabilityInitializer {
+ /**
+ * Initializes provided capability.
+ *
+ * @throws Exception
+ */
+ void initializeCapability() throws Exception;
+
+ /**
+ * Finalizes provided capability and frees allocated resources.
+ *
+ * @throws Exception
+ */
+ void finalizeCapability() throws Exception;
+
+ /**
+ * Returns true when capability should be initialized.
+ *
+ * @return true when capability should be initialized.
+ */
+ boolean isCapabilityEnabled();
+}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/JMSInitializer.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/JMSInitializer.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/JMSInitializer.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -0,0 +1,168 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.demo.push;
+
+import static org.richfaces.demo.push.JMSMessageProducer.PUSH_JMS_TOPIC;
+import static
org.richfaces.demo.push.TopicsContextMessageProducer.PUSH_TOPICS_CONTEXT_TOPIC;
+import static org.richfaces.tests.metamer.bean.a4j.A4JPushBean.METAMER_TOPIC;
+
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.richfaces.demo.push.provider.AS6MessagingProviderManagement;
+import org.richfaces.demo.push.provider.AS7MessagingProviderManagement;
+import org.richfaces.demo.push.provider.CustomMessagingServerManagement;
+import org.richfaces.demo.push.provider.InitializationFailedException;
+import org.richfaces.demo.push.provider.MessagingProviderManagement;
+
+/**
+ * Initializes JMS server and creates requested topics.
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ */
+public class JMSInitializer extends AbstractCapabilityInitializer {
+
+ private static final Logger LOGGER =
Logger.getLogger(JMSInitializer.class.getName());
+ private static final AtomicReference<Boolean> JMS_ENABLED = new
AtomicReference<Boolean>(null);
+
+ private MessagingProviderManagement provider;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.demo.push.Initializer#initialize()
+ */
+ public void initializeCapability() throws Exception {
+ initializeJMS();
+ }
+
+ @Override
+ public boolean isCapabilityEnabled() {
+ return isJmsEnabled();
+ }
+
+ private void initializeJMS() throws Exception {
+ provider = initializeCurrentProvider();
+
+ if (provider != null) {
+ createTopic(PUSH_JMS_TOPIC, "/topic/" + PUSH_JMS_TOPIC);
+ createTopic(PUSH_TOPICS_CONTEXT_TOPIC, "/topic/" +
PUSH_TOPICS_CONTEXT_TOPIC);
+ createTopic(METAMER_TOPIC, "/topic/" + METAMER_TOPIC);
+ }
+ }
+
+ private void createTopic(String topicName, String jndiName) throws Exception {
+ try {
+ LOGGER.info("creating topic " + topicName);
+ provider.createTopic(topicName, jndiName);
+ } catch (Exception e) {
+ throw new RuntimeException("Unable to create topic '" +
topicName + "' (JNDI: " + jndiName + ")", e);
+ }
+ }
+
+ protected static boolean isJmsEnabled() {
+ if (null == JMS_ENABLED.get()) {
+ boolean isJmsEnabled = isConnectionFactoryRegistered() || isTomcat();
+ JMS_ENABLED.compareAndSet(null, isJmsEnabled);
+ }
+ return JMS_ENABLED.get();
+ }
+
+ private static boolean isTomcat() {
+ try {
+ Class<?> clazz =
Class.forName("org.apache.catalina.util.ServerInfo");
+ String serverInfo = (String)
clazz.getMethod("getServerInfo").invoke(null);
+ return serverInfo.contains("Tomcat");
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.demo.push.Initializer#unload()
+ */
+ public void finalizeCapability() throws Exception {
+ if (provider != null) {
+ provider.finalizeProvider();
+ }
+ }
+
+ /**
+ * Returns all providers which are available from current context
+ *
+ * @return all providers which are available from current context
+ */
+ @SuppressWarnings("unchecked")
+ private Class<? extends MessagingProviderManagement>[] getAvailableProviders()
{
+ if (isConnectionFactoryRegistered()) {
+ return new Class[] { AS7MessagingProviderManagement.class,
AS6MessagingProviderManagement.class };
+ } else {
+ return new Class[] { CustomMessagingServerManagement.class };
+ }
+ }
+
+ /**
+ * Returns one of providers available from current context which are able to
initialize successfully
+ *
+ * @return one of providers available from current context which are able to
initialize successfully
+ */
+ private MessagingProviderManagement initializeCurrentProvider() {
+ for (Class<? extends MessagingProviderManagement> c :
getAvailableProviders()) {
+ try {
+ LOGGER.info("initializing");
+ MessagingProviderManagement provider = c.newInstance();
+ provider.initializeProvider();
+ LOGGER.info(c.getSimpleName() + " initialized");
+ return provider;
+ } catch (InitializationFailedException e) {
+ LOGGER.severe(c.getSimpleName() + " initialization failed");
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ throw new IllegalStateException("no management provider has been
successfully initialized");
+ }
+
+ /**
+ * Returns true if ConnectionFactory is already registered
+ *
+ * @return true if ConnectionFactory is already registered
+ */
+ private static boolean isConnectionFactoryRegistered() {
+ try {
+ return null != InitialContext.doLookup("java:/ConnectionFactory");
+ } catch (NamingException e) {
+ if (!(e instanceof NameNotFoundException)) {
+ LOGGER.log(Level.SEVERE, "Can't access naming context",
e);
+ }
+ return false;
+ }
+ }
+
+}
\ No newline at end of file
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/JMSMessageProducer.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/JMSMessageProducer.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/JMSMessageProducer.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -0,0 +1,148 @@
+/**
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.demo.push;
+
+import java.io.Serializable;
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.jms.JMSException;
+import javax.jms.ObjectMessage;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+/**
+ * Sends message to JMS topic.
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ */
+public class JMSMessageProducer implements MessageProducer {
+
+ public static final String PUSH_JMS_TOPIC = "pushJms";
+
+ private static final Logger LOGGER =
Logger.getLogger(JMSMessageProducer.class.getName());
+
+ private Topic topic;
+ private TopicConnection connection = null;
+ private TopicSession session = null;
+ private TopicPublisher publisher = null;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.demo.push.MessageProducer#sendMessage()
+ */
+ public void sendMessage() throws Exception {
+ try {
+ initializeMessaging();
+ ObjectMessage message = session.createObjectMessage(createMessage());
+ publisher.publish(message);
+ } catch (NameNotFoundException e) {
+ LOGGER.fine(e.getMessage());
+ } catch (JMSException e) {
+ LOGGER.log(Level.SEVERE, e.getMessage(), e);
+ }
+ }
+
+ private Serializable createMessage() {
+ DateFormat dateFormat = DateFormat.getDateTimeInstance();
+ dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
+ String dateMessage = dateFormat.format(new Date());
+ return dateMessage;
+ }
+
+ private void initializeMessaging() throws JMSException, NamingException {
+ if (connection == null) {
+ TopicConnectionFactory tcf = getTopicConnectionFactory();
+ connection = tcf.createTopicConnection();
+ }
+ if (session == null) {
+ session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ }
+ if (topic == null) {
+ topic = InitialContext.doLookup("topic/" + PUSH_JMS_TOPIC);
+ }
+ if (publisher == null) {
+ publisher = session.createPublisher(topic);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.demo.push.MessageProducer#getInterval()
+ */
+ public int getInterval() {
+ return 5000;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.demo.push.MessageProducer#finalizeProducer()
+ */
+ public void finalizeProducer() {
+ if (publisher != null) {
+ try {
+ publisher.close();
+ } catch (JMSException e) {
+ LOGGER.severe("unable to close publisher");
+ }
+ }
+ if (session != null) {
+ try {
+ session.close();
+ } catch (JMSException e) {
+ LOGGER.severe("unable to close session");
+ }
+ }
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (JMSException e) {
+ LOGGER.severe("unable to close connection");
+ }
+ }
+ }
+
+ private TopicConnectionFactory getTopicConnectionFactory() {
+ try {
+ return (TopicConnectionFactory)
InitialContext.doLookup("java:/ConnectionFactory");
+ } catch (NamingException e) {
+ try {
+ return (TopicConnectionFactory)
InitialContext.doLookup("ConnectionFactory");
+ } catch (NamingException e2) {
+ throw new IllegalStateException("Can't find registered
ConnectionFactory");
+ }
+ }
+ }
+}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/JMSMessageProducerInitializer.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/JMSMessageProducerInitializer.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/JMSMessageProducerInitializer.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.demo.push;
+
+/**
+ * Starts the thread with JMS message producer.
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ */
+public class JMSMessageProducerInitializer extends AbstractMessageProducerInitializer {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.richfaces.demo.push.AbstractMessageProducerInitializer#createMessageProducer()
+ */
+ @Override
+ public MessageProducer createMessageProducer() {
+ return new JMSMessageProducer();
+ }
+
+ @Override
+ public boolean isCapabilityEnabled() {
+ return JMSInitializer.isJmsEnabled();
+ }
+}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/MessageProducer.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/MessageProducer.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/MessageProducer.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.demo.push;
+
+/**
+ * Interface for implementations producing messages.
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ */
+public interface MessageProducer {
+
+ /**
+ * Sends a message.
+ *
+ * @throws Exception any exception which was thrown when trying to send message.
+ */
+ void sendMessage() throws Exception;
+
+ /**
+ * Interval which will be producer sleeping after last message sent before start of
sending of next message.
+ *
+ * @return interval in miliseconds
+ */
+ int getInterval();
+
+ /**
+ * Finalizes the producer (frees all associated resources)
+ */
+ void finalizeProducer();
+}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/MessageProducerRunnable.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/MessageProducerRunnable.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/MessageProducerRunnable.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.demo.push;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Runnable which are periodically sending messages until it is stopped or underlying
thread is interrupted.
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ */
+public class MessageProducerRunnable implements Runnable {
+
+ private static final Logger LOGGER =
Logger.getLogger(MessageProducerRunnable.class.getName());
+
+ private AtomicBoolean runFlag = new AtomicBoolean(true);
+ private MessageProducer messageProducer;
+
+ /**
+ * Creates runnable with associated message producer.
+ *
+ * @param messageProducer will be associated with this runnable
+ */
+ public MessageProducerRunnable(MessageProducer messageProducer) {
+ this.messageProducer = messageProducer;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Runnable#run()
+ */
+ public void run() {
+ while (runFlag.get()) {
+ try {
+ messageProducer.sendMessage();
+ } catch (Exception e) {
+ LOGGER.log(Level.SEVERE, e.getMessage(), e);
+ }
+
+ try {
+ Thread.sleep(messageProducer.getInterval());
+ } catch (InterruptedException e) {
+ LOGGER.log(Level.INFO, "MessageProducer has been
interrupted");
+ break;
+ }
+ }
+ }
+
+ /**
+ * Stops the cycle with body sending messages.
+ */
+ public void stop() {
+ runFlag.set(false);
+ }
+}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/PushConfiguration.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/PushConfiguration.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/PushConfiguration.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */package org.richfaces.demo.push;
+
+import javax.faces.bean.ApplicationScoped;
+import javax.faces.bean.ManagedBean;
+import javax.faces.context.FacesContext;
+import javax.servlet.ServletContext;
+
+/**
+ * Initializes JMS server and creates requested topics.
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ */
+@ApplicationScoped
+@ManagedBean
+public class PushConfiguration {
+
+ public boolean isJmsEnabled() {
+ return JMSInitializer.isJmsEnabled();
+ }
+
+ public boolean isPushEnabled() {
+ ServletContext servletContext = (ServletContext)
FacesContext.getCurrentInstance().getExternalContext().getContext();
+ String pushDisabled =
servletContext.getInitParameter("org.richfaces.showcase.pushDisabled");
+ if (pushDisabled == null) {
+ return true;
+ }
+ return Boolean.valueOf(pushDisabled);
+ }
+}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsContextMessageProducer.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsContextMessageProducer.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsContextMessageProducer.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -0,0 +1,70 @@
+/**
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.demo.push;
+
+import org.richfaces.application.push.MessageException;
+import org.richfaces.application.push.TopicKey;
+import org.richfaces.application.push.TopicsContext;
+
+/**
+ * Sends message to topic using TopicsContext.
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ */
+public class TopicsContextMessageProducer implements MessageProducer {
+
+ public static final String PUSH_TOPICS_CONTEXT_TOPIC =
"pushTopicsContext";
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.demo.push.MessageProducer#sendMessage()
+ */
+ public void sendMessage() throws Exception {
+ try {
+ TopicKey topicKey = new TopicKey(PUSH_TOPICS_CONTEXT_TOPIC);
+ TopicsContext topicsContext = TopicsContext.lookup();
+ topicsContext.publish(topicKey, "message");
+ } catch (MessageException e) {
+ if (!e.getMessage().matches("^Topic .* not found$")) {
+ throw e;
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.demo.push.MessageProducer#getInterval()
+ */
+ public int getInterval() {
+ return 5000;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.demo.push.MessageProducer#finalizeProducer()
+ */
+ public void finalizeProducer() {
+ }
+}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsContextMessageProducerInitializer.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsContextMessageProducerInitializer.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsContextMessageProducerInitializer.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.demo.push;
+
+/**
+ * Starts the thread with TopicsContext message producer.
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ */
+public class TopicsContextMessageProducerInitializer extends
AbstractMessageProducerInitializer {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.richfaces.demo.push.AbstractMessageProducerInitializer#createMessageProducer()
+ */
+ @Override
+ public MessageProducer createMessageProducer() {
+ return new TopicsContextMessageProducer();
+ }
+}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsInitializer.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsInitializer.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsInitializer.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -0,0 +1,102 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.demo.push;
+
+import static org.richfaces.demo.push.JMSMessageProducer.PUSH_JMS_TOPIC;
+import static
org.richfaces.demo.push.TopicsContextMessageProducer.PUSH_TOPICS_CONTEXT_TOPIC;
+import static org.richfaces.tests.metamer.bean.a4j.A4JPushBean.METAMER_TOPIC;
+
+import java.util.logging.Logger;
+
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.richfaces.application.push.Topic;
+import org.richfaces.application.push.TopicKey;
+import org.richfaces.application.push.TopicsContext;
+import org.richfaces.application.push.impl.DefaultMessageDataSerializer;
+
+/**
+ * Registers topics in RichFaces subsytem.
+ *
+ * @author Nick Belaevski
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ */
+public class TopicsInitializer extends AbstractCapabilityInitializer {
+
+ private static final Logger LOGGER =
Logger.getLogger(TopicsInitializer.class.getName());
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.demo.push.Initializer#initialize()
+ */
+ public void initializeCapability() throws Exception {
+ TopicsContext.lookup();
+
+ new RegisterTopicThread(PUSH_JMS_TOPIC).start();
+ new RegisterTopicThread(PUSH_TOPICS_CONTEXT_TOPIC).start();
+ new RegisterTopicThread(METAMER_TOPIC).start();
+ }
+
+ private class RegisterTopicThread extends Thread {
+
+ public RegisterTopicThread(final String topicName) {
+ super(new Runnable() {
+
+ public void run() {
+ if (JMSInitializer.isJmsEnabled()) {
+ waitForJmsTopicReady();
+ }
+
+ TopicsContext topicsContext = TopicsContext.lookup();
+ Topic pushJmsTopic = topicsContext.getOrCreateTopic(new
TopicKey(topicName));
+
pushJmsTopic.setMessageDataSerializer(DefaultMessageDataSerializer.instance());
+ }
+
+ private void waitForJmsTopicReady() {
+ while (!isJmsTopicReady()) {
+ try {
+ LOGGER.severe("topic " + topicName + " not
ready yet, sleeping");
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+
+ private boolean isJmsTopicReady() {
+ try {
+ InitialContext.doLookup("topic/" + topicName);
+ return true;
+ } catch (NameNotFoundException e) {
+ return false;
+ } catch (NamingException e) {
+ LOGGER.severe(e.getMessage());
+ }
+ return false;
+ }
+ }, "RegisterTopicThread");
+ }
+ }
+}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/AS6MessagingProviderManagement.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/AS6MessagingProviderManagement.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/AS6MessagingProviderManagement.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.demo.push.provider;
+
+import java.io.UnsupportedEncodingException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.management.MBeanServerConnection;
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import org.hornetq.api.core.management.ObjectNameBuilder;
+import org.hornetq.api.jms.management.JMSServerControl;
+
+/**
+ * Connects to JMS RMI interface and creates topics using {@link JMSServerControl}.
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ */
+public class AS6MessagingProviderManagement implements MessagingProviderManagement {
+
+ private JMSServerControl serverControl;
+
+ public void initializeProvider() throws InitializationFailedException {
+ //determine bound IP address
+ String ipAddr = System.getProperty("jboss.bind.address");
+
+ if(ipAddr.isEmpty()){
+ ipAddr = "localhost";
+ }
+
+ try {
+ ObjectName on = ObjectNameBuilder.DEFAULT.getJMSServerObjectName();
+ JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(
+ "service:jmx:rmi:///jndi/rmi://" + ipAddr +
":1090/jmxrmi"), new HashMap<String, Object>());
+ MBeanServerConnection mbsc = connector.getMBeanServerConnection();
+ serverControl = (JMSServerControl)
MBeanServerInvocationHandler.newProxyInstance(mbsc, on,
+ JMSServerControl.class, false);
+ } catch (Exception e) {
+ throw new InitializationFailedException();
+ }
+ }
+
+ public void finalizeProvider() {
+ }
+
+ public void createTopic(String topicName, String jndiName) throws Exception {
+ if (!getAvailableTopics().contains(topicName)) {
+ serverControl.createTopic(topicName, jndiName);
+ }
+ }
+
+ private Set<String> getAvailableTopics() {
+ String[] topicNames = serverControl.getTopicNames();
+ return new HashSet<String>(Arrays.asList(topicNames));
+ }
+}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/AS7MessagingProviderManagement.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/AS7MessagingProviderManagement.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/AS7MessagingProviderManagement.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -0,0 +1,107 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.demo.push.provider;
+
+import java.io.IOException;
+import java.net.UnknownHostException;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.jboss.as.controller.client.ModelControllerClient;
+import org.jboss.dmr.ModelNode;
+
+/**
+ * Manages AS7 to create JMS topics using ModelControllerClient.
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ */
+public class AS7MessagingProviderManagement implements MessagingProviderManagement {
+
+ private static final Logger LOGGER =
Logger.getLogger(AS7MessagingProviderManagement.class.getName());
+
+ private List<ModelControllerClient> clients = new
LinkedList<ModelControllerClient>();
+
+ public void initializeProvider() throws InitializationFailedException {
+ try {
+ // tries to connect - when creating topic, own client will be created
(RF-11695)
+ createClient().close();
+ } catch (Exception e) {
+ throw new InitializationFailedException();
+ } catch (NoClassDefFoundError e) {
+ throw new InitializationFailedException();
+ }
+ }
+
+ private ModelControllerClient createClient() throws UnknownHostException {
+ return ModelControllerClient.Factory.create("127.0.0.1", 9999);
+ }
+
+ public void finalizeProvider() {
+ try {
+ for (ModelControllerClient client : clients) {
+ client.close();
+ }
+ } catch (IOException e) {
+ LOGGER.log(Level.SEVERE, "wasn't able to finalize AS7 messaging
management");
+ }
+ }
+
+ public void createTopic(String topicName, String jndiName) throws Exception {
+
+ // create own client for each topic creation (RF-11695)
+ ModelControllerClient client = createClient();
+ clients.add(client);
+
+ boolean as71 = false;
+
+ jndiName = jndiName.replaceFirst("/", "");
+
+ ModelNode operation = new ModelNode();
+ operation.get("operation").set("read-resource");
+ operation.get("address").add("subsystem",
"messaging");
+ ModelNode result = client.execute(operation, null);
+
+ // AS 7.1 or higher (hornetq-server=default address node added)
+ if
(result.get("result").toString().contains("hornetq-server")) {
+ as71 = true;
+ operation = new ModelNode();
+ operation.get("operation").set("read-resource");
+ operation.get("address").add("subsystem",
"messaging");
+ operation.get("address").add("hornetq-server",
"default");
+ result = client.execute(operation, null);
+ }
+
+ if
(!result.get("result").get("jms-topic").toString().contains("\""
+ topicName + "\"")) {
+ operation = new ModelNode();
+ operation.get("operation").set("add");
+ operation.get("address").add("subsystem",
"messaging");
+ if (as71) {
+ operation.get("address").add("hornetq-server",
"default");
+ }
+ operation.get("address").add("jms-topic", topicName);
+ operation.get("entries").add("topic/" + topicName);
+ client.executeAsync(operation, null);
+ }
+ }
+}
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/CustomMessagingServerManagement.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/CustomMessagingServerManagement.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/CustomMessagingServerManagement.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -0,0 +1,128 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.demo.push.provider;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.naming.InitialContext;
+
+import org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.core.config.Configuration;
+import org.hornetq.core.config.impl.ConfigurationImpl;
+import org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory;
+import org.hornetq.core.remoting.impl.netty.NettyConnectorFactory;
+import org.hornetq.core.server.HornetQServer;
+import org.hornetq.core.server.HornetQServers;
+import org.hornetq.jms.server.JMSServerManager;
+import org.hornetq.jms.server.config.ConnectionFactoryConfiguration;
+import org.hornetq.jms.server.config.impl.ConnectionFactoryConfigurationImpl;
+import org.hornetq.jms.server.impl.JMSServerManagerImpl;
+
+/**
+ * Starts HornetQ, binds ConnectionFactory to the context and create topics.
+ *
+ * @author Nick Belaevski
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ */
+public class CustomMessagingServerManagement implements MessagingProviderManagement {
+
+ private static final Logger LOGGER =
Logger.getLogger(CustomMessagingServerManagement.class.getName());
+
+ private HornetQServer jmsServer;
+ private JMSServerManager jmsServerManager;
+
+ public void initializeProvider() throws InitializationFailedException {
+ try {
+ startJMSServer();
+ startJMSServerManager();
+ createJMSConnectionFactory();
+ } catch (Exception e) {
+ throw new InitializationFailedException();
+ }
+ }
+
+ public void createTopic(String topicName, String jndiName) throws Exception {
+ jmsServerManager.createTopic(false, topicName, jndiName);
+ }
+
+ public void finalizeProvider() {
+ try {
+ stopJMSServerManager();
+ stopJMSServer();
+ } catch (Exception e) {
+ LOGGER.log(Level.SEVERE, "wasn't able to finalize custom
messaging");
+ }
+ }
+
+ private void startJMSServer() throws Exception {
+ jmsServer = HornetQServers.newHornetQServer(createHornetQConfiguration());
+ }
+
+ private void startJMSServerManager() throws Exception {
+ jmsServerManager = new JMSServerManagerImpl(jmsServer);
+
+ InitialContext context = new InitialContext();
+ jmsServerManager.setContext(context);
+ jmsServerManager.start();
+ }
+
+ private void createJMSConnectionFactory() throws Exception {
+ List<String> connectors = Arrays.asList(new String[] { "netty"
});
+
+ ConnectionFactoryConfiguration connectionFactoryConfiguration = new
ConnectionFactoryConfigurationImpl(
+ "ConnectionFactory", false, connectors, (String) null);
+ connectionFactoryConfiguration.setUseGlobalPools(false);
+
+ jmsServerManager.createConnectionFactory(false, connectionFactoryConfiguration,
"ConnectionFactory");
+ }
+
+ private void stopJMSServer() throws Exception {
+ jmsServer.stop();
+ jmsServer = null;
+ }
+
+ private void stopJMSServerManager() throws Exception {
+ jmsServerManager.stop();
+ jmsServerManager = null;
+ }
+
+ private Configuration createHornetQConfiguration() {
+ Configuration configuration = new ConfigurationImpl();
+ configuration.setPersistenceEnabled(false);
+ configuration.setSecurityEnabled(false);
+
+ TransportConfiguration transportationConfiguration = new TransportConfiguration(
+ NettyAcceptorFactory.class.getName());
+ HashSet<TransportConfiguration> setTransp = new
HashSet<TransportConfiguration>();
+ setTransp.add(transportationConfiguration);
+ configuration.setAcceptorConfigurations(setTransp);
+ configuration.getConnectorConfigurations().put("netty",
+ new TransportConfiguration(NettyConnectorFactory.class.getName()));
+
+ return configuration;
+ }
+
+}
\ No newline at end of file
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/InitializationFailedException.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/InitializationFailedException.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/InitializationFailedException.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.demo.push.provider;
+
+/**
+ * Thrown when messaging provider management initialization fails.
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ */
+public class InitializationFailedException extends Exception {
+ private static final long serialVersionUID = 1L;
+}
\ No newline at end of file
Added:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/MessagingProviderManagement.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/MessagingProviderManagement.java
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/provider/MessagingProviderManagement.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.demo.push.provider;
+
+/**
+ * Interface for management of messaging provider.
+ *
+ * Is able to initialize, createTopic and finalize.
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ */
+public interface MessagingProviderManagement {
+ /**
+ * Initializes messaging management, called at application startup.
+ *
+ * @throws InitializationFailedException
+ * when initialize of provider fails
+ */
+ void initializeProvider() throws InitializationFailedException;
+
+ /**
+ * Creates JMS topic using this provider
+ *
+ * @param topicName
+ * the name of the topic
+ * @param jndiName
+ * the JNDI binding to use for given topic
+ * @throws Exception
+ * when creating of topic fails
+ */
+ void createTopic(String topicName, String jndiName) throws Exception;
+
+ /**
+ * Finalizes messaging provider management at on application tear down.
+ */
+ void finalizeProvider();
+}
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/a4j/A4JPushBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/a4j/A4JPushBean.java 2011-12-07
11:05:52 UTC (rev 23056)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/a4j/A4JPushBean.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -34,8 +34,6 @@
import org.richfaces.component.UIPush;
import org.richfaces.tests.metamer.Attributes;
import org.richfaces.tests.metamer.Message;
-import org.richfaces.tests.metamer.listener.HornetQInitializer;
-import org.richfaces.tests.metamer.listener.TopicsInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,6 +48,9 @@
public class A4JPushBean implements Serializable {
private static final long serialVersionUID = 4810889475400649809L;
+ public static final String METAMER_TOPIC = "metamer";
+ public static final String METAMER_SUBTOPIC = "xxx";
+
private static Logger logger;
private transient TopicsContext topicsContext;
private Attributes attributes;
@@ -64,11 +65,9 @@
logger = LoggerFactory.getLogger(getClass());
logger.debug("initializing bean " + getClass().getName());
- // TODO refactor
// set up messaging
- new HornetQInitializer().processEvent(null);
- new TopicsInitializer().processEvent(null);
-
+ // TODO JJa 2011-12-07: make sure if initialization is required even use
initialization mechanism from showcase
+
topicsContext = TopicsContext.lookup();
attributes = Attributes.getComponentAttributesFromClass(UIPush.class,
getClass());
@@ -132,7 +131,7 @@
try {
logger.info("sending message \"" + message + "\" by
user " + username);
Message msg = new Message(message, username, new Date().toString());
- getTopicsContext().publish(new TopicKey("metamer",
"xxx"), msg);
+ getTopicsContext().publish(new TopicKey(METAMER_TOPIC, METAMER_SUBTOPIC),
msg);
} catch (MessageException messageException) {
logger.error("Could not send message \"" + message +
"\" by user " + username + ".", messageException);
}
Deleted:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/listener/HornetQInitializer.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/listener/HornetQInitializer.java 2011-12-07
11:05:52 UTC (rev 23056)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/listener/HornetQInitializer.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -1,143 +0,0 @@
-/*******************************************************************************
- * JBoss, Home of Professional Open Source
- * Copyright 2010-2011, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- *******************************************************************************/
-package org.richfaces.tests.metamer.listener;
-
-import java.util.HashSet;
-
-import javax.faces.application.Application;
-import javax.faces.context.FacesContext;
-import javax.faces.event.AbortProcessingException;
-import javax.faces.event.PreDestroyApplicationEvent;
-import javax.faces.event.SystemEvent;
-import javax.faces.event.SystemEventListener;
-import javax.naming.InitialContext;
-
-import org.hornetq.api.core.TransportConfiguration;
-import org.hornetq.core.config.Configuration;
-import org.hornetq.core.config.impl.ConfigurationImpl;
-import org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory;
-import org.hornetq.core.remoting.impl.netty.NettyConnectorFactory;
-import org.hornetq.core.server.HornetQServer;
-import org.hornetq.core.server.HornetQServers;
-import org.hornetq.jms.server.JMSServerManager;
-import org.hornetq.jms.server.config.ConnectionFactoryConfiguration;
-import org.hornetq.jms.server.config.impl.ConnectionFactoryConfigurationImpl;
-import org.hornetq.jms.server.impl.JMSServerManagerImpl;
-import org.richfaces.application.ServiceTracker;
-import org.richfaces.application.push.PushContextFactory;
-import org.richfaces.tests.metamer.bean.VersionBean;
-import org.richfaces.tests.metamer.bean.VersionBean.FailToRetrieveInfo;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Listener that initializes HornetQ in Tomcat.
- *
- * @author Nick Belaevski
- * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
- * @version $Revision$
- */
-public class HornetQInitializer implements SystemEventListener {
-
- private static Logger logger;
- private JMSServerManager serverManager;
-
- public HornetQInitializer() {
- logger = LoggerFactory.getLogger(getClass());
- }
-
- public void processEvent(SystemEvent event) throws AbortProcessingException {
- String serverType = null;
-
- try {
- serverType = VersionBean.getTomcatVersionInfo();
- } catch (FailToRetrieveInfo e) {
- serverType = e.getMessage();
- }
-
- if (serverType != null && serverType.contains("Tomcat")) {
- try {
- startHornetQ();
- } catch (Exception e) {
- throw new AbortProcessingException(e);
- }
-
- //force push context initialization so that its PreDestroyApplicationevent
listener is added before HornetQ stopper
- ServiceTracker.getService(PushContextFactory.class).getPushContext();
-
- Application application =
FacesContext.getCurrentInstance().getApplication();
- application.subscribeToEvent(PreDestroyApplicationEvent.class, this);
- } else {
- try {
- stopHornetQ();
- } catch (Exception e) {
- throw new AbortProcessingException(e);
- }
- }
- }
-
- private void stopHornetQ() throws Exception {
- if (serverManager != null) {
- logger.info("stopping HornetQ");
- serverManager.stop();
- serverManager = null;
- }
- }
-
- private void startHornetQ() throws Exception {
- logger.info("starting HornetQ");
-
- // create the Configuration and set the properties accordingly
- Configuration configuration = new ConfigurationImpl();
- configuration.setPersistenceEnabled(false);
- configuration.setSecurityEnabled(false);
-
- TransportConfiguration transpConf = new
TransportConfiguration(NettyAcceptorFactory.class.getName());
-
- HashSet<TransportConfiguration> setTransp = new
HashSet<TransportConfiguration>();
- setTransp.add(transpConf);
-
- configuration.setAcceptorConfigurations(setTransp);
-
- // create and start the server
- HornetQServer server = HornetQServers.newHornetQServer(configuration);
-
- serverManager = new JMSServerManagerImpl(server);
-
- //if you want to use JNDI, simple inject a context here or don't call this
method and make sure the JNDI parameters are set.
- InitialContext context = new InitialContext();
- serverManager.setContext(context);
- serverManager.start();
-
- ConnectionFactoryConfiguration connectionFactoryConfiguration = new
ConnectionFactoryConfigurationImpl("ConnectionFactory",
- new TransportConfiguration(NettyConnectorFactory.class.getName()),
(String) null);
- connectionFactoryConfiguration.setUseGlobalPools(false);
-
- serverManager.createConnectionFactory(false, connectionFactoryConfiguration,
"ConnectionFactory");
-
- serverManager.createTopic(false, "metamer",
"/topic/metamer");
- }
-
- public boolean isListenerForSource(Object source) {
- return true;
- }
-}
Deleted:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/listener/TopicsInitializer.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/listener/TopicsInitializer.java 2011-12-07
11:05:52 UTC (rev 23056)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/listener/TopicsInitializer.java 2011-12-07
11:25:47 UTC (rev 23057)
@@ -1,99 +0,0 @@
-/*******************************************************************************
- * JBoss, Home of Professional Open Source
- * Copyright 2010-2011, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- *******************************************************************************/
-package org.richfaces.tests.metamer.listener;
-
-import java.text.MessageFormat;
-
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.event.AbortProcessingException;
-import javax.faces.event.SystemEvent;
-import javax.faces.event.SystemEventListener;
-import javax.servlet.http.HttpServletRequest;
-
-import org.richfaces.application.push.Session;
-import org.richfaces.application.push.SessionPreSubscriptionEvent;
-import org.richfaces.application.push.SessionSubscriptionEvent;
-import org.richfaces.application.push.SessionTopicListener;
-import org.richfaces.application.push.SessionUnsubscriptionEvent;
-import org.richfaces.application.push.Topic;
-import org.richfaces.application.push.TopicKey;
-import org.richfaces.application.push.TopicsContext;
-import org.richfaces.application.push.impl.DefaultMessageDataSerializer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Listener that subscribes to JMS topics.
- *
- * @author Nick Belaevski
- * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
- * @version $Revision$
- */
-public class TopicsInitializer implements SystemEventListener {
-
- private static Logger logger;
-
- public TopicsInitializer() {
- logger = LoggerFactory.getLogger(getClass());
- }
-
- public void processEvent(SystemEvent event) throws AbortProcessingException {
- TopicsContext topicsContext = TopicsContext.lookup();
-
- Topic topic = topicsContext.getOrCreateTopic(new TopicKey("metamer",
"xxx"));
-
- topic.setMessageDataSerializer(DefaultMessageDataSerializer.instance());
-
- topic.addTopicListener(new SessionTopicListener() {
-
- public void processUnsubscriptionEvent(SessionUnsubscriptionEvent event) {
- logger.info("unsubscibe from JMS topic");
- 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) {
- logger.info("subscibe to JMS topic");
- 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) {
- logger.info("presubscription to JMS topic");
- ExternalContext externalContext =
FacesContext.getCurrentInstance().getExternalContext();
- }
- });
- }
-
- public boolean isListenerForSource(Object source) {
- return true;
- }
-}
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/WEB-INF/faces-config.xml 2011-12-07
11:05:52 UTC (rev 23056)
+++
modules/tests/metamer/trunk/application/src/main/webapp/WEB-INF/faces-config.xml 2011-12-07
11:25:47 UTC (rev 23057)
@@ -4,18 +4,25 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<application>
-<!--
+
<system-event-listener>
-
<system-event-listener-class>org.richfaces.tests.metamer.listener.HornetQInitializer</system-event-listener-class>
+
<system-event-listener-class>org.richfaces.demo.push.JMSInitializer</system-event-listener-class>
<system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class>
</system-event-listener>
<system-event-listener>
-
<system-event-listener-class>org.richfaces.tests.metamer.listener.TopicsInitializer</system-event-listener-class>
+
<system-event-listener-class>org.richfaces.demo.push.TopicsInitializer</system-event-listener-class>
<system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class>
</system-event-listener>
- -->
+ <!-- system-event-listener>
+
<system-event-listener-class>org.richfaces.demo.push.JMSMessageProducerInitializer</system-event-listener-class>
+
<system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class>
+ </system-event-listener-->
+ <!-- system-event-listener>
+
<system-event-listener-class>org.richfaces.demo.push.TopicsContextMessageProducerInitializer</system-event-listener-class>
+
<system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class>
+ </system-event-listener-->
</application>
-
+
<lifecycle>
<phase-listener>org.richfaces.tests.metamer.RichPhaseListener</phase-listener>
</lifecycle>
Modified: modules/tests/metamer/trunk/application/src/main/webapp/WEB-INF/web.xml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/WEB-INF/web.xml 2011-12-07
11:05:52 UTC (rev 23056)
+++ modules/tests/metamer/trunk/application/src/main/webapp/WEB-INF/web.xml 2011-12-07
11:25:47 UTC (rev 23057)
@@ -53,21 +53,12 @@
</context-param>
<filter>
- <filter-name>PushFilter</filter-name>
- <filter-class>org.richfaces.webapp.PushFilter</filter-class>
- <async-supported>true</async-supported>
- </filter>
- <filter>
<filter-name>Test Identity Filter</filter-name>
<filter-class>org.richfaces.tests.metamer.TestIdentityFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
- <filter-name>PushFilter</filter-name>
- <servlet-name>Faces Servlet</servlet-name>
- </filter-mapping>
- <filter-mapping>
<filter-name>Test Identity Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>