Examples of AckMsg


Examples of org.nasutekds.server.replication.protocol.AckMsg

    }

    if (preparedAssuredInfo.expectedServers == null)
    {
      // No eligible servers found, send the ack immediately
      AckMsg ack = new AckMsg(cn);
      sourceHandler.sendAck(ack);
    }

    return preparedAssuredInfo;
  }
View Full Code Here

Examples of org.nasutekds.server.replication.protocol.AckMsg

            /**
             * Immediately return the ack for an assured message in safe data
             * mode with safe data level 1, coming from a DS. No need to wait
             * for more acks
             */
            AckMsg ack = new AckMsg(cn);
            sourceHandler.sendAck(ack);
          } else
          {
            if (safeDataLevel != (byte) 0)
            {
              /**
               * level > 1 : We need further acks
               * The message will be posted in assured mode to eligible
               * servers. The embedded safe data level is not changed, and his
               * value will be used by a remote RS to determine if he must send
               * an ack (level > 1) or not (level = 1)
               */
              interestedInAcks = true;
            } else
            {
              // Should never happen
            }
          }
        } else
        { // A RS sent us the safe data message, for sure no further ack to wait
          if (safeDataLevel == (byte) 1)
          {
            /**
             * The original level was 1 so the RS that sent us this message
             * should have already sent his ack to the sender DS. Level 1 has
             * already been reached so no further acks to wait.
             * This should not happen in theory as the sender RS server should
             * have sent us a matching not assured message so we should not come
             * to here.
             */
          } else
          {
            // level > 1, so Ack this message to originator RS
            AckMsg ack = new AckMsg(cn);
            sourceHandler.sendAck(ack);
          }
        }
      }
    }

    List<Integer> expectedServers = new ArrayList<Integer>();
    if (interestedInAcks)
    {
      if (sourceHandler.isDataServer())
      {
        // Look for RS eligible for assured
        for (ReplicationServerHandler handler : replicationServers.values())
        {
          if (handler.getGroupId() == groupId)
            // No ack expected from a RS with different group id
          {
            if ((generationId > 0) &&
              (generationId == handler.getGenerationId()))
              // No ack expected from a RS with bad gen id
            {
              expectedServers.add(handler.getServerId());
            }
          }
        }
      }
    }

    // Return computed structures
    PreparedAssuredInfo preparedAssuredInfo = new PreparedAssuredInfo();
    int nExpectedServers = expectedServers.size();
    if (interestedInAcks) // interestedInAcks so level > 1
    {
      if (nExpectedServers > 0)
      {
        // Some other acks to wait for
        int sdl = update.getSafeDataLevel();
        int neededAdditionalServers = sdl - 1;
        // Change the number of expected acks if not enough available eligible
        // servers: the level is a best effort thing, we do not want to timeout
        // at every assured SD update for instance if a RS has had his gen id
        // reseted
        byte finalSdl = ((nExpectedServers >= neededAdditionalServers) ?
          (byte)sdl : // Keep level as it was
          (byte)(nExpectedServers+1)); // Change level to match what's available
        preparedAssuredInfo.expectedAcksInfo = new SafeDataExpectedAcksInfo(cn,
          sourceHandler, finalSdl, expectedServers);
        preparedAssuredInfo.expectedServers = expectedServers;
      } else
      {
        // level > 1 and source is a DS but no eligible servers found, send the
        // ack immediately
        AckMsg ack = new AckMsg(cn);
        sourceHandler.sendAck(ack);
      }
    }

    return preparedAssuredInfo;
View Full Code Here

