• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java LifecycleManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.appengine.api.LifecycleManager的典型用法代码示例。如果您正苦于以下问题:Java LifecycleManager类的具体用法?Java LifecycleManager怎么用?Java LifecycleManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



LifecycleManager类属于com.google.appengine.api包,在下文中一共展示了LifecycleManager类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: init

import com.google.appengine.api.LifecycleManager; //导入依赖的package包/类
@Override
public void init() {
  Security.addProvider(new BouncyCastleProvider());

  // If metric reporter failed to instantiate for any reason (bad keyring, bad json credential,
  // etc), we log the error but keep the main thread running. Also the shutdown hook will only be
  // registered if metric reporter starts up correctly.
  try {
    metricReporter.get().startAsync().awaitRunning(10, TimeUnit.SECONDS);
    logger.info("Started up MetricReporter");
    LifecycleManager.getInstance()
        .setShutdownHook(
            () -> {
              try {
                metricReporter.get().stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
                logger.info("Shut down MetricReporter");
              } catch (TimeoutException timeoutException) {
                logger.severefmt("Failed to stop MetricReporter: %s", timeoutException);
              }
            });
  } catch (Exception e) {
    logger.severefmt(e, "Failed to initialize MetricReporter: %s");
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:25,代码来源:FrontendServlet.java


示例2: init

import com.google.appengine.api.LifecycleManager; //导入依赖的package包/类
@Override
public void init() {
  Security.addProvider(new BouncyCastleProvider());

  // If metric reporter failed to instantiate for any reason (bad keyring, bad json credential,
  // etc), we log the error but keep the main thread running. Also the shutdown hook will only be
  // registered if metric reporter starts up correctly.
  try {
    metricReporter.get().startAsync().awaitRunning(10, TimeUnit.SECONDS);
    logger.info("Started up MetricReporter");
    LifecycleManager.getInstance()
        .setShutdownHook(
            () -> {
              try {
                metricReporter.get().stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
                logger.info("Shut down MetricReporter");
              } catch (TimeoutException timeoutException) {
                logger.severefmt("Failed to stop MetricReporter: %s", timeoutException);
              }
            });
  } catch (Exception e) {
    logger.severefmt(e, "Failed to initialize MetricReporter.");
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:25,代码来源:BackendServlet.java


示例3: doGet

import com.google.appengine.api.LifecycleManager; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {

	logger.info("module start");
	LifecycleManager.getInstance().setShutdownHook(this);
	// ModulesService modulesApi =
	// ModulesServiceFactory.getModulesService();
	// if ("0".equals(modulesApi.getCurrentInstanceId())) {
	//
	// logger.info("module start");
	// LifecycleManager.getInstance().setShutdownHook(this);
	//
	// }

	return;
}
 
开发者ID:HotswapProjects,项目名称:HotswapAgentExamples,代码行数:18,代码来源:ModuleStartServlet.java


示例4: doHang

import com.google.appengine.api.LifecycleManager; //导入依赖的package包/类
private void doHang(HttpServletResponse res) throws IOException {
  res.setContentType("text/plain");
  res.getWriter().println("Starting...");
  final Thread requestThread = Thread.currentThread();
  final boolean[] hookState = new boolean[] {false, false};
  LifecycleManager.getInstance()
      .setShutdownHook(
          new LifecycleManager.ShutdownHook() {
            public void shutdown() {
              hookState[0] = true; // Hook called
              LifecycleManager.getInstance().interruptAllRequests();
              hookState[1] = true;
            }
          });
  hang();
  res.getWriter().println("Hook: " + hookState[0] + " " + hookState[1]);
  res.getWriter().println("Exiting.");
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:19,代码来源:ShutdownServlet.java


示例5: service

import com.google.appengine.api.LifecycleManager; //导入依赖的package包/类
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
  // Check if the instance is shutting down, in that case return unhealthy (lameduck).
  LifecycleManager lifeCycleManager = LifecycleManager.getInstance();
  if (LifecycleManager.getInstance().isShuttingDown()) {
     long remainingShutdownTime = lifeCycleManager.getRemainingShutdownTime();
     response.sendError(HttpServletResponse.SC_BAD_GATEWAY,
                        "App is shutting down, time remaining: " + remainingShutdownTime + " ms");
     return;
  }
  String expectedVersion = request.getParameter("VersionID");
  String actualVersion = fullVersionId();
  if ((expectedVersion == null) || expectedVersion.equals(actualVersion)){
    response.setContentType("text/plain");
    response.getWriter().write("ok");
  } else {
    response.setContentType("text/plain");
    response.getWriter().write(
        String.format("version mismatch \"%s\" != \"%s\"", expectedVersion, actualVersion));
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:22,代码来源:VmHealthServlet.java


示例6: doPolling

import com.google.appengine.api.LifecycleManager; //导入依赖的package包/类
private void doPolling() {
  Queue notificationQueue = QueueFactory.getQueue("notification-delivery");

  Worker worker = new Worker(notificationQueue);
  while (!LifecycleManager.getInstance().isShuttingDown()) {
    boolean tasksProcessed = worker.processBatchOfTasks();
    ApiProxy.flushLogs();

    if (!tasksProcessed) {
      // Wait before trying to lease tasks again.
      try {
        Thread.sleep(MILLISECONDS_TO_WAIT_WHEN_NO_TASKS_LEASED);
      } catch (InterruptedException e) {
        return;
      }
    }
  }

  log.info("Instance is shutting down");
}
 
开发者ID:googlesamples,项目名称:io2014-codelabs,代码行数:21,代码来源:WorkerServlet.java


示例7: doPolling

import com.google.appengine.api.LifecycleManager; //导入依赖的package包/类
private void doPolling() {
  Queue notificationQueue = QueueFactory.getQueue("notification-delivery");

  PushNotificationWorker worker = new PushNotificationWorker(notificationQueue);
  while (!LifecycleManager.getInstance().isShuttingDown()) {
    boolean tasksProcessed = worker.processBatchOfTasks();
    ApiProxy.flushLogs();

    if (!tasksProcessed) {
      // Wait before trying to lease tasks again.
      try {
        Thread.sleep(MILLISECONDS_TO_WAIT_WHEN_NO_TASKS_LEASED);
      } catch (InterruptedException e) {
        return;
      }
    }
  }

  log.info("Instance is shutting down");
}
 
开发者ID:GoogleCloudPlatform,项目名称:solutions-ios-push-notification-sample-backend-java,代码行数:21,代码来源:PushNotificationWorkerServlet.java


示例8: registerShutdownHook

import com.google.appengine.api.LifecycleManager; //导入依赖的package包/类
public void registerShutdownHook() {
    LifecycleManager.getInstance().setShutdownHook(new ShutdownHook() {
        public void shutdown() {
            logger.info("App will stop");
            ProcessingQueue.getInstance().setShutdown();
        }
    });
}
 
开发者ID:dataiku,项目名称:wt1,代码行数:9,代码来源:InitializationServlet.java


示例9: hang

import com.google.appengine.api.LifecycleManager; //导入依赖的package包/类
public void hang() {
  LifecycleManager runtime = LifecycleManager.getInstance();
  log.info("Shutting down: " + runtime.isShuttingDown());
  while (!runtime.isShuttingDown()) {
    try {
      log.info("Sleeping for 10s");
      Thread.sleep(10000);
    } catch (InterruptedException ex) {
      // expected
    }
    log.info("Shutting down: " + runtime.isShuttingDown());
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:14,代码来源:ShutdownServlet.java


示例10: doHello

import com.google.appengine.api.LifecycleManager; //导入依赖的package包/类
private void doHello(HttpServletResponse res) throws IOException {
  log.info("Hello!");
  LifecycleManager.getInstance()
      .setShutdownHook(
          new LifecycleManager.ShutdownHook() {
            public void shutdown() {
              log.info("Goodbye, world!");
              LifecycleManager.getInstance().interruptAllRequests();
              if (Thread.interrupted()) {
                log.info("Interrupted");
              }
            }
          });
  res.getWriter().println("Hello, world!");
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:16,代码来源:ShutdownServlet.java


示例11: service

import com.google.appengine.api.LifecycleManager; //导入依赖的package包/类
@Override
public void service(HttpServletRequest req, HttpServletResponse res) {
  CountServlet.localCount.getAndAdd(datastoreCount());
  final Key key = KeyFactory.createKey("Counter", getKeyName());
  LifecycleManager.getInstance()
      .setShutdownHook(
          new ShutdownHook() {
            @Override
            public void shutdown() {
              datastoreSave(key);
            }
          });
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:14,代码来源:ServersStartServlet.java


示例12: doFilter

import com.google.appengine.api.LifecycleManager; //导入依赖的package包/类
/**
 * Handle stop requests.
 *
 * Stop requests are intercepted by this filter and never forwarded to user code.
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {
  // Requests to /_ah/stop are filtered by the appserver (and soon VM-local nginx). Any stop
  // requests that make it here are from trusted code.
  logger.info("Running shutdown hook");
  long deadline = System.currentTimeMillis() + SHUTDOWN_HOOK_DEADLINE_MILLIS;
  LifecycleManager.getInstance().beginShutdown(deadline);

  response.setContentType("text/plain");
  response.getWriter().write("ok");
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:18,代码来源:VmStopFilter.java


示例13: setLifecycleManager

import com.google.appengine.api.LifecycleManager; //导入依赖的package包/类
/**
 * 
 */
private void setLifecycleManager() {
    /* Specify the lifecycle manager to be used */
    LifecycleManager.getInstance().setShutdownHook(new ShutdownHook() {
        @Override
        public void shutdown() {
            /*
             * Calls interrupt on all threads within this instance.
             * Therefore, periodic checks must be make to ensure this
             * instance hasn't been told to shutdown.
             */
            LifecycleManager.getInstance().interruptAllRequests();
        }
    });
}
 
开发者ID:lolletsoc,项目名称:dissertation-project,代码行数:18,代码来源:FileJoinerBackend.java



注:本文中的com.google.appengine.api.LifecycleManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CopyMapper类代码示例发布时间:2022-05-22
下一篇:
Java Event类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap