2009年12月23日星期三

GAE学习笔记

Google App Engine学习笔记

Google App Engine学习笔记              1

2009-12-11:了解Google App Engine              1

1.              特点Features              1

2.              应用开发的环境:概要              2

3.              应用开发的环境:Sandbox              3

4.              应用开发的环境:Java Runtime Environment              3

5.              大概的开发流程              4

2009-12-17: Getting Started with Java              4

1.              Installing the Java SDK              4

2.              Creating and Testing a Project              6

2009-12-11:了解Google App Engine

1.     特点Features

1)       有着Google强壮可靠和安全的基础架构!

App Engine makes it easy to build and scale web applications with Google's robust and reliable infrastructure.

2)       使你建立可扩展的Web应用

Google App Engine enables you to build web applications on the same scalable systems that power Google applications.

easy to scale as your traffic and data storage needs grow. 

3)       不需要管理服务器,不需要担心用户数增多所带来的服务器问题

With App Engine, there are no servers to maintain: You just upload your application, and it's ready to serve to your users.

Once your application is uploaded to Google we host and scale your application for you. You no longer need to worry about system administration, bringing up new instances of your application, sharding your database or buying machines. We take care of all the maintenance so you can focus on features for your users.

No matter how many users you have or how much data your application stores, App Engine can scale to meet your needs.

4)       可以使用Google applications在用的技术,如:BigTableGFS

For the the first time your applications can take advantage of the same scalable technologies that Google applications are built on, things like BigTable and GFS.

5)       跟李开复的创新工厂一样,Google其实是在输出它的经验!

With App Engine you can take advantage of the 10 years of knowledge Google has in running massively scalable, performance driven systems.

6)       Google其实是非常注重安全的。

The same security, privacy and data protection policies we have for Google's applications applies to all App Engine applications. We take security very seriously and have measures in place to protect your code and application data.

7)       免费地开始使用,超出的storage所带来的价格也是合理的

Detailed pricing for usage that has exceeded the free quota of 500 MB of storage and around 5M pageviews per month is available here.

There are no set-up costs and no recurring fees.

8)       可以自定义访问的域名,也可以使用免费的appspot.com域名

You can serve your app from your own domain name (such as 
http://www.example.com/) using Google Apps. Or, you can serve your app using a free name on the appspot.com domain.

9)       可以公开到整个Internet,也可以限制只能特定的人访问

You can share your application with the world, or limit access to members of your organization.

10)   javajava相关的语言支持很好

With App Engine's Java runtime environment, you can build your app using standard Java technologies, including the JVM, Java servlets, and the Java programming language—or any other language using a JVM-based interpreter or compiler, such as JavaScript or Ruby.

11)   python的支持极好

App Engine also features a dedicated Python runtime environment, which includes a fast Python interpreter and the Python standard library.

From

[1] See what other companies are doing with App Engine
http://code.google.com/appengine/casestudies.html

[2] Why App Engine
http://code.google.com/appengine/whyappengine.html

[3] What Is Google App Engine?
http://code.google.com/appengine/docs/whatisgoogleappengine.html

2.     应用开发的环境:概要

Google App Engine makes it easy to build an application that runs reliably, even under heavy load and with large amounts of data. App Engine includes the following features:

·              dynamic web serving, with full support for common web technologies

·              persistent storage with queries, sorting and transactions

·              自动扩展和负载均衡
automatic scaling and load balancing

·              APIs for authenticating users and sending email using Google Accounts

·              本地的全套开发环境
a fully featured local development environment that simulates Google App Engine on your computer

·              没懂?task queues for performing work outside of the scope of a web request

·              scheduled tasks for triggering events at specified times and regular intervals

From:

[1] What Is Google App Engine?
http://code.google.com/appengine/docs/whatisgoogleappengine.html

3.     应用开发的环境:Sandbox

1)       根据traffic需求来开启和停止服务器

These limitations allow App Engine to distribute web requests for the application across multiple servers, and start and stop servers to meet traffic demands.

2)       沙盒环境的限制

·              这样的话,我们的发送指令必须要转化为一个web请求
An application can only access other computers on the Internet through the provided URL fetch and email services. Other computers can only connect to the application by making HTTP (or HTTPS) requests on the standard ports.

·              关于怎么存储数据的问题,可以用数据库和内存缓存
An application cannot write to the file system. An app can read files, but only files uploaded with the application code. The app must use the App Engine datastore, memcache or other services for all data that persists between requests.

·              啥叫a queued task a scheduled task
Application code only runs in response to a web request, a queued task, or a scheduled task, and must return response data within 30 seconds in any case. A request handler cannot spawn a sub-process or execute code after the response has been sent.

From:

[1] What Is Google App Engine?
http://code.google.com/appengine/docs/whatisgoogleappengine.html

4.     应用开发的环境:Java Runtime Environment

1)       貌似不能打开一个socket连接

The restrictions of the sandbox environment are implemented in the JVM. An app can use any JVM bytecode or library feature, as long as it does not exceed the sandbox restrictions. For instance, bytecode that attempts to open a socket or write to a file will throw a runtime exception.

2)       常用的Java API

For the App Engine datastore, the Java SDK includes implementations of the Java Data Objects (JDO) and Java Persistence API (JPA) interfaces. Your app can use the JavaMail API to send email messages with the App Engine Mail service. The java.net HTTP APIs access the App Engine URL fetch service. App Engine also includes low-level APIs for its services to implement additional adapters, or to use directly from the application. See the documentation for the datastore, memcache, URL fetch, mail, imagesand Google Accounts APIs.

