本文整理汇总了Java中com.google.appengine.api.taskqueue.TaskOptions类的典型用法代码示例。如果您正苦于以下问题:Java TaskOptions类的具体用法?Java TaskOptions怎么用?Java TaskOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TaskOptions类属于com.google.appengine.api.taskqueue包,在下文中一共展示了TaskOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scheduleNotificationBuild
import com.google.appengine.api.taskqueue.TaskOptions; //导入依赖的package包/类
public static void scheduleNotificationBuild(String objectType, Long id,
String action) {
if (objectType == null || objectType.isEmpty()) {
throw new IllegalArgumentException("No Specified Object Type");
}
if (id == null) {
throw new IllegalArgumentException("No Specified Object Id");
}
if (action == null || action.isEmpty()) {
throw new IllegalArgumentException("No Action Specified");
}
// Execute the servlet to pull from the queue
Queue executionQueue = QueueFactory.getQueue("notification-building");
executionQueue.add(TaskOptions.Builder
.withUrl("/notifications/builder/").method(Method.GET)
.param("objectType", objectType)
.param("id", String.valueOf(id.longValue()))
.param("action", action));
}
示例2: run
import com.google.appengine.api.taskqueue.TaskOptions; //导入依赖的package包/类
@Override
public void run(CheckedTransaction tx, SlobId convId, List<ChangeData<String>> newDeltas,
long resultingVersion, ReadableSlob resultingState)
throws RetryableFailure, PermanentFailure {
ImmutableSet.Builder<ParticipantId> out = ImmutableSet.builder();
for (ChangeData<String> delta : newDeltas) {
WaveletOperation op;
try {
op = SERIALIZER.deserializeDelta(delta.getPayload());
} catch (MessageException e) {
throw new RuntimeException("Malformed op: " + delta, e);
}
if (op instanceof RemoveParticipant) {
out.add(((RemoveParticipant) op).getParticipantId());
}
}
ImmutableSet<ParticipantId> removedParticipants = out.build();
if (!removedParticipants.isEmpty()) {
log.info("Will unindex " + convId + " for " + removedParticipants);
tx.enqueueTask(postCommitActionQueue,
TaskOptions.Builder.withPayload(
new HandleRemovedParticipantsTask(convId, removedParticipants)));
}
}
示例3: doGet
import com.google.appengine.api.taskqueue.TaskOptions; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
Enumeration e = req.getHeaderNames();
while(e.hasMoreElements()) {
String param = (String)e.nextElement();
log.info("header:" + param + req.getHeader(param));
}
String cronHeader = req.getHeader("X-Appengine-Cron");
if(cronHeader == null || !cronHeader.trim().equals("true")) {
resp.setStatus(403);
return;
}
Queue queue = QueueFactory.getQueue("reaper");
queue.add(TaskOptions.Builder.withUrl("/reaper"));
}
示例4: enqueueDomainResourceTask
import com.google.appengine.api.taskqueue.TaskOptions; //导入依赖的package包/类
/**
* Enqueues a task in the LORDN queue representing a line of CSV for LORDN export.
*/
public static void enqueueDomainResourceTask(DomainResource domain) {
ofy().assertInTransaction();
// This method needs to use ofy transactionTime as the DomainResource's creationTime because
// CreationTime isn't yet populated when this method is called during the resource flow.
String tld = domain.getTld();
if (domain.getLaunchNotice() == null) {
getQueue(QUEUE_SUNRISE).add(TaskOptions.Builder
.withTag(tld)
.method(Method.PULL)
.payload(getCsvLineForSunriseDomain(domain, ofy().getTransactionTime())));
} else {
getQueue(QUEUE_CLAIMS).add(TaskOptions.Builder
.withTag(tld)
.method(Method.PULL)
.payload(getCsvLineForClaimsDomain(domain, ofy().getTransactionTime())));
}
}
示例5: export
import com.google.appengine.api.taskqueue.TaskOptions; //导入依赖的package包/类
public void export(BigQueryMetric metric) {
try {
String hostname = modulesService.getVersionHostname("backend", null);
TaskOptions opts =
withUrl(MetricsExportAction.PATH)
.header("Host", hostname)
.param("insertId", idGenerator.get());
for (Entry<String, String> entry : metric.getBigQueryRowEncoding().entrySet()) {
opts.param(entry.getKey(), entry.getValue());
}
opts.param("tableId", metric.getTableId());
queue.add(opts);
} catch (TransientFailureException e) {
// Log and swallow. We may drop some metrics here but this should be rare.
logger.info(e, e.getMessage());
}
}
示例6: enqueueAsyncDelete
import com.google.appengine.api.taskqueue.TaskOptions; //导入依赖的package包/类
/** Enqueues a task to asynchronously delete a contact or host, by key. */
public void enqueueAsyncDelete(
EppResource resourceToDelete,
DateTime now,
String requestingClientId,
Trid trid,
boolean isSuperuser) {
Key<EppResource> resourceKey = Key.create(resourceToDelete);
logger.infofmt(
"Enqueuing async deletion of %s on behalf of registrar %s.",
resourceKey, requestingClientId);
TaskOptions task =
TaskOptions.Builder.withMethod(Method.PULL)
.countdownMillis(asyncDeleteDelay.getMillis())
.param(PARAM_RESOURCE_KEY, resourceKey.getString())
.param(PARAM_REQUESTING_CLIENT_ID, requestingClientId)
.param(PARAM_CLIENT_TRANSACTION_ID, trid.getClientTransactionId())
.param(PARAM_SERVER_TRANSACTION_ID, trid.getServerTransactionId())
.param(PARAM_IS_SUPERUSER, Boolean.toString(isSuperuser))
.param(PARAM_REQUESTED_TIME, now.toString());
addTaskToQueueWithRetry(asyncDeletePullQueue, task);
}
示例7: makeTaskOptions
import com.google.appengine.api.taskqueue.TaskOptions; //导入依赖的package包/类
/**
* Generates the TaskOptions needed to trigger an AppEngine Datastore backup job.
*
* @see <a href="https://developers.google.com/appengine/articles/scheduled_backups">Scheduled Backups</a>
*/
private static TaskOptions makeTaskOptions(
String queue, String name, String gcsBucket, ImmutableSet<String> kinds) {
String hostname = modulesService.getVersionHostname("default", DATASTORE_ADMIN_VERSION_NAME);
TaskOptions options = TaskOptions.Builder.withUrl("/_ah/datastore_admin/backup.create")
.header("Host", hostname)
.method(Method.GET)
.param("name", name + "_") // Add underscore since the name will be used as a prefix.
.param("filesystem", "gs")
.param("gs_bucket_name", gcsBucket)
.param("queue", queue);
for (String kind : kinds) {
options.param("kind", kind);
}
return options;
}
示例8: testSuccess_enqueuePollTask_withChainedTask
import com.google.appengine.api.taskqueue.TaskOptions; //导入依赖的package包/类
@Test
public void testSuccess_enqueuePollTask_withChainedTask() throws Exception {
TaskOptions chainedTask = TaskOptions.Builder
.withUrl("/_dr/something")
.method(Method.POST)
.header("X-Testing", "foo")
.param("testing", "bar");
new BigqueryPollJobEnqueuer(ENQUEUER).enqueuePollTask(
new JobReference().setProjectId(PROJECT_ID).setJobId(JOB_ID),
chainedTask,
getQueue(CHAINED_QUEUE_NAME));
assertTasksEnqueued(BigqueryPollJobAction.QUEUE, newPollJobTaskMatcher("POST"));
TaskStateInfo taskInfo = getOnlyElement(
TaskQueueHelper.getQueueInfo(BigqueryPollJobAction.QUEUE).getTaskInfo());
ByteArrayInputStream taskBodyBytes = new ByteArrayInputStream(taskInfo.getBodyAsBytes());
TaskOptions taskOptions = (TaskOptions) new ObjectInputStream(taskBodyBytes).readObject();
assertThat(taskOptions).isEqualTo(chainedTask);
}
示例9: doGet
import com.google.appengine.api.taskqueue.TaskOptions; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws IOException {
// Increment the count for the current namespace asynchronously.
QueueFactory.getDefaultQueue().add(
TaskOptions.Builder.withUrl("/_ah/update_count")
.param("countName", "SomeRequest"));
// Increment the global count and set the
// namespace locally. The namespace is
// transferred to the invoked request and
// executed asynchronously.
String namespace = NamespaceManager.get();
try {
NamespaceManager.set("-global-");
QueueFactory.getDefaultQueue().add(
TaskOptions.Builder.withUrl("/_ah/update_count")
.param("countName", "SomeRequest"));
} finally {
NamespaceManager.set(namespace);
}
resp.setContentType("text/plain");
resp.getWriter().println("Counts are being updated.");
}
示例10: doGet
import com.google.appengine.api.taskqueue.TaskOptions; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
// Increment the count for the current namespace asynchronously.
QueueFactory.getDefaultQueue()
.add(TaskOptions.Builder.withUrl("/_ah/update_count").param("countName", "SomeRequest"));
// Increment the global count and set the
// namespace locally. The namespace is
// transferred to the invoked request and
// executed asynchronously.
String namespace = NamespaceManager.get();
try {
NamespaceManager.set("-global-");
QueueFactory.getDefaultQueue()
.add(TaskOptions.Builder.withUrl("/_ah/update_count").param("countName", "SomeRequest"));
} finally {
NamespaceManager.set(namespace);
}
resp.setContentType("text/plain");
resp.getWriter().println("Counts are being updated.");
}
示例11: gameFinished
import com.google.appengine.api.taskqueue.TaskOptions; //导入依赖的package包/类
/**
* called when a game finished normally
* @param p_game
*/
public static void gameFinished(Game p_game)
{
p_game.setStatus( GameStatus.History );
GlobalVars.incrementCurrentGameCount( -1 );
if( p_game.getGameType() == GameType.MultiPlayer )
{
// add all stat related to finished game
GlobalVars.incrementFGameNbConfigGameTime( p_game.getConfigGameTime(), 1 );
GlobalVars.incrementFGameNbOfHexagon( p_game.getNumberOfHexagon() );
GlobalVars.incrementFGameNbPlayer( p_game.getSetRegistration().size() );
QueueFactory.getDefaultQueue().add(
TaskOptions.Builder.withPayload( new UpdateStat4FinishedGame( p_game.getId(), true ) ) );
// the following action was causing datastore contention
// updateStat4FinishedGame( p_game, true );
}
else if( p_game.getGameType() == GameType.Initiation )
{
GlobalVars.incrementFGameInitiationCount( 1 );
}
}
示例12: gameAbort
import com.google.appengine.api.taskqueue.TaskOptions; //导入依赖的package包/类
/**
* called when a game is aborted
* @param p_game
*/
public static void gameAbort(Game p_game)
{
if( p_game.getStatus() == GameStatus.History && p_game.getGameType() == GameType.MultiPlayer )
{
// for game that are History, we have to remove stat
GlobalVars.incrementFGameNbConfigGameTime( p_game.getConfigGameTime(), -1 );
GlobalVars.incrementFGameNbOfHexagon( -1 * p_game.getNumberOfHexagon() );
GlobalVars.incrementFGameNbPlayer( -1 * p_game.getSetRegistration().size() );
// almost the reverse of updateStat4FinishedGame.
// must be call for game that will be cancelled after finished
QueueFactory.getQueue( "longDBTask" ).add(
TaskOptions.Builder.withPayload( new RemovePlayerGameStatistics( p_game.getId(), p_game
.getEndDate() ) ) );
}
else if( p_game.getStatus() == GameStatus.Running )
{
GlobalVars.incrementCurrentGameCount( -1 );
}
p_game.setStatus( GameStatus.Aborted );
}
示例13: queueToIndex
import com.google.appengine.api.taskqueue.TaskOptions; //导入依赖的package包/类
/**
* @param name
* @param id
*/
public static void queueToIndex (String name, Long id) {
Queue queue = QueueFactory.getDefaultQueue();
TaskOptions options = TaskOptions.Builder.withMethod(Method.POST)
.url(INDEX_SEARCH_URL).param(ENTITY_NAME_KEY, name)
.param(ENTITY_ID_KEY, id.toString());
int retry = RETRY_COUNT;
do {
try {
queue.add(options);
// success no need to retry
retry = 0;
} catch (TransientFailureException ex) {
retry--;
}
} while (retry > 0);
}
示例14: reset
import com.google.appengine.api.taskqueue.TaskOptions; //导入依赖的package包/类
/**
* Reset reservations in datastore to match those in RTDB. Reservations in RTDB are used
* as the source of truth, corresponding reservations in datastore are updated to match
* those in RTDB. Reservations in RTDB that do not exist in datastore are added to datastore.
* Reservations that exist in datastore and do not exist in RTDB are updated in datastore
* with status DELETED.
*
* Use of this endpoint should be followed by a user data sync.
*
* @param user User making request (injected by Endpoints)
*/
@ApiMethod(name = "reset", path = "reset")
public void reset(User user)
throws UnauthorizedException {
if (user == null) {
throw new UnauthorizedException("Invalid credentials");
}
// Add Sync Reservations worker to queue.
Queue queue = QueueFactory.getQueue("SyncReservationsQueue");
TaskOptions taskOptions = TaskOptions.Builder
.withUrl("/queue/syncres")
.method(Method.GET);
queue.add(taskOptions);
}
示例15: enqueueTask
import com.google.appengine.api.taskqueue.TaskOptions; //导入依赖的package包/类
@Override
public void enqueueTask(String taskName, Map<String, String[]> paramMap) {
checkNotNull(taskName);
final Queue queue = QueueFactory.getDefaultQueue();
final TaskOptions options = TaskOptions.Builder.withUrl(String.format(PATH_ADMIN_TASK, taskName));
for (Map.Entry<String, String[]> param : paramMap.entrySet()) {
for (String value : param.getValue()) {
options.param(param.getKey(), value);
}
}
try {
queue.add(options);
LOGGER.info("Added admin task to queue {}", taskName);
} catch (TransientFailureException tfe) {
LOGGER.error("Run admin task fail {} ", tfe.getMessage());
}
}