<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Let's go inside

    this blog is deprecated as a result of laziness.
    posts - 59, comments - 2, trackbacks - 0, articles - 0

    TrailBlazer第7天--MDB

    Posted on 2006-07-27 14:24 Earth 閱讀(218) 評(píng)論(0)  編輯  收藏 所屬分類: JavaEE5/EJB3

    The JMS clients send messages to message queues managed by the server (e.g., an email inbox can be a message queue). The message queues are monitored by a special kind of EJBs --Message Driven Beans (MDBs). The MDB processes the incoming messages and perform the services requested by the message. The MDBs are the end-point for JMS service request messages.
    JMS客戶端向消息隊(duì)列(比如收件箱)發(fā)送消息。
    消息隊(duì)列(收件箱)由MDB監(jiān)視,MDB處理進(jìn)來(lái)的消息并提供消息所需要的服務(wù)

    In this trail, the investment calculator application is refactored to use a Message Driven Bean. When you click on the "Calculate" button on the web form, the JSP page (calculator.jsp) sends a message containing the calculation parameters to a message queue. It then forwards to another JSP page (check.jsp) to periodically check whether the calculation result becomes available.
    當(dāng)你點(diǎn)擊頁(yè)面中的Calculate按鈕時(shí),JSP會(huì)把含有計(jì)算所需參數(shù)的信息發(fā)送到一個(gè)消息隊(duì)列,然后頁(yè)面跳轉(zhuǎn)到check.jsp, check.jsp不斷刷新自己以定期檢查計(jì)算結(jié)果是否可用。

    The message queue is monitored by a MDB, which retrieves the incoming message, parses its contents, and performs the calculation. After the calculation is done, the MDB saves the result to an application-wide shared cache. The result is then picked up and displayed by the result-monitoring JSP page (i.e., check.jsp).
    該消息隊(duì)列由一個(gè)MDB監(jiān)控,當(dāng)它檢索到一條消息后,解析消息內(nèi)容,然后進(jìn)行計(jì)算,然后把計(jì)算 結(jié)果放在application中。最后這個(gè)結(jié)果被check.jsp捕獲并顯示。

    1。監(jiān)聽(tīng)器 The Message Driven Beans

    @MessageDriven(activationConfig? =
    {
    ??@ActivationConfigProperty(propertyName
    = " destinationType " ,
    ????propertyValue
    = " javax.jms.Queue " ),
    ??@ActivationConfigProperty(propertyName
    = " destination " ,
    ????propertyValue
    = " queue/mdb " )
    })
    public ? class ?CalculatorBean? implements ?MessageListener?{

    ??
    public ? void ?onMessage?(Message?msg)?{
    ????
    try ?{
    ??????TextMessage?tmsg?
    = ?(TextMessage)?msg;
    ??????Timestamp?sent?
    =
    ??????????
    new ?Timestamp(tmsg.getLongProperty( " sent " ));
    ??????StringTokenizer?st?
    =
    ??????????
    new ?StringTokenizer(tmsg.getText(),? " , " );

    ??????
    int ?start? = ?Integer.parseInt(st.nextToken());
    ??????
    int ?end? = ?Integer.parseInt(st.nextToken());
    ??????
    double ?growthrate? = ?Double.parseDouble(st.nextToken());
    ??????
    double ?saving? = ?Double.parseDouble(st.nextToken());

    ??????
    double ?result? =
    ??????????calculate?(start,?end,?growthrate,?saving);
    ??????RecordManager.addRecord?(sent,?result);

    ????}?
    catch ?(Exception?e)?{
    ??????e.printStackTrace?();
    ????}
    ??}
    }

    MDB用@MessageDriven標(biāo)注
    destinationType 表示所監(jiān)聽(tīng)的消息的類型
    destination 表示所監(jiān)聽(tīng)的消息隊(duì)列的名字(比如queue/mdb)
    如果這個(gè)隊(duì)列并不存在, JBoss會(huì)在deploy的時(shí)候自動(dòng)創(chuàng)建一個(gè),所以不需要XML配置文件!


    2。在客戶端的使用

    ? <% @?page? import = " trail.mdb.*,?javax.naming.*,?java.text.*,
    ??????????????????javax.jms. * ,
    ??????????????????java.sql.Timestamp
    " %>
    ?
    ?
    <%
    ???
    if ?( " send " .equals(request.getParameter?( " action " )))?{
    ?
    ?????QueueConnection?cnn?
    = ? null ;
    ?????QueueSender?sender?
    = ? null ;
    ?????QueueSession?sess?
    = ? null ;
    ?????Queue?queue?
    = ? null ;
    ?
    ?????
    try ?{
    ???????InitialContext?ctx?
    = ? new ?InitialContext();
    ???????queue?
    = ?(Queue)?ctx.lookup( " queue/mdb " );
    ???????QueueConnectionFactory?factory?
    =
    ???????????(QueueConnectionFactory)?ctx.lookup(
    " ConnectionFactory " );
    ???????cnn?
    = ?factory.createQueueConnection();
    ???????sess?
    = ?cnn.createQueueSession( false ,
    ???????????????????QueueSession.AUTO_ACKNOWLEDGE);
    ?
    ?????}?
    catch ?(Exception?e)?{
    ???????e.printStackTrace?();
    ?????}
    ?
    ?????TextMessage?msg?
    = ?sess.createTextMessage(
    ?????????request.getParameter?(
    " start " )? + ? " , " ? +
    ?????????request.getParameter?(
    " end " )? + ? " , " ? +
    ?????????request.getParameter?(
    " growthrate " )? + ? " , " ? +
    ?????????request.getParameter?(
    " saving " )
    ?????);
    ?????
    // ?The?sent?timestamp?acts?as?the?message's?ID
    ????? long ?sent? = ?System.currentTimeMillis();
    ?????msg.setLongProperty(
    " sent " ,?sent);
    ?
    ?????sender?
    = ?sess.createSender(queue);
    ?????sender.send(msg);
    ?????
    // ?sess.commit?();
    ?????sess.close?();
    ?
    %>

    To use the message driven bean, the client (i.e, JSP page calculator.jsp in this case) use the standard JMS API to obtain the target message queue to the MDB using the queue name (queue/mdb), and then send the message to the queue.

    to be continued

    主站蜘蛛池模板: 免费毛片在线看不用播放器| 无人在线观看免费高清| 亚洲区小说区图片区QVOD| 中文字幕免费视频| 亚洲av无码日韩av无码网站冲| JLZZJLZZ亚洲乱熟无码| 永久黄色免费网站| 曰批免费视频播放在线看片二| 久久精品国产亚洲夜色AV网站| 最近中文字幕mv手机免费高清| 国产三级在线免费观看| 性xxxx黑人与亚洲| 亚洲精品无码专区在线在线播放| 成年在线观看网站免费| aaa毛片免费观看| 亚洲精品精华液一区二区| 久久久无码精品亚洲日韩蜜桃| 在线免费观看一级片| 91禁漫免费进入| 国产精品无码免费专区午夜| 亚洲天堂一区在线| 国产亚洲综合一区柠檬导航| 免费大黄网站在线观看| 亚洲免费福利在线视频| 亚洲精品无码MV在线观看| 波多野结衣一区二区免费视频| 免费专区丝袜脚调教视频| 99久久免费国产特黄| 国产AV无码专区亚洲AV琪琪| 亚洲精品在线不卡| 亚洲国产第一站精品蜜芽| 亚洲第一区精品日韩在线播放| 最近中文字幕免费mv视频8| 日韩电影免费在线观看中文字幕 | 免费夜色污私人影院网站电影| 亚洲成人午夜电影| 亚洲AV无码一区二区三区DV | 国产成人免费永久播放视频平台| 亚洲一区免费视频| 99久久免费精品视频| 日本免费污片中国特一级|