docs: commander docs + refactoring (#2878)

This commit is contained in:
Ilkka Seppälä
2024-03-30 17:37:02 +02:00
committed by GitHub
parent 2228212c23
commit 81ebcf0a79
9 changed files with 166 additions and 30 deletions
@@ -121,7 +121,7 @@ public class Commander {
sendShippingRequest(order);
}
private void sendShippingRequest(Order order) throws Exception {
private void sendShippingRequest(Order order) {
var list = shippingService.exceptionsList;
Retry.Operation op = (l) -> {
if (!l.isEmpty()) {
@@ -233,7 +233,7 @@ public class Commander {
try {
r.perform(list, order);
} catch (Exception e1) {
e1.printStackTrace();
LOG.error("An exception occurred", e1);
}
});
t.start();
@@ -282,7 +282,7 @@ public class Commander {
try {
r.perform(list, qt);
} catch (Exception e1) {
e1.printStackTrace();
LOG.error("An exception occurred", e1);
}
});
t.start();
@@ -305,7 +305,7 @@ public class Commander {
try {
r.perform(list, null);
} catch (Exception e1) {
e1.printStackTrace();
LOG.error("An exception occurred", e1);
}
});
t2.start();
@@ -324,12 +324,12 @@ public class Commander {
};
Retry.HandleErrorIssue<QueueTask> handleError = (o, err) -> {
};
var r = new Retry<QueueTask>(op, handleError, numOfRetries, retryDuration,
var r = new Retry<>(op, handleError, numOfRetries, retryDuration,
e -> DatabaseUnavailableException.class.isAssignableFrom(e.getClass()));
try {
r.perform(list, null);
} catch (Exception e1) {
e1.printStackTrace();
LOG.error("An exception occurred", e1);
}
});
t3.start();
@@ -351,7 +351,7 @@ public class Commander {
try {
r.perform(list, order);
} catch (Exception e1) {
e1.printStackTrace();
LOG.error("An exception occurred", e1);
}
});
t.start();
@@ -409,7 +409,7 @@ public class Commander {
try {
r.perform(list, order);
} catch (Exception e1) {
e1.printStackTrace();
LOG.error("An exception occurred", e1);
}
});
t.start();
@@ -465,7 +465,7 @@ public class Commander {
try {
r.perform(list, order);
} catch (Exception e1) {
e1.printStackTrace();
LOG.error("An exception occurred", e1);
}
});
t.start();
@@ -537,7 +537,7 @@ public class Commander {
try {
r.perform(list, order);
} catch (Exception e1) {
e1.printStackTrace();
LOG.error("An exception occurred", e1);
}
});
t.start();
@@ -94,7 +94,7 @@ public class Retry<T> {
this.errors.add(e);
if (this.attempts.incrementAndGet() >= this.maxAttempts || !this.test.test(e)) {
this.handleError.handleIssue(obj, e);
return; //return here...dont go further
return; //return here... don't go further
}
try {
long testDelay =
@@ -47,7 +47,7 @@ public class EmployeeHandle extends Service {
var o = (Order) parameters[0];
if (database.get(o.id) == null) {
database.add(o);
return o.id; //true rcvd - change addedToEmployeeHandle to true else dont do anything
return o.id; //true rcvd - change addedToEmployeeHandle to true else don't do anything
}
return null;
}
@@ -38,7 +38,7 @@ public class MessagingDatabase extends Database<MessageRequest> {
@Override
public MessageRequest add(MessageRequest r) {
return data.put(r.reqId, r);
return data.put(r.reqId(), r);
}
@Override
@@ -44,11 +44,7 @@ public class MessagingService extends Service {
PAYMENT_SUCCESSFUL
}
@RequiredArgsConstructor
static class MessageRequest {
final String reqId;
final MessageToSend msg;
}
record MessageRequest(String reqId, MessageToSend msg) {}
public MessagingService(MessagingDatabase db, Exception... exc) {
super(db, exc);
@@ -51,7 +51,7 @@ public class PaymentService extends Service {
*/
public String receiveRequest(Object... parameters) throws DatabaseUnavailableException {
//it could also be sending a userid, payment details here or something, not added here
//it could also be sending an userid, payment details here or something, not added here
var id = generateId();
var req = new PaymentRequest(id, (float) parameters[0]);
return updateDb(req);
@@ -25,7 +25,6 @@
package com.iluwatar.commander.queue;
import com.iluwatar.commander.Database;
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
import com.iluwatar.commander.exceptions.IsEmptyException;
import java.util.ArrayList;
import java.util.List;