SkillAgentSearch skills...

Activej

ActiveJ is an alternative Java platform built from the ground up. ActiveJ redefines core, web and high-load programming in Java, providing simplicity, maximum performance and scalability

Install / Use

/learn @activej/Activej

README

Maven Central GitHub

Introduction

ActiveJ is a modern Java platform built from the ground up. It is designed to be self-sufficient (no third-party dependencies), simple, lightweight and provides competitive performance. ActiveJ consists of a range of orthogonal libraries, from dependency injection and high-performance asynchronous I/O (inspired by Node.js), to application servers and big data solutions.

These libraries have as few dependencies as possible with respect to each other and can be used together or separately. ActiveJ in not yet another framework that forces the user to use it on an all-or-nothing basis, but instead it gives the user as much freedom as possible in terms of choosing library components for particular tasks.

ActiveJ components

ActiveJ consists of several modules, which can be logically grouped into the following categories :

  • Async.io - High-performance asynchronous IO with the efficient event loop, NIO, promises, streaming, and CSP. Alternative to Netty, RxJava, Akka, and others. (Promise, Eventloop, Net, CSP, Datastream)

    // Basic eventloop usage
    public static void main(String[] args) {
        Eventloop eventloop = Eventloop.create();
    
        eventloop.post(() -> System.out.println("Hello, world!"));
    
        eventloop.run();
    }
    
    // Promise chaining
    public static void main(String[] args) {
        Eventloop eventloop = Eventloop.builder()
            .withCurrentThread()
            .build();
    
        Promises.delay(Duration.ofSeconds(1), "world")
            .map(string -> string.toUpperCase())
            .then(string -> Promises.delay(Duration.ofSeconds(3))
                .map($ -> "HELLO " + string))
            .whenResult(string -> System.out.println(string));
    
        eventloop.run();
    }
    
    // CSP workflow example
    ChannelSuppliers.ofValues(1, 2, 3, 4, 5, 6)
        .filter(x -> x % 2 == 0)
        .map(x -> 2 * x)
        .streamTo(ChannelConsumers.ofConsumer(System.out::println));
    
    // Datastream workflow example
    StreamSuppliers.ofValues(1, 2, 3, 4, 5, 6)
        .transformWith(StreamTransformers.filter(x -> x % 2 == 0))
        .transformWith(StreamTransformers.mapper(x -> 2 * x))
        .streamTo(StreamConsumers.ofConsumer(System.out::println));
    
  • HTTP - High-performance HTTP server and client with WebSocket support. It can be used as a simple web server or as an application server. Alternative to other conventional HTTP clients and servers. (HTTP)

    // Server
    public static void main(String[] args) throws IOException {
        Eventloop eventloop = Eventloop.create();
    
        AsyncServlet servlet = request -> HttpResponse.ok200()
            .withPlainText("Hello world")
            .toPromise();
    
        HttpServer server = HttpServer.builder(eventloop, servlet)
            .withListenPort(8080)
            .build();
    
        server.listen();
    
        eventloop.run();
    }
    
    // Client
    public static void main(String[] args) {
        Eventloop eventloop = Eventloop.create();
    
        HttpClient client = HttpClient.create(eventloop);
    
        HttpRequest request = HttpRequest.get("http://localhost:8080").build();
    
        client.request(request)
            .then(response -> response.loadBody())
            .map(body -> body.getString(StandardCharsets.UTF_8))
            .whenResult(bodyString -> System.out.println(bodyString));
    
        eventloop.run();
    }
    
  • ActiveJ Inject - Lightweight library for dependency injection. Optimized for fast application start-up and performance at runtime. Supports annotation-based component wiring as well as reflection-free wiring. (ActiveJ Inject)

    // Manual binding
    public static void main(String[] args) {
        Module module = ModuleBuilder.create()
            .bind(int.class).toInstance(101)
            .bind(String.class).to(number -> "Hello #" + number, int.class)
            .build();
    
        Injector injector = Injector.of(module);
    
        String string = injector.getInstance(String.class);
    
        System.out.println(string); // "Hello #101"
    }
    
    // Binding via annotations
    public static class MyModule extends AbstractModule {
        @Provides
        int number() {
            return 101;
        }
    
        @Provides
        String string(int number) {
            return "Hello #" + number;
        }
    }
    
    public static void main(String[] args) {
        Injector injector = Injector.of(new MyModule());
    
        String string = injector.getInstance(String.class);
    
        System.out.println(string); // "Hello #101"
    }
    
  • Boot - Production-ready tools for running and monitoring an ActiveJ application. Concurrent control of services lifecycle based on their dependencies. Various service monitoring utilities with JMX and Zabbix support. (Launcher, Service Graph, JMX, Triggers)

    public class MyLauncher extends Launcher {
        @Inject
        String message;
    
        @Provides
        String message() {
            return "Hello, world!";
        }
    
        @Override
        protected void run() {
            System.out.println(message);
        }
    
        public static void main(String[] args) throws Exception {
            Launcher launcher = new MyLauncher();
            launcher.launch(args);
        }
    }
    
  • Bytecode manipulation

    • ActiveJ Codegen - Dynamic bytecode generator for classes and methods on top of ObjectWeb ASM library. Abstracts the complexity of direct bytecode manipulation and allows you to create custom classes on the fly using Lisp-like AST expressions. (ActiveJ Codegen)

      // Manually implemented method
      public class MyCounter implements Counter { 
          @Override
          public int countSum() {
              int sum = 0;
              for (int i = 0; i < 100; i++) {
                  sum += i;
              }
              return sum;
          }
      }
      
      // The same method generated via ActiveJ Codegen 
      public static void main(String[] args) {
          DefiningClassLoader classLoader = DefiningClassLoader.create();
      
          Counter counter = ClassGenerator.builder(Counter.class)
              .withMethod("countSum",
                  let(value(0), sum ->
                      sequence(
                          iterate(
                              value(0),
                              value(100),
                              i -> set(sum, add(sum, i))),
                          sum
                      )))
              .build()
              .generateClassAndCreateInstance(classLoader);
      
          System.out.println(counter.countSum()); // 4950
      }
      
    • ActiveJ Serializer - Fast and space-efficient serializers created with bytecode engineering. Introduces schema-free approach for best performance. (ActiveJ Serializer)

      // A class to be serialized
      public class User {
          private final int id;
          private final String name;
      
          public User(@Deserialize("id") int id, @Deserialize("name") String name) {
              this.id = id;
              this.name = name;
          }
      
          @Serialize
          public int getId() {
              return id;
          }
      
          @Serialize
          public String getName() {
              return name;
          }
      }
      
      // Serialization and deserialization
      public static void main(String[] args) {
          BinarySerializer<User> userSerializer = SerializerFactory.defaultInstance()
              .create(User.class);
      
          User john = new User(1, "John");
      
          byte[] buffer = new byte[100];
          userSerializer.encode(buffer, 0, john);
      
          User decoded = userSerializer.decode(buffer, 0);
      
          System.out.println(decoded.id);   // 1
          System.out.println(decoded.name); // John
      }
      
      // Serialization of Java records
      @SerializeRecord
      public record User(int id, String name) {
      }
      
      // StreamCodec usage example
      public static void main(String[] args) throws IOException {
          StreamCodec<User> userStreamCodec = StreamCodec.create(User::new,
              User::getId, StreamCodecs.ofVarInt(),
              User::getName, StreamCodecs.ofString()
          );
      
          List<User> users = List.of(
              new User(1, "John"),
              new User(2, "Sarah"),
              new User(3, "Ben")
          );
      
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          try (StreamOutput streamOutput = StreamOutput.create(baos)) {
              for (User user : users) {
                  userStreamCodec.encode(streamOutput, user);
              }
          }
      
          ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
          try (StreamInput streamInput = StreamInput.create(bais)) {
              while (!streamInput.isEndOfStream()) {
                  User dec
      
View on GitHub
GitHub Stars985
CategoryDevelopment
Updated1d ago
Forks81

Languages

Java

Security Score

100/100

Audited on Mar 26, 2026

No findings