public void process(Exchange exchange) throws Exception { MongoDbOperation operation = endpoint.getOperation(); Object header = exchange.getIn().getHeader(MongoDbConstants.OPERATION_HEADER); if (header != null) { LOG.debug("Overriding default operation with operation specified on header: {}", header); try { if (header instanceof MongoDbOperation) { operation = ObjectHelper.cast(MongoDbOperation.class, header); } else { // evaluate as a String operation = MongoDbOperation.valueOf(exchange.getIn().getHeader(MongoDbConstants.OPERATION_HEADER, String.class)); } } catch (Exception e) { throw new CamelMongoDbException("Operation specified on header is not supported. Value: " + header, e); } } try { invokeOperation(operation, exchange); } catch (Exception e) { throw MongoDbComponent.wrapInCamelMongoDbException(e); } }
private T getNextElement() { if (asn1InputStream == null) { return null; } try { ASN1Primitive current = getNextEntry(); if (current != null) { T instance = ObjectHelper.cast(clazz, createGenericTypeObject(current, clazz)); return instance; } else { LOGGER.trace("close asn1InputStream"); return null; } } catch (Throwable exception) { // Just wrap the IOException as CamelRuntimeException throw new RuntimeCamelException(exception); } }
@Override public int processBatch(Queue<Object> exchanges) throws Exception { int total = exchanges.size(); for (int index = 0; index < total && isBatchAllowed(); index++) { // only loop if we are started (allowed to run) final Exchange exchange = ObjectHelper.cast(Exchange.class, exchanges.poll()); // add current index and total as properties exchange.setProperty(Exchange.BATCH_INDEX, index); exchange.setProperty(Exchange.BATCH_SIZE, total); exchange.setProperty(Exchange.BATCH_COMPLETE, index == total - 1); // update pending number of exchanges pendingExchanges = total - index - 1; getAsyncProcessor().process(exchange, doneSync -> LOG.trace("Processing exchange done")); } return total; } }
@Override public int processBatch(Queue<Object> exchanges) throws Exception { int total = exchanges.size(); for (int index = 0; index < total && isBatchAllowed(); index++) { // only loop if we are started (allowed to run) final Exchange exchange = ObjectHelper.cast(Exchange.class, exchanges.poll()); // add current index and total as properties exchange.setProperty(Exchange.BATCH_INDEX, index); exchange.setProperty(Exchange.BATCH_SIZE, total); exchange.setProperty(Exchange.BATCH_COMPLETE, index == total - 1); // update pending number of exchanges pendingExchanges = total - index - 1; getAsyncProcessor().process(exchange, new AsyncCallback() { @Override public void done(boolean doneSync) { LOG.trace("Processing exchange done"); } }); } return total; }
@Override public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception { InputStream berOut = null; if (usingIterator) { if (clazzName != null) { Class<?> clazz = exchange.getContext().getClassResolver().resolveMandatoryClass(clazzName); encodeGenericTypeObject(exchange, clazz, stream); return; } Object record = exchange.getIn().getBody(); if (record instanceof ASN1Primitive) { ASN1Primitive asn1Primitive = ObjectHelper.cast(ASN1Primitive.class, record); berOut = new ByteArrayInputStream(asn1Primitive.getEncoded()); } else if (record instanceof byte[]) { berOut = new ByteArrayInputStream(ObjectHelper.cast(byte[].class, record)); } } else { byte[] byteInput = exchange.getContext().getTypeConverter().mandatoryConvertTo(byte[].class, exchange, graph); berOut = new ByteArrayInputStream(byteInput); } try { IOHelper.copy(berOut, stream); } finally { IOHelper.close(berOut, stream); } }
@Override public int processBatch(Queue<Object> exchanges) throws Exception { int total = exchanges.size(); for (int index = 0; index < total && isBatchAllowed(); index++) { // only loop if we are started (allowed to run) final Exchange exchange = ObjectHelper.cast(Exchange.class, exchanges.poll()); // add current index and total as properties exchange.setProperty(Exchange.BATCH_INDEX, index); exchange.setProperty(Exchange.BATCH_SIZE, total); exchange.setProperty(Exchange.BATCH_COMPLETE, index == total - 1); // update pending number of exchanges pendingExchanges = total - index - 1; getAsyncProcessor().process(exchange, new AsyncCallback() { @Override public void done(boolean doneSync) { LOG.trace("Processing exchange done"); } }); } return total; }
Exchange exchange = ObjectHelper.cast(Exchange.class, exchanges.poll());
@Override public int processBatch(Queue<Object> exchanges) throws Exception { int total = exchanges.size(); // limit if needed if (maxMessagesPerPoll > 0 && total > maxMessagesPerPoll) { LOG.debug("Limiting to maximum messages to poll {} as there were {} messages in this poll.", maxMessagesPerPoll, total); total = maxMessagesPerPoll; } for (int index = 0; index < total && isBatchAllowed(); index++) { // only loop if we are started (allowed to run) Exchange exchange = ObjectHelper.cast(Exchange.class, exchanges.poll()); // add current index and total as properties exchange.setProperty(Exchange.BATCH_INDEX, index); exchange.setProperty(Exchange.BATCH_SIZE, total); exchange.setProperty(Exchange.BATCH_COMPLETE, index == total - 1); // update pending number of exchanges pendingExchanges = total - index - 1; LOG.trace("Processing exchange [{}]...", exchange); getProcessor().process(exchange); if (exchange.getException() != null) { // if we failed then throw exception throw exchange.getException(); } if (endpoint.isRemove()) { remove((byte[]) exchange.getIn().getHeader(HBaseAttribute.HBASE_MARKED_ROW_ID.asHeader())); } } return total; }
final Exchange exchange = ObjectHelper.cast(Exchange.class, exchanges.poll());
Exchange exchange = ObjectHelper.cast(Exchange.class, exchanges.poll());
public int processBatch(Queue<Object> exchanges) throws Exception { int total = exchanges.size(); for (int index = 0; index < total && isBatchAllowed(); index++) { // only loop if we are started (allowed to run) Exchange exchange = ObjectHelper.cast(Exchange.class, exchanges.poll()); // add current index and total as properties exchange.setProperty(Exchange.BATCH_INDEX, index); exchange.setProperty(Exchange.BATCH_SIZE, total); exchange.setProperty(Exchange.BATCH_COMPLETE, index == total - 1); // update pending number of exchanges pendingExchanges = total - index - 1; LOG.trace("Processing exchange [{}]...", exchange); getProcessor().process(exchange); if (exchange.getException() != null) { // if we failed then throw exception throw exchange.getException(); } blobStore.removeBlob(container, exchange.getProperty(JcloudsConstants.BLOB_NAME, String.class)); } return total; } }
DataHolder holder = ObjectHelper.cast(DataHolder.class, exchanges.poll()); EntityManager entityManager = holder.manager; Exchange exchange = holder.exchange;
final Exchange exchange = ObjectHelper.cast(Exchange.class, exchanges.poll());
DataHolder holder = ObjectHelper.cast(DataHolder.class, exchanges.poll()); Exchange exchange = holder.exchange; Object data = holder.data;