class TradeWriter extends ItemStreamSupport implements ItemWriter<Trade> {

	private static final Log log = LogFactory.getLog(TradeWriter.class);

	public static final String TOTAL_AMOUNT_KEY = "TOTAL_AMOUNT";

	private TradeDao dao;

	private List<String> failingCustomers = new ArrayList<>();

	private BigDecimal totalPrice = BigDecimal.ZERO;

	@Override
	public void write(Chunk<? extends Trade> trades) {<FILL_FUNCTION_BODY>}

	@AfterWrite
	public void updateTotalPrice(Chunk<Trade> trades) {
		for (Trade trade : trades) {
			this.totalPrice = this.totalPrice.add(trade.getPrice());
		}
	}

	@Override
	public void open(ExecutionContext executionContext) {
		if (executionContext.containsKey(TOTAL_AMOUNT_KEY)) {
			this.totalPrice = (BigDecimal) executionContext.get(TOTAL_AMOUNT_KEY);
		}
		else {
			//
			// Fresh run. Disregard old state.
			//
			this.totalPrice = BigDecimal.ZERO;
		}
	}

	@Override
	public void update(ExecutionContext executionContext) {
		executionContext.put(TOTAL_AMOUNT_KEY, this.totalPrice);
	}

	public BigDecimal getTotalPrice() {
		return totalPrice;
	}

	public void setDao(TradeDao dao) {
		this.dao = dao;
	}

	/**
	 * Public setter for the customers on which failure should occur.
	 * @param failingCustomers The customers to fail on
	 */
	public void setFailingCustomers(List<String> failingCustomers) {
		this.failingCustomers = failingCustomers;
	}

}


		for (Trade trade : trades) {

			log.debug(trade);

			dao.writeTrade(trade);

			Assert.notNull(trade.getPrice(), "price must not be null"); // There must be a
																		// price to total

			if (this.failingCustomers.contains(trade.getCustomer())) {
				throw new WriteFailedException("Something unexpected happened!");
			}
		}

	
<methods>public non-sealed void <init>() ,public void close() ,public java.lang.String getExecutionContextKey(java.lang.String) ,public java.lang.String getName() ,public void open(org.springframework.batch.item.ExecutionContext) ,public void setName(java.lang.String) ,public void update(org.springframework.batch.item.ExecutionContext) <variables>private final org.springframework.batch.item.util.ExecutionContextUserSupport executionContextUserSupport