package javax.resource.spi.work;
import java.util.EventObject;
import java.io.ObjectStreamField;
import java.io.ObjectInputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import org.jboss.util.id.SerialVersion;
public class WorkEvent extends EventObject
{
static final long serialVersionUID;
private static final ObjectStreamField[] serialPersistentFields;
private static final int TYPE_IDX = 0;
private static final int WORK_IDX = 1;
private static final int EXCPEPTION_IDX = 2;
private static final int DURATION_IDX = 2;
public static final int WORK_ACCEPTED = 1;
public static final int WORK_REJECTED = 2;
public static final int WORK_STARTED = 3;
public static final int WORK_COMPLETED = 4;
static
{
if (SerialVersion.version == SerialVersion.LEGACY)
{
serialVersionUID = 6971276136970053051L;
serialPersistentFields = new ObjectStreamField[] {
new ObjectStreamField("type", int.class),
new ObjectStreamField("work", Work.class),
new ObjectStreamField("e", WorkException.class),
new ObjectStreamField("startDuration", long.class)
};
}
else
{
serialVersionUID = -3063612635015047218L;
serialPersistentFields = new ObjectStreamField[] {
new ObjectStreamField("type", int.class),
new ObjectStreamField("work", Work.class),
new ObjectStreamField("exception", WorkException.class),
new ObjectStreamField("startDuration", long.class)
};
}
}
private int type;
private Work work;
private WorkException e;
private long startDuration;
public WorkEvent(Object source, int type, Work work, WorkException e)
{
this(source, type, work, e, 0l);
}
public WorkEvent(Object source, int type, Work work, WorkException e, long startDuration)
{
super(source);
this.type = type;
this.work = work;
this.e = e;
this.startDuration = startDuration;
}
public int getType()
{
return type;
}
public Work getWork()
{
return work;
}
public WorkException getException()
{
return e;
}
public long getStartDuration()
{
return startDuration;
}
private void readObject(ObjectInputStream ois)
throws ClassNotFoundException, IOException
{
ObjectInputStream.GetField fields = ois.readFields();
String name = serialPersistentFields[TYPE_IDX].getName();
this.type = fields.get(name, 0);
name = serialPersistentFields[WORK_IDX].getName();
this.work = (Work) fields.get(name, null);
name = serialPersistentFields[EXCPEPTION_IDX].getName();
this.e = (WorkException) fields.get(name, null);
name = serialPersistentFields[DURATION_IDX].getName();
this.startDuration = fields.get(name, 0L);
}
private void writeObject(ObjectOutputStream oos)
throws IOException
{
ObjectOutputStream.PutField fields = oos.putFields();
String name = serialPersistentFields[TYPE_IDX].getName();
fields.put(name, type);
name = serialPersistentFields[WORK_IDX].getName();
fields.put(name, work);
name = serialPersistentFields[EXCPEPTION_IDX].getName();
fields.put(name, e);
name = serialPersistentFields[DURATION_IDX].getName();
fields.put(name, startDuration);
oos.writeFields();
}
}