These few lines can be formatted better (more Scala-like) as 
```
Option(getChannel.take()) match {
              case Some(event) =>
                val headers = toCharSequenceMap(event.getHeaders)
                val body = ByteBuffer.wrap(event.getBody)
                events.add(new SparkSinkEvent(headers, body))
                gotEventsInThisTxn = true

              case None =>
                if (!gotEventsInThisTxn) {
                  if (maxBatchSize >= Int.MaxValue / 2) {
                    // Random sanity check
                    throw new RuntimeException("Safety exception - polled too many times, no events!")
                  }
                  maxBatchSize += 1
                  Thread.sleep(500)
                } else {
                  loop.break()
                }
            }
```