code: @Override
      public void write(Packet out) {
          if (ioSession != null) {
              final Semaphore lock = getLock();
              if (log.isTraceEnabled()) {
                  log.trace("Write lock wait count: {} closed: {}", lock.getQueueLength(), isClosed());
              }
              while (!isClosed()) {
                  boolean acquired = false;
                  try {
                      acquired = lock.tryAcquire(10, TimeUnit.MILLISECONDS);
                      if (acquired) {
                          if (log.isTraceEnabled()) {
                              log.trace("Writing message");
                          }
                          writingMessage(out);
                          ioSession.write(out);
                          break;
                      }
                  } catch (InterruptedException e) {
                      log.warn("Interrupted while waiting for write lock. State: {}", RTMP.states[state.getState()], e);
                      if (log.isInfoEnabled()) {
                          // further debugging to assist with possible connection problems
                          log.info("Session id: {} in queue size: {} pending msgs: {} last ping/pong: {}", getSessionId(), currentQueueSize(), getPendingMessages(), getLastPingSentAndLastPongReceivedInterval());
                          log.info("Available permits - decoder: {} encoder: {}", decoderLock.availablePermits(), encoderLock.availablePermits());
                      }
                      String exMsg = e.getMessage();
                      // if the exception cause is null break out of here to prevent looping until closed
                      if (exMsg == null || exMsg.indexOf("null") >= 0) {
                          log.debug("Exception writing to connection: {}", this);
                          break;
                      }
                  } finally {
                      if (acquired) {
                          lock.release();
                      }
                  }
              }
          }
      }
docs: {@inheritDoc}