protected boolean interpolatePath() {
   long timeNow = System.currentTimeMillis();
   PathLocAndDir locAndDir = pathState.interpolatePath(timeNow);
   long oid = obj.getOid();
   //         if (locAndDir != null) {
   //             if (Log.loggingDebug) {
   //                 Log.debug("BaseBehavior.interpolatePath: oid = " + oid + "; loc = " +
   // locAndDir.getLoc() + "; dir = " + locAndDir.getDir());
   //             }
   //         }
   //         else {
   //             if (Log.loggingDebug)
   //                 Log.debug("BaseBehavior.interpolatePath: oid = " + oid + "; locAndDir is
   // null");
   //         }
   if (locAndDir == null) {
     // We have arrived - - turn off interpolation, and cancel that path
     interpolatingPath = false;
     if (Log.loggingDebug)
       Log.debug(
           "BaseBehavior.interpolatePath: cancelling path: oid = "
               + oid
               + "; myLoc = "
               + obj.getWorldNode().getLoc());
     cancelPathInterpolator(oid);
     obj.getWorldNode().setDir(new MVVector(0, 0, 0));
   } else {
     obj.getWorldNode()
         .setPathInterpolatorValues(
             timeNow, locAndDir.getDir(), locAndDir.getLoc(), locAndDir.getOrientation());
     MobManagerPlugin.getTracker(obj.getInstanceOid()).updateEntity(obj);
   }
   return interpolatingPath;
 }
Example #2
0
 /** Initializes a random variable */
 private void createRandom() {
   this.random =
       new Random(
           System.currentTimeMillis()
               + Thread.currentThread().getId()
               - Thread.currentThread().hashCode()
               + this.cname.hashCode());
 }
 protected long setupPathInterpolator(
     long oid, Point myLoc, Point dest, boolean follow, boolean followsTerrain) {
   long timeNow = System.currentTimeMillis();
   WorldManagerClient.MobPathReqMessage reqMsg =
       pathState.setupPathInterpolator(timeNow, myLoc, dest, mobSpeed, follow, followsTerrain);
   if (reqMsg != null) {
     try {
       Engine.getAgent().sendBroadcast(reqMsg);
       if (Log.loggingDebug)
         Log.debug("BaseBehavior.setupPathInterpolator: send MobPathReqMessage " + reqMsg);
     } catch (Exception e) {
       throw new RuntimeException(e);
     }
     interpolatingPath = true;
     return pathState.pathTimeRemaining();
   } else {
     interpolatingPath = false;
     return 0;
   }
 }
