summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/PoisonBean.java
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/PoisonBean.java
downloadStudium-master.tar.gz
Studium-master.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/PoisonBean.java')
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/PoisonBean.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/PoisonBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/PoisonBean.java
new file mode 100644
index 0000000..2bdfcba
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/PoisonBean.java
@@ -0,0 +1,40 @@
+package examples.messaging;
+
+import javax.jms.*;
+import javax.ejb.*;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+
+@MessageDriven(activationConfig =
+{ @ActivationConfigProperty(propertyName = "destinationType",
+ propertyValue = "javax.jms.Topic") })
+public class PoisonBean implements MessageListener {
+
+ @Resource
+ private MessageDrivenContext ctx;
+
+ public PoisonBean() {
+ System.out.println("PoisonBean created");
+ }
+
+ public void onMessage(Message msg) {
+ try {
+ System.out.println("Received msg " + msg.getJMSMessageID());
+
+ // Let’s sleep a little bit so that we don’t
+ // see rapid fire re-sends of the message.
+ Thread.sleep(3000);
+
+ // We could either throw a system exception here or
+ // manually force a rollback of the transaction.
+ ctx.setRollbackOnly();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @PreDestroy
+ public void remove() {
+ System.out.println("PoisonBean destroyed.");
+ }
+} \ No newline at end of file