Subversion Repositories bacoAlunos

Rev

Rev 1070 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
995 jmachado 1
package pt.estgp.estgweb.domain;
2
 
3
import org.apache.log4j.Logger;
4
import pt.estgp.estgweb.services.jobs.JobHandler;
5
import pt.estgp.estgweb.services.jobs.ServiceJob;
6
 
7
import java.io.Serializable;
8
 
9
/**
10
 * @author Jorge Machado
11
 * @date 2/Mar/2008
12
 * @time 10:27:25
13
 * @see pt.estgp.estgweb.domain
14
 */
15
public class JobServiceTaskImpl extends JobServiceTask implements JobHandler
16
{
17
    private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(JobServiceTaskImpl.class);
18
 
19
    public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable()
20
    {
21
        return getId();
22
    }
23
 
24
    @1.5.0/docs/api/java/lang/Override.html">Override
25
    public void runJob()
26
    {
27
        try {
28
            ServiceJob job = (ServiceJob) 1.5.0/docs/api/java/lang/Class.html">Class.forName(getTargetService()).newInstance();
29
            job.setParameters(getServiceTaskParameters());
30
            job.setJobServiceTask(this);
31
            job.runJob();
32
        } catch (1.5.0/docs/api/java/lang/InstantiationException.html">InstantiationException e) {
33
            logger.error(e,e);
34
        } catch (1.5.0/docs/api/java/lang/IllegalAccessException.html">IllegalAccessException e) {
35
            logger.error(e,e);
36
        } catch (1.5.0/docs/api/java/lang/ClassNotFoundException.html">ClassNotFoundException e) {
37
            logger.error(e, e);
38
        }
39
    }
40
 
41
    public static enum JobStatus
42
    {
43
        PENDING,
44
        STARTED,
45
        FINISHED,
46
        FAILED,
47
        UNKNOWN_ERROR;
48
 
49
        public static JobStatus parse(1.5.0/docs/api/java/lang/String.html">String status)
50
        {
51
            if(status == null)
52
                return PENDING;
53
            if(status.equals(PENDING.name()))
54
                return PENDING;
55
            if(status.equals(STARTED.name()))
56
                return STARTED;
57
            if(status.equals(FINISHED.name()))
58
                return FINISHED;
59
            if(status.equals(FAILED.name()))
60
                return FAILED;
61
            return UNKNOWN_ERROR;
62
        }
63
    }
64
 
65
    public JobStatus getStatusEnum()
66
    {
67
        return JobStatus.parse(getStatus());
68
    }
69
 
70
    public void setStatusEnum(JobStatus statusEnum)
71
    {
72
        if(statusEnum == null)
73
            setStatus(JobStatus.UNKNOWN_ERROR.name());
74
        setStatus(statusEnum.name());
75
    }
76
 
77
}