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.
7
package org.gearman.worker;
9
import org.gearman.client.Job;
10
import org.gearman.util.ByteArrayBuffer;
11
import org.gearman.util.ByteUtils;
13
public class WorkerJob implements Job {
15
// The handle is opaque to the worker, so the null termination byte is
17
private byte[] handle;
21
private String functionName;
25
private byte[] result;
27
private Job.JobState state;
29
private Job.JobProgress progress = new JobProgressImpl();
32
* this is currently geared towards PacketType.JOB_ASSIGN
34
* we may wish to do something different for PacketType.JOB_ASSIGN_UNIQ
37
* a byte[] from a PacketgetData.getData()
39
public WorkerJob(byte[] responseData) {
40
// Parse null terminated params - job handle, function name, function
42
ByteArrayBuffer baBuff = new ByteArrayBuffer(responseData);
44
int end = baBuff.indexOf(ByteUtils.NULL);
45
// Treat handle as opaque, so keep null terminator
46
byte[] handle = baBuff.subArray(start, end + 1);
48
end = baBuff.indexOf(ByteUtils.NULL, start);
49
byte[] name = baBuff.subArray(start, end);
51
byte[] data = baBuff.subArray(start, responseData.length);
56
this.functionName = new String(name);
57
this.state = JobState.NEW;
60
public WorkerJob(byte[] handle, String functionName, byte[] id, byte[] data) {
64
this.functionName = functionName;
65
this.state = JobState.NEW;
68
public byte[] getData() {
72
public byte[] getHandle() {
76
public byte[] getID() {
80
public String getFunctionName() {
84
public byte[] getResult() {
88
public void setResult(byte[] result) {
93
* @return the current state of a Job
95
public Job.JobState getState() {
100
* Sets the current state of a job.
105
public void setState(Job.JobState state) {
109
public Job.JobProgress getProgress() {
114
* Represents the per cent completion of a job.
116
private static class JobProgressImpl implements JobProgress {
117
private int numerator = 0;
118
private int denominator = 100;
120
public int getNumerator() {
124
public void setNumerator(int numerator) {
125
this.numerator = numerator;
128
public int getDenominator() {
132
public void setDenominator(int denominator) {
133
this.denominator = denominator;