public List<Message> getMessArrivedBySource(Integer idSource) {
   List<Message> list = new ArrayList<Message>();
   for (Message m : getMessageArrives()) {
     if (m.getSource().getId() == idSource) {
       list.add(m);
     }
   }
   return list;
 }
 /* Supposons qu'on a un liste de messages arrives. Definissons:
  * dSi: le date qu'un message i est envoye'
  * dAi: la date qu'un message i est arrive'
  * latence = (sum[0->nbMessTotal](dAi-dSi)/uniteTemps(source qui envoie message i))/nbMessTotal
  */
 public void calculLatence() {
   double temp = 0;
   for (Message m : getMessageArrives()) {
     temp +=
         (m.getDateMessDelivre() - m.getDate())
             / getUniteTemps(m.getSource().getId(), m.getTaille());
   }
   setLatence(temp / (getSequencer().getBuffer().size()));
 }
  /* Calculer le debit du reseau
   * Debit Total = sum (debit sur chaque machine)
   */
  public void calculateDebit() {
    Map<Integer, Integer> nbMessEachSource = new HashMap<Integer, Integer>();
    Map<Integer, Double> sumEachSource = new HashMap<Integer, Double>();
    for (int i = 0; i < getNbMachines(); i++) {
      nbMessEachSource.put(i, 1);
      sumEachSource.put(i, 1.0);
    }

    for (Message m : getMessageArrives()) {
      int temp1 = nbMessEachSource.get(m.getSource().getId());
      double temps2 = sumEachSource.get(m.getSource().getId());
      temp1 += 1;
      temps2 +=
          (m.getDateMessDelivre() - m.getDate())
              / getUniteTemps(m.getSource().getId(), m.getSource().getCapacCarte());
      nbMessEachSource.put(m.getSource().getId(), temp1);
      sumEachSource.put(m.getSource().getId(), temps2);
    }

    double debit = 0;
    for (int i = 0; i < getNbMachines(); i++) {
      debit += nbMessEachSource.get(i) / sumEachSource.get(i);
    }
    setDebit(debit);
  }
 public void sendMulticast(
     Machine source, List<Machine> destinations, double taille, double date) {
   source.incrementerNbMessSend();
   Message mess = new Message(source, destinations, TypeMessage.MULTICAST, taille, date);
   // Kiem tra may co ranh de cho gui hay khong
   if (source.getMomentAvaiableToSend() > mess.getDate()) { // ko ranh
     mess.setDate(source.getMomentAvaiableToSend());
   }
   source.setMomentAvaiableToSend(mess.getDate() + mess.getTaille() / source.getCapacCarte());
   getSequencer().addMessToBuffer(mess);
 }
Пример #5
0
  public static Message readFileLocally(String filePath) {

    byte[] data = SerializationHelper.getBytesFromFile(filePath);

    Message msg = new Message(OPERATION.READ_FILE, SENDER.CHUNK_SERVER, filePath);

    if (data == null) msg.retValue = Retval.NOT_FOUND;
    else msg.retValue = Retval.OK;

    msg.bytes = data;

    return msg;
  }
 public void send(Message mess) {
   mess.getSource().incrementerNbMessSend();
   if (mess.getSource().getMomentAvaiableToSend() > mess.getDate()) {
     mess.setDate(mess.getSource().getMomentAvaiableToSend());
   }
   mess.getSource()
       .setMomentAvaiableToSend(
           mess.getDate() + mess.getTaille() / mess.getSource().getCapacCarte());
   getSequencer().addMessToBuffer(mess);
 }
Пример #7
0
 /**
  * Puts a message in the database Note: the timestamp will be stored as the current time at which
  * this method is called.
  */
 public void storeMessage(Message message) {
   con.updateDB(
       "INSERT INTO "
           + MESSAGES
           + " VALUES ( \""
           + message.getFrom()
           + "\", \""
           + message.getTo()
           + "\", \""
           + message.getBody()
           + "\", "
           + null
           + ", "
           + message.getType()
           + ")");
 }
 public void deliverAMessage(int nbSequence, int idDestinationMachine) {
   // Remove message from buffer
   Message m = this.machinesDefault[idDestinationMachine].removeMessFromBuffer(nbSequence);
   if (this.machinesDefault[idDestinationMachine].getMomentAvaiableToReceive()
       < (m.getDate() + getTempsPropa())) {
     this.machinesDefault[idDestinationMachine].setMomentAvaiableToReceive(
         getUniteTemps(m, this.machinesDefault[idDestinationMachine]));
   } else {
     this.machinesDefault[idDestinationMachine].setMomentAvaiableToReceive(
         getMachine(idDestinationMachine).getMomentAvaiableToReceive()
             + m.getTaille() / getMachine(idDestinationMachine).getCapacCarte());
   }
   m.setDateMessDelivre(getMachine(idDestinationMachine).getMomentAvaiableToReceive());
   System.out.println(
       "*****************Delivred a messages in destination machine "
           + idDestinationMachine
           + " ********************\n"
           + m.toString());
   this.messageArrives.add(m);
 }
Пример #9
0
  /**
   * Lit sur le flux d'entrée {@code in} le bon nombre d'octet pour renvoyer le {@link Message}
   * correspondant.
   *
   * @param in Le flux d'entrée sur lequel on lit.
   * @return Le MessageHeader lu.
   * @throws IOException
   */
  public static Message readMessage(InputStream in) throws IOException {
    MessageHeader msgH = readMessageHeader(in);
    int l = msgH.getPayloadLength();

    int n = 0;
    int readBytesNb;
    byte[] bTab = new byte[l];
    while (n != l) {
      readBytesNb = in.read(bTab, n, l - n);
      if (readBytesNb == -1) throw new IOException();
      n += readBytesNb;
    }
    short[] sTab = toShortTable(bTab);

    Message msg = Message.parseMessage(msgH, sTab);

    return msg;
  }
 public double getUniteTemps(Message m, Machine machine) {
   return getTempsPropa() + m.getTaille() / machine.getCapacCarte() + m.getDate();
 }
Пример #11
0
 /**
  * Envoie vers le flux de sortie {@code out} le message {@code m}.
  *
  * @param out Le flux de sortie vers lequel on envoie le message.
  * @param m Le message à envoyer.
  * @throws IOException
  */
 public static void sendMessage(OutputStream out, Message m) throws IOException {
   out.write(toByteTable(m.toShortTab()));
   out.flush();
 }