View Javadoc
1   package net.sf.appstatus.batch;
2   
3   /*
4    * Copyright 2010 Capgemini
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   *
17   */
18  
19  import java.util.Date;
20  
21  import net.sf.appstatus.core.batch.AbstractBatchProgressMonitor;
22  import net.sf.appstatus.core.batch.IBatch;
23  import net.sf.appstatus.core.batch.IBatchProgressMonitor;
24  import net.sf.appstatus.core.batch.IBatchProgressMonitorExt;
25  
26  /**
27   * Log job progress agent.
28   *
29   * @author Guillaume Mary
30   * @author Nicolas Richeton
31   *
32   */
33  public class InProcessBatchProgressMonitor extends AbstractBatchProgressMonitor implements IBatchProgressMonitorExt {
34  
35  	private InProcessBatchManager manager;
36  
37  	/**
38  	 * Default constructor.
39  	 *
40  	 * @param executionId
41  	 *            job execution id
42  	 * @param manager
43  	 *            batch manager
44  	 * @param batch
45  	 *            current batch
46  	 */
47  	public InProcessBatchProgressMonitor(String executionId, IBatch batch, InProcessBatchManager manager) {
48  		super(executionId, batch);
49  		this.manager = manager;
50  	}
51  
52  	/**
53  	 * Private constructor used to create a sub task.
54  	 *
55  	 * @param executionId
56  	 *            execution id
57  	 * @param parent
58  	 *            parent monitor
59  	 * @param parentWork
60  	 *            parent amount of work
61  	 * @param batch
62  	 *            current batch
63  	 */
64  	private InProcessBatchProgressMonitor(String executionId, InProcessBatchProgressMonitor parent, int parentWork,
65  			Batch batch) {
66  		super(executionId, parent, parentWork, batch);
67  		this.manager = parent.manager;
68  	}
69  
70  	@Override
71  	public Batch getBatch() {
72  		return (Batch) super.getBatch();
73  	}
74  
75  	@Override
76  	public Date getEndDate() {
77  		return super.getEndDate();
78  	}
79  
80  	@Override
81  	public Date getStartDate() {
82  		return super.getStartDate();
83  	}
84  
85  	@Override
86  	protected IBatchProgressMonitor newInstance(int work) {
87  		return new InProcessBatchProgressMonitor(executionId, this, work, getBatch());
88  	}
89  
90  	@Override
91  	protected void onBatchEnd() {
92  		manager.batchEnd(getBatch());
93  	}
94  
95  	/**
96  	 * {@inheritDoc}
97  	 */
98  	@Override
99  	public void worked(int work) {
100 		super.worked(work);
101 	}
102 
103 }