I need help identifying any significant design issues with some code I have generated to track status updates.
I have a big task A which contains multiple small tasks and each of these small tasks updates the status of A in the data store.
This is how I've implemented: For each type of Task A(A can be of multiple types), I'll create an enum class implementing the interface StatusTask given below.
And then, I'll call StatusTask.Chain.start(starting enum object, param);
public interface StatusTask<T, V extends Enum<V> & StatusTask<T,V>>
{
public V execute(T t) throws Exception;
public void fail(Exception e) throws Exception;
public static class Chain
{
public static <T,V extends Enum<V> & StatusTask<T,V>> void start(V v, T t)
{
V n = null;
try
{
n = v.execute(t);
}
catch(Exception e)
{
v.fail(e);
}
if(n == null || n == v)
{
return;
}
start(n, t);
}
}
}
Do you see any significant flaws with this design?
Is there a better design to handle such a scenario?
Example Scenario: Fetching a file and processing it. Following are the task-status: (0. Initial task. Move to Task 1.)
- Send Request and mark status as Sent Request
- Successful Response Received and mark status as Response Received and move to task 4
- Error Response Received and mark status as Response Received
- If file present, then mark status as Processing and execute step 4 else step 5
- Mark status as File not available and exit
- Parse file. If no error, goto step 7 else step 8
- Mark status as File parsing succeeded and do something.....
- Mark status as File parsing failed and exit