3)       对其他语言如JavaScript, Ruby, or Scala的支持

With the use of JVM-compatible compilers or interpreters, you can also use other languages to develop web applications, such as JavaScript, Ruby, or Scala.

From:

[1] What Is Google App Engine?
http://code.google.com/appengine/docs/whatisgoogleappengine.html

5.     大概的开发流程

1)       Each SDK完全模拟了App Engine services on your local computer,包括a web server applicationchecks for attempts to access system resources

2)       You can test the new version on App Engine while the old version is still running.

3)       google-appengine-docs很好,可以从这边下载:
http://code.google.com/appengine/downloads.html#Download_the_Google_App_Engine_Documentation

From:

[1] What Is Google App Engine?
http://code.google.com/appengine/docs/whatisgoogleappengine.html

2009-12-17: Getting Started with Java

1.     Installing the Java SDK

1)      安装JDK

装好以后,用java version看一下版本,例如下面的是我的:

然后还要看一下javac有没有添加到环境变量?!javac -version

C:\Users\clzqwdy>java -version

java version "1.6.0_15"

Java(TM) SE Runtime Environment (build 1.6.0_15-b03)

Java HotSpot(TM) Client VM (build 14.1-b02, mixed mode, sharing)

2)      Using Eclipse and the Google Plugin for Eclipse

如果使用Eclipse的话,最好使用插件,The plugin includes everything you need to build, test and deploy your app, entirely within Eclipse.

对应Eclipse版本的插件如下:

·              The Google Plugin for Eclipse, for Eclipse 3.3 (Europa):

http://dl.google.com/eclipse/plugin/3.3

·              The Google Plugin for Eclipse, for Eclipse 3.4 (Ganymede):

http://dl.google.com/eclipse/plugin/3.4

·              The Google Plugin for Eclipse, for Eclipse 3.5 (Galileo):

http://dl.google.com/eclipse/plugin/3.5

              我的是Galileo版本的:)具体如何安装,可以见这里:

http://code.google.com/appengine/docs/java/tools/eclipse.html#Installing_the_Google_Plugin_for_Eclipse

3)      Getting the SDK

使用Eclipse插件,可以直接从Software Update安装App Engine SDK了,而不用单独下载Google App Engine Java SDK来安装了,真棒!

装完后,SDK位于:the SDK is located in your Eclipse installation directory,
under plugins/com.google.appengine.eclipse.sdkbundle_VERSION/, where VERSION is a version identifier for the SDK.

4)      Trying a Demo Application

SDK目录有个demo文件夹,

If you are using Windows, start the guest book demo in the development server by running the following command at a command prompt:

appengine-java-sdk\bin\dev_appserver.cmd appengine-java-sdk\demos\guestbook\war

              当然要切换到appengine-java-sdk目录下!还有启动得有点慢,得稍微等一下!

              我第一次运行的时候,报Error 500的错误,根据提示应该是javac没有添加到环境变量的缘故!java文件夹下的bin文件夹添加到系统变量path中。

C:\Users\clzqwdy>javac -version

javac 1.6.0_05

              命令行运行的结果如下:

C:\Users\clzqwdy\Software\Eclipse-Android\plugins\com.google.appengine.eclipse.s

dkbundle.1.3.0_1.3.0.v200912141120\appengine-java-sdk-1.3.0\bin>dev_appserver.cm

d ..\demos\guestbook\war

The server is running at http://localhost:8080/

2009-12-17 4:56:34 com.google.appengine.tools.development.LocalResourceFileServl

et doGet

WARNING: No file found for: /favicon.ico

              大概的效果如下:

我输入hello的效果如下:

From:

[1] Installing the Java SDK - Google App Engine - Google Code
http://code.google.com/appengine/docs/java/gettingstarted/installing.html

2.     Creating and Testing a Project

1)       eclipse创建并且run一个web application

把端口设置在8080后,访问http://localhost:8080/,得到如下结果:

它的eclipse调试是很强大的,可以在调试时修改代码并尝试insert it into the running web server,而不需要把正在running web server关掉后再修改代码。仅仅只有在改变web.xmlor other configuration files的时候,才需要stop and start the server for the changes to take effect.

如何stop the servermake sure the Debug panel is selected, then click the Terminate button: The Eclipse terminate button.

2)       试验一下Uploading to Google App Engine

需要注册一个application ID,并且在appengine-web.xml文件中加入这个new ID

是在<application>...</application>这个位置,我的配置是:

<application>watersky-go-abroad</application>

部署时控制台的信息如下:

Creating staging directory

Scanning for jsp files.

Scanning files on local disk.

Initiating update.

Cloning 1 static files.

Cloning 14 application files.

Uploading 1 files.

Uploaded 1 files.

Deploying new version.

Will check again in 1 seconds

Will check again in 2 seconds

Will check again in 4 seconds

Closing update: new version is ready to start serving.

Uploading index definitions.

Deployment completed successfully

              效果如下图,注意地址栏的url

3)       一些特性只能用命令行的工具:

Some features of the App Engine Java SDK tools are only available by running the tools directly from the command line. If you have installed the SDK using Eclipse, you can run these tools from the Eclipse plugin installation directory.

For more information on the features available exclusively from the command line, see Uploading and Managing.

From:

[1] Creating a Project - Google App Engine - Google Code
http://code.google.com/appengine/docs/java/gettingstarted/creating.html

[2] http://code.google.com/appengine/docs/java/tools/eclipse.html