本文整理汇总了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");
}
}
示例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.");
}
}
示例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;
}
示例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.");
}
示例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));
}
}
示例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");
}
示例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();
}
});
}
示例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());
}
}
示例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!");
}
示例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);
}
});
}
示例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");
}
示例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();
}
});
}