Design and Implementation of a Behaviorally Typed Programming System for Web Services
Total Page:16
File Type:pdf, Size:1020Kb
Universidade Nova de Lisboa Faculdade de Cienciasˆ e Tecnologia Departamento de Informatica´ Dissertac¸ao˜ de Mestrado Mestrado em Engenharia Informatica´ Design and Implementation of a Behaviorally Typed Programming System for Web Services Filipe David Oliveira Militao˜ (26948) Lisboa (2008) Universidade Nova de Lisboa Faculdade de Cienciasˆ e Tecnologia Departamento de Informatica´ Dissertac¸ao˜ de Mestrado Design and Implementation of a Behaviorally Typed Programming System for Web Services Filipe David Oliveira Militao˜ (26948) Orientador: Prof. Doutor Lu´ıs Caires J ´uri Presidente: • Doutor Jos´eAlberto Cardoso e Cunha, Professor Catedratico,´ Departamento de Informatica´ da Faculdade de Cienciasˆ e Tecnologia, Universidade Nova de Lisboa. Vogais: • Doutor Francisco Martins, Professor Auxiliar, Departamento de Informatica´ da Faculdade de Ciencias,ˆ Universidade de Lisboa. • Doutor Lu´ısManuel Marques da Costa Caires, Professor Associado, Departa- mento de Informatica´ da Faculdade de Cienciasˆ e Tecnologia, Universidade Nova de Lisboa. Disserta¸c˜aoapresentada na Faculdade de Ciˆenciase Tecnologia da Uni- versidade Nova de Lisboa para a obten¸c˜aodo Grau de Mestre em En- genharia Inform´atica. Lisboa (2008) Acknowledgements This work was partially supported by a CITI/PLM/1001/2007 research grant. v Summary The growing use of the Internet as a global infrastructure for communication between dis- tributed applications is leading to the development of a considerable amount of technologies to ease the deployment, description and data exchange among services and thus improve their in- teroperability. There is also a growing interest in the use of the “software as a service” business model where a software vendor develops and hosts applications to be used by its clients over the Internet. The use of these Web Services is provided through an API describing the inter- face of the service that can hide how the service provider hosts the application. This approach allows for the creation of an abstraction layer that offers additional capabilities without increas- ing the maintenance cost usually linked to the management of those machines (like software and hardware updates or just application/system configuration). However, the main tools provided by the standards and existing technology to combine these services usually only account for limited automatic verification techniques (based on standard signature checking of methods in interface descriptions) and thus relying the behav- ioral compatibility among services to the programmer. The programmer then becomes depen- dent on the quality of the documentation and the development time available to manually (and without formal guarantees) assure the correctness of the code. In this thesis, we propose a behavioral type system, in the context of yak, a prototype script- ing language for web services, that enhances traditional typecheckers by allowing to statically check the correct usage of services (as remote or local objects). Our language uses behavioral annotations in the protocol descriptions, similar to regular expressions, that are translated to deterministic finite automatons during the typechecking phase. The intent of this work is to ease the creation and deployment of Web Services by providing a friendly integration of be- havioral type concepts within a practical programming language, so to make the use of these services (with behavioral descriptions) transparent and effortless to the programmer. We also provide a full implementation of the interpreter, behavioral typechecker and run-time support system for the yak language, that may be used to develop prototypical systems and experiment with web services and behavioral types. Keywords: Web Services, Behavioral Typechecking, Resource Usage Analysis, Type System, Type Inference, Scripting Language. vii Sum´ario A crescente utilizac¸ao˜ da Internet como meio de comunicac¸ao˜ entre aplicac¸oes˜ levou ao de- senvolvimento de tecnologias para a disponibilizac¸ao,˜ descric¸ao˜ e comunicac¸ao˜ entre servic¸os como consequenciaˆ da heterogeneidade do codigo´ e das maquinas´ envolvidas. Deste modo, ha´ tambem´ um grande interesse no fornecimento de “software como servic¸o” onde uma em- presa desenvolve e disponibiliza aplicac¸oes˜ ao seus clientes por intermedio´ da Internet. Os clientes dialogam com estes Web Services atraves´ de APIs que descrevem a interface do servic¸o e escondem o modo como este esta´ alojado nos servidores. Assim, permitem criar um n´ıvel de abstracc¸ao˜ relativamente ao fornecimento de capacidades diversas sem impor o custo de manutenc¸ao˜ normalmente associado a` sua gestao˜ (tal como por exemplo, manutenc¸ao˜ de hard- ware ou configurac¸ao˜ e actualizac¸ao˜ das aplicac¸oes).˜ Contudo, as principais ferramentas disponibilizadas pelas normas e tecnologias actual- mente existentes para a combinac¸ao˜ destes servic¸os apenas permitem uma verificac¸ao˜ au- tomatica´ limitada (baseada na comparac¸ao˜ das assinaturas dos metodos´ descritos nas inter- faces) e deste modo delegam a garantia de compatibilidade de comportamentos para o pro- gramador. Este fica entao˜ dependente da qualidade da documentac¸ao˜ e da disponibilidade de tempo necessario´ para garantir manualmente (e sem garantias formais) a adequac¸ao˜ da sua soluc¸ao.˜ Nesta tese propomos um sistema de tipos comportamental, no contexto de yak, um prototipo´ de uma linguagem de scripting para Web Services que complementa a verificac¸ao˜ de tipos tradicional ao garantir estaticamente a correcta utilizac¸ao˜ de servic¸os (tanto remotos como lo- cais). Esta linguagem permite a descric¸ao˜ do comportamento por intermedio´ de anotac¸oes˜ adi- cionais, sob uma forma semelhante a expressoes˜ regulares, que sao˜ traduzidas em automatos´ finitos deterministas para a verificac¸ao.˜ O objectivo deste trabalho e´ facilitar a disponibilizac¸ao˜ e criac¸ao˜ de Web Services (com informac¸ao˜ comportamental) atraves´ da incorporac¸ao˜ de mecan- ismos na propria´ linguagem que tornam estes elementos transparentes ao programador e de utilizac¸ao˜ imediata. Disponibilizamos ainda a implementac¸ao˜ completa do interpretador, sis- tema de tipos comportamental e sistema de execuc¸ao˜ para a linguagem yak, suficientes para o desenvolvimento de sistemas experimentais com Web Services e tipos comportamentais. Palavras-chave: Web Services, Tipificac¸ao˜ Comportamental, Analise´ de Utilizac¸ao˜ de Recursos, Sistema de Tipos, Inferenciaˆ de Tipos, Linguagem de Scripting. ix Contents 1 Introduction 1 1.1 Motivation.........................................1 1.2 Context and description.................................3 1.3 Related work........................................4 1.4 Proposed solution..................................... 11 1.5 Contributions....................................... 13 1.5.1 Design and formalization of a behavioral type system............ 13 1.5.2 Design of the programming language yak................... 14 1.5.3 Implementation of a proof-of-concept prototype............... 14 1.6 Document overview................................... 15 2 The Yak Language and Type System 17 2.1 The language: syntax and informal semantics..................... 17 2.2 SubTyping......................................... 21 2.2.1 Simulation..................................... 25 2.3 Type System........................................ 29 2.3.1 Basic constructions................................ 30 2.3.2 Control flow.................................... 32 2.3.3 Variables...................................... 36 2.3.4 Calls........................................ 38 2.3.5 Exceptions..................................... 41 2.3.6 Basic types..................................... 46 2.3.7 Class type..................................... 46 2.3.8 Class Consistency Check............................. 47 2.3.9 Containers..................................... 50 2.4 Remarks.......................................... 51 3 Examples 53 3.1 Files............................................. 54 3.2 Machines.......................................... 56 3.3 Purchase.......................................... 58 xi CONTENTS 4 The Prototype 61 4.1 Technologies........................................ 62 4.2 Main changes to the formalization........................... 63 4.3 Implementation of the Typechecker........................... 64 4.3.1 Basic mechanisms................................ 64 4.3.2 Program Constructions............................. 75 4.3.3 Checking class consistency........................... 90 4.4 Implementation of the Interpreter............................ 98 4.5 Principles of the distribution mechanism....................... 99 4.6 Remarks.......................................... 101 5 Conclusions 103 5.1 Future work........................................ 104 A Complete Grammar 111 B Behavioral Protocols 115 C Quick User Guide 117 C.1 How to compile...................................... 117 C.2 How to run......................................... 117 C.3 Values............................................ 118 C.3.1 Object....................................... 118 C.3.2 Integer....................................... 118 C.3.3 Double....................................... 119 C.3.4 Boolean...................................... 120 C.3.5 String........................................ 120 C.3.6 XML........................................ 121 C.3.7 Default library.................................. 122 C.3.8 Maps........................................ 122 C.3.9 Queues......................................