Message Driven Bean Example 2 - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Message Driven Bean Example 2

Description:

Message Driven Bean Example 2. A DealerBean for Bridge. Group #4. What a Card Dealer Should Do... nature of http even with auto-reload web page every 5 secs. ... – PowerPoint PPT presentation

Number of Views:187
Avg rating:3.0/5.0
Slides: 10
Provided by: jerem60
Category:
Tags: bean | driven | example | message

less

Transcript and Presenter's Notes

Title: Message Driven Bean Example 2


1
Message Driven Bean Example 2
  • A DealerBean for Bridge
  • Group 4

2
What a Card Dealer Should Do
  • Shuffle cards
  • Deal cards
  • Be Fair

3
The Model MDB JMS Topic
4
Shuffle Cards Session Bean PublisherBean.java
  • A card a java.net.URL or URI object represents
    the path of a cards images. (http//www.server,
    ldap//ldapserver)
  • A deck of cards a URLs52
  • A shuffled/deal card a Vector contains the 52
    cards image URL objects, which will be randomly
    selected to be removed and sent to the topic.
  • -- why sending the URL objects, not the image
    files?
  • (source code http//www.ecst.csuchico.edu/pc/M
    DB/MDB.htm)

5
Why not just sending image files as messages?
  • The java.io package is prohibited
  • An enterprise bean must not use the java.io
    package to attempt to access files and
    directories in the file system.
  • - EJB 2.0 Specification, Section 24.1.2
    Programming restriction
  • - Portability J2EE Application might not
    be platform depended.
  • - Performance I/O Overhead increased,
    performance decreased.
  • - Security Required security policy
    cannot be enforced.
  • How should an EJB gets/sets its resource
  • - JDBC - URL - JavaMail
    - JMS
  • (Ref EJB 2.0 spec http//java.sun.com/products/ej
    b/docs.html )

6
More on Message Objectcard
  • 3 types of message are suitable for this example
  • TextMessage Send text (java.lang.String) as
    message.
  • textMessage.setText(http//www.myCardServer.edu
    )
  • MapMessage name-value pair message (String,
    Object)
  • mapMessage.setObject(heartA,heartAUrl)
    MessageFormatExcption
  • ObjectMessage Send an object (Serializable) as
    Message.
  • textMessage.setObject(new URL(http//example.e
    du/)

7
Deal Cards Message Driven Bean
  • Displaying cards on a web page (JSP vs. Applet)
  • JSP seems cannot really instantly retrieve the
    message because of the nature of http even with
    auto-reload web page every 5 secs.
  • Applet able to accomplish dynamic/instant
    updating, but must use JApplet, which is not very
    well supported by some browsers. (can be
    overcome, though)
  • An enterprise Bean must not use the AWT
    functionality to attempt to output information to
    display
  • - EJB 2.0 Specification, Section C.1.2
    Programming restrictions

8
How to implement Be Fair
  • While shuffling cards
  • Randomizing by generating java.util.Random or
    java.lang.Math.
  • While dealing card -- Message Delivery Mode
    PERSISTENT
  • Using persistent mode, Once and only once
    delivery guaranteed
  • A JMS provider must deliver a PERSISTENT message
    once-and-only-once. This means a JMS provider
    failure must not cause it to be lost and it must
    not deliver it twice.
    JMS SPEC.
  • (reference http//docs.sun.com/db/doc/816-5904-1
    0)

9
Deployment
  • Add connection Factory and Destination-j2eeadmin
    -addJmsFactory jms/DurableTopicCF topic -props
    clientIDMyID-j2eeadmin -addJmsDestination
    jms/MyTopic topic
  • .ear file source code
  • http//www.ecst.csuchico.edu/pc/BMD/BMD.htmTh
    ank you.
Write a Comment
User Comments (0)
About PowerShow.com