热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

org.zstack.core.asyncbatch.While类的使用及代码示例

本文整理了Java中org.zstack.core.asyncbatch.While类的一些代码示例,展示了While类的具体用法。这些代码示

本文整理了Java中org.zstack.core.asyncbatch.While类的一些代码示例,展示了While类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。While类的具体详情如下:
包路径:org.zstack.core.asyncbatch.While
类名称:While

While介绍

[英]Created by xing5 on 2017/3/5.
[中]由兴5于2017年3月5日创建。

代码示例

代码示例来源:origin: zstackio/zstack

private void detachIpFromVmNicCascade(List msgs, final Completion completion) {
if (msgs.isEmpty()) {
completion.success();
return;
}
new While<>(msgs).all((msg, compl) -> bus.send(msg, new CloudBusCallBack(compl) {
@Override
public void run(MessageReply reply) {
if (!reply.isSuccess()) {
logger.warn(String.format("failed to detach ip[uuid:%s] from vmNic [uuid:%s], %s." +
" However, detaching will go on", msg.getUsedIpUuid(), msg.getVmNicUuid(), reply.getError()));
}
compl.done();
}
})).run(new NoErrorCompletion(completion) {
@Override
public void done() {
completion.success();
}
});
}

代码示例来源:origin: zstackio/zstack

private void pingFilter(PrimaryStorageInventory inv, int count, int oneStepLimit, Completion completion){
List stepCount = new ArrayList<>();
for(int i = 0; i <= count/oneStepLimit; i ++){
stepCount.add(i);
}
List errs = new ArrayList<>();
new While<>(stepCount).each((currentStep, compl) -> {
pingFilterStep(inv, currentStep, oneStepLimit, new Completion(compl) {
@Override
public void success() {
compl.allDone();
}
@Override
public void fail(ErrorCode errorCode) {
errs.add(errorCode);
compl.done();
}
});
}).run(new NoErrorCompletion(completion) {
@Override
public void done() {
if(errs.size() == stepCount.size()){
completion.fail(errs.get(0));
}else {
completion.success();
}
}
});
}

代码示例来源:origin: zstackio/zstack

@Override
public void send(List msgs, int parallelLevel, CloudBusSteppingCallback callback) {
DebugUtils.Assert(!msgs.isEmpty(), "you cannot pass an empty message list to me");
msgs.forEach(this::evaluateMessageTimeout);
new While<>(msgs).step((msg, completion) -> send(msg, new CloudBusCallBack(completion) {
@Override
public void run(MessageReply reply) {
callback.run(msg, reply);
completion.done();
}
}), parallelLevel).run(new NopeNoErrorCompletion());
}

代码示例来源:origin: zstackio/zstack

public void run(NoErrorCompletion completion) {
DebugUtils.Assert(consumer != null, "each() or all() or step() must be called before run()");
if (items.isEmpty()) {
completion.done();
return;
}
if (mode == EACH) {
run(items.iterator(), completion);
} else if (mode == ALL) {
runAll(completion);
} else if (mode == STEP) {
runStep(completion);
} else {
DebugUtils.Assert(false, "should be here");
}
}

代码示例来源:origin: zstackio/zstack

