Writing apps in your favorite language on the web is fun and rewarding for developers — and can be a good value proposition for small businesses and start ups. This is easily possible with Google App Engine (GAE), with Java as the language of development. It’s very important to know the landscape within which you can build your application using emerging GAE, and to understand the limitations of an evolving product.
在网络上以您喜欢的语言编写应用程序对开发人员来说是有趣而又有意义的,对于小型企业和初创企业而言,这可能是一个不错的价值主张。 使用Java作为开发语言的Google App Engine(GAE)可以轻松实现这一点。 了解使用新兴的GAE可以在其中构建应用程序的环境,并了解不断发展的产品的局限性非常重要。
Applications in Google run on Java 6 JVM, and the SDK supports Java 5 or later. The applications run in a sandboxed environment where they are isolated for services and security. In the restricted sandbox environment, the application can execute the code, query & write to the datastore, use app engine services like mail and URLFetch, and can accept requests from users to send them back a response. However, we need to understand there are certain limitations in this sandboxed environment:
Google中的应用程序在Java 6 JVM上运行,并且SDK支持Java 5或更高版本。 这些应用程序在沙盒环境中运行,在这些环境中它们被隔离以实现服务和安全性。 在受限的沙箱环境中,应用程序可以执行代码,查询和写入数据存储,使用邮件和URLFetch等应用引擎服务,并可以接受来自用户的请求以将其发送回响应。 但是,我们需要了解在此沙盒环境中存在某些限制:
The application can not write to the filesystem. Reading from filesystem to scope of application files is allowed.
应用程序无法写入文件系统。 允许从文件系统读取应用程序文件的范围。
Opening a socket and accessing a host directly is not allowed. The user can use URL fetch service for accessing URLs.
不允许打开套接字并直接访问主机。 用户可以使用URL提取服务来访问URL。
The application can not create new threads. The restriction also applies to JRE classes which use threads like java.util.Timer. The application can perform actions against the current thread though, like getting a dumpStack.
应用程序无法创建新线程。 该限制还适用于使用诸如java.util.Timer之类的线程的JRE类。 但是,应用程序可以针对当前线程执行操作,例如获取dumpStack。
Reflection is allowed for all application classes including private members. However for JRE & SDK classes, only public members can be accessed using reflection.
允许对所有应用程序类进行反射,包括私有成员。 但是,对于JRE和SDK类,只能使用反射访问公共成员。
The system properties that you set are only limited to the application.
您设置的系统属性仅限于该应用程序。
Only classes listed in the White list can be used from all Java Library classes.
所有Java库类都只能使用白名单中列出的类。
Each application gets an app-id and the URL for that application is app-id.appspot.com, and you can also have subdomains like mail.app-id.appspot.com. Deployed applications can have versions and the default version serves the requests. Each version has its own URL, thus you can test your application on the server without affecting the default live version. For example version 7 of the above application can be accessed using 7.latest.app-id.appspot.com
每个应用程序都有一个应用程序ID,该应用程序的URL为app-id.appspot.com ,您还可以拥有子域,如mail.app-id.appspot.com 。 部署的应用程序可以具有版本,默认版本可以处理请求。 每个版本都有自己的URL,因此您可以在服务器上测试应用程序而不会影响默认的实时版本。 例如,可以使用7.latest.app-id.appspot.com访问上述应用程序的版本7。
All requests received are handled by servlets as defined in your web.xml file in the web application. The Java Servlet API is used for request response handling. For backend requests, backend.xml or backend.yaml is used to invoke servlets matching the request criteria.
收到的所有请求均由Web应用程序中web.xml文件中定义的servlet处理。 Java Servlet API用于请求响应处理。 对于后端请求,使用backend.xml或backend.yaml来调用符合请求条件的servlet。
The app engine uses multiple web servers to handle requests to your application and scaling the number of servers is handled by platform. Requests are clustered across multiple web servers, and each web server processes one request at a time. If you want web servers to receive multiple requests, you can do so by adding the <threadsafe>true</threadsafe> element to appengine-web.xml.
该应用程序引擎使用多个Web服务器来处理对您的应用程序的请求,并且扩展服务器的数量由平台处理。 请求被群集在多个Web服务器上,并且每个Web服务器一次处理一个请求。 如果希望Web服务器接收多个请求,可以通过将<threadsafe> true </ threadsafe>元素添加到appengine-web.xml中来实现。
The app engine passes on requests for the application to process and once a response is received, it is passed back to the client, but streaming is not supported. One important note of caution here, which if not handled has been a pain of various developers and businesses: the request handler has to finish the processing in or less than 60 seconds, else the JRE will throw com.google.apphosting.api.DeadlineExceededException and where this exception is not handled will lead to an Error 500 for the end user. The app engine is built for many small requests of a few seconds rather than longer requests. It’s the shift in paradigm with which applications need to be designed for GAE. Requests which need to run longer need to handled using alternatives such as task queues or a backend.
应用引擎将请求传递给应用程序进行处理,一旦收到响应,它就会被传递回客户端,但是不支持流传输。 这里需要注意的一个重要注意事项是,如果不加以处理,这将使各种开发人员和企业感到痛苦:请求处理程序必须在60秒以内完成处理,否则JRE将抛出com.google.apphosting.api.DeadlineExceededException并且未处理此异常的地方将导致最终用户错误500。 该应用引擎是为几秒钟的许多小请求而不是较长的请求而构建的。 这是范式的转变,需要针对GAE设计应用程序。 需要运行更长的请求需要使用诸如任务队列或后端之类的替代方案来处理。
The Eclipse plugin for the App Engine comes bundled with App Engine SDK and GWT SDK. The plugin provides the ability to create app engine projects, debug and one-click cloud deployment. The plugin allows you to upload application files and download log files. It also has a component for Apache Ant to automate common developement and deployment tasks. Third party plugins are also available for NetBeans and IntelliJ.
App Engine的Eclipse插件与App Engine SDK和GWT SDK捆绑在一起。 该插件提供了创建应用程序引擎项目,调试和一键式云部署的功能。 该插件允许您上传应用程序文件和下载日志文件。 它还具有Apache Ant的组件,可自动执行常见的开发和部署任务。 第三方插件也可用于NetBeans和IntelliJ。
You can alternatively use the “appcfg” command line tool, which allows you to enable all tasks possible through the IDE like uploading your application files, getting logs from server and so on.
您也可以使用“ appcfg”命令行工具,该工具允许您通过IDE启用所有可能的任务,例如上载应用程序文件,从服务器获取日志等等。
The development server that comes with the SDK enables you to test your application locally, by simulating the datastore, services, sandbox restrictions and can generate indexes based on queries that generate indexes.
SDK随附的开发服务器使您可以通过模拟数据存储,服务,沙箱限制在本地测试应用程序,并可以基于生成索引的查询生成索引。
With this understanding of the development and run-time environment we get a fair idea of the platform. The next part of this series is going to focus on setup and getting familiar with configurations and deployment structure. Keep watching!
了解了开发和运行时环境后,我们对平台有了一个很好的了解。 本系列的下一部分将着重于设置并熟悉配置和部署结构。 一直在看!
Christian Lagerek Images on Shutterstock
Christian Lagerek图片在Shutterstock上
翻译自: https://www.sitepoint.com/understanding-google-app-engine-gae-java-api-part-1-landscape-overview-2/
相关资源:doco:Doco-Google App Engine搜索API的文档转换器-源码