Examples of org.nasutekds.server.replication.protocol.AckMsg

         */
        if (expectedAcksInfo.processReceivedAck(ackingServer, ack))
        {
          // Remove the object from the map as no more needed
          waitingAcks.remove(cn);
          AckMsg finalAck = expectedAcksInfo.createAck(false);
          ServerHandler origServer = expectedAcksInfo.getRequesterServer();
          try
          {
            origServer.sendAck(finalAck);
          } catch (IOException e)
View Full Code Here

Examples of org.nasutekds.server.replication.protocol.AckMsg

  /**
   * {@inheritDoc}
   */
  public AckMsg createAck(boolean timeout)
  {
    AckMsg ack = new AckMsg(changeNumber);

    if (timeout)
    {
      // Fill collected errors info
      ack.setHasTimeout(true);
      // Tell wich servers did not send an ack in time
      List<Integer> failedServers = new ArrayList<Integer>();
      Set<Integer> serverIds = expectedServersAckStatus.keySet();
      serversInTimeout = new ArrayList<Integer>(); // Use next loop to fill it
      for (Integer serverId : serverIds)
      {
        boolean ackReceived = expectedServersAckStatus.get(serverId);
        if (!ackReceived)
        {
          failedServers.add(serverId);
          serversInTimeout.add(serverId);
        }
      }
      ack.setFailedServers(failedServers);
    }

    return ack;
  }
View Full Code Here

Examples of org.nasutekds.server.replication.protocol.AckMsg

          if (!(msg instanceof HeartbeatMsg))
            TRACER.debugVerbose("Message received <" + msg + ">");

        if (msg instanceof AckMsg)
        {
          AckMsg ack = (AckMsg) msg;
          receiveAck(ack);
        }
        else if (msg instanceof InitializeRequestMsg)
        {
          // Another server requests us to provide entries
View Full Code Here

Examples of org.nasutekds.server.replication.protocol.AckMsg

        if (msgAssuredMode == AssuredMode.SAFE_READ_MODE)
        {
          if (rsGroupId == groupId)
          {
            // Send the ack
            AckMsg ackMsg = new AckMsg(msg.getChangeNumber());
            if (replayErrorMsg != null)
            {
              // Mark the error in the ack
              //   -> replay error occured
              ackMsg.setHasReplayError(true);
              //   -> replay error occured in our server
              List<Integer> idList = new ArrayList<Integer>();
              idList.add(serverID);
              ackMsg.setFailedServers(idList);
            }
            broker.publish(ackMsg);
            if (replayErrorMsg != null)
            {
              assuredSrReceivedUpdatesNotAcked.incrementAndGet();
View Full Code Here

Examples of org.nasutekds.server.replication.protocol.AckMsg

  /**
   * {@inheritDoc}
   */
  public AckMsg createAck(boolean timeout)
  {
    AckMsg ack = new AckMsg(changeNumber);

    // Fill collected errors info
    ack.setHasTimeout(hasTimeout);
    ack.setHasWrongStatus(hasWrongStatus);
    ack.setHasReplayError(hasReplayError);

    if (timeout)
    {
      // Force anyway timeout flag if requested
      ack.setHasTimeout(true);

      // Add servers that did not respond in time
      Set<Integer> serverIds = expectedServersAckStatus.keySet();
      serversInTimeout = new ArrayList<Integer>(); // Use next loop to fill it
      for (int serverId : serverIds)
      {
        boolean ackReceived = expectedServersAckStatus.get(serverId);
        if (!ackReceived)
        {
          if (!failedServers.contains(serverId))
          {
            failedServers.add(serverId);
            serversInTimeout.add(serverId);
          }
        }
      }
    }

    ack.setFailedServers(failedServers);

    return ack;
  }
View Full Code Here

Examples of org.openhab.binding.maxcul.internal.messages.AckMsg

      messageHandler.sendPairPong(devAddr, this);
      state = PairingInitialisationState.PONG_ACKED;
      break;
    case PONG_ACKED:
      if (msg.msgType == MaxCulMsgType.ACK) {
        AckMsg ack = new AckMsg(msg.rawMsg);
        if (!ack.getIsNack()) {
          if (this.deviceType == MaxCulDevice.PUSH_BUTTON) {
            /* for a push button we're done now */
            state = PairingInitialisationState.FINISHED;
          } else {
            /* send group id information */
            logger.debug("Sending GROUP_ID");
            messageHandler.sendSetGroupId(devAddr, group_id, this);
            state = PairingInitialisationState.GROUP_ID_ACKED;
          }
        } else {
          logger.error("PAIR_PONG was nacked. Ending sequence");
          state = PairingInitialisationState.FINISHED;
        }
      } else {
        logger.error("Received " + msg.msgType + " when expecting ACK");
      }
      break;
    case GROUP_ID_ACKED:
      if (msg.msgType == MaxCulMsgType.ACK) {
        AckMsg ack = new AckMsg(msg.rawMsg);
        if (!ack.getIsNack()
            && (this.deviceType == MaxCulDevice.RADIATOR_THERMOSTAT
                || this.deviceType == MaxCulDevice.WALL_THERMOSTAT || this.deviceType == MaxCulDevice.RADIATOR_THERMOSTAT_PLUS)) {
          // send temps for comfort/eco etc
          messageHandler.sendConfigTemperatures(devAddr, this,
              config.getComfortTemp(), config.getEcoTemp(),
              config.getMaxTemp(), config.getMinTemp(),
              config.getMeasurementOffset(),
              config.getWindowOpenTemperature(),
              config.getWindowOpenDuration());
          state = PairingInitialisationState.CONFIG_TEMPS_ACKED;
        } else {
          logger.error("SET_GROUP_ID was nacked. Ending sequence");
          state = PairingInitialisationState.FINISHED;
        }
      } else {
        logger.error("Received " + msg.msgType + " when expecting ACK");
      }
      break;
    case CONFIG_TEMPS_ACKED:
      if (msg.msgType == MaxCulMsgType.ACK) {
        AckMsg ack = new AckMsg(msg.rawMsg);
        if (!ack.getIsNack()) {

          /*
           * associate device with us so we get updates - we pretend
           * to be the MAX! Cube
           */
          messageHandler.sendAddLinkPartner(devAddr, this,
              msg.dstAddrStr, MaxCulDevice.CUBE);

          /*
           * if there are more associations to come then set up
           * iterator and goto state to transmit more associations
           */
          if (associations.isEmpty() == false) {
            assocIter = associations.iterator();
            state = PairingInitialisationState.SENDING_ASSOCIATIONS;
          } else {
            logger.debug("No user configured associations");
            state = PairingInitialisationState.SENDING_ASSOCIATIONS_ACKED;
          }
        } else {
          logger.error("CONFIG_TEMPERATURES was nacked. Ending sequence");
          state = PairingInitialisationState.FINISHED;
        }
      } else {
        logger.error("Received " + msg.msgType + " when expecting ACK");
      }
      break;
    case SENDING_ASSOCIATIONS:
      if (msg.msgType == MaxCulMsgType.ACK) {
        AckMsg ack = new AckMsg(msg.rawMsg);
        if (!ack.getIsNack()) {
          if (assocIter.hasNext()) /*
                       * this should always be true, but
                       * good to check
                       */
          {
            MaxCulBindingConfig partnerCfg = assocIter.next();
            messageHandler.sendAddLinkPartner(this.devAddr, this,
                partnerCfg.getDevAddr(),
                partnerCfg.getDeviceType());
            /*
             * if it's the last association message then wait for
             * last ACK
             */
            if (assocIter.hasNext()) {
              state = PairingInitialisationState.SENDING_ASSOCIATIONS;
            } else {
              state = PairingInitialisationState.SENDING_ASSOCIATIONS_ACKED;
            }
          } else {
            // TODO NOTE: if further states are added then ensure
            // you go to the right state. I.e. when all associations
            // are done
            state = PairingInitialisationState.FINISHED;
          }
        } else {
          logger.error("SENDING_ASSOCIATIONS was nacked. Ending sequence");
          state = PairingInitialisationState.FINISHED;
        }
      } else {
        logger.error("Received " + msg.msgType + " when expecting ACK");
      }
      break;
    case SENDING_ASSOCIATIONS_ACKED:
      state = PairingInitialisationState.FINISHED;
      break;
    case SENDING_WEEK_PROFILE:
      // TODO implement this - but where to get a week profile from.
      // Meaningless at the moment!
      state = PairingInitialisationState.FINISHED;
      break;
    case FINISHED:
      /* done, do nothing */
      break;
    case RETX_WAKEUP_ACK:
      /* here are waiting for an ACK after sending a wakeup message */
      if (msg.msgType == MaxCulMsgType.ACK) {
        AckMsg ack = new AckMsg(msg.rawMsg);
        if (!ack.getIsNack()) {
          logger.debug("Attempt retransmission - resuming");
          this.useFast = true;
          messageHandler.sendMessage(reTxMsg);
          state = reTxState; // resume back to previous state
        } else {
View Full Code Here

Examples of org.openhab.binding.maxcul.internal.messages.AckMsg

      break;
    case SET_TEMPERATURE:
      new SetTemperatureMsg(data).printMessage();
      break;
    case ACK:
      new AckMsg(data).printMessage();
      break;
    case PAIR_PING:
      new PairPingMsg(data).printMessage();
      break;
    case PAIR_PONG:
View Full Code Here

Examples of org.openhab.binding.maxcul.internal.messages.AckMsg

      }
      break;
    case HANDLE_RESPONSE:
      /* check for ACK */
      if (msg.msgType == MaxCulMsgType.ACK) {
        AckMsg ack = new AckMsg(msg.rawMsg);
        if (ack.getIsNack()) {
          logger.error("TIME_INFO was nacked. Ending sequence");
          state = TimeUpdateRequestState.FINISHED;
        } else
          state = TimeUpdateRequestState.FINISHED;
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.