本文整理汇总了Java中org.osgi.util.promise.Deferred类的典型用法代码示例。如果您正苦于以下问题:Java Deferred类的具体用法?Java Deferred怎么用?Java Deferred使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Deferred类属于org.osgi.util.promise包,在下文中一共展示了Deferred类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: restart
import org.osgi.util.promise.Deferred; //导入依赖的package包/类
@Override
public Promise<Void> restart() {
Deferred<Void> future = new Deferred<>();
Thread restartThread = new Thread("Restart-Server-Thread") {
@Override
public void run() {
Server.inMaintenance = true;
try {
log.info("Restarting server.");
boolean successStarted = startNewServer();
if (!successStarted) {
throw new Exception("Fail to start new server process.");
}
log.info("Restart server (pid:" + ServerUtil.getCurrentPid() + ")");
future.resolve(null);
} catch (Exception ex) {
future.fail(ex);
}
}
};
restartThread.start();
return future.getPromise();
}
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:26,代码来源:Server.java
示例2: callAsyncPromise
import org.osgi.util.promise.Deferred; //导入依赖的package包/类
@Override
public Promise<String> callAsyncPromise(final int delay) {
final Deferred<String> deferred = new Deferred<String>();
new Thread(new Runnable() {
@Override
public void run() {
if (delay == -1) {
deferred.fail(new ExpectedTestException());
return;
}
sleep(delay);
deferred.resolve("Finished");
}
}).start();
return deferred.getPromise();
}
开发者ID:apache,项目名称:aries-rsa,代码行数:19,代码来源:MyServiceImpl.java
示例3: getLongResult
import org.osgi.util.promise.Deferred; //导入依赖的package包/类
@Override
public Promise<Long> getLongResult() {
Deferred<Long> d = new Deferred<>();
Promise<Long> promise = superSlowService.compute();
promise.onResolve(() -> {
new Thread(new Runnable() {
@Override
public void run() {
d.resolveWith(promise);
}
}).start();
});
Promise<Long> promise2 = d.getPromise();
return promise2;
}
开发者ID:primeval-io,项目名称:aspecio,代码行数:19,代码来源:DemoConsumerImpl.java
示例4: forward
import org.osgi.util.promise.Deferred; //导入依赖的package包/类
private Promise<NeuralNetworkSequenceResult> forward(int index, UUID[] inputIds, UUID[] outputIds, List<Tensor>[] inputs, String... tags){
int sequenceLength = inputs[0].size();
storeSequenceMemories(index);
return forward(inputIds, outputIds, getSequenceInputs(index, inputs), tags).then(p -> {
// store output
storeSequenceOutputs(index, p.getValue().tensors);
// increment counter
int next = index + 1;
// check if we are done
if(next == sequenceLength){
Deferred<NeuralNetworkSequenceResult> d = new Deferred<>();
d.resolve(new NeuralNetworkSequenceResult(sequenceOutputs, tags));
return d.getPromise();
} else {
return forward(next, inputIds, outputIds, inputs, tags);
}
});
}
开发者ID:ibcn-cloudlet,项目名称:dianne,代码行数:23,代码来源:NeuralNetworkWrapper.java
示例5: getNeuralNetwork
import org.osgi.util.promise.Deferred; //导入依赖的package包/类
@Override
public Promise<NeuralNetwork> getNeuralNetwork(NeuralNetworkInstanceDTO nni) {
Deferred<NeuralNetwork> result = new Deferred<>();
NeuralNetwork nn = nnServices.get(nni.id);
if(nn!=null){
result.resolve(nn);
return result.getPromise();
}
ToWatch w = new ToWatch();
w.nni = nni;
w.deferred = result;
toWatchFor.put(nni.id, w);
createNeuralNetwork(nni.id);
return result.getPromise();
}
开发者ID:ibcn-cloudlet,项目名称:dianne,代码行数:20,代码来源:DianneImpl.java
示例6: AsyncResponseFuture
import org.osgi.util.promise.Deferred; //导入依赖的package包/类
public AsyncResponseFuture(ClassLoader loader, Method method, SerializationStrategy serializationStrategy, DispatchQueue queue) {
this.loader = loader;
this.method = method;
this.serializationStrategy = serializationStrategy;
this.queue = queue;
this.deferred = new Deferred<>();
}
开发者ID:apache,项目名称:aries-rsa,代码行数:8,代码来源:AsyncPromiseInvocationStrategy.java
示例7: exceptionPromise
import org.osgi.util.promise.Deferred; //导入依赖的package包/类
@Override
public Promise<String> exceptionPromise() throws IOException {
final Deferred<String> deferred = new Deferred<String>();
new Thread(() -> {
sleep(500);
deferred.fail(new IOException("test"));
}).start();
return deferred.getPromise();
}
开发者ID:apache,项目名称:aries-rsa,代码行数:10,代码来源:PromiseInvocationTest.java
示例8: createPromiseResult
import org.osgi.util.promise.Deferred; //导入依赖的package包/类
private Object createPromiseResult(final Method method, final Object[] args) {
final Deferred<Object> deferred = new Deferred<Object>();
new Thread(new Runnable() {
@Override
public void run() {
try {
deferred.resolve(handleSyncCall(method, args));
} catch (Throwable e) {
deferred.fail(e);
}
}
}).start();
return deferred.getPromise();
}
开发者ID:apache,项目名称:aries-rsa,代码行数:16,代码来源:TcpInvocationHandler.java
示例9: compute
import org.osgi.util.promise.Deferred; //导入依赖的package包/类
@Override
@Timed
public Promise<Long> compute() {
Deferred<Long> deferred = new Deferred<>();
executor.submit(() -> {
Uninterruptibles.sleepUninterruptibly(3, TimeUnit.SECONDS);
deferred.resolve(42L);
});
return deferred.getPromise();
}
开发者ID:primeval-io,项目名称:aspecio,代码行数:11,代码来源:SuperSlowServiceImpl.java
示例10: trigger
import org.osgi.util.promise.Deferred; //导入依赖的package包/类
private synchronized void trigger(String rfid){
// first keep the old deferred we have to resolve
Deferred<String> toResolve = nextRFID;
// create new deferred for next, since we will call
// a new nextRFID() when the previous is resolved
nextRFID = new Deferred<String>();
// resolve previous
toResolve.resolve(rfid);
// set lastRFID
this.lastRFID = rfid;
}
开发者ID:osgi,项目名称:osgi.iot.contest.sdk,代码行数:14,代码来源:EmulatorFactory.java
示例11: helloPromise
import org.osgi.util.promise.Deferred; //导入依赖的package包/类
@Override
public Promise<String> helloPromise() {
final Deferred<String> deferred = new Deferred<String>();
new Thread(() -> deferred.resolve("Hello")).start();
return deferred.getPromise();
}
开发者ID:apache,项目名称:aries-rsa,代码行数:7,代码来源:PromiseInvocationTest.java
示例12: trigger
import org.osgi.util.promise.Deferred; //导入依赖的package包/类
private synchronized void trigger(String trainId, String segment) {
// info("trigger: trainId={} segment={}", trainId, segment);
Deferred<String> currentLocation = nextLocation;
nextLocation = new Deferred<String>();
currentLocation.resolve(trainId + ":" + segment);
}
开发者ID:osgi,项目名称:osgi.iot.contest.sdk,代码行数:7,代码来源:TrainLocationClient.java
示例13: trigger
import org.osgi.util.promise.Deferred; //导入依赖的package包/类
private synchronized void trigger(String trainId, String segment) {
Deferred<String> currentLocation = nextLocation;
nextLocation = new Deferred<String>();
currentLocation.resolve(trainId + ":" + segment);
}
开发者ID:osgi,项目名称:osgi.iot.contest.sdk,代码行数:6,代码来源:TrainControllerImpl.java
示例14: trigger
import org.osgi.util.promise.Deferred; //导入依赖的package包/类
private synchronized void trigger(String rfid) {
Deferred<String> toResolve = nextRFID;
nextRFID = new Deferred<String>();
toResolve.resolve(rfid);
this.lastRFID = rfid;
}
开发者ID:osgi,项目名称:osgi.iot.contest.sdk,代码行数:7,代码来源:RFIDSegmentImpl.java
注:本文中的org.osgi.util.promise.Deferred类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论