Airframe Documentation
repository·main·Indexed 20 days ago
https://github.com/wvlet/airframeA collection of essential building blocks for Scala application development. Airframe provides a suite of libraries including a dependency injection (DI) framework, airframe-config for YAML and properties-based configuration, airframe-codec for MessagePack-based serialization, airframe-canvas for managing large off-heap memory regions, and airframe-control for simplifying control flow.
What's inside Airframe
- airframe-control is a library designed to simplify writing control flow in your applications.
Overview of Airframe capabilities
mainAirframe provides essential building blocks for Scala application development. Its core features include:
- Logging: Standardized logging utilities.
- Object Serialization: Support for JSON and MessagePack.
- Dependency Injection (DI): A DI library specifically tailored for Scala.
- HTTP & RPC: HTTP server and client capabilities with RPC support, enabling Scala to be used for both frontend and backend programming.
- Functional Testing: Provided via the AirSpec library.
Overview of airframe-codec
mainairframe-codec is a MessagePack-based schema-on-read data transcoder designed for Scala and Scala.js. It enables efficient serialization and deserialization of Scala objects and provides flexible data conversion capabilities.
Key features include:
- Object Serialization/Deserialization: Encode and decode Scala objects (such as case classes and collections) to and from MessagePack format.
- JDBC Integration: Convert JDBC result sets into MessagePack.
- Custom Codecs: Extend functionality by implementing your own pack/unpack logic.
- Schema-on-Read: Automatically convert data types during decoding if the target schema requires it. For example, string representations of numbers (e.g., "1", "2") can be automatically converted to integers if the target Scala object expects integer values.
Overview of airframe-http
mainairframe-http is a library designed for creating HTTP web servers with ease. It provides a low-friction approach to building web services in Scala.
Key components:
- airframe-http: The core library for HTTP server creation.
- airframe-http-finagle: An extension that allows you to use Finagle as the underlying HTTP server backend.
What is airframe-canvas and when to use it
mainairframe-canvasis a library designed to manage large off-heap memory regions (called Canvas) that exceed the 2GB ($2^{31}$ bytes) limit of standard JVM byte arrays.Key benefits include:
- Bypassing JVM limits: Allocate memory regions larger than the
-XmxJVM heap setting. - Performance: Avoids the CPU cost of zero-filling when initializing arrays.
- Memory Management: Allows for quick manual release of memory via
Canvas.release(orclose()), and provides a safety net where memory is released during Garbage Collection (GC) even if not manually released.
- Bypassing JVM limits: Allocate memory regions larger than the
Overview of AirSpec
mainAirSpec is a functional testing framework designed for Scala and Scala.js. It leverages pure Scala functions for writing test cases, minimizing the learning curve for Scala developers.
Key features include:
- Test cases written using pure Scala functions.
- Optional support for dependency injection in test cases.
- Optional support for property-based testing.
Overview of airframe-jdbc
mainairframe-jdbc is a reusable JDBC connection pool implementation designed to manage database connections efficiently within the Airframe ecosystem.Overview of airframe-metrics
mainairframe-metrics is a library designed to provide human-readable representations of various units, such as time durations and data byte sizes. It is part of the wvlet/airframe ecosystem.Overview of Airframe core frameworks
mainAirframe provides several core frameworks for building applications across Scala, Scala.js, and Scala Native:
- Airframe DI: Dependency Injection.
- Airframe RPC: A framework for using Scala for both Frontend and Backend programming (built on top of
airframe-http). - Airframe Rx: ReactiveX implementation for Scala.
- AirSpec: A testing framework.
Additional utility modules include
airframe-codec(MessagePack-based schema-on-read),airframe-config(YAML-based configuration), and many others.Airframe RPC core features and backends
mainAirframe RPC is a framework for building RPC services using Scala as a unified interface. Key features include:
- Backends: Supports Netty (HTTP/1) for standard web/browser compatibility and gRPC (HTTP/2) for high-performance requirements.
- Serialization: Automatically handles data encoding into JSON or MessagePack (a compact binary format).
- Client Generation: Uses the
sbt-airframeplugin to generate type-safe HTTP client code from your Scala interfaces, eliminating the need for manual HTTP request construction. - Cross-Platform: Supports Scala 2.13, 3.x, and Scala.js, enabling the same interface definitions to be used on both the JVM (server) and in the browser (client).
- Schema Generation: Supports Open API schema generation.
Key features of Airframe RPC
mainAirframe RPC provides several advantages for service communication:
- Type Safety: The client and server share the exact same interface definition.
- Multiple Protocols: Supports JSON, MessagePack, and gRPC.
- Cross-Platform: Compatible with Scala.js for frontend development.
- Automatic Code Generation: Client code is automatically generated from the
@RPCinterfaces.
Compare Airframe with other DI frameworks
mainAirframe is a run-time dependency injection (DI) framework for Scala. When choosing a DI approach, consider the following trade-offs:
Run-time DI (e.g., Airframe, Google Guice)
- Pros: Supports dynamic-type binding (useful for switching implementations based on environment like test vs. production), simpler binding code (only direct dependencies need to be written), and rich life-cycle management.
- Cons: Missing bindings are discovered at runtime rather than compile time.
Compile-time DI (e.g., MacWire, Dagger2)
- Pros: Validates the presence of all dependencies at compile time.
- Cons: Less flexible (no dynamic binding), requires enumerating all dependencies (including transitive ones) in a single scope, and life-cycle management is often difficult or requires reflection-based interceptors.
Pure-Scala Approaches (e.g., Cake Pattern, Reader Monad)
- Pros: No external framework required; missing dependencies are caught at compile time.
- Cons: Requires manual wiring/overrides and careful management of explicit or implicit parameters.