Project

General

Profile

Revision a5f35c6f

IDa5f35c6f0b5be57fe57696b2dbe05f564ad6590b
Parent 4010865d
Child cac1390b

Added by Andreas Müller over 4 years ago

Change serial version id for identifiable entity and other minor issues

View differences:

cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/monitor/DefaultProgressMonitor.java
1
// $Id$
2
/**
3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.common.monitor;
11

  
12
import java.io.Serializable;
13

  
14
import org.apache.log4j.Level;
15
import org.apache.log4j.Logger;
16

  
17
/**
18
 * This is a console style progress monitor with prints the progress information to configured {@link Logger} with level {@link Level#INFO}
19
 *
20
 * @author a.mueller
21
 * @date 14.09.2010
22
 *
23
 */
24
public class DefaultProgressMonitor implements IProgressMonitor {
25
    private static final Logger logger = Logger.getLogger(DefaultProgressMonitor.class);
26

  
27
    public static final DefaultProgressMonitor NewInstance(){
28
        return new DefaultProgressMonitor();
29
    }
30

  
31
    private boolean isCanceled = false;
32
    protected String taskName = "No task name";
33
    protected int totalWork = 0;
34
    protected double workDone = 0;
35
    protected String subTask = "No subtask name";
36

  
37

  
38
    private Serializable feedback;
39
    private transient Object feedbackLock;
40
    private boolean isWaitingForFeedback = false;
41
    private long feedbackWaitStartTime;
42
    private static final long DEFAULT_FEEDBACK_WAIT_TIMEOUT = 1000 * 60 * 60 * 24; // 24 hours
43
    private long feedbackWaitTimeout = DEFAULT_FEEDBACK_WAIT_TIMEOUT;
44

  
45
    private String owner;
46

  
47
    protected DefaultProgressMonitor(){
48

  
49
    }
50

  
51

  
52
    /* (non-Javadoc)
53
     * @see eu.etaxonomy.cdm.common.IProgressMonitor#beginTask(java.lang.String, int)
54
     */
55
    @Override
56
    public void beginTask(String taskName, int totalWork) {
57
        logger.info("Start " + taskName);
58
        this.taskName = taskName;
59
        this.totalWork = totalWork;
60
    }
61

  
62
    /* (non-Javadoc)
63
     * @see eu.etaxonomy.cdm.common.IProgressMonitor#done()
64
     */
65
    @Override
66
    public void done() {
67
        logger.info(taskName + "...Done");
68
    }
69

  
70
    /* (non-Javadoc)
71
     * @see eu.etaxonomy.cdm.common.IProgressMonitor#isCanceled()
72
     */
73
    @Override
74
    public boolean isCanceled() {
75
        return isCanceled;
76
    }
77

  
78
    /* (non-Javadoc)
79
     * @see eu.etaxonomy.cdm.common.IProgressMonitor#setCanceled(boolean)
80
     */
81
    @Override
82
    public void setCanceled(boolean isCanceled) {
83
        this.isCanceled = isCanceled;
84
    }
85

  
86
    /* (non-Javadoc)
87
     * @see eu.etaxonomy.cdm.common.IProgressMonitor#setTaskName(java.lang.String)
88
     */
89
    @Override
90
    public void setTaskName(String taskName) {
91
        this.taskName = taskName;
92
    }
93

  
94
    /* (non-Javadoc)
95
     * @see eu.etaxonomy.cdm.common.IProgressMonitor#subTask(java.lang.String)
96
     */
97
    @Override
98
    public void subTask(String subTask) {
99
        this.subTask = subTask;
100
        logger.info(/*getPercentage() + "% done." + */  " Next Task: " + subTask);
101
    }
102

  
103
    /* (non-Javadoc)
104
     * @see eu.etaxonomy.cdm.common.IProgressMonitor#worked(int)
105
     */
106
    @Override
107
    public void worked(int work) {
108
        computeWorked(work);
109
//      this.workDone = this.workDone +  work;
110
    }
111

  
112

  
113
    @Override
114
    public void internalWorked(double work) {
115
        computeWorked(work);
116
//      this.workDone = this.workDone +  work;
117
    }
118

  
119
    private void computeWorked(double work){
120
        this.workDone = this.workDone +  work;
121
        logger.info(getPercentage() + "% done (Completed Task: " + subTask + ")");
122
    }
123

  
124
    /* (non-Javadoc)
125
     * @see eu.etaxonomy.cdm.common.IProgressMonitor#warning(java.lang.String)
126
     */
127
    @Override
128
    public void warning(String warning) {
129
        logger.warn(warning);
130
    }
131

  
132
    /* (non-Javadoc)
133
     * @see eu.etaxonomy.cdm.common.IProgressMonitor#warning(java.lang.String, java.lang.Exception)
134
     */
135
    @Override
136
    public void warning(String warning, Throwable exception) {
137
        logger.warn(warning);
138
        exception.printStackTrace();
139
    }
140

  
141
    public Double getPercentage(){
142
        if(totalWork == 0 ){
143
            return null;
144
        }
145
        double result = this.workDone * 100 / this.totalWork ;
146
        return result;
147
    }
148

  
149

  
150
    /**
151
     * {@inheritDoc}
152
     */
153
    @Override
154
    public void waitForFeedback() {
155
        if(feedbackLock == null) {
156
            feedbackLock =  new Object();
157
        }
158
        synchronized (feedbackLock) {
159
            feedback = null;
160
            while(feedback == null) {
161
                isWaitingForFeedback = true;
162
                try {
163
                    feedbackWaitStartTime = System.currentTimeMillis();
164
                    feedbackLock.wait();
165
                } catch (InterruptedException ie) {
166
                    throw new IllegalStateException(ie);
167
                }
168
            }
169
        }
170
    }
171

  
172
    /**
173
     * {@inheritDoc}
174
     */
175
    @Override
176
    public void setFeedback(Serializable feedback) {
177
        synchronized (feedbackLock) {
178
            this.feedback = feedback;
179
            this.feedbackLock.notifyAll();
180
            isWaitingForFeedback = false;
181
        }
182
    }
183

  
184

  
185
    /**
186
     * {@inheritDoc}
187
     */
188
    @Override
189
    public Serializable getFeedback() {
190
        return feedback;
191
    }
192

  
193
    /**
194
     * {@inheritDoc}
195
     */
196
    @Override
197
    public boolean getIsWaitingForFeedback() {
198
        return isWaitingForFeedback;
199
    }
200

  
201

  
202
    /**
203
     * {@inheritDoc}
204
     */
205
    @Override
206
    public void waitForFeedback(long feedbackWaitTimeout) {
207
        if(feedbackWaitTimeout <= 0 ) {
208
            throw new IllegalStateException("Feedback wait timeout should be a positive number");
209
        }
210
        this.feedbackWaitTimeout = feedbackWaitTimeout;
211
        waitForFeedback();
212
    }
213

  
214

  
215
    /**
216
     * {@inheritDoc}
217
     */
218
    @Override
219
    public boolean hasFeedbackWaitTimedOut() {
220
       long now = System.currentTimeMillis();
221
       return isWaitingForFeedback && (now - feedbackWaitStartTime > feedbackWaitTimeout);
222
    }
223

  
224

  
225

  
226
    /**
227
     * {@inheritDoc}
228
     */
229
    @Override
230
    public String getOwner() {
231
        return owner;
232
    }
233

  
234

  
235
    /**
236
     * {@inheritDoc}
237
     */
238
    @Override
239
    public void setOwner(String owner) {
240
        this.owner = owner;
241
    }
242

  
243

  
244
    /**
245
     * {@inheritDoc}
246
     */
247
    @Override
248
    public void interrupt() {
249
        // do nothing
250
    }
251

  
252

  
253

  
254
}
1
// $Id$
2
/**
3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.common.monitor;
11

  
12
import java.io.Serializable;
13

  
14
import org.apache.log4j.Level;
15
import org.apache.log4j.Logger;
16

  
17
/**
18
 * This is a console style progress monitor with prints the progress information to configured {@link Logger} with level {@link Level#INFO}
19
 *
20
 * @author a.mueller
21
 * @date 14.09.2010
22
 *
23
 */
