KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > ic2d > spy > SpyMessageEvent


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.ic2d.spy;
32
33 import org.objectweb.proactive.core.UniqueID;
34 import org.objectweb.proactive.core.event.MessageEvent;
35
36 public class SpyMessageEvent extends SpyEvent implements java.io.Serializable JavaDoc {
37   
38   /** The name of the method called */
39   protected String JavaDoc methodName;
40   
41   /** The UniqueID of the body sending the call */
42   protected UniqueID sourceID;
43
44   /** The UniqueID of the body receiving the call */
45   protected UniqueID destinationID;
46
47   /** The unique sequence number for the call */
48   protected long sequenceNumber;
49   
50   /** The request queue length of the body that sent the event or -1 */
51   protected int requestQueueLength;
52
53
54   public SpyMessageEvent(int eventType, MessageEvent message) {
55     super(eventType, (message.wasSent()) ? message.getSourceBodyID() : message.getDestinationBodyID());
56     this.methodName = message.getMethodName();
57     this.sourceID = message.getSourceBodyID();
58     this.destinationID = message.getDestinationBodyID();
59     this.sequenceNumber = message.getSequenceNumber();
60     this.requestQueueLength = message.getRequestQueueLength();
61   }
62   
63   public String JavaDoc toString() {
64     return super.toString()+" methodName="+methodName+" requestQueue="+requestQueueLength;
65   }
66   
67   /**
68    * Return the id of the sender of the request
69    */

70   public UniqueID getSourceBodyID() {
71     return sourceID;
72   }
73
74
75   public String JavaDoc getMethodName() {
76     return methodName;
77   }
78
79
80   public long getSequenceNumber() {
81     return sequenceNumber;
82   }
83
84
85   public UniqueID getDestinationBodyID() {
86     return destinationID;
87   }
88
89   public int getRequestQueueLength() {
90      return requestQueueLength;
91   }
92
93   /** Returns whether the body that created the event sent the message included in the event
94    * or received it. */

95   public boolean wasSent() {
96     return type == REPLY_SENT_MESSAGE_TYPE || type == REQUEST_SENT_MESSAGE_TYPE;
97   }
98
99   /** Returns true if the event was created when a request was sent or received. */
100   public boolean isRequestMessage() {
101     return type == REQUEST_SENT_MESSAGE_TYPE || type == REQUEST_RECEIVED_MESSAGE_TYPE;
102   }
103
104   /** Returns true if the event was created when a reply was sent or received or a void request was finished. */
105   public boolean isReplyMessage() {
106     return type == REPLY_SENT_MESSAGE_TYPE || type == REPLY_RECEIVED_MESSAGE_TYPE ||
107             type == VOID_REQUEST_SERVED_TYPE;
108   }
109
110   /** Returns whether matching event belongs to the same Qsend Qrecv Rsend Rrecv set */
111   public boolean matches(SpyMessageEvent matchingEvent) {
112     if (matchingEvent.sequenceNumber != sequenceNumber) return false;
113     if (! matchingEvent.methodName.equals(methodName)) return false;
114     if ( (matchingEvent.sourceID.equals(sourceID) && matchingEvent.destinationID.equals(destinationID))
115          || (matchingEvent.sourceID.equals(destinationID) && matchingEvent.destinationID.equals(sourceID)) )
116        return true;
117     return false;
118   }
119   
120 }
Popular Tags