~elambert/gearmanij/gearman_java_library

« back to all changes in this revision

Viewing changes to src/org/gearman/worker/WorkerJob.java

  • Committer: Eric Lambert
  • Date: 2009-07-10 04:07:39 UTC
  • Revision ID: eric.d.lambert@gmail.com-20090710040739-ru4tgzfcnuo9b9uc
removed unused worker and job

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2009 by Robert Stewart <robert@wombatnation.com>
3
 
 * Use and distribution licensed under the 
4
 
 * GNU Lesser General Public License (LGPL) version 2.1.
5
 
 * See the COPYING file in the parent directory for full text.
6
 
 */
7
 
package org.gearman.worker;
8
 
 
9
 
import org.gearman.client.Job;
10
 
import org.gearman.util.ByteArrayBuffer;
11
 
import org.gearman.util.ByteUtils;
12
 
 
13
 
public class WorkerJob implements Job {
14
 
 
15
 
    // The handle is opaque to the worker, so the null termination byte is
16
 
    // retained
17
 
    private byte[] handle;
18
 
 
19
 
    private byte[] id;
20
 
 
21
 
    private String functionName;
22
 
 
23
 
    private byte[] data;
24
 
 
25
 
    private byte[] result;
26
 
 
27
 
    private Job.JobState state;
28
 
 
29
 
    private Job.JobProgress progress = new JobProgressImpl();
30
 
 
31
 
    /**
32
 
     * this is currently geared towards PacketType.JOB_ASSIGN
33
 
     * 
34
 
     * we may wish to do something different for PacketType.JOB_ASSIGN_UNIQ
35
 
     * 
36
 
     * @param responseData
37
 
     *            a byte[] from a PacketgetData.getData()
38
 
     */
39
 
    public WorkerJob(byte[] responseData) {
40
 
        // Parse null terminated params - job handle, function name, function
41
 
        // arg
42
 
        ByteArrayBuffer baBuff = new ByteArrayBuffer(responseData);
43
 
        int start = 0;
44
 
        int end = baBuff.indexOf(ByteUtils.NULL);
45
 
        // Treat handle as opaque, so keep null terminator
46
 
        byte[] handle = baBuff.subArray(start, end + 1);
47
 
        start = end + 1;
48
 
        end = baBuff.indexOf(ByteUtils.NULL, start);
49
 
        byte[] name = baBuff.subArray(start, end);
50
 
        start = end + 1;
51
 
        byte[] data = baBuff.subArray(start, responseData.length);
52
 
 
53
 
        this.data = data;
54
 
        this.handle = handle;
55
 
        this.id = null;
56
 
        this.functionName = new String(name);
57
 
        this.state = JobState.NEW;
58
 
    }
59
 
 
60
 
    public WorkerJob(byte[] handle, String functionName, byte[] id, byte[] data) {
61
 
        this.data = data;
62
 
        this.handle = handle;
63
 
        this.id = id;
64
 
        this.functionName = functionName;
65
 
        this.state = JobState.NEW;
66
 
    }
67
 
 
68
 
    public byte[] getData() {
69
 
        return data;
70
 
    }
71
 
 
72
 
    public byte[] getHandle() {
73
 
        return handle;
74
 
    }
75
 
 
76
 
    public byte[] getID() {
77
 
        return id;
78
 
    }
79
 
 
80
 
    public String getFunctionName() {
81
 
        return functionName;
82
 
    }
83
 
 
84
 
    public byte[] getResult() {
85
 
        return result;
86
 
    }
87
 
 
88
 
    public void setResult(byte[] result) {
89
 
        this.result = result;
90
 
    }
91
 
 
92
 
    /**
93
 
     * @return the current state of a Job
94
 
     */
95
 
    public Job.JobState getState() {
96
 
        return state;
97
 
    }
98
 
 
99
 
    /**
100
 
     * Sets the current state of a job.
101
 
     * 
102
 
     * @param state
103
 
     *            the new JobState
104
 
     */
105
 
    public void setState(Job.JobState state) {
106
 
        this.state = state;
107
 
    }
108
 
 
109
 
    public Job.JobProgress getProgress() {
110
 
        return progress;
111
 
    }
112
 
 
113
 
    /**
114
 
     * Represents the per cent completion of a job.
115
 
     */
116
 
    private static class JobProgressImpl implements JobProgress {
117
 
        private int numerator = 0;
118
 
        private int denominator = 100;
119
 
 
120
 
        public int getNumerator() {
121
 
            return numerator;
122
 
        }
123
 
 
124
 
        public void setNumerator(int numerator) {
125
 
            this.numerator = numerator;
126
 
        }
127
 
 
128
 
        public int getDenominator() {
129
 
            return denominator;
130
 
        }
131
 
 
132
 
        public void setDenominator(int denominator) {
133
 
            this.denominator = denominator;
134
 
        }
135
 
    }
136
 
 
137
 
}