Simple stock market analysis

Post on 17-May-2015

3.032 views 3 download

Tags:

description

Implement a simple stock market analysis program with Google App Engine and Google Web Toolkit,

Transcript of Simple stock market analysis

Simple Stock Market Analysis

Cloud Computing

Lina QuIndependent Study instructed by Dr. Yacobellis

2011.05.10

Outline

1. Introduction2. Cloud Computing3. Google App Engine™ platform4. Google Web Toolkit5. Simple Stock Market Analysis6. References

1. Introduction

Using the cloud computing platform, Google App Engine™ platform in this case, together with Google Web Toolkit to develop and deploy a simple program ---- Simple Stock Market Analysis. Through this project, we can learn briefly:• Cloud Computing and its service models;• Google App Engine(GAE) as develop platform;• Google Web Toolkit(GWT) as a development toolkit;• Big Table as a distributed storage system;• An example project actually runs on GAE.

2. Cloud Computing2.1 What is Cloud Computing?

A large-scale distributed computing paradigm that is driven by economies of scale, in which a pool of abstracted, virtualized, dynamically-scalable, managed computing power, storage, platforms, and services are delivered on demand to external customers over the Internet[1].

Cloud computing refers to the provision of computational resources on demand via a computer network, such as applications, databases, file services, email, etc. (----Wikipedia)

2. Cloud Computing2.2 Key characters of Cloud Computing

• On-demand self-service• Broad network access• Resource pooling• Rapid elasticity• Measured Service

2. Cloud Computing2.3 Service models of Cloud Computing

1. Software as a Service (SaaS)

2. Platform as a Service (PaaS)

3. Infrastructure as a Service (IaaS)

Access computer infrastructure via Web.Google Pack, Salesforce.com, NetSuite.

Do the development in the cloud.Google App Engine, Windows® Azure, Force.com.

Applications are hosted by a provider, or could be accessed via the Web.Amazon EC2 (Elastic Cloud Computing) Service, S3 (Simple Storage Service), IBM® Cloud.

2. Cloud Computing2.3 Service models of Cloud Computing

3. Google App Engine™ platform3.1 What is Google App Engine?

It lets you run your web applications on Google’s infrastructure.

Visit here for more information.Google App Engine FAQ.Sample Apps Code is here.

3. Google App Engine™ platform3.2 Why Google App Engine?

• Easy to build- Easy to get Started[17]

- Simple app configuration• Easy to maintain- Cost efficient hosting- Risk free trial period- The reliability, performance and security of Google's

infrastructure• Easy to scale- Automatic scalability- APIs

3. Google App Engine™ platform3.3 Google App Engine Architecture

urlfech

mail

imagesapp

stdlibPythonVM

process

memcache datastore

req/respstateless APIs R/O FS

statefulAPIs

Source: [15]

3. Google App Engine™ platform3.3 Google App Engine Architecture

The App Engine request handling architecture[13].

3. Google App Engine™ platform3.4 Key Concepts in Google App Engine

• Sandbox: -Security; It isolates your application in its own secure, reliable environment ; the hardware, operating system and physical location of the web server.

3. Google App Engine™ platform3.4 Key Concepts in Google App Engine

• Bigtable: A Distributed Storage System for Structured Data[8].

-It uses the distributed Google File System(GFS[25]) to store log and data files.-It uses Google SSTable file format to store data. (persistent, ordered immutable map from keys to values)-It relies on a highly-available and persistent distributed lock service called Chubby.-It is designed to scale to a very large size.-It does not support a full relational data model.

3. Google App Engine™ platform3.4 Key Concepts in Google App Engine

• Datastore: A distributed data storage service grows with your data.

-Abstraction on top of Bigtable; It provides a scalable, transactional storage system for creating, storing, and querying data objects.-Two data storage options[18, 19]: The Master/Slave Datastore and the High Replication Datastore.- APIs For Java: Java Data Objects(JDO) 2.3 and Java Persistence API (JPA) 1.0

3. Google App Engine™ platform3.4 Key Concepts in Google App Engine

• Hierarchical Datastore

OBJECT ORIENTED RELATIONAL DATABASE DATASTORE

Class Table Kind

Object Record Entity

Attribute Column Property

3. Google App Engine™ platform3.4 Key Concepts in Google App Engine

• Indexes- index.yaml; the development server automatically

determines the index configuration for you[22].- Properties are automatically indexed by type+value[15,

21]. • Queries

-JDOQL: is similar to SQL, but is more appropriate for object-oriented databases like the App Engine datastore.-GQL[24]: is a SQL-like language for retrieving entities or keys from the App Engine scalable datastore.