Example #4
0
  /**
   * Send data to all participants registered as receivers, using the current timeStamp and payload
   * type. The RTP timestamp will be the same for all the packets.
   *
   * @param buffers A buffer of bytes, should not bed padded and less than 1500 bytes on most
   *     networks.
   * @param csrcArray an array with the SSRCs of contributing sources
   * @param markers An array indicating what packets should be marked. Rarely anything but the first
   *     one
   * @param rtpTimestamp The RTP timestamp to be applied to all packets
   * @param seqNumbers An array with the sequence number associated with each byte[]
   * @return null if there was a problem sending the packets, 2-dim array with {RTP Timestamp,
   *     Sequence number}
   */
  public long[][] sendData(
      byte[][] buffers, long[] csrcArray, boolean[] markers, long rtpTimestamp, long[] seqNumbers) {
    logger.debug("-> RTPSession.sendData(byte[])");

    // Same RTP timestamp for all
    if (rtpTimestamp < 0) rtpTimestamp = System.currentTimeMillis();

    // Return values
    long[][] ret = new long[buffers.length][2];

    for (int i = 0; i < buffers.length; i++) {
      byte[] buf = buffers[i];

      boolean marker = false;
      if (markers != null) marker = markers[i];

      if (buf.length > 1500) {
        System.out.println(
            "RTPSession.sendData() called with buffer exceeding 1500 bytes (" + buf.length + ")");
      }

      // Get the return values
      ret[i][0] = rtpTimestamp;
      if (seqNumbers == null) {
        ret[i][1] = getNextSeqNum();
      } else {
        ret[i][1] = seqNumbers[i];
      }
      // Create a new RTP Packet
      RtpPkt pkt = new RtpPkt(rtpTimestamp, this.ssrc, (int) ret[i][1], this.payloadType, buf);

      if (csrcArray != null) pkt.setCsrcs(csrcArray);

      pkt.setMarked(marker);

      // Creates a raw packet
      byte[] pktBytes = pkt.encode();

      // System.out.println(Integer.toString(StaticProcs.bytesToUIntInt(pktBytes, 2)));

      // Pre-flight check, are resolving an SSRC conflict?
      if (this.conflict) {
        System.out.println("RTPSession.sendData() called while trying to resolve conflict.");
        return null;
      }

      if (this.mcSession) {
        DatagramPacket packet = null;

        try {
          packet =
              new DatagramPacket(pktBytes, pktBytes.length, this.mcGroup, this.rtpMCSock.getPort());
        } catch (Exception e) {
          System.out.println("RTPSession.sendData() packet creation failed.");
          e.printStackTrace();
          return null;
        }

        try {
          rtpMCSock.send(packet);
          // Debug
          if (this.debugAppIntf != null) {
            this.debugAppIntf.packetSent(
                1,
                (InetSocketAddress) packet.getSocketAddress(),
                new String(
                    "Sent multicast RTP packet of size "
                        + packet.getLength()
                        + " to "
                        + packet.getSocketAddress().toString()
                        + " via "
                        + rtpMCSock.getLocalSocketAddress().toString()));
          }
        } catch (Exception e) {
          System.out.println("RTPSession.sendData() multicast failed.");
          e.printStackTrace();
          return null;
        }

      } else {
        // Loop over recipients
        Iterator<Participant> iter = partDb.getUnicastReceivers();
        while (iter.hasNext()) {
          InetSocketAddress receiver = iter.next().rtpAddress;
          DatagramPacket packet = null;

          logger.debug("   Sending to {}", receiver);

          try {
            packet = new DatagramPacket(pktBytes, pktBytes.length, receiver);
          } catch (Exception e) {
            System.out.println("RTPSession.sendData() packet creation failed.");
            e.printStackTrace();
            return null;
          }

          // Actually send the packet
          try {
            rtpSock.send(packet);
            // Debug
            if (this.debugAppIntf != null) {
              this.debugAppIntf.packetSent(
                  0,
                  (InetSocketAddress) packet.getSocketAddress(),
                  new String(
                      "Sent unicast RTP packet of size "
                          + packet.getLength()
                          + " to "
                          + packet.getSocketAddress().toString()
                          + " via "
                          + rtpSock.getLocalSocketAddress().toString()));
            }
          } catch (Exception e) {
            System.out.println("RTPSession.sendData() unicast failed.");
            e.printStackTrace();
            return null;
          }
        }
      }

      // Update our stats
      this.sentPktCount++;
      this.sentOctetCount++;

      logger.info("<- RTPSession.sendData(byte[])", pkt.getSeqNumber());
    }

    return ret;
  }
    public void run() {
      // every second, go through all the packets that havent been
      // ack'd
      List<RDPConnection> conList = new LinkedList<RDPConnection>();
      long lastCounterTime = System.currentTimeMillis();
      while (true) {
        try {
          long startTime = System.currentTimeMillis();
          long interval = startTime - lastCounterTime;
          if (interval > 1000) {

            if (Log.loggingNet) {
              Log.net(
                  "RDPServer counters: activeChannelCalls "
                      + activeChannelCalls
                      + ", selectCalls "
                      + selectCalls
                      + ", transmits "
                      + transmits
                      + ", retransmits "
                      + retransmits
                      + " in "
                      + interval
                      + "ms");
            }
            activeChannelCalls = 0;
            selectCalls = 0;
            transmits = 0;
            retransmits = 0;
            lastCounterTime = startTime;
          }
          if (Log.loggingNet) Log.net("RDPServer.RETRY: startTime=" + startTime);

          // go through all the rdpconnections and re-send any
          // unacked packets
          conList.clear();

          lock.lock();
          try {
            // make a copy since the values() collection is
            // backed by the map
            Set<RDPConnection> conCol = RDPServer.getAllConnections();
            if (conCol == null) {
              throw new MVRuntimeException("values() returned null");
            }
            conList.addAll(conCol); // make non map backed copy
          } finally {
            lock.unlock();
          }

          Iterator<RDPConnection> iter = conList.iterator();
          while (iter.hasNext()) {
            RDPConnection con = iter.next();
            long currentTime = System.currentTimeMillis();

            // is the connection in CLOSE_WAIT
            if (con.getState() == RDPConnection.CLOSE_WAIT) {
              long closeTime = con.getCloseWaitTimer();
              long elapsedTime = currentTime - closeTime;
              Log.net(
                  "RDPRetryThread: con is in CLOSE_WAIT: elapsed close timer(ms)="
                      + elapsedTime
                      + ", waiting for 30seconds to elapse. con="
                      + con);
              if (elapsedTime > 30000) {
                // close the connection
                Log.net("RDPRetryThread: removing CLOSE_WAIT connection. con=" + con);
                removeConnection(con);
              } else {
                Log.net(
                    "RDPRetryThread: time left on CLOSE_WAIT timer: "
                        + (30000 - (currentTime - closeTime)));
              }
              // con.close();
              continue;
            }
            if (Log.loggingNet)
              Log.net(
                  "RDPServer.RETRY: resending expired packets "
                      + con
                      + " - current list size = "
                      + con.unackListSize());

            // see if we should send a null packet, but only if con is already open
            if ((con.getState() == RDPConnection.OPEN)
                && ((currentTime - con.getLastNullPacketTime()) > 30000)) {
              con.getLock().lock();
              try {
                RDPPacket nulPacket = RDPPacket.makeNulPacket();
                con.sendPacketImmediate(nulPacket, false);
                con.setLastNullPacketTime();
                if (Log.loggingNet) Log.net("RDPServer.retry: sent nul packet: " + nulPacket);
              } finally {
                con.getLock().unlock();
              }
            } else {
              if (Log.loggingNet)
                Log.net(
                    "RDPServer.retry: sending nul packet in "
                        + (30000 - (currentTime - con.getLastNullPacketTime())));
            }
            con.resend(
                currentTime - resendTimerMS, // resend cutoff time
                currentTime - resendTimeoutMS); // giveup time
          }

          long endTime = System.currentTimeMillis();
          if (Log.loggingNet)
            Log.net(
                "RDPServer.RETRY: endTime=" + endTime + ", elapse(ms)=" + (endTime - startTime));
          Thread.sleep(250);
        } catch (Exception e) {
          Log.exception("RDPServer.RetryThread.run caught exception", e);
        }
      }
    }