You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2009/06/03 02:41:29 UTC

svn commit: r781229 - in /openejb/trunk/openejb3/examples/webapps/moviefun/src/main/java/org/superbiz/moviefun: MoviesImpl.java Notifier.java NotifierImpl.java

Author: dblevins
Date: Wed Jun  3 00:41:28 2009
New Revision: 781229

URL: http://svn.apache.org/viewvc?rev=781229&view=rev
Log:
JMS Notifications

Added:
    openejb/trunk/openejb3/examples/webapps/moviefun/src/main/java/org/superbiz/moviefun/Notifier.java
    openejb/trunk/openejb3/examples/webapps/moviefun/src/main/java/org/superbiz/moviefun/NotifierImpl.java
Modified:
    openejb/trunk/openejb3/examples/webapps/moviefun/src/main/java/org/superbiz/moviefun/MoviesImpl.java

Modified: openejb/trunk/openejb3/examples/webapps/moviefun/src/main/java/org/superbiz/moviefun/MoviesImpl.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/moviefun/src/main/java/org/superbiz/moviefun/MoviesImpl.java?rev=781229&r1=781228&r2=781229&view=diff
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/moviefun/src/main/java/org/superbiz/moviefun/MoviesImpl.java (original)
+++ openejb/trunk/openejb3/examples/webapps/moviefun/src/main/java/org/superbiz/moviefun/MoviesImpl.java Wed Jun  3 00:41:28 2009
@@ -17,6 +17,7 @@
 package org.superbiz.moviefun;
 
 import javax.ejb.Stateless;
+import javax.ejb.EJB;
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
 import javax.persistence.Query;
@@ -30,6 +31,9 @@
         targetNamespace = "http://superbiz.org/wsdl")
 public class MoviesImpl implements Movies {
 
+    @EJB
+    private Notifier notifier;
+
     @PersistenceContext(unitName = "movie-unit")
     private EntityManager entityManager;
 
@@ -44,6 +48,8 @@
     public void deleteMovieId(long id) throws Exception {
         Movie movie = entityManager.find(Movie.class, id);
         entityManager.remove(movie);
+
+        notifier.notify("Deleted Movie \"" + movie.getTitle() + "\" (" + movie.getYear() + ")");
     }
 
     public List<Movie> getMovies() throws Exception {

Added: openejb/trunk/openejb3/examples/webapps/moviefun/src/main/java/org/superbiz/moviefun/Notifier.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/moviefun/src/main/java/org/superbiz/moviefun/Notifier.java?rev=781229&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/moviefun/src/main/java/org/superbiz/moviefun/Notifier.java (added)
+++ openejb/trunk/openejb3/examples/webapps/moviefun/src/main/java/org/superbiz/moviefun/Notifier.java Wed Jun  3 00:41:28 2009
@@ -0,0 +1,24 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.superbiz.moviefun;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public interface Notifier {
+    void notify(String message);
+}

Added: openejb/trunk/openejb3/examples/webapps/moviefun/src/main/java/org/superbiz/moviefun/NotifierImpl.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/webapps/moviefun/src/main/java/org/superbiz/moviefun/NotifierImpl.java?rev=781229&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/webapps/moviefun/src/main/java/org/superbiz/moviefun/NotifierImpl.java (added)
+++ openejb/trunk/openejb3/examples/webapps/moviefun/src/main/java/org/superbiz/moviefun/NotifierImpl.java Wed Jun  3 00:41:28 2009
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.superbiz.moviefun;
+
+import javax.annotation.Resource;
+import javax.ejb.Stateless;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+
+@Stateless
+public class NotifierImpl implements Notifier {
+
+    @Resource
+    private ConnectionFactory connectionFactory;
+
+    @Resource(name = "notifications")
+    private Topic notificationsTopic;
+
+    public void notify(String message) {
+        try {
+            Connection connection = null;
+            Session session = null;
+
+            try {
+                connection = connectionFactory.createConnection();
+                connection.start();
+
+                // Create a Session
+                session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+                // Create a MessageProducer from the Session to the Topic or Queue
+                MessageProducer producer = session.createProducer(notificationsTopic);
+                producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+                // Create a message
+                TextMessage textMessage = session.createTextMessage(message);
+
+                // Tell the producer to send the message
+                producer.send(textMessage);
+            } finally {
+                // Clean up
+                if (session != null) session.close();
+                if (connection != null) connection.close();
+            }
+        } catch (JMSException e) {
+            throw new IllegalStateException(e);
+        }
+
+    }
+
+}