Skip to content

Commit 0991deb

Browse files
committed
make asyncback as a mandotry constructor parameter for callbacks
1 parent 4b87000 commit 0991deb

File tree

79 files changed

+182
-223
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+182
-223
lines changed

compute/src/main/java/org/zstack/compute/allocator/HostAllocatorManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ private void handle(final AllocateHostMsg msg) {
312312

313313
if (msg.isDryRun()) {
314314
final AllocateHostDryRunReply reply = new AllocateHostDryRunReply();
315-
strategy.dryRun(spec, new ReturnValueCompletion<List<HostInventory>>() {
315+
strategy.dryRun(spec, new ReturnValueCompletion<List<HostInventory>>(msg) {
316316
@Override
317317
public void success(List<HostInventory> returnValue) {
318318
reply.setHosts(returnValue);

compute/src/main/java/org/zstack/compute/host/HostBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ public String getName() {
505505
}
506506

507507
protected void handle(final APIChangeHostStateMsg msg) {
508-
thdf.chainSubmit(new ChainTask() {
508+
thdf.chainSubmit(new ChainTask(msg) {
509509
@Override
510510
public String getName() {
511511
return "change-host-state-" + self.getUuid();

compute/src/main/java/org/zstack/compute/host/HostManagerImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ public void run(FailToAddHostExtensionPoint ext) {
371371
private void handle(final AddHostMsg msg) {
372372
final AddHostReply reply = new AddHostReply();
373373

374-
doAddHost(msg, new ReturnValueCompletion<HostInventory>() {
374+
doAddHost(msg, new ReturnValueCompletion<HostInventory>(msg) {
375375
@Override
376376
public void success(HostInventory returnValue) {
377377
reply.setInventory(returnValue);
@@ -390,7 +390,7 @@ public void fail(ErrorCode errorCode) {
390390
private void handle(final APIAddHostMsg msg) {
391391
final APIAddHostEvent evt = new APIAddHostEvent(msg.getId());
392392

393-
doAddHost(msg, new ReturnValueCompletion<HostInventory>() {
393+
doAddHost(msg, new ReturnValueCompletion<HostInventory>(msg) {
394394
@Override
395395
public void success(HostInventory inventory) {
396396
evt.setInventory(inventory);
@@ -541,7 +541,8 @@ private void loadHost() {
541541
msgs.add(connectMsg);
542542
}
543543

544-
bus.send(msgs, HostGlobalConfig.HOST_LOAD_PARALLELISM_DEGREE.value(Integer.class), new CloudBusSteppingCallback() {
544+
bus.send(msgs, HostGlobalConfig.HOST_LOAD_PARALLELISM_DEGREE.value(Integer.class),
545+
new CloudBusSteppingCallback(null) {
545546
@Override
546547
public void run(NeedReplyMessage msg, MessageReply reply) {
547548
ConnectHostMsg cmsg = (ConnectHostMsg) msg;

compute/src/main/java/org/zstack/compute/host/HostTrackImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private void handleReply(final String hostUuid, MessageReply reply) {
8989
msg.setHostUuid(hostUuid);
9090
msg.setSkipIfHostConnected(true);
9191
bus.makeTargetServiceIdByResourceUuid(msg, HostConstant.SERVICE_ID, hostUuid);
92-
bus.send(msg, new CloudBusCallBack() {
92+
bus.send(msg, new CloudBusCallBack(null) {
9393
@Override
9494
public void run(MessageReply reply) {
9595
inReconnectingHost.remove(hostUuid);
@@ -126,7 +126,8 @@ public void run() {
126126
return;
127127
}
128128

129-
bus.send(msgs, HostGlobalConfig.HOST_TRACK_PARALLELISM_DEGREE.value(Integer.class), new CloudBusSteppingCallback() {
129+
bus.send(msgs, HostGlobalConfig.HOST_TRACK_PARALLELISM_DEGREE.value(Integer.class),
130+
new CloudBusSteppingCallback(null) {
130131
@Override
131132
public void run(NeedReplyMessage msg, MessageReply reply) {
132133
PingHostMsg pmsg = (PingHostMsg)msg;

compute/src/main/java/org/zstack/compute/vm/RebootVmInstanceJob.java

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void run() {
3737
RebootVmInstanceMsg rmsg = new RebootVmInstanceMsg();
3838
rmsg.setVmInstanceUuid(vmUuid);
3939
bus.makeTargetServiceIdByResourceUuid(rmsg, VmInstanceConstant.SERVICE_ID, vmUuid);
40-
bus.send(rmsg, new CloudBusCallBack() {
40+
bus.send(rmsg, new CloudBusCallBack(null) {
4141
@Override
4242
public void run(MessageReply reply) {
4343
if (reply.isSuccess()) {

compute/src/main/java/org/zstack/compute/vm/StartVmInstanceJob.java

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void run() {
3838
smsg.setVmInstanceUuid(vmUuid);
3939
smsg.setAccountUuid(getAccountUuid());
4040
bus.makeTargetServiceIdByResourceUuid(smsg, VmInstanceConstant.SERVICE_ID, vmUuid);
41-
bus.send(smsg, new CloudBusCallBack() {
41+
bus.send(smsg, new CloudBusCallBack(null) {
4242
@Override
4343
public void run(MessageReply reply) {
4444
if (reply.isSuccess()) {

compute/src/main/java/org/zstack/compute/vm/StopVmInstanceJob.java

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void run() {
4141
StopVmInstanceMsg smsg = new StopVmInstanceMsg();
4242
smsg.setVmInstanceUuid(vmUuid);
4343
bus.makeTargetServiceIdByResourceUuid(smsg, VmInstanceConstant.SERVICE_ID, vmUuid);
44-
bus.send(smsg, new CloudBusCallBack() {
44+
bus.send(smsg, new CloudBusCallBack(null) {
4545
@Override
4646
public void run(MessageReply reply) {
4747
if (reply.isSuccess()) {

compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ public String getName() {
13461346

13471347
private void handle(final MigrateVmMsg msg) {
13481348
final MigrateVmReply reply = new MigrateVmReply();
1349-
thdf.chainSubmit(new ChainTask() {
1349+
thdf.chainSubmit(new ChainTask(msg) {
13501350
@Override
13511351
public String getSyncSignature() {
13521352
return syncThreadName;
@@ -1529,7 +1529,7 @@ public String getName() {
15291529

15301530
private void handle(final VmAttachNicMsg msg) {
15311531
final VmAttachNicReply reply = new VmAttachNicReply();
1532-
attachNic(msg, msg.getL3NetworkUuid(), new ReturnValueCompletion<VmNicInventory>() {
1532+
attachNic(msg, msg.getL3NetworkUuid(), new ReturnValueCompletion<VmNicInventory>(msg) {
15331533
@Override
15341534
public void success(VmNicInventory nic) {
15351535
reply.setInventroy(nic);
@@ -3142,7 +3142,7 @@ private void stretchInstanceOfferingForRunningVm(List<ChangeInstanceOfferingExte
31423142
hmsg.setHostUuid(self.getHostUuid());
31433143
hmsg.setInstanceOfferingInventory(inv);
31443144
bus.makeTargetServiceIdByResourceUuid(hmsg, HostConstant.SERVICE_ID, self.getHostUuid());
3145-
bus.send(hmsg, new CloudBusCallBack() {
3145+
bus.send(hmsg, new CloudBusCallBack(null) {
31463146
@Override
31473147
public void run(MessageReply reply) {
31483148
if (!reply.isSuccess()) {
@@ -3902,7 +3902,7 @@ public void run(SyncTaskChain chain) {
39023902

39033903
protected void handle(final APIDestroyVmInstanceMsg msg) {
39043904
final APIDestroyVmInstanceEvent evt = new APIDestroyVmInstanceEvent(msg.getId());
3905-
destroyVm(msg, new Completion() {
3905+
destroyVm(msg, new Completion(msg) {
39063906
@Override
39073907
public void success() {
39083908
bus.publish(evt);

compute/src/main/java/org/zstack/compute/vm/VmInstanceManagerImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ private void createVmButNotStart(CreateVmInstanceMsg msg, VmInstanceInventory in
711711
}
712712

713713
private void handle(final CreateVmInstanceMsg msg) {
714-
doCreateVmInstance(msg, null, new ReturnValueCompletion<VmInstanceInventory>() {
714+
doCreateVmInstance(msg, null, new ReturnValueCompletion<VmInstanceInventory>(msg) {
715715
@Override
716716
public void success(VmInstanceInventory inv) {
717717
CreateVmInstanceReply reply = new CreateVmInstanceReply();
@@ -757,7 +757,7 @@ private CreateVmInstanceMsg fromAPICreateVmInstanceMsg(APICreateVmInstanceMsg ms
757757
}
758758

759759
private void handle(final APICreateVmInstanceMsg msg) {
760-
doCreateVmInstance(fromAPICreateVmInstanceMsg(msg), msg, new ReturnValueCompletion<VmInstanceInventory>() {
760+
doCreateVmInstance(fromAPICreateVmInstanceMsg(msg), msg, new ReturnValueCompletion<VmInstanceInventory>(msg) {
761761
APICreateVmInstanceEvent evt = new APICreateVmInstanceEvent(msg.getId());
762762

763763
@Override
@@ -1794,7 +1794,7 @@ public void run(GCContext context, final GCCompletion completion) {
17941794
VmCheckOwnStateMsg msg = new VmCheckOwnStateMsg();
17951795
msg.setVmInstanceUuid(uuid);
17961796
bus.makeTargetServiceIdByResourceUuid(msg, VmInstanceConstant.SERVICE_ID, uuid);
1797-
bus.send(msg, new CloudBusCallBack() {
1797+
bus.send(msg, new CloudBusCallBack(completion) {
17981798
@Override
17991799
public void run(MessageReply reply) {
18001800
if (reply.isSuccess()) {
@@ -1895,7 +1895,7 @@ public ExpungeVmMsg call(Tuple t) {
18951895
return false;
18961896
}
18971897

1898-
bus.send(msgs, 100, new CloudBusListCallBack() {
1898+
bus.send(msgs, 100, new CloudBusListCallBack(null) {
18991899
@Override
19001900
public void run(List<MessageReply> replies) {
19011901
for (MessageReply r : replies) {

console/src/main/java/org/zstack/console/AbstractConsoleProxyBackend.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public abstract class AbstractConsoleProxyBackend implements ConsoleBackend, Com
6565
protected abstract boolean isAgentConnected();
6666

6767
private void establishNewProxy(ConsoleProxy proxy, SessionInventory session, final VmInstanceInventory vm, final ReturnValueCompletion<ConsoleInventory> complete) {
68-
proxy.establishProxy(session, vm, new ReturnValueCompletion<ConsoleProxyInventory>() {
68+
proxy.establishProxy(session, vm, new ReturnValueCompletion<ConsoleProxyInventory>(complete) {
6969
@Override
7070
public void success(ConsoleProxyInventory ret) {
7171
ConsoleProxyVO vo = new ConsoleProxyVO();

console/src/main/java/org/zstack/console/ConsoleManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public void beforeMigrateVm(VmInstanceInventory inv, String destHostUuid) {
213213
@Override
214214
public void afterMigrateVm(VmInstanceInventory inv, String srcHostUuid) {
215215
ConsoleBackend bkd = getBackend();
216-
FutureCompletion completion = new FutureCompletion();
216+
FutureCompletion completion = new FutureCompletion(null);
217217
bkd.deleteConsoleSession(inv, completion);
218218
try {
219219
synchronized (completion) {

console/src/main/java/org/zstack/console/ConsoleProxyAgentTracker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void handleReply(final String resourceUuid, MessageReply reply) {
7373

7474
ConsoleBackend bkd = cmgr.getConsoleBackend();
7575
rmsg.setServiceId(bkd.returnServiceIdForConsoleAgentMsg(rmsg, resourceUuid));
76-
bus.send(rmsg, new CloudBusCallBack() {
76+
bus.send(rmsg, new CloudBusCallBack(null) {
7777
@Override
7878
public void run(MessageReply reply) {
7979
//TODO

core/src/main/java/org/zstack/core/aspect/AsyncBackupAspect.aj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,12 @@ public aspect AsyncBackupAspect {
205205
backup(completion.getBackups(), t);
206206
}
207207
}
208+
209+
void around(org.zstack.header.core.AbstractCompletion completion) : this(completion) && execution(void org.zstack.header.core.workflow.FlowFinallyHandler+.Finally(..)) {
210+
try {
211+
proceed(completion);
212+
} catch (Throwable t) {
213+
backup(completion.getBackups(), t);
214+
}
215+
}
208216
}

core/src/main/java/org/zstack/core/asyncbatch/AsyncBatch.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ public abstract class AsyncBatch extends AbstractCompletion {
2222
private List<AsyncBatchRunner> runners = new ArrayList<>();
2323
protected List<ErrorCode> errors = new ArrayList<>();
2424

25-
public AsyncBatch(AsyncBackup... backups) {
26-
super(backups);
27-
}
28-
29-
public AsyncBatch() {
25+
public AsyncBatch(AsyncBackup one, AsyncBackup... others) {
26+
super(one, others);
3027
}
3128

3229
protected void batch(AsyncBatchRunner runner) {

core/src/main/java/org/zstack/core/asyncbatch/AsyncLoop.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void start() {
4141
Collection<T> items = collectionForLoop();
4242
DebugUtils.Assert(items != null, "collectionForLoop cannot return null");
4343

44-
runItem(items.iterator(), new Completion(backups) {
44+
runItem(items.iterator(), new Completion(null, backups) {
4545
@Override
4646
public void success() {
4747
done();

core/src/main/java/org/zstack/core/asyncbatch/LoopAsyncBatch.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99
* Created by xing5 on 2016/6/26.
1010
*/
1111
public abstract class LoopAsyncBatch<T> extends AsyncBatch {
12-
public LoopAsyncBatch(AsyncBackup... backups) {
13-
super(backups);
14-
}
15-
16-
public LoopAsyncBatch() {
12+
public LoopAsyncBatch(AsyncBackup one, AsyncBackup... others) {
13+
super(one, others);
1714
}
1815

1916
protected abstract Collection<T> collect();

core/src/main/java/org/zstack/core/cascade/CascadeFacadeImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public void asyncCascade(CascadeAction action, final Completion completion) {
203203
public void run(final FlowTrigger trigger, Map data) {
204204
logger.debug(String.format("[Async cascade (%s)]: %s --> %s",
205205
caction.getActionCode(), caction.getParentIssuer(), node.getName()));
206-
node.getExtension().asyncCascade(caction, new Completion() {
206+
node.getExtension().asyncCascade(caction, new Completion(trigger) {
207207
@Override
208208
public void success() {
209209
trigger.next();
@@ -218,12 +218,12 @@ public void fail(ErrorCode errorCode) {
218218
});
219219
}
220220

221-
chain.done(new FlowDoneHandler() {
221+
chain.done(new FlowDoneHandler(completion) {
222222
@Override
223223
public void handle(Map data) {
224224
completion.success();
225225
}
226-
}).error(new FlowErrorHandler() {
226+
}).error(new FlowErrorHandler(completion) {
227227
@Override
228228
public void handle(ErrorCode errCode, Map data) {
229229
completion.fail(errCode);

core/src/main/java/org/zstack/core/cloudbus/CloudBusCallBack.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66
import org.zstack.header.message.NeedReplyMessage;
77

88
public abstract class CloudBusCallBack extends AbstractCompletion {
9-
public CloudBusCallBack(AsyncBackup...backup) {
10-
super(backup);
11-
}
12-
13-
public CloudBusCallBack() {
9+
public CloudBusCallBack(AsyncBackup one, AsyncBackup...others) {
10+
super(one, others);
1411
}
1512

1613
public abstract void run(MessageReply reply);

core/src/main/java/org/zstack/core/cloudbus/CloudBusImpl2.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,7 @@ private void parallelSend(final Iterator<NeedReplyMessage> it, final List<Messag
15181518
}
15191519

15201520
final NeedReplyMessage fmsg = msg;
1521-
send(fmsg, new CloudBusCallBack() {
1521+
send(fmsg, new CloudBusCallBack(completion) {
15221522
@Override
15231523
public void run(MessageReply reply) {
15241524
int replyNum;
@@ -1557,7 +1557,7 @@ public void send(final List<? extends NeedReplyMessage> msgs, final int parallel
15571557
final List<MessageReply> replies = new ArrayList<MessageReply>();
15581558
final int retNum = msgs.size();
15591559
for (NeedReplyMessage nmsg : init) {
1560-
send(nmsg, new CloudBusCallBack() {
1560+
send(nmsg, new CloudBusCallBack(null) {
15611561

15621562
private MessageReply findReply(final Message msg) {
15631563
return CollectionUtils.find(replies, new Function<MessageReply, MessageReply>() {
@@ -1611,7 +1611,7 @@ private void steppingSend(final Iterator<NeedReplyMessage> it, final CloudBusSte
16111611
}
16121612

16131613
final NeedReplyMessage fmsg = msg;
1614-
send(msg, new CloudBusCallBack() {
1614+
send(msg, new CloudBusCallBack(null) {
16151615
@Override
16161616
public void run(MessageReply reply) {
16171617
try {
@@ -1642,7 +1642,7 @@ public void send(final List<? extends NeedReplyMessage> msgs, final int parallel
16421642

16431643
final Iterator<NeedReplyMessage> it = copy.iterator();
16441644
for (final NeedReplyMessage msg : init) {
1645-
send(msg, new CloudBusCallBack() {
1645+
send(msg, new CloudBusCallBack(null) {
16461646
@Override
16471647
public void run(MessageReply reply) {
16481648
try {

core/src/main/java/org/zstack/core/cloudbus/CloudBusListCallBack.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77
import java.util.List;
88

99
public abstract class CloudBusListCallBack extends AbstractCompletion {
10-
public CloudBusListCallBack(AsyncBackup... backup) {
11-
super(backup);
12-
}
13-
14-
public CloudBusListCallBack() {
10+
public CloudBusListCallBack(AsyncBackup one, AsyncBackup... others) {
11+
super(one, others);
1512
}
1613

1714
public abstract void run(List<MessageReply> replies);

core/src/main/java/org/zstack/core/cloudbus/CloudBusSteppingCallback.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99
/**
1010
*/
1111
public abstract class CloudBusSteppingCallback extends AbstractCompletion {
12-
public CloudBusSteppingCallback(AsyncBackup...backup) {
13-
super(backup);
14-
}
15-
16-
public CloudBusSteppingCallback() {
12+
public CloudBusSteppingCallback(AsyncBackup one, AsyncBackup... others) {
13+
super(one, others);
1714
}
1815

1916
public abstract void run(NeedReplyMessage msg, MessageReply reply);

core/src/main/java/org/zstack/core/gc/GCCompletion.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77
* Created by frank on 8/5/2015.
88
*/
99
public abstract class GCCompletion extends Completion {
10-
public GCCompletion(AsyncBackup... backup) {
11-
super(backup);
12-
}
13-
14-
public GCCompletion() {
10+
public GCCompletion(AsyncBackup one, AsyncBackup... others) {
11+
super(one, others);
1512
}
1613

1714
public abstract void cancel();

core/src/main/java/org/zstack/core/gc/GCFacadeImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ private void scheduleTask(final EventBasedGCPersistentContext context, final Gar
214214

215215
final RunningOnce once = new RunningOnce();
216216

217-
final GCCompletion completion = new GCCompletion() {
217+
final GCCompletion completion = new GCCompletion(null) {
218218
@Override
219219
public void success() {
220220
vo.setStatus(GCStatus.Done);
@@ -274,7 +274,7 @@ public void cancel() {
274274
private void scheduleTask(final TimeBasedGCPersistentContext context, final GarbageCollectorVO vo, boolean instant, final boolean updateDb) {
275275
final RunningOnce once = new RunningOnce();
276276

277-
final GCCompletion completion = new GCCompletion() {
277+
final GCCompletion completion = new GCCompletion(null) {
278278
@Override
279279
public void success() {
280280
vo.setStatus(GCStatus.Done);
@@ -363,7 +363,7 @@ private void scheduleTask(final EventBasedGCEphemeralContext context) {
363363

364364
final RunningOnce once = new RunningOnce();
365365

366-
final GCCompletion completion = new GCCompletion() {
366+
final GCCompletion completion = new GCCompletion(null) {
367367
@Override
368368
public void success() {
369369
logger.debug(String.format("GC ephemeral job[name:%s] is done", context.getName()));
@@ -417,7 +417,7 @@ public void run() {
417417
private void scheduleTask(final TimeBasedGCEphemeralContext context, boolean instant) {
418418
final RunningOnce once = new RunningOnce();
419419

420-
final GCCompletion completion = new GCCompletion() {
420+
final GCCompletion completion = new GCCompletion(null) {
421421
@Override
422422
public void success() {
423423
logger.debug(String.format("GC ephemeral job[name:%s] is done", context.getName()));

0 commit comments

Comments
 (0)