3. Google App Engine™ platform3.5 Develop Web app with Google App Engine

GAE Application Development Cycle[10]

3. Google App Engine™ platform3.6 Managing Your App

3. Google App Engine™ platform3.6 Managing Your App

• Quotas-5M pageviews/month-Channel API Calls: 657K calls-Stored Data: 1GB-Datastore API Calls: 141M calss-Number of Indexes: 200-Requests(includes HTTPS): 43.2M requests-CPU Time: 6.5 CPU-hours/day-Task Queue API Calls: 100K-UrlFetch API Calls: 657K calls-XMPP API Calls: 46M calls

3. Google App Engine™ platform3.6 Managing Your App

3. Google App Engine™ platform3.7 Support

• Java[7]

-Java 6-Common Java web technology standards-Plugin for the Eclipse IDE-Other languages: JRuby, JavaScript(Thino), Scala.-Spring, Struts 1&2, Apache Commons FileUpload, etc.

• Python[27]

-Complete Python standard library-Django-CGI or WSGI

3. Google App Engine™ platform3.8 Summary in Google App Engine

Strengths - Python, Java support. (with SDK)- Collections of APIs.- Dashboard.- Generous Quotas lead to low entry cost.- GFS, Bigtable

3. Google App Engine™ platform3.8 Summary in Google App Engine

Weaknesses - Non-relational database lead to many constraints.- Quotas' limit often cause substantial headaches for developers.- Impose on the basis of security, HTTPS/HTTP.- Not very stable version in 2011.- Being blocked in China

4. Google Web Toolkit4.1 What is Google Web Toolkit?

Google Web Toolkit (GWT) is a development toolkit for building and optimizing complex browser-based applications. It is Java Web development and let you develop and debug AJAX applications in the Java Language[40].

Visit here for more information.Google Web Toolkit showcase : here.Google Web Toolkit Widget Gallery.

4. Google Web Toolkit4.2 Why is Google Web Toolkit? [38]

Its goal is to enable productive development of high-performance web applications without the developer having to be an expert in browser quirks, HMLHttpRequest, and JavaScript.

• Open Source, completely free. • Code stable, efficient and cross-browser apps (include mobile), offline compatible.• Developer friendly, IDE support etc.

4. Google Web Toolkit4.3 Google Web Toolkit Architecture.

Source: [40]

5. Simple Stock Market Analysis5.1 Functions

• Sign in with users' account

• Display the users' stock list

• Search stock quote and save the quote for users

• Remove specific stock from users’ stock list

• Log out

5. Simple Stock Market Analysis5.2 Features

• Relative real-time Stock Information[33]

• IE, Chrome Compatible

• Suggestion for stock quote search

5. Simple Stock Market Analysis5.3 Program UI

• Index

5. Simple Stock Market Analysis5.3 Program UI

• Sign In

5. Simple Stock Market Analysis5.3 Program UI

• Home

5. Simple Stock Market Analysis5.3 Program UI

• Search Quote (1/2)

5. Simple Stock Market Analysis5.3 Program UI

• Search Quote (2/2)

5. Simple Stock Market Analysis5.3 Program UI

• Remove Quote (Before)

5. Simple Stock Market Analysis5.3 Program UI

• Remove Quote (2 items removed)

5. Simple Stock Market Analysis5.3 Program UI

• IE Compatible

5. Simple Stock Market Analysis5.4 Code Snip

public class LoginServiceImpl extends RemoteServiceServlet implements LoginService { public LoginInfo login(String requestUri) { UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); LoginInfo loginInfo = new LoginInfo(); if (user != null) { loginInfo.setLoggedIn(true); loginInfo.setEmailAddress(user.getEmail()); loginInfo.setNickname(user.getNickname()); loginInfo.setLogoutUrl(userService.createLogoutURL(requestUri)); } else { loginInfo.setLoggedIn(false); loginInfo.setLoginUrl(userService.createLoginURL(requestUri)); } return loginInfo; }}

• Sign In – RPC – Server

5. Simple Stock Market Analysis5.4 Code Snip

public void onModuleLoad() { //Using Login Service checks the login status. LoginServiceAsync loginService = GWT.create(LoginService.class); //void loyola.lqu.client.LoginServiceAsync.login(String requestUri, AsyncCallback<LoginInfo> async) loginService.login(GWT.getHostPageBaseURL(), new AsyncCallback<LoginInfo>() { //new object of Type AsyncCallback<LoginInfo> public void onFailure(Throwable error) { } public void onSuccess(LoginInfo result) { loginInfo = result; if(loginInfo.isLoggedIn()) {

String name = "Welcome! " + loginInfo.getNickname(); userNickName = new Label(name); loadStockWatcher(); } else { loadLogin(); } } });

