Universität Paderborn - Home Universität Paderborn
Die Universität der Informationsgesellschaft

Parallel Programming WS 2014/2015 - File Message.java

public class Message
{
   public static final int DUMMY = 0;  // marks a dummy message (PPJ-74)
   public static final int PROBE = 1;  // marks a probe message (PPJ-74)
   public static final int ECHO  = 2;  // marks an echo message (PPJ-74)
   
   private int kind;          // discriminates different kinds of messages
   private Node sender;       // the sending node
   private int value;         // value passed in the message
   
   // construct a message
   private Message (Node sender, int kind, int value)
   {
      this.sender = sender;
      this.kind = kind;
      this.value = value;
   }
   
   // factory methods for building specific kinds of messages
   public static Message createDummy (Node sender)
   { return new Message(sender, DUMMY, 0); }
   
   public static Message createProbe (Node sender)
   { return new Message(sender, PROBE, 0); }

   public static Message createEcho (Node sender, int value)
   { return new Message(sender, ECHO, value); }

   // retrieve the kind of this message (DUMMY, PROBE or ECHO)
   public int getKind ()
   { return kind; }
   
   // retrieve the sending node
   public Node getSender ()
   { return sender; }

   // retrieve the value passed in this message
   // only valid for messages of kind ECHO
   public int getValue ()
   {
      if (kind != ECHO)
         throw new IllegalArgumentException("only ECHO messages carry a value");
      return value;
   }
}

Generiert mit Camelot | Probleme mit Camelot? | Geändert am: 02.02.2015