24
public class DefaultProgressMonitor implements IProgressMonitor {
25
    private static final long serialVersionUID = 8782649283568146667L;
26

  
27
    private static final Logger logger = Logger.getLogger(DefaultProgressMonitor.class);
28

  
29
    public static final DefaultProgressMonitor NewInstance(){
30
        return new DefaultProgressMonitor();
31
    }
32

  
33
    private boolean isCanceled = false;
34
    protected String taskName = "No task name";
35
    protected int totalWork = 0;
36
    protected double workDone = 0;
37
    protected String subTask = "No subtask name";
38

  
39

  
40
    private Serializable feedback;
41
    private transient Object feedbackLock;
42
    private boolean isWaitingForFeedback = false;
43
    private long feedbackWaitStartTime;
44
    private static final long DEFAULT_FEEDBACK_WAIT_TIMEOUT = 1000 * 60 * 60 * 24; // 24 hours
45
    private long feedbackWaitTimeout = DEFAULT_FEEDBACK_WAIT_TIMEOUT;
46

  
47
    private String owner;
48

  
49
    protected DefaultProgressMonitor(){
50

  
51
    }
52

  
53

  
54
    /* (non-Javadoc)
55
     * @see eu.etaxonomy.cdm.common.IProgressMonitor#beginTask(java.lang.String, int)
56
     */
57
    @Override
58
    public void beginTask(String taskName, int totalWork) {
59
        logger.info("Start " + taskName);
60
        this.taskName = taskName;
61
        this.totalWork = totalWork;
62
    }
63

  
64
    /* (non-Javadoc)
65
     * @see eu.etaxonomy.cdm.common.IProgressMonitor#done()
66
     */
67
    @Override
68
    public void done() {
69
        logger.info(taskName + "...Done");
70
    }
71

  
72
    /* (non-Javadoc)
73
     * @see eu.etaxonomy.cdm.common.IProgressMonitor#isCanceled()
74
     */
75
    @Override
76
    public boolean isCanceled() {
77
        return isCanceled;
78
    }
79

  
80
    /* (non-Javadoc)
81
     * @see eu.etaxonomy.cdm.common.IProgressMonitor#setCanceled(boolean)
82
     */
83
    @Override
84
    public void setCanceled(boolean isCanceled) {
85
        this.isCanceled = isCanceled;
86
    }
87

  
88
    /* (non-Javadoc)
89
     * @see eu.etaxonomy.cdm.common.IProgressMonitor#setTaskName(java.lang.String)
90
     */
91
    @Override
92
    public void setTaskName(String taskName) {
93
        this.taskName = taskName;
94
    }
95

  
96
    /* (non-Javadoc)
97
     * @see eu.etaxonomy.cdm.common.IProgressMonitor#subTask(java.lang.String)
98
     */
99
    @Override
100
    public void subTask(String subTask) {
101
        this.subTask = subTask;
102
        logger.info(/*getPercentage() + "% done." + */  " Next Task: " + subTask);
103
    }
104

  
105
    /* (non-Javadoc)
106
     * @see eu.etaxonomy.cdm.common.IProgressMonitor#worked(int)
107
     */
108
    @Override
109
    public void worked(int work) {
110
        computeWorked(work);
111
//      this.workDone = this.workDone +  work;
112
    }
113

  
114

  
115
    @Override
116
    public void internalWorked(double work) {
117
        computeWorked(work);
118
//      this.workDone = this.workDone +  work;
119
    }
120

  
121
    private void computeWorked(double work){
122
        this.workDone = this.workDone +  work;
123
        logger.info(getPercentage() + "% done (Completed Task: " + subTask + ")");
124
    }
125

  
126
    /* (non-Javadoc)
127
     * @see eu.etaxonomy.cdm.common.IProgressMonitor#warning(java.lang.String)
128
     */
129
    @Override
130
    public void warning(String warning) {
131
        logger.warn(warning);
132
    }
133

  
134
    /* (non-Javadoc)
135
     * @see eu.etaxonomy.cdm.common.IProgressMonitor#warning(java.lang.String, java.lang.Exception)
136
     */
137
    @Override
138
    public void warning(String warning, Throwable exception) {
139
        logger.warn(warning);
140
        exception.printStackTrace();
141
    }
142

  
143
    public Double getPercentage(){
144
        if(totalWork == 0 ){
145
            return null;
146
        }
147
        double result = this.workDone * 100 / this.totalWork ;
148
        return result;
149
    }
150

  
151

  
152
    /**
153
     * {@inheritDoc}
154
     */
155
    @Override
156
    public void waitForFeedback() {
157
        if(feedbackLock == null) {
158
            feedbackLock =  new Object();
159
        }
160
        synchronized (feedbackLock) {
161
            feedback = null;
162
            while(feedback == null) {
163
                isWaitingForFeedback = true;
164
                try {
165
                    feedbackWaitStartTime = System.currentTimeMillis();
166
                    feedbackLock.wait();
167
                } catch (InterruptedException ie) {
168
                    throw new IllegalStateException(ie);
169
                }
170
            }
171
        }
172
    }
173

  
174
    /**
175
     * {@inheritDoc}
176
     */
177
    @Override
178
    public void setFeedback(Serializable feedback) {
179
        synchronized (feedbackLock) {
180
            this.feedback = feedback;
181
            this.feedbackLock.notifyAll();
182
            isWaitingForFeedback = false;
183
        }
184
    }
185

  
186

  
187
    /**
188
     * {@inheritDoc}
189
     */
190
    @Override
191
    public Serializable getFeedback() {
192
        return feedback;
193
    }
194

  
195
    /**
196
     * {@inheritDoc}
197
     */
198
    @Override
199
    public boolean getIsWaitingForFeedback() {
200
        return isWaitingForFeedback;
201
    }
202

  
203

  
204
    /**
205
     * {@inheritDoc}
206
     */
207
    @Override
208
    public void waitForFeedback(long feedbackWaitTimeout) {
209
        if(feedbackWaitTimeout <= 0 ) {
210
            throw new IllegalStateException("Feedback wait timeout should be a positive number");
211
        }
212
        this.feedbackWaitTimeout = feedbackWaitTimeout;
213
        waitForFeedback();
214
    }
215

  
216

  
217
    /**
218
     * {@inheritDoc}
219
     */
220
    @Override
221
    public boolean hasFeedbackWaitTimedOut() {
222
       long now = System.currentTimeMillis();
223
       return isWaitingForFeedback && (now - feedbackWaitStartTime > feedbackWaitTimeout);
224
    }
225

  
226

  
227

  
228
    /**
229
     * {@inheritDoc}
230
     */
231
    @Override
232
    public String getOwner() {
233
        return owner;
234
    }
235

  
236

  
237
    /**
238
     * {@inheritDoc}
239
     */
240
    @Override
241
    public void setOwner(String owner) {
242
        this.owner = owner;
243
    }
244

  
245

  
246
    /**
247
     * {@inheritDoc}
248
     */
249
    @Override
250
    public void interrupt() {
251
        // do nothing
252
    }
253

  
254

  
255

  
256
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/IdentifiableEntity.java
92 92
@MappedSuperclass
93 93
public abstract class IdentifiableEntity<S extends IIdentifiableEntityCacheStrategy> extends AnnotatableEntity
94 94
        implements IIdentifiableEntity /*, ISourceable<IdentifiableSource> */ {
95
    private static final long serialVersionUID = -5610995424730659058L;
95
    private static final long serialVersionUID = 7912083412108359559L;
96

  
96 97
    private static final Logger logger = Logger.getLogger(IdentifiableEntity.class);
97 98

  
98 99
    @XmlTransient
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v36_40/SchemaUpdater_36_40.java
274 274
        stepList.add(step);
275 275

  
276 276
        //Media_TaxonBase.Media_id -> MediaKey_id
277
        stepName = "DefinedTermBase_MeasurementUnit.DefinedTermBase_id -> Feature_id";
277
        stepName = "Media_TaxonBase.DefinedTermBase_id -> Feature_id";
278 278
        tableName = "Media_TaxonBase";
279 279
        oldColumnName = "media_id";
280 280
        newColumnName = "mediakey_id";

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)