KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > jbi > serviceengine > comm > MessageReceiver


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.jbi.serviceengine.comm;
24
25 import com.sun.enterprise.jbi.serviceengine.work.WorkManager;
26 import com.sun.enterprise.jbi.serviceengine.work.OneWork;
27 import java.util.logging.Level JavaDoc;
28 import java.util.logging.Logger JavaDoc;
29
30 /**
31  * An instance of this class is used to receive a
32  * reply for a 2-way message exchane from NMR.
33  * The object that need to receive the message calls receive()
34  * on the instance of this class, after setting MessageExchange.
35  * receive() method will block until MessageAcceptor releases it
36  * when it receives a reply for the MEP.
37  *
38  * Typically MessageReceiver.receive() is called on the application
39  * thread.
40  *
41  * @author Binod PG
42  */

43 public class MessageReceiver extends OneWork {
44
45     /**
46      * Just calls doWork()
47      */

48     public void receive() {
49         execute();
50     }
51
52     /**
53      * MessageAcceptor executes this method to notify the waiting
54      * thread about the arrival of reply message.
55      */

56     public void release() {
57         synchronized (this) {
58             notify();
59         }
60     }
61
62     /**
63      * Register the receiver with MessageAcceptor and waits for
64      * the reply/notification.
65      */

66     public void doWork() {
67         MessageAcceptor acceptor = getWorkManager().getMessageAcceptor();
68         acceptor.register(this);
69
70         synchronized (this) {
71             try {
72                 wait();
73             } catch (InterruptedException JavaDoc ie) {
74                 setException(ie);
75             }
76         }
77     }
78
79 }
80
81
Popular Tags