本文整理汇总了Java中com.google.appengine.api.taskqueue.DeferredTask类的典型用法代码示例。如果您正苦于以下问题:Java DeferredTask类的具体用法?Java DeferredTask怎么用?Java DeferredTask使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DeferredTask类属于com.google.appengine.api.taskqueue包,在下文中一共展示了DeferredTask类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deferredTask
import com.google.appengine.api.taskqueue.DeferredTask; //导入依赖的package包/类
private static void deferredTask(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
String queue = req.getParameter("queue");
Queue q;
if (queue == null) {
q = QueueFactory.getDefaultQueue();
} else {
q = QueueFactory.getQueue(queue);
}
final String data = req.getParameter("deferredData");
TaskOptions opts =
TaskOptions.Builder.withPayload(
new DeferredTask() {
@Override
public void run() {
gotCalledBack(data);
}
});
latch = new CountDownLatch(1);
TaskHandle handle = q.add(opts);
resp.getWriter().print(handle.getQueueName());
}
示例2: newDeferredTask
import com.google.appengine.api.taskqueue.DeferredTask; //导入依赖的package包/类
private static DeferredTask newDeferredTask(Constructor<DeferredTask> ctor, Object arg) {
try {
return ctor.newInstance(arg);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:8,代码来源:DeferredDatastoreSessionStore.java
示例3: publishMessages
import com.google.appengine.api.taskqueue.DeferredTask; //导入依赖的package包/类
/**
* Publishes messages to clients listening on an object.
*/
public void publishMessages(ObjectId object, String jsonString) {
for (Platform platform : Platform.values()) {
DeferredTask notify = new PushNotify(object.toString(), jsonString, platform);
QUEUE.add(TaskOptions.Builder.withPayload(notify));
}
log.info("Scheduled push notifications: " + object + " " + jsonString);
}
示例4: scheduleRequest
import com.google.appengine.api.taskqueue.DeferredTask; //导入依赖的package包/类
public static void scheduleRequest(RideRequest rideRequest) {
DeferredTask task = new SendNotificationTask(rideRequest.getId());
QueueFactory.getQueue(QUEUE_NAME).add(TaskOptions.Builder.withPayload(task));
}
示例5: run
import com.google.appengine.api.taskqueue.DeferredTask; //导入依赖的package包/类
@Override
public void run() {
if(event == null || eventHandlers.isEmpty())
return;
String key = event.getClass().getName();
if(!eventHandlers.containsKey(key))
return;
List<Class<? extends EventHandler<? extends Event>>> handlersForType = eventHandlers.get(key);
List<DeferredTask> taskList = new ArrayList<DeferredTask>();
/*
* Loop through all of the event handlers for the event being published
* and attempt to instantiate the handlers through reflection.
*/
for(Class<? extends EventHandler<? extends Event>> handler : handlersForType){
try{
/*
* get a constructor that expects a single parameter value that matches the event's type
*/
Constructor<? extends EventHandler<? extends Event>> constructor = handler.getDeclaredConstructor(event.getClass());
constructor.setAccessible(true);
taskList.add(constructor.newInstance(event));
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
/*
* unable to create an instance of the handler.
* more than likely this is caused by the handler
* not implementing a constructor that takes a single
* parameter instance of the event.
*
* There are several possibilities for this situation
* - Publish a new event
* - Log the exception
* - Send an email to an administrator
* - etc..
*/
}
}
if(taskList.isEmpty())
return;
Queue taskQueue = null;
if(queue != null)
taskQueue = QueueFactory.getQueue(queue);
else
taskQueue = QueueFactory.getDefaultQueue();
for(DeferredTask task : taskList){
taskQueue.addAsync(TaskOptions.Builder.withPayload(task));
}
}