• GWT Entry Point Method (StockWather.java) - Client

5. Simple Stock Market Analysis5.4 Code Snip

private void loadLogin() { //in StockWather.java // Assemble login panel. signInLink.setHref(loginInfo.getLoginUrl()); loginLabel.addStyleDependentName("loginLabel");

loginPanel.add(loginLabel); loginPanel.add(signInLink); //Add the the GWT entry module into html page for displaying. RootPanel.get("stockList").add(loginPanel);}

• Login Panel – GWT – Client

In StockWatcher.html page: <div id="errorMsgLabel"></div> <div id="stockList"></div>

5. Simple Stock Market Analysis5.4 Code Snip

private void loadStockWatcher() {// Set up sign out hyperlink.signOutLink.setHref(loginInfo.getLogoutUrl());

// Create required column for display stock data.stocksFlexTable.setText(0, 0, "Symbol");stocksFlexTable.setText(0, 1, "Name");stocksFlexTable.setText(0, 2, "Price");stocksFlexTable.setText(0, 3, "Change");stocksFlexTable.setText(0, 4, "Volume");stocksFlexTable.setText(0, 5, "Remove");stocksFlexTable.setCellPadding(6);

• Main Panel – GWT – Client (1/5)

5. Simple Stock Market Analysis5.4 Code Snip

// Add styles to elements in the stock list table. stocksFlexTable.getRowFormatter().addStyleName(0, "watchListHeader"); stocksFlexTable.addStyleName("watchList"); stocksFlexTable.getCellFormatter().addStyleName(0, 1, "watchListNumericColumn"); stocksFlexTable.getCellFormatter().addStyleName(0, 2, "watchListNumericColumn"); stocksFlexTable.getCellFormatter().addStyleName(0, 3, "watchListNumericColumn"); stocksFlexTable.getCellFormatter().addStyleName(0, 4, "watchListNumericColumn"); stocksFlexTable.getCellFormatter().addStyleName(0, 5, "watchListNumericColumn"); loadStocks(); addPanel.add(newSymbolTextBox); //Get suggest from ItemSuggestOracle instance. ItemSuggestOracle oracle = new ItemSuggestOracle(); newSymbolSuggestBox = new SuggestBox(oracle, newSymbolTextBox); newSymbolSuggestBox.setLimit(5); addPanel.add(newSymbolSuggestBox); addPanel.add(addButton);

• Main Panel – GWT – Client (2/5)

5. Simple Stock Market Analysis5.4 Code Snip

addPanel.add(newSymbolTextBox);

//Get suggest from ItemSuggestOracle instance. ItemSuggestOracle oracle = new ItemSuggestOracle(); newSymbolSuggestBox = new SuggestBox(oracle, newSymbolTextBox); newSymbolSuggestBox.setLimit(5);

//Assemble the addPanel for searching quote addPanel.add(newSymbolSuggestBox); addPanel.add(addButton);

• Main Panel – GWT – Client (3/5)

5. Simple Stock Market Analysis5.4 Code Snip

• Main Panel – GWT – Client (4/5)// Assemble the Main panel.mainPanel.add(userNickName); //Display welcome informationmainPanel.add(lastUpdatedLabel); //Display last Updated time

mainPanel.add(addPanel);mainPanel.add(stocksFlexTable);mainPanel.add(new HTML("</br>”);mainPanel.add(signOutLink);

// Associate the Main panel with the HTML host page, host page got an <div> id's name is stockList.RootPanel.get("stockList").add(mainPanel);

// Move cursor focus to the inputbox.newSymbolTextBox.setFocus(true);

5. Simple Stock Market Analysis5.4 Code Snip

Timer refreshTimer = new Timer(){@Overridepublic void run() { refreshWatchList(); } }; refreshTimer.scheduleRepeating(REFRESH_INTERVAL); addButton.addClickHandler(new ClickHandler(){ //Deal with Button Click Event public void onClick(ClickEvent event){ addStock(); } }); newSymbolTextBox.addKeyPressHandler(new KeyPressHandler(){//Deal with Keyboard Event @Override public void onKeyPress(KeyPressEvent event) { if(event.getCharCode() == KeyCodes.KEY_ENTER){ addStock(); }} }); }

• Main Panel – GWT – Client (5/5)

5. Simple Stock Market Analysis5.4 Code Snip

<?xml version="1.0" encoding="utf-8"?><appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> <application>lqu-stockanalysis</application> <version>11</version> <!-- Configure java.util.logging --> <system-properties> <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/> </system-properties></appengine-web-app>

• appengine-web.xml

5. Simple Stock Market Analysis5.4 Code Snip

<welcome-file-list> <welcome-file>StockWatcher.html</welcome-file> </welcome-file-list>

<servlet> <servlet-name>loginService</servlet-name> <servlet-class>loyola.lqu.server.LoginServiceImpl</servlet-class> </servlet> <servlet-mapping> <servlet-name>loginService</servlet-name> <url-pattern>/stockwatcher/login</url-pattern> </servlet-mapping>……

• web.xml

5. Simple Stock Market Analysis5.5 Application Dashboard in Google App Engine

5. Simple Stock Market Analysis5.5 Application Dashboard in Google App Engine

5. Simple Stock Market Analysis5.6 Technology

• Google App Engine[5]

• The Users Java API[30]

• Google Web Toolkit[34]

• GWT-RPC[29]

• JSON[32]

• CSS, JavaScript etc.

6. Reference1. Cloud Computing and Grid Computing 360-Degree Compared, Ian Foster, Yong

Zhao, Ioan Raicu, Shiyong Lu.

2. Cloud computing service models, Part 2: Platform as a Service : Learn the benefits of PaaS.

3. Cloud and industry, Part 1: PaaS best practices and patterns : Learn about the requirements and functions of three models to deliver industry solutions, IaaS, PaaS, SaaS, and how you can use best practices and patterns with the PaaS framework in particular to deploy and manage cloud computing solutions.

4. Connecting to the cloud, Part 1: Leverage the cloud in applications: Explore cloud computing and the offerings from the major cloud platform vendors: Amazon, Google, Microsoft®, and SalesForce.com.

5. Google App Engine Home Page : Learn more about Google App Engine™ platform.

6. Install Google Plugin for Eclipse: Get started with the plug-ins.

6. Reference7. Will it play in App Engine for Java?: Lists the level of compatibility of various

Java technologies and App Engine (Java).

8. What's BigTable?: Read the Google research publication to find out.

9. Cloud computing fundamentals: Aid you in assimilating the reality of the revolution, so you can use it for your own profit and well being.

10. Stanford University Wiki – Google App Engine Project.

11. Slatkin, Brett. Building Scalable Web Applications with Google App Engine. Google IO 2008.

12. Ashcraft, Ken. Best Practices - Building a Production Quality Application on Google App Engine. Google IO 2008.

13. Dan Sanderson, Programming Google App Engine. O’Reilly, GoogleTM Press.

14. Getting Started: Java. Helpful sample from Google App Engine site.

6. Reference15. Presentation by Guido van Rossum. Google App Engine: Run your web

applications on Google's infrastructure. Stanford EE Computer Systems Colloquium. 5 Nov 2008.

16. Why App Engine. Brief explain why developers choose Google App Engine.

17. Google App Engine Samples. A list of samples and its source code.

18. Choosing a Datastore(Java). Comparing the Data Storage Options, choose the right one.

19. Datastore Overview(Python).

20. Barrett, Ryan. Under the Covers of the Google App Engine Datastore. Google IO 2008.

21. Introduction to Indexes.

22. Java Index Configuration Using YAML.

6. Reference23. Queries in JDO.

24. GQL Reference.

25. The Google File System. Get a in-depth understanding of GFS.

26. Google App Engine Articles. Articles related to Google App Engine in many aspects by category.

27. Google App Engine Python SDK Release Notes.

28. Google Web Toolkit Overview.

29. GWT-RPC. Making Remote Procedure Calls in Google Web Toolkit.

30. The Users Java API. Google App Engine applications can authenticate users who have Google Accounts

31. My Stock Watcher. Reference for code.

6. Reference32. JSON. Official site of JSON.

33. YAHOO! FINANCE disclaimer. See the page footer.

34. Google Web Toolkit Home.

35. Google Web Toolkit showcase.

36. Google Web Toolkit Widget Gallery.

37. Google Web Toolkit Gallery. Actual GWT Apps projects collection.

38. What's New in GWT 2.3? Along with release notes.

39. GWT + Gears : The browser is the platform. Brief introduction to GWT.

40. Google Web Tookit (GWT). Slides by Sang Shin. Sun Microsystems, Inc.

EndCloud Computing

Lina QuIndependent Study instructed by Dr. Yacobellis

2011.05.10