Example #1
0
 /** {@inheritDoc} */
 public void execute(ISchedulingService service) {
   // ensure the job is not already running
   if (running.compareAndSet(false, true)) {
     // get now
     long now = System.currentTimeMillis();
     // get the current bytes read count on the connection
     long currentReadBytes = getReadBytes();
     // get our last bytes read count
     long previousReadBytes = lastBytesRead.get();
     log.debug(
         "Time now: {} current read count: {} last read count: {}",
         new Object[] {now, currentReadBytes, previousReadBytes});
     if (currentReadBytes > previousReadBytes) {
       log.debug("Client is still alive, no ping needed");
       // client has sent data since last check and thus is not dead. No need to ping
       if (lastBytesRead.compareAndSet(previousReadBytes, currentReadBytes)) {
         // update the timestamp to match our update
         lastBytesReadTime = now;
       }
     } else {
       // client didn't send response to ping command and didn't sent data for too long,
       // disconnect
       long lastPingTime = lastPingSent.get();
       long lastPongTime = lastPongReceived.get();
       if (lastPongTime > 0
           && (lastPingTime - lastPongTime > maxInactivity)
           && !(now - lastBytesReadTime < maxInactivity)) {
         log.debug("Keep alive job name {}", keepAliveJobName);
         if (log.isTraceEnabled()) {
           log.trace("Scheduled job list");
           for (String jobName : service.getScheduledJobNames()) {
             log.trace("Job: {}", jobName);
           }
         }
         service.removeScheduledJob(keepAliveJobName);
         keepAliveJobName = null;
         log.warn(
             "Closing {}, with id {}, due to too much inactivity ({} ms), last ping sent {} ms ago",
             new Object[] {
               RTMPConnection.this, getId(), (lastPingTime - lastPongTime), (now - lastPingTime)
             });
         // Add the following line to (hopefully) deal with a very common support request
         // on the Red5 list
         log.warn(
             "This often happens if YOUR Red5 application generated an exception on start-up. Check earlier in the log for that exception first!");
         onInactive();
       }
       // send ping command to client to trigger sending of data
       ping();
     }
     // reset running flag
     running.compareAndSet(true, false);
   }
 }
Example #2
0
 private void unscheduleWaitForHandshakeJob() {
   getWriteLock().lock();
   try {
     if (waitForHandshakeJob != null) {
       schedulingService.removeScheduledJob(waitForHandshakeJob);
       waitForHandshakeJob = null;
       log.debug("Removed waitForHandshakeJob for: {}", getId());
     }
   } finally {
     getWriteLock().unlock();
   }
 }
 /** Stop this server-side stream */
 public void stop() {
   if (state == StreamState.PLAYING || state == StreamState.PAUSED) {
     if (liveJobName != null) {
       scheduler.removeScheduledJob(liveJobName);
       liveJobName = null;
     }
     if (vodJobName != null) {
       scheduler.removeScheduledJob(vodJobName);
       vodJobName = null;
     }
     if (msgIn != null) {
       msgIn.unsubscribe(this);
       msgIn = null;
     }
     if (nextRTMPMessage != null) {
       nextRTMPMessage.getBody().release();
     }
     stopRecording();
     setState(StreamState.STOPPED);
   }
 }
