KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > event > MessageEvent


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

31 package org.objectweb.proactive.core.event;
32
33 import org.objectweb.proactive.core.UniqueID;
34 import org.objectweb.proactive.core.body.message.Message;
35
36 /**
37  * <p>
38  * A <code>MessageEvent</code> occurs when a <code>Message</code> get sent or received or
39  * when the treatment of a request begins or ends.
40  * </p>
41  *
42  * @see org.objectweb.proactive.core.body.message.Message
43  * @author ProActive Team
44  * @version 1.0, 2001/10/23
45  * @since ProActive 0.9
46  *
47  */

48 public class MessageEvent extends ProActiveEvent implements Message, java.io.Serializable JavaDoc {
49   
50   /** constant indicating the encapsulated message has been sent */
51   public static final int REQUEST_SENT = 10;
52   /** constant indicating the encapsulated message has been received */
53   public static final int REQUEST_RECEIVED = 20;
54   /** constant indicating the encapsulated message has been sent */
55   public static final int REPLY_SENT = 30;
56   /** constant indicating the encapsulated message has been received */
57   public static final int REPLY_RECEIVED = 40;
58   /** constant indicating the encapsulated request without reply has been served */
59   public static final int VOID_REQUEST_SERVED = 50;
60   /** constant indicating that the serving of the encapsulated request has started */
61   public static final int SERVING_STARTED = 60;
62
63   protected UniqueID destinationID;
64   
65   /** Length of the request queue of the body that sends this event or -1
66    * if this message did not affect the request queue length. */

67   protected int requestQueueLength;
68   
69   /**
70    * Creates a new <code>MessageEvent</code> based on the message
71    * <code>message</code> and on the given action
72    * @param <code>message</code> the message on which this event is based.
73    * @param <code>messageActionType</code> the type of the action occuring with
74    * this message either REQUEST_SENT/RECEIVED, REPLY_SENT/RECEIVED,
75    * VOID_REQUEST_SERVED or SERVING_STARTED.
76    * @param <code>requestQueueLength</code> the length of the request queue of the
77    * body that sends this event or -1 if this event did not affect the queue length.
78    */

79   public MessageEvent(Message message, int messageActionType, UniqueID destinationID,
80             int requestQueueLength) {
81     super(message, messageActionType);
82     this.destinationID = destinationID;
83     this.requestQueueLength = requestQueueLength;
84   }
85   
86
87   //
88
// -- PUBLIC METHODS -----------------------------------------------
89
//
90

91   /**
92    * Returns the id of the body receiver of the encapsulated message.
93    * For a VOID_REQUEST_SERVED message, this is the destination body of the
94    * encapsulated request, i.e. the body that sends this event!
95    * @return the id of the body receiver of the encapsulated message
96    */

97   public UniqueID getDestinationBodyID() {
98     return destinationID;
99   }
100   
101     /**
102      * Returns the length of the request queue of the sending body or -1.
103      * @return the length of the request queue of the sending body or -1.
104      */

105   public int getRequestQueueLength() {
106         return requestQueueLength;
107   }
108   
109   /**
110    * Returns a string representation of this event
111    * @return a string representation of this event
112    */

113   public String JavaDoc toString() {
114     return "methodName="+getMethodName()+" sourceID="+getSourceBodyID()+" destinationID="+getDestinationBodyID()+" sequenceNumber="+getSequenceNumber();
115   }
116   
117   public boolean wasSent() {
118     return type == REQUEST_SENT || type == REPLY_SENT;
119   }
120   
121   //
122
// -- implements Message -----------------------------------------------
123
//
124

125   public UniqueID getSourceBodyID() {
126     return getMessage().getSourceBodyID();
127   }
128
129   public String JavaDoc getMethodName() {
130     return getMessage().getMethodName();
131   }
132
133   public long getSequenceNumber() {
134     return getMessage().getSequenceNumber();
135   }
136
137   public boolean isOneWay() {
138     return getMessage().isOneWay();
139   }
140
141
142   //
143
// -- PRIVATE METHODS -----------------------------------------------
144
//
145

146   private final Message getMessage() {
147     return (Message) getSource();
148   }
149
150 }
Popular Tags