private void throwIfClosed() throws EventDeliveryException { if (!isOpen) { throw new EventDeliveryException("Rpc Client is closed"); } }
private void checkIfChannelExceptionAndThrow(Throwable e) throws EventDeliveryException { if (e instanceof ChannelException) { throw new EventDeliveryException("Error in processing transaction.", e); } else if (e instanceof Error || e instanceof RuntimeException) { Throwables.propagate(e); } throw new EventDeliveryException("Error in processing transaction.", e); }
@Override public void handle(Event event, Throwable cause) throws EventDeliveryException { LOG.error("Event delivery failed: " + cause.getLocalizedMessage()); LOG.debug("Exception follows.", cause); throw new EventDeliveryException(cause); }
/** * If the connection state != READY, throws {@link EventDeliveryException}. */ private void assertReady() throws EventDeliveryException { stateLock.lock(); try { ConnState curState = connState; if (curState != ConnState.READY) { throw new EventDeliveryException("RPC failed, client in an invalid " + "state: " + curState); } } finally { stateLock.unlock(); } }
@Override public void append(Event event) throws EventDeliveryException { try { this.appendAsync(event).get(); } catch (Exception ex) { throw new EventDeliveryException(ex); } }
@Override public void close() throws EventDeliveryException { if (nEventsHandled > 0) { try { writer.close(); } catch (RuntimeException ex) { throw new EventDeliveryException(ex); } finally { writer = null; nEventsHandled = 0; } } }
@Override public void appendBatch(List<Event> events) throws EventDeliveryException { try { this.appendBatchAsync(events).get(); } catch (Exception ex) { throw new EventDeliveryException(ex); } }
@Override public void appendBatch(List<Event> events) throws EventDeliveryException { try { appendBatch(events, requestTimeout, TimeUnit.MILLISECONDS); } catch (Throwable t) { // we mark as no longer active without trying to clean up resources // client is required to call close() to clean up resources setState(ConnState.DEAD); if (t instanceof Error) { throw (Error) t; } if (t instanceof TimeoutException) { throw new EventDeliveryException(this + ": Failed to send event. " + "RPC request timed out after " + requestTimeout + " ms", t); } throw new EventDeliveryException(this + ": Failed to send batch", t); } }
@Override public void append(Event event) throws EventDeliveryException { try { append(event, requestTimeout, TimeUnit.MILLISECONDS); } catch (Throwable t) { // we mark as no longer active without trying to clean up resources // client is required to call close() to clean up resources setState(ConnState.DEAD); if (t instanceof Error) { throw (Error) t; } if (t instanceof TimeoutException) { throw new EventDeliveryException(this + ": Failed to send event. " + "RPC request timed out after " + requestTimeout + "ms", t); } throw new EventDeliveryException(this + ": Failed to send event", t); } }
@Override public Void call() throws Exception { Status status = client.client.append(e); if (status != Status.OK) { throw new EventDeliveryException("Failed to deliver events. Server " + "returned status : " + status.name()); } return null; } });
@Override public Void call() throws Exception { Status status = client.client.appendBatch(e); if (status != Status.OK) { throw new EventDeliveryException("Failed to deliver events. Server " + "returned status : " + status.name()); } return null; } });
/** * Adds event to the channel owned by the agent. Note however, that the * event is not copied and as such, the byte array and headers cannot * be re-used by the caller. * @param event * @throws EventDeliveryException if unable to add event to channel */ public void put(Event event) throws EventDeliveryException { if (state != State.STARTED) { throw new IllegalStateException("Cannot put events unless started"); } try { embeddedSource.put(event); } catch (ChannelException ex) { throw new EventDeliveryException("Embedded agent " + name + ": Unable to process event: " + ex.getMessage(), ex); } }
/** * Adds events to the channel owned by the agent. Note however, that the * event is not copied and as such, the byte array and headers cannot * be re-used by the caller. * @param events * @throws EventDeliveryException if unable to add event to channel */ public void putAll(List<Event> events) throws EventDeliveryException { if (state != State.STARTED) { throw new IllegalStateException("Cannot put events unless started"); } try { embeddedSource.putAll(events); } catch (ChannelException ex) { throw new EventDeliveryException("Embedded agent " + name + ": Unable to process event: " + ex.getMessage(), ex); } }
@Override public Status process() throws EventDeliveryException { Status status = null; Iterator<Sink> sinkIterator = selector.createSinkIterator(); while (sinkIterator.hasNext()) { Sink sink = sinkIterator.next(); try { status = sink.process(); break; } catch (Exception ex) { selector.informSinkFailed(sink); LOGGER.warn("Sink failed to consume event. " + "Attempting next sink if available.", ex); } } if (status == null) { throw new EventDeliveryException("All configured sinks have failed"); } return status; }
@Override public void execute() throws Exception { try { BulkResponse bulkResponse = bulkRequestBuilder.execute().actionGet(); if (bulkResponse.hasFailures()) { throw new EventDeliveryException(bulkResponse.buildFailureMessage()); } } finally { bulkRequestBuilder = client.prepareBulk(); } }
@Override public void append(Event event) throws EventDeliveryException { throwIfClosed(); boolean eventSent = false; Iterator<HostInfo> it = selector.createHostIterator(); while (it.hasNext()) { HostInfo host = it.next(); try { RpcClient client = getClient(host); client.append(event); eventSent = true; break; } catch (Exception ex) { selector.informFailure(host); LOGGER.warn("Failed to send event to host " + host, ex); } } if (!eventSent) { throw new EventDeliveryException("Unable to send event to any host"); } }
@Override public void appendBatch(List<Event> events) throws EventDeliveryException { throwIfClosed(); boolean batchSent = false; Iterator<HostInfo> it = selector.createHostIterator(); while (it.hasNext()) { HostInfo host = it.next(); try { RpcClient client = getClient(host); client.appendBatch(events); batchSent = true; break; } catch (Exception ex) { selector.informFailure(host); LOGGER.warn("Failed to send batch to host " + host, ex); } } if (!batchSent) { throw new EventDeliveryException("Unable to send batch to any host"); } }
public Status process() throws EventDeliveryException { Exception exception = getStartException(); if (exception != null) { throw new FlumeException("Source had error configuring or starting", exception); } if (!isStarted()) { throw new EventDeliveryException("Source is not started. It is in '" + getLifecycleState() + "' state"); } return doProcess(); }
@Override public void handle(Event event, Throwable cause) throws EventDeliveryException { try { if (writer == null) { writer = dataset.newWriter(); } final AvroFlumeEvent avroEvent = new AvroFlumeEvent(); avroEvent.setBody(ByteBuffer.wrap(event.getBody())); avroEvent.setHeaders(toCharSeqMap(event.getHeaders())); writer.write(avroEvent); nEventsHandled++; } catch (RuntimeException ex) { throw new EventDeliveryException(ex); } }
@Override public Status process() throws EventDeliveryException { Status result = Status.READY; Channel channel = getChannel(); Transaction transaction = channel.getTransaction(); Event event = null; try { transaction.begin(); event = channel.take(); if (event != null) { if (logger.isInfoEnabled()) { logger.info("Event: " + EventHelper.dumpEvent(event, maxBytesToLog)); } } else { // No event found, request back-off semantics from the sink runner result = Status.BACKOFF; } transaction.commit(); } catch (Exception ex) { transaction.rollback(); throw new EventDeliveryException("Failed to log event: " + event, ex); } finally { transaction.close(); } return result; } }