1   package com.trendmicro.grid.acl.ds.bclog;
2   
3   import com.trendmicro.grid.acl.ds.ProcessingResultReceiver;
4   import com.trendmicro.grid.acl.l0.datatypes.ProcessPackageDataSet;
5   import org.slf4j.Logger;
6   import org.slf4j.LoggerFactory;
7   import org.springframework.stereotype.Service;
8   
9   import javax.annotation.Resource;
10  import java.io.IOException;
11  import java.util.Collection;
12  
13  /**
14   * Implements a result receiver that logs all results into a chunked binary log.
15   *
16   * @author juergen_kellerer, 2010-05-28
17   * @version 1.0
18   */
19  @Service
20  public class LoggingProcessingResultReceiver implements ProcessingResultReceiver {
21  
22  	private static final Logger log = LoggerFactory.getLogger(LoggingProcessingResultReceiver.class);
23  
24  	@Resource
25  	BinaryChangeLogQueue queue;
26  
27  	/**
28  	 * {@inheritDoc}
29  	 */
30  	public void receive(Collection<ProcessPackageDataSet> dataSets) {
31  
32  		// TODO: Implement multiplexing to connected ACL nodes in the same GRID site
33  
34  		for (ProcessPackageDataSet dataSet : dataSets) {
35  			try {
36  				queue.put(dataSet);
37  			} catch (InterruptedException e) {
38  				log.warn("TMACL-00670: Caught term signal; Not writing results of job '" +
39  						dataSet.getReferringJob() + "' to the binary changelog.");
40  				Thread.currentThread().interrupt();
41  				return;
42  			}
43  		}
44  	}
45  
46  	/**
47  	 * {@inheritDoc}
48  	 */
49  	public void checkpoint() {
50  		try {
51  			queue.checkpoint();
52  		} catch (InterruptedException e) {
53  			Thread.currentThread().interrupt();
54  		} catch (IOException e) {
55  			log.error("TMACL-00690:Failed to checkpoint the current binary changelog.", e);
56  		}
57  	}
58  }