Designed by | Sanjiva Weerawarana, James Clark, Sameera Jayasoma, Hasitha Aravinda, Srinath Perera, Frank Leymann and WSO2 [1] |
---|---|
Developer | WSO2 |
First appeared | 2017 |
Typing discipline | Structural, strong, static, inferred |
Implementation language | Java, Ballerina, TypeScript [2] |
OS | Cross-platform |
License | Apache License 2.0 [3] |
Website | ballerina |
Influenced by | |
Java, Javascript, Go, Rust, C# [4] |
Ballerina is an open source general-purpose programming language designed by WSO2 for cloud-era application programmers. [2]
The project started in 2015 by architects from WSO2 as a code-based alternative to the configuration-based integration tools such as EAI, ESB, and workflow products. [5] [6]
It has various constructs geared toward cloud-native development including support for various data formats and protocols, reliability, distributed transactions, APIs, and event streams. [7] [8] [9]
Ballerina was first publicly announced in 2017 and version 1.0 was released on September 10, 2019. [10]
Ballerina is a general-purpose language with a familiar syntax along with a direct graphical representation of the code in the form of sequence diagrams. It has fundamental abstractions designed to make integration problems easier to program. [11] Ballerina was designed by WSO2 to improve productivity for application developers that have to work with distributed computing. It is easy to write and modify and is suitable for application programmers. [12] [13] [14]
The designers, who provided enterprise integration products for over 10 years, used their knowledge of the industry when designing the language, [15] [16] says WSO2 director and Ballerina founder James Clark.
The regular Hello World program:
importballerina/io;publicfunctionmain(){io:println("Hello World!");}
To execute the above program, place the source code in a .bal
file and provide the path of the file to the bal run
command.
$ ballerinarunhello_world.bal Hello World!
The service version of the Hello World program:
import ballerina/http; service /greet on new http:Listener(9090) { resource function get . () returns string { return "Hello World!"; } }
Services are executed in the same manner, except they don't terminate like regular programs do. Once the service is up and running, one can use an HTTP client to invoke the service. For example, the above service can be invoked using the following cURL command:
$ curlhttp://localhost:9090/greetHello World!
importballerina/http;serviceonnewhttp:Listener(9090){resourcefunctionpostfactorial(@http:Payloadstringpayload)returnshttp:Ok|http:BadRequest{int|errornum=int:fromString(payload);ifnumiserror{return<http:BadRequest>{body:"Invalid integer: "+payload};}ifnum<0{return<http:BadRequest>{body:"Integer should be >= 0"};}intresult=1;foreachintiin2...num{result*=i;}return<http:Ok>{body:result};}}
$ curlhttp://localhost:9090/factorial-d5120
importballerina/graphql;service/stocksonnewgraphql:Listener(4000){resourcefunctiongetquote()returnsStockQuote{return{ticker:"EXPO",price:287.5,open:285,prevClose:285.5,low:276.25,high:297};}}typeStockQuoterecord{|stringticker;floatprice;floatopen;floatprevClose;floatlow;floathigh;|};
$ curl-H"Content-type: application/json"-d'{"query": "{ quote { ticker, price } }" }''http://localhost:4000/stocks'{"data":{"quote":{"ticker":"EXPO", "price":287.5}}}
The generated sequence diagram is a canonical representation of the source code. The two representations can be used interchangeably. The diagram support is provided through the Ballerina VS Code plugin. The following are a couple of such generated sequence diagrams, compared with its associated code.
A sample program for retrieving and processing COVID-19 data:
A sample program for creating a report out of pull request data retrieved from GitHub:
The language provides support for working with JSON values. The builtin type `json` is defined as the following union: ()|boolean|int|float|decimal|string|json[]|map<json>
importballerina/io;publicfunctionmain()returnserror{// Syntax for `json` object values is very similar to the syntax of JSONjsonperson={name:"John Doe",age:25};// Serialized `json` values conforms to the JSON specification io:println(person);// The fields of the `json` value can be accessed as followsstringname=checkperson.name;intage=checkperson.age;}
Docker and Kubernetes artifacts required for deploying the code to the cloud can be generated when building the code. Values required for these artifacts are derived from the code. Additionally, one can override these values as well using the Cloud.toml
file. To enable generation of the cloud artifacts, the users can use the cloud
build option in the Ballerina.toml
file. Use docker
to generate just the Docker image and the Dockerfile and use k8s
to generate Kubernetes artifacts as well. Minimal sample config TOML files would look something like the following:
Ballerina.toml
file:
[package]distribution="2201.0.0"[build-options]cloud="k8s"
Cloud.toml
file:
[container.image]repository="bal_user"name="greet"tag="v0.1.0"
importballerina/http;importballerina/lang.'int;importballerina/io;// Workers interact with each other by sending and receiving messages.// Ballerina validates every worker interaction (send and receive)// to avoid deadlocks.publicfunctionmain(){@strand{thread:"any"}workerw1{intw1val=checkpaniccalculate("2*3");// Sends a message asynchronously to the worker `w2`.w1val->w2;// Receives a message from the worker `w2`.intw2val=<-w2;io:println("[w1] Message from w2: ",w2val);// Sends messages synchronously to the worker `w3`. The worker `w1` will wait// until the worker `w3` receives the message.w1val->>w3;w2val->w3;// Flushes all messages sent asynchronously to the worker `w3`. The worker// will halt at this point until all messages are sent or until the worker `w3`// fails.checkpanicflushw3;}// A worker can have an explicit return type, or else, if a return type is not mentioned,// it is equivalent to returning ().@strand{thread:"any"}workerw2{intw2val=checkpaniccalculate("17*5");// Receives a message from the worker `w1`.intw1val=<-w1;io:println("[w2] Message from w1: ",w1val);// Sends a message asynchronously to the worker `w1`.w1val+w2val->w1;}workerw3{int|errorw1val=<-w1;int|errorw2val=<-w1;io:println("[w3] Messages from w1: ",w1val,", ",w2val);}// Waits for the worker `w1`to finish.waitw1;}functioncalculate(stringexpr)returnsint|error{http:ClienthttpClient=checknew("https://api.mathjs.org");stringresponse=checkhttpClient->get(string`/v4/?expr=${expr}`);returncheck'int:fromString(response);}
The Java Remote Method Invocation is a Java API that performs remote method invocation, the object-oriented equivalent of remote procedure calls (RPC), with support for direct transfer of serialized Java classes and distributed garbage-collection.
In mathematics and computer science, a higher-order function (HOF) is a function that does at least one of the following:
YAML is a human-readable data serialization language. It is commonly used for configuration files and in applications where data is being stored or transmitted. YAML targets many of the same communications applications as Extensible Markup Language (XML) but has a minimal syntax that intentionally differs from Standard Generalized Markup Language (SGML). It uses Python-style indentation to indicate nesting and does not require quotes around most string values.
The syntax of Java is the set of rules defining how a Java program is written and interpreted.
In software engineering, dependency injection is a programming technique in which an object or function receives other objects or functions that it requires, as opposed to creating them internally. Dependency injection aims to separate the concerns of constructing objects and using them, leading to loosely coupled programs. The pattern ensures that an object or function that wants to use a given service should not have to know how to construct those services. Instead, the receiving "client" is provided with its dependencies by external code, which it is not aware of. Dependency injection makes implicit dependencies explicit and helps solve the following problems:
In computer programming, an entry point is the place in a program where the execution of a program begins, and where the program has access to command line arguments.
In mathematics and in computer programming, a variadic function is a function of indefinite arity, i.e., one which accepts a variable number of arguments. Support for variadic functions differs widely among programming languages.
Pnuts is a dynamic scripting language for the Java platform. It is designed to be used in a dual language system with the Java programming language. The goals of the Pnuts project are to provide a small, fast scripting language that has tight integration with the Java language. Pnuts uses syntax that is simple and friendly to Java developers, while also being very expressive.
WSO2 LLC is an open-source technology provider founded in 2005. It delivers software and cloud solutions that provide foundational technologies for application development and identity and access management (IAM). This represents an expansion upon its original focus on integrating application programming interfaces (APIs), applications, and web services locally and across the Internet.
WSO2 Mashup Server, an open-source mashup platform that used to host JavaScript-based mashups, is now deprecated and no longer in use. It was based on Apache Axis2 and other open-source projects, and allowed JavaScript to consume, compose and emit web services, feeds, scraped web pages, email, and instant messages. The source code was freely available under the open-source Apache License. It provided a runtime platform for developing and deploying mashups and could be downloaded and deployed locally or within an organization.
Go is a statically typed, compiled high-level general purpose programming language. It was designed at Google in 2009 by Robert Griesemer, Rob Pike, and Ken Thompson. It is syntactically similar to C, but also has memory safety, garbage collection, structural typing, and CSP-style concurrency. It is often referred to as Golang because of its former domain name, golang.org
, but its proper name is Go.
Agent-oriented programming (AOP) is a programming paradigm where the construction of the software is centered on the concept of software agents. In contrast to object-oriented programming which has objects at its core, AOP has externally specified agents at its core. They can be thought of as abstractions of objects. Exchanged messages are interpreted by receiving "agents", in a way specific to its class of agents.
Ateji PX is an object-oriented programming language extension for Java. It is intended to facilliate parallel computing on multi-core processors, GPU, Grid and Cloud.
Nemerle is a general-purpose, high-level, statically typed programming language designed for platforms using the Common Language Infrastructure (.NET/Mono). It offers functional, object-oriented, aspect-oriented, reflective and imperative features. It has a simple C#-like syntax and a powerful metaprogramming system.
Gson, or Google Gson, is an open-source Java library that serializes Java objects to JSON.
In software engineering, the module pattern is a design pattern used to implement the concept of software modules, defined by modular programming, in a programming language with incomplete direct support for the concept.
Elm is a domain-specific programming language for declaratively creating web browser-based graphical user interfaces. Elm is purely functional, and is developed with emphasis on usability, performance, and robustness. It advertises "no runtime exceptions in practice", made possible by the Elm compiler's static type checking.
Nim is a general-purpose, multi-paradigm, statically typed, compiled high-level system programming language, designed and developed by a team around Andreas Rumpf. Nim is designed to be "efficient, expressive, and elegant", supporting metaprogramming, functional, message passing, procedural, and object-oriented programming styles by providing several features such as compile time code generation, algebraic data types, a foreign function interface (FFI) with C, C++, Objective-C, and JavaScript, and supporting compiling to those same languages as intermediate representations.
Apache Commons Logging is a Java-based logging utility and a programming model for logging and for other toolkits. It provides APIs, log implementations, and wrapper implementations over some other tools.
The Thing Description (TD) (or W3C WoT Thing Description (TD)) is a royalty-free, open information model with a JSON based representation format for the Internet of Things (IoT). A TD provides a unified way to describe the capabilities of an IoT device or service with its offered data model and functions, protocol usage, and further metadata. Using Thing Descriptions help reduce the complexity of integrating IoT devices and their capabilities into IoT applications.
{{cite journal}}
: Cite journal requires |journal=
(help)