opel

Asynchronous expression language

License

License

GroupId

GroupId

pl.allegro.tech
ArtifactId

ArtifactId

opbox-opel
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

opel
Asynchronous expression language
Project URL

Project URL

https://github.com/allegro/opel
Source Code Management

Source Code Management

https://github.com/allegro/opel

Download opbox-opel

How to add to project

<!-- https://jarcasting.com/artifacts/pl.allegro.tech/opbox-opel/ -->
<dependency>
    <groupId>pl.allegro.tech</groupId>
    <artifactId>opbox-opel</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/pl.allegro.tech/opbox-opel/
implementation 'pl.allegro.tech:opbox-opel:0.1.0'
// https://jarcasting.com/artifacts/pl.allegro.tech/opbox-opel/
implementation ("pl.allegro.tech:opbox-opel:0.1.0")
'pl.allegro.tech:opbox-opel:jar:0.1.0'
<dependency org="pl.allegro.tech" name="opbox-opel" rev="0.1.0">
  <artifact name="opbox-opel" type="jar" />
</dependency>
@Grapes(
@Grab(group='pl.allegro.tech', module='opbox-opel', version='0.1.0')
)
libraryDependencies += "pl.allegro.tech" % "opbox-opel" % "0.1.0"
[pl.allegro.tech/opbox-opel "0.1.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.21
org.parboiled : parboiled-java jar 1.1.7
org.apache.commons : commons-lang3 jar 3.4

test (1)

Group / Artifact Type Version
org.spockframework : spock-core jar 1.0-groovy-2.4

Project Modules

There are no modules declared in this project.

Travis (.org) Codecov Quality Gate Status GitHub Release Date GitHub license

opel - asynchronous expression language

opel was designed to let you write simple, short asynchronous expressions. It uses Parboiled as a language grammar engine and common Java 8 CompletableFuture.

For example temperature() function asks REST service for temperature in Fahrenheit for given capital city and we want to convert it to Celsius. We can write a simple expression to achievie it.

(temperature('Warsaw') - 32) * 5 / 9

this expression will be transformed to equivalent code:

temperature('Warsaw')
	.thenCombine(CompletableFuture.completedFuture(32), (l, r) -> l - r)
	.thenCombine(CompletableFuture.completedFuture(5), (l, r) -> l * r)
	.thenCombine(CompletableFuture.completedFuture(9), (l, r) -> l / r)

Contents

Our business case

In OpBox which is our solution to build frontend in microservices world we have to prepare site title depending on data returned from data source (REST service). For show product page it may look like:

restService('showProduct') + ' - Allegro.pl - Więcej niż aukcje.'

Why have we created another language?

Allegro is a big platform with huge traffic. We encounter many performance issues so we decided to design everything asynchronously. Whenever it's possible we use CompletableFutures. It's a bit more complicated that way but opel abstraction layer enables our users (non developers) to write simple expressions in easy way.

After checking some expression languages like: SpEL or JEXL we didn't find any libraries supporting required asynchronous behavior.

What opel can't do?

opel aims at very simple expressions. Certainly it won't be enough to make complicated scripts - but we want opel to stay that way.

What can opel do for you?

opel supports:

  • primary math and string operations (i.e. 2+2*2, 'Hello' + 'world !')
  • relational and equality operators (i.e. 2 == 3, 2 > 1 != false)
  • logic operators (i.e. true && false, false || true)
  • simple map element access (i.e. map.field or map['field'])
  • simple list element access (i.e. list[index])
  • object method calls (i.e. 'Hello, World!'.length())
  • if expressions (i.e. if (2 > 3) 'a' else 'b')
  • defining local constant values (i.e. val x = 2+2*2; x * x)
  • registrable implicit conversions (i.e. 2 + '2' or 'Hello, World!'.myMethod())
  • registrable functions (i.e. myFunction('Hello, World!'))
  • registrable constant values (i.e. 'Hello, ' + WORLD_VALUE)

More can be found in documentation.

Using with Gradle

Basically, all you have to do is to add a compile dependency:

dependencies {
    compile 'pl.allegro.tech:opel:1.0.1'
}
pl.allegro.tech

Allegro Tech

Allegro Tech Open Source Projects

Versions

Version
0.1.0