本文整理汇总了Java中com.google.appengine.api.taskqueue.QueueFactory类的典型用法代码示例。如果您正苦于以下问题:Java QueueFactory类的具体用法?Java QueueFactory怎么用?Java QueueFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QueueFactory类属于com.google.appengine.api.taskqueue包,在下文中一共展示了QueueFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scheduleNotificationBuild
import com.google.appengine.api.taskqueue.QueueFactory; //导入依赖的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: configure
import com.google.appengine.api.taskqueue.QueueFactory; //导入依赖的package包/类
@Override protected void configure() {
StoreModuleHelper.makeBasicBindingsAndExposures(binder(), ConvStore.class);
StoreModuleHelper.bindEntityKinds(binder(), ROOT_ENTITY_KIND);
bind(SlobModel.class).to(WaveObjectStoreModel.class);
bind(AccessChecker.class).to(ConvAccessChecker.class);
bind(PermissionSource.class).to(ConvPermissionSource.class);
Multibinder<PreCommitAction> preCommitActions =
Multibinder.newSetBinder(binder(), PreCommitAction.class);
preCommitActions.addBinding().to(IndexTask.ConvPreCommit.class);
Multibinder<PostCommitAction> postCommitActions =
Multibinder.newSetBinder(binder(), PostCommitAction.class);
postCommitActions.addBinding().to(IndexTask.Conv.class);
bind(Queue.class).annotatedWith(PostCommitActionQueue.class).toInstance(
QueueFactory.getQueue("post-commit-conv"));
}
示例3: doGet
import com.google.appengine.api.taskqueue.QueueFactory; //导入依赖的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: register_updateRepProfileTask
import com.google.appengine.api.taskqueue.QueueFactory; //导入依赖的package包/类
/**
* Registers an update-replay-profile task.
* @param sha1 SHA-1 of the file
* @param incCommentsCount tells if comments count has to be incremented
* @param incGgsCount tells if GG count has to be incremented
* @param incBgsCount tells if BG count has to be incremented
*/
public static void register_updateRepProfileTask( final String sha1, final boolean incCommentsCount, final boolean incGgsCount, final boolean incBgsCount ) {
int entitySelector;
try {
// SHA-1 algorithm is designed so every bit of SHA-1 depends on the input,
// so the first byte depends on the input (and changes) just like all of it
// It's enough to decide/assign the queue based on the first byte
entitySelector = Integer.parseInt( sha1.substring( 0, 2 ), 16 );
} catch ( final Exception e ) { // NumberFormatException is not enough, IndexOutOfBoundsException is raised if sha1 is shorter than 2 chars
// This should never happen, but since sha1 is not checked syntactically,
// it might happen someone sends an invalid sha1
entitySelector = sha1.hashCode();
}
QueueFactory.getQueue( getEntityUpdateQueueName( entitySelector ) ).add(
buildTask( OPERATION_UPDATE_REP_PROFILE )
.param( PARAM_SHA1 , sha1 )
.param( PARAM_INC_COMMENTS_COUNT, Boolean.toString( incCommentsCount ) )
.param( PARAM_INC_GGS_COUNT , Boolean.toString( incGgsCount ) )
.param( PARAM_INC_BGS_COUNT , Boolean.toString( incBgsCount ) )
);
}
示例5: doGet
import com.google.appengine.api.taskqueue.QueueFactory; //导入依赖的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.");
}
示例6: doGet
import com.google.appengine.api.taskqueue.QueueFactory; //导入依赖的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.");
}
示例7: gameFinished
import com.google.appengine.api.taskqueue.QueueFactory; //导入依赖的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 );
}
}
示例8: gameAbort
import com.google.appengine.api.taskqueue.QueueFactory; //导入依赖的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 );
}
示例9: queueToIndex
import com.google.appengine.api.taskqueue.QueueFactory; //导入依赖的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);
}
示例10: reset
import com.google.appengine.api.taskqueue.QueueFactory; //导入依赖的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);
}
示例11: enqueueTask
import com.google.appengine.api.taskqueue.QueueFactory; //导入依赖的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());
}
}
示例12: doGet
import com.google.appengine.api.taskqueue.QueueFactory; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String channelKey = getChannelKey();
String filterText = req.getParameter("filterText");
filterText = (filterText == null) ? "" : filterText;
String tag = req.getParameter("tag");
String requestId = req.getParameter("reqId");
String userId = userService.getCurrentUser().getUserId();
Queue queue = QueueFactory.getDefaultQueue();
TaskOptions taskOptions = withUrl("/fetch")
.param("displayStyle", req.getParameter("displayStyle"))
.param("filterText", filterText)
.param("key", channelKey)
.param("networkCode", req.getParameter("networkCode"))
.param("userId", userId)
.param("tag", tag)
.param("reqId", requestId)
.param("typeOverride", req.getParameter("typeOverride"));
queue.add(taskOptions.method(Method.GET));
resp.getWriter().print(channelKey);
}
示例13: addDeferredTask
import com.google.appengine.api.taskqueue.QueueFactory; //导入依赖的package包/类
/**
* Adds the given task, to be run after the specified time, to the specified queue.
*
* @param task the task object containing the details of task to be added
* @param countdownTime the time delay for the task to be executed
*/
public void addDeferredTask(TaskWrapper task, long countdownTime) {
Queue requiredQueue = QueueFactory.getQueue(task.getQueueName());
TaskOptions taskToBeAdded = TaskOptions.Builder.withUrl(task.getWorkerUrl());
if (countdownTime > 0) {
taskToBeAdded.countdownMillis(countdownTime);
}
for (Map.Entry<String, String[]> entry : task.getParamMap().entrySet()) {
String name = entry.getKey();
String[] values = entry.getValue();
for (String value : values) {
taskToBeAdded = taskToBeAdded.param(name, value);
}
}
requiredQueue.add(taskToBeAdded);
}
示例14: deferredTask
import com.google.appengine.api.taskqueue.QueueFactory; //导入依赖的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());
}
示例15: leaseAndDeleteTasks
import com.google.appengine.api.taskqueue.QueueFactory; //导入依赖的package包/类
private void leaseAndDeleteTasks(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
int numTasks = Integer.parseInt(req.getParameter("numTasks"));
Double lease = Double.parseDouble(req.getParameter("lease"));
String queue = req.getParameter("queue");
Queue q = QueueFactory.getQueue(queue);
Boolean doDelete = Boolean.parseBoolean(req.getParameter("doDelete"));
List<TaskHandle> tasks = q.leaseTasks(lease.intValue() * 1000, TimeUnit.MILLISECONDS, numTasks);
for (TaskHandle task : tasks) {
if (doDelete) {
q.deleteTask(task.getName());
}
}
resp.getWriter().print(queue + "," + tasks.size());
}