Example #4
0
    /** {@inheritDoc} */
    public void execute(ISchedulingService service) {
      long thisRead = getReadBytes();
      long previousReadBytes = lastBytesRead.get();
      if (thisRead > previousReadBytes) {
        // Client sent data since last check and thus is not dead. No
        // need to ping.
        if (lastBytesRead.compareAndSet(previousReadBytes, thisRead))
          lastBytesReadTime = System.currentTimeMillis();
        return;
      }
      // Client didn't send response to ping command
      // and didn't sent data for too long, disconnect
      if (lastPongReceived.get() > 0
          && (lastPingSent.get() - lastPongReceived.get() > maxInactivity)
          && !(System.currentTimeMillis() - lastBytesReadTime < maxInactivity)) {

        getWriteLock().lock();
        try {
          log.debug("Keep alive job name {}", keepAliveJobName);
          if (log.isDebugEnabled()) {
            log.debug("Scheduled job list");
            for (String jobName : service.getScheduledJobNames()) {
              log.debug("Job: {}", jobName);
            }
          }
          service.removeScheduledJob(keepAliveJobName);
          keepAliveJobName = null;
        } finally {
          getWriteLock().unlock();
        }
        log.warn(
            "Closing {}, with id {}, due to too much inactivity ({}ms), "
                + "last ping sent {}ms ago",
            new Object[] {
              RTMPConnection.this,
              getId(),
              (lastPingSent.get() - lastPongReceived.get()),
              (System.currentTimeMillis() - lastPingSent.get())
            });
        onInactive();
        return;
      }
      // Send ping command to client to trigger sending of data.
      ping();
    }
Example #5
0
  /** {@inheritDoc} */
  @Override
  public void close() {
    getWriteLock().lock();
    try {
      if (keepAliveJobName != null) {
        schedulingService.removeScheduledJob(keepAliveJobName);
        keepAliveJobName = null;
      }
    } finally {
      getWriteLock().unlock();
    }
    Red5.setConnectionLocal(this);
    IStreamService streamService =
        (IStreamService) getScopeService(scope, IStreamService.class, StreamService.class);
    if (streamService != null) {
      for (Map.Entry<Integer, IClientStream> entry : streams.entrySet()) {
        IClientStream stream = entry.getValue();
        if (stream != null) {
          log.debug("Closing stream: {}", stream.getStreamId());
          streamService.deleteStream(this, stream.getStreamId());
          usedStreams.decrementAndGet();
        }
      }
      streams.clear();
    }
    channels.clear();

    getWriteLock().lock();
    try {
      if (bwContext != null && getScope() != null && getScope().getContext() != null) {
        IBWControlService bwController =
            (IBWControlService) getScope().getContext().getBean(IBWControlService.KEY);
        bwController.unregisterBWControllable(bwContext);
        bwContext = null;
      }
    } finally {
      getWriteLock().unlock();
    }
    super.close();
  }
Example #6
0
 /** {@inheritDoc} */
 @Override
 public void close() {
   getWriteLock().lock();
   try {
     if (keepAliveJobName != null) {
       schedulingService.removeScheduledJob(keepAliveJobName);
       keepAliveJobName = null;
     }
   } finally {
     getWriteLock().unlock();
   }
   Red5.setConnectionLocal(this);
   IStreamService streamService =
       (IStreamService) getScopeService(scope, IStreamService.class, StreamService.class);
   if (streamService != null) {
     for (Map.Entry<Integer, IClientStream> entry : streams.entrySet()) {
       IClientStream stream = entry.getValue();
       if (stream != null) {
         log.debug("Closing stream: {}", stream.getStreamId());
         streamService.deleteStream(this, stream.getStreamId());
         usedStreams.decrementAndGet();
       }
     }
   }
   // close the base connection - disconnect scopes and unregister client
   super.close();
   // kill all the collections etc
   if (channels != null) {
     channels.clear();
     channels = null;
   } else {
     log.trace("Channels collection was null");
   }
   if (streams != null) {
     streams.clear();
     streams = null;
   } else {
     log.trace("Streams collection was null");
   }
   if (pendingCalls != null) {
     pendingCalls.clear();
     pendingCalls = null;
   } else {
     log.trace("PendingCalls collection was null");
   }
   if (deferredResults != null) {
     deferredResults.clear();
     deferredResults = null;
   } else {
     log.trace("DeferredResults collection was null");
   }
   if (pendingVideos != null) {
     pendingVideos.clear();
     pendingVideos = null;
   } else {
     log.trace("PendingVideos collection was null");
   }
   if (streamBuffers != null) {
     streamBuffers.clear();
     streamBuffers = null;
   } else {
     log.trace("StreamBuffers collection was null");
   }
 }
Example #7
0
 public void shutdown() {
   scheduler.removeScheduledJob(jobName);
 }