@@ -23,7 +23,7 @@ import java.util.concurrent.{TimeUnit, CountDownLatch, Callable}
2323import scala .util .control .Breaks
2424
2525import org .apache .flume .{Transaction , Channel }
26- import org .apache .spark .flume .{SparkSinkEvent , ErrorEventBatch , EventBatch }
26+ import org .apache .spark .flume .{SparkSinkEvent , EventBatch }
2727import org .slf4j .LoggerFactory
2828
2929
@@ -50,7 +50,8 @@ private class TransactionProcessor(val channel: Channel, val seqNum: String,
5050 private val LOG = LoggerFactory .getLogger(classOf [TransactionProcessor ])
5151
5252 // If a real batch is not returned, we always have to return an error batch.
53- @ volatile private var eventBatch : EventBatch = new ErrorEventBatch (" Unknown Error" )
53+ @ volatile private var eventBatch : EventBatch = new EventBatch (" Unknown Error" , " " ,
54+ util.Collections .emptyList())
5455
5556 // Synchronization primitives
5657 val batchGeneratedLatch = new CountDownLatch (1 )
@@ -70,7 +71,7 @@ private class TransactionProcessor(val channel: Channel, val seqNum: String,
7071 /**
7172 * Get an event batch from the channel. This method will block until a batch of events is
7273 * available from the channel. If no events are available after a large number of attempts of
73- * polling the channel, this method will return [[ ErrorEventBatch ]].
74+ * polling the channel, this method will return an [[ EventBatch ]] with a non-empty error message
7475 *
7576 * @return An [[EventBatch ]] instance with sequence number set to seqNum, filled with a
7677 * maximum of maxBatchSize events
@@ -96,16 +97,14 @@ private class TransactionProcessor(val channel: Channel, val seqNum: String,
9697
9798 /**
9899 * Populates events into the event batch. If the batch cannot be populated,
99- * this method will not set the event batch which will stay [[ ErrorEventBatch ]]
100+ * this method will not set the events into the event batch, but it sets an error message.
100101 */
101102 private def populateEvents () {
102103 try {
103104 txOpt = Option (channel.getTransaction)
104105 if (txOpt.isEmpty) {
105- assert(eventBatch.isInstanceOf [ErrorEventBatch ])
106- eventBatch.asInstanceOf [ErrorEventBatch ].message = " Something went wrong. Channel was " +
107- " unable to create a transaction!"
108- eventBatch
106+ eventBatch.setErrorMsg(" Something went wrong. Channel was " +
107+ " unable to create a transaction!" )
109108 }
110109 txOpt.map(tx => {
111110 tx.begin()
@@ -135,16 +134,16 @@ private class TransactionProcessor(val channel: Channel, val seqNum: String,
135134 val msg = " Tried several times, " +
136135 " but did not get any events from the channel!"
137136 LOG .warn(msg)
138- eventBatch.asInstanceOf [ ErrorEventBatch ].message = msg
137+ eventBatch.setErrorMsg( msg)
139138 } else {
140139 // At this point, the events are available, so fill them into the event batch
141- eventBatch = new EventBatch (seqNum, events)
140+ eventBatch = new EventBatch (" " , seqNum, events)
142141 }
143142 })
144143 } catch {
145144 case e : Exception =>
146145 LOG .error(" Error while processing transaction." , e)
147- eventBatch.asInstanceOf [ ErrorEventBatch ].message = e.getMessage
146+ eventBatch.setErrorMsg( e.getMessage)
148147 try {
149148 txOpt.map(tx => {
150149 rollbackAndClose(tx, close = true )
0 commit comments