new While<>(vmUuids).step((vmUuid, compl) -> {
MigrateVmMsg msg = new MigrateVmMsg();
msg.setVmInstanceUuid(vmUuid);
List errors = Collections.synchronizedList(new ArrayList<>());
List vmFailedToStop = Collections.synchronizedList(new ArrayList<>());
new While<>(vmUuids).step((vmUuid, coml) -> {
StopVmInstanceMsg msg = new StopVmInstanceMsg();
msg.setVmInstanceUuid(vmUuid);

代码示例来源:origin: zstackio/zstack

new While<>(mons).each((mon, compl) -> {
GetFactsCmd cmd = new GetFactsCmd();
cmd.uuid = self.getUuid();

代码示例来源:origin: zstackio/zstack

new While<>(msgs).all((msg, compl) -> bus.send(msg, new CloudBusCallBack(compl) {
@Override
public void run(MessageReply reply) {
})).run(new NoErrorCompletion(completion) {
@Override
public void done() {

代码示例来源:origin: zstackio/zstack

List selectedHosts = new ArrayList<>();
List errs = new ArrayList<>();
new While<>(hosts).each((h, wcmpl) -> {
reserveHost(h, new Completion(wcmpl) {
@Override
}).run(new NoErrorCompletion(completion) {
@Override
public void done() {

代码示例来源:origin: zstackio/zstack

@Override
public void send(List msgs, int parallelLevel, CloudBusListCallBack callBack) {
DebugUtils.Assert(!msgs.isEmpty(), "you cannot pass an empty message list to me");
msgs.forEach(this::evaluateMessageTimeout);
Map replies = Collections.synchronizedMap(new HashMap<>(msgs.size()));
new While<>(msgs).step((msg, completion) -> send(msg, new CloudBusCallBack(completion) {
@Override
public void run(MessageReply reply) {
replies.put(msg.getId(), reply);
completion.done();
}
}), parallelLevel).run(new NoErrorCompletion(callBack) {
@Override
public void done() {
List results = new ArrayList<>();
assert msgs.size() == replies.size();
msgs.forEach(msg -> results.add(replies.get(msg.getId())));
callBack.run(results);
}
});
}

代码示例来源:origin: zstackio/zstack

new While<>(detachIsoFromVmInstanceMsgs).all((detachIsoFromVmInstanceMsg, completion) -> {
bus.send(detachIsoFromVmInstanceMsg, new CloudBusCallBack(completion) {
@Override

代码示例来源:origin: zstackio/zstack

new While<>(msgs).all((msg, whileCompletion) -> {
bus.send(msg, new CloudBusCallBack(whileCompletion) {
@Override
}).run(new NoErrorCompletion(completion) {
@Override
public void done() {

代码示例来源:origin: zstackio/zstack

new While<>(ps).each((pvo, completion) -> {
mount(PrimaryStorageInventory.valueOf(pvo), inv.getUuid(), new Completion(completion){
}).run(new NoErrorCompletion() {
@Override
public void done() {

代码示例来源:origin: zstackio/zstack

private void syncVolumeSize(){
new While<>(volumeUuids).step((volUuid, completion) -> {
if (!volumeInTracking.add(volUuid)) {
completion.done();
return;
}
SyncVolumeSizeMsg msg = new SyncVolumeSizeMsg();
msg.setVolumeUuid(volUuid);
bus.makeTargetServiceIdByResourceUuid(msg, VolumeConstant.SERVICE_ID, volUuid);
bus.send(msg, new CloudBusCallBack(msg) {
@Override
public void run(MessageReply reply) {
volumeInTracking.remove(msg.getVolumeUuid());
if (!reply.isSuccess()) {
logger.warn(String.format("fail to refresh volume[uuid:%s] size, try again soon", volUuid));
}
completion.done();
}
});
}, 50).run(new NopeNoErrorCompletion());
}

代码示例来源:origin: zstackio/zstack

new While<>(msgs).all((msg, whileCompletion) -> {
bus.send(msg, new CloudBusCallBack(whileCompletion) {
@Override
}).run(new NoErrorCompletion(completion) {
@Override
public void done() {

代码示例来源:origin: zstackio/zstack

new While<>(stepCount).each((currentStep, compl) -> pingHook(new Completion(compl) {
@Override
public void success() {
})).run(new NoErrorCompletion(msg) {
@Override
public void done() {

代码示例来源:origin: zstackio/zstack

@Override
public void afterHostConnected(HostInventory inv) {
if (inv.getStatus().equals(HostStatus.Connected.toString())){
List vmUuids = Q.New(VmInstanceVO.class).select(VmInstanceVO_.uuid)
.eq(VmInstanceVO_.hostUuid, inv.getUuid())
.listValues();
if(vmUuids.isEmpty()){
return;
}
new While<>(vmUuids).step((vmUuid, completion) -> {
VmCheckOwnStateMsg msg = new VmCheckOwnStateMsg();
msg.setVmInstanceUuid(vmUuid);
bus.makeTargetServiceIdByResourceUuid(msg, VmInstanceConstant.SERVICE_ID, vmUuid);
bus.send(msg, new CloudBusCallBack(completion) {
@Override
public void run(MessageReply reply) {
if(!reply.isSuccess()){
logger.warn(String.format("the host[uuid:%s] connected, but the vm[uuid:%s] fails to " +
"update it's state , %s", inv.getUuid(), vmUuid, reply.getError()));
}
completion.done();
}
});
}, 200).run(new NopeNoErrorCompletion());
}
}
}

代码示例来源:origin: zstackio/zstack

new While<>(msgs).all((msg, noErrorCompletion) -> {
bus.send(msg, new CloudBusCallBack(noErrorCompletion) {
@Override
}).run(new NoErrorCompletion(completion) {
@Override
public void done() {

代码示例来源:origin: zstackio/zstack

private void rollbackCertificate(VirtualRouterVmInventory vr, List struct, final NoErrorCompletion completion){
Set certificateUuids = getCertificates(struct);
new While<>(certificateUuids).each((uuid, wcmpl) -> {
VirtualRouterAsyncHttpCallMsg msg = new VirtualRouterAsyncHttpCallMsg();
msg.setVmInstanceUuid(vr.getUuid());
msg.setPath(DELETE_CERTIFICATE_PATH);
CertificateCmd cmd = new CertificateCmd();
cmd.setUuid(uuid);
msg.setCommand(cmd);
bus.makeTargetServiceIdByResourceUuid(msg, VmInstanceConstant.SERVICE_ID, vr.getUuid());
bus.send(msg, new CloudBusCallBack(wcmpl) {
@Override
public void run(MessageReply reply) {
wcmpl.done();
}
});
}).run(new NoErrorCompletion(completion) {
@Override
public void done() {
completion.done();
}
});
}

代码示例来源:origin: zstackio/zstack

@Override
public void afterChangeHostStatus(String hostUuid, HostStatus before, HostStatus next) {
if(next == HostStatus.Disconnected) {
List vmUuids = Q.New(VmInstanceVO.class).select(VmInstanceVO_.uuid)
.eq(VmInstanceVO_.hostUuid, hostUuid)
.listValues();
if(vmUuids.isEmpty()){
return;
}
new While<>(vmUuids).step((vmUuid, completion) -> {
VmStateChangedOnHostMsg msg = new VmStateChangedOnHostMsg();
msg.setVmInstanceUuid(vmUuid);
msg.setHostUuid(hostUuid);
msg.setStateOnHost(VmInstanceState.Unknown);
bus.makeTargetServiceIdByResourceUuid(msg, VmInstanceConstant.SERVICE_ID, vmUuid);
bus.send(msg, new CloudBusCallBack(completion) {
@Override
public void run(MessageReply reply) {
if(!reply.isSuccess()){
logger.warn(String.format("the host[uuid:%s] disconnected, but the vm[uuid:%s] fails to " +
"change it's state to Unknown, %s", hostUuid, vmUuid, reply.getError()));
} else {
logger.debug(String.format("the host[uuid:%s] disconnected, change the VM[uuid:%s]' state to Unknown", hostUuid, vmUuid));
}
completion.done();
}
});
}, 200).run(new NopeNoErrorCompletion());
}
}

代码示例来源:origin: zstackio/zstack

new While<>(msgs).all((msg, com) -> bus.send(msg, new CloudBusCallBack(com) {
@Override
public void run(MessageReply reply) {
})).run(new NoErrorCompletion() {
@Override
public void done() {

推荐阅读
author-avatar
微微aviviya
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有