public synchronized void send(final BatchEvent events) {
    if (rpcClient == null) {
      rpcClient = connect(agents, retries, connectTimeoutMillis, requestTimeoutMillis);
    }

    if (rpcClient != null) {
      try {
        LOGGER.trace("Sending batch of {} events", events.getEvents().size());
        rpcClient.appendBatch(events.getEvents());
      } catch (final Exception ex) {
        rpcClient.close();
        rpcClient = null;
        final String msg =
            "Unable to write to "
                + getName()
                + " at "
                + agents[current].getHost()
                + ':'
                + agents[current].getPort();
        LOGGER.warn(msg, ex);
        throw new AppenderLoggingException("No Flume agents are available");
      }
    } else {
      final String msg =
          "Unable to write to "
              + getName()
              + " at "
              + agents[current].getHost()
              + ':'
              + agents[current].getPort();
      LOGGER.warn(msg);
      throw new AppenderLoggingException("No Flume agents are available");
    }
  }
  @Override
  public synchronized void send(final Event event) {
    if (batchSize == 1) {
      if (rpcClient == null) {
        rpcClient = connect(agents, retries, connectTimeoutMillis, requestTimeoutMillis);
      }

      if (rpcClient != null) {
        try {
          rpcClient.append(event);
        } catch (final Exception ex) {
          rpcClient.close();
          rpcClient = null;
          final String msg =
              "Unable to write to "
                  + getName()
                  + " at "
                  + agents[current].getHost()
                  + ':'
                  + agents[current].getPort();
          LOGGER.warn(msg, ex);
          throw new AppenderLoggingException("No Flume agents are available");
        }
      } else {
        final String msg =
            "Unable to write to "
                + getName()
                + " at "
                + agents[current].getHost()
                + ':'
                + agents[current].getPort();
        LOGGER.warn(msg);
        throw new AppenderLoggingException("No Flume agents are available");
      }
    } else {
      batchEvent.addEvent(event);
      final int eventCount = batchEvent.getEvents().size();
      if (eventCount == 1) {
        nextSend = System.nanoTime() + delayNanos;
      }
      if (eventCount >= batchSize || System.nanoTime() >= nextSend) {
        send(batchEvent);
        batchEvent = new BatchEvent();
      }
    }
  }
 @Override
 protected boolean releaseSub(final long timeout, final TimeUnit timeUnit) {
   boolean closed = true;
   if (rpcClient != null) {
     try {
       synchronized (this) {
         try {
           if (batchSize > 1 && batchEvent.getEvents().size() > 0) {
             send(batchEvent);
           }
         } catch (final Exception ex) {
           LOGGER.error("Error sending final batch: {}", ex.getMessage());
           closed = false;
         }
       }
       rpcClient.close();
     } catch (final Exception ex) {
       LOGGER.error("Attempt to close RPC client failed", ex);
       closed = false;
     }
   }
   rpcClient = null;
   return closed;
 }