{"id":16284126,"url":"https://github.com/activej/activej","last_synced_at":"2025-05-13T19:08:38.866Z","repository":{"id":41123834,"uuid":"267619299","full_name":"activej/activej","owner":"activej","description":"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","archived":false,"fork":false,"pushed_at":"2024-12-17T18:58:52.000Z","size":16128,"stargazers_count":947,"open_issues_count":46,"forks_count":77,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-04-27T04:51:49.486Z","etag":null,"topics":["async","code-generation","dependency-injection","framework","high-performance","java","microservice","microservices","rpc","rpc-framework","serializer","web"],"latest_commit_sha":null,"homepage":"https://activej.io","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/activej.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-28T14:58:00.000Z","updated_at":"2025-04-23T15:56:12.000Z","dependencies_parsed_at":"2023-09-22T06:05:07.684Z","dependency_job_id":"7e03216a-3d5e-447e-a2af-40717bbbd1b4","html_url":"https://github.com/activej/activej","commit_stats":{"total_commits":1992,"total_committers":11,"mean_commits":181.0909090909091,"dds":0.2349397590361446,"last_synced_commit":"007785780e15d3f4938c14583a81185202566c44"},"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/activej%2Factivej","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/activej%2Factivej/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/activej%2Factivej/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/activej%2Factivej/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/activej","download_url":"https://codeload.github.com/activej/activej/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251089412,"owners_count":21534512,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","code-generation","dependency-injection","framework","high-performance","java","microservice","microservices","rpc","rpc-framework","serializer","web"],"created_at":"2024-10-10T19:18:27.913Z","updated_at":"2025-04-27T04:51:58.159Z","avatar_url":"https://github.com/activej.png","language":"Java","readme":"[![Maven Central](https://img.shields.io/maven-central/v/io.activej/activej)](https://mvnrepository.com/artifact/io.activej)\n[![GitHub](https://img.shields.io/github/license/activej/activej)](https://github.com/activej/activej/blob/master/LICENSE)\n\n## Introduction\n\n[ActiveJ](https://activej.io) is a modern Java platform built from the ground up.\nIt is designed to be self-sufficient (no third-party dependencies), simple, lightweight and provides competitive performance.\nActiveJ consists of a range of orthogonal libraries, from dependency injection and high-performance\nasynchronous I/O (inspired by Node.js), to application servers and big data solutions. \n\nThese libraries have as few dependencies as possible with respect to each other and can be used together or separately. \nActiveJ in not yet another framework that forces the user to use it on an all-or-nothing basis, but instead it gives \nthe user as much freedom as possible in terms of choosing library components for particular tasks.\n\n## ActiveJ components\n\nActiveJ consists of several modules, which can be logically grouped into the following categories :\n\n* **Async.io** - High-performance asynchronous IO with the efficient event loop, NIO, promises, streaming, and CSP.\n  Alternative to Netty, RxJava, Akka, and others. ([Promise](https://activej.io/async-io/promise),\n  [Eventloop](https://activej.io/async-io/eventloop), [Net](https://activej.io/async-io/net),\n  [CSP](https://activej.io/async-io/csp), [Datastream](https://activej.io/async-io/datastream))\n\n  ```java\n  // Basic eventloop usage\n  public static void main(String[] args) {\n      Eventloop eventloop = Eventloop.create();\n  \n      eventloop.post(() -\u003e System.out.println(\"Hello, world!\"));\n  \n      eventloop.run();\n  }\n  ```\n\n  ```java\n  // Promise chaining\n  public static void main(String[] args) {\n      Eventloop eventloop = Eventloop.builder()\n          .withCurrentThread()\n          .build();\n  \n      Promises.delay(Duration.ofSeconds(1), \"world\")\n          .map(string -\u003e string.toUpperCase())\n          .then(string -\u003e Promises.delay(Duration.ofSeconds(3))\n              .map($ -\u003e \"HELLO \" + string))\n          .whenResult(string -\u003e System.out.println(string));\n  \n      eventloop.run();\n  }\n  ```\n\n  ```java\n  // CSP workflow example\n  ChannelSuppliers.ofValues(1, 2, 3, 4, 5, 6)\n      .filter(x -\u003e x % 2 == 0)\n      .map(x -\u003e 2 * x)\n      .streamTo(ChannelConsumers.ofConsumer(System.out::println));\n  ```\n\n  ```java\n  // Datastream workflow example\n  StreamSuppliers.ofValues(1, 2, 3, 4, 5, 6)\n      .transformWith(StreamTransformers.filter(x -\u003e x % 2 == 0))\n      .transformWith(StreamTransformers.mapper(x -\u003e 2 * x))\n      .streamTo(StreamConsumers.ofConsumer(System.out::println));\n  ```\n\n* **HTTP** - High-performance HTTP server and client with WebSocket support. It can be used as a simple web server or as an\n  application server. Alternative to other conventional HTTP clients and servers. ([HTTP](https://activej.io/http))\n\n  ```java\n  // Server\n  public static void main(String[] args) throws IOException {\n      Eventloop eventloop = Eventloop.create();\n  \n      AsyncServlet servlet = request -\u003e HttpResponse.ok200()\n          .withPlainText(\"Hello world\")\n          .toPromise();\n  \n      HttpServer server = HttpServer.builder(eventloop, servlet)\n          .withListenPort(8080)\n          .build();\n  \n      server.listen();\n  \n      eventloop.run();\n  }\n  ```\n\n  ```java\n  // Client\n  public static void main(String[] args) {\n      Eventloop eventloop = Eventloop.create();\n  \n      HttpClient client = HttpClient.create(eventloop);\n  \n      HttpRequest request = HttpRequest.get(\"http://localhost:8080\").build();\n  \n      client.request(request)\n          .then(response -\u003e response.loadBody())\n          .map(body -\u003e body.getString(StandardCharsets.UTF_8))\n          .whenResult(bodyString -\u003e System.out.println(bodyString));\n  \n      eventloop.run();\n  }\n  ```\n\n* **ActiveJ Inject** - Lightweight library for dependency injection. Optimized for fast application start-up and\n  performance at runtime. Supports annotation-based component wiring as well as reflection-free\n  wiring. ([ActiveJ Inject](https://activej.io/inject))\n\n  ```java\n  // Manual binding\n  public static void main(String[] args) {\n      Module module = ModuleBuilder.create()\n          .bind(int.class).toInstance(101)\n          .bind(String.class).to(number -\u003e \"Hello #\" + number, int.class)\n          .build();\n  \n      Injector injector = Injector.of(module);\n  \n      String string = injector.getInstance(String.class);\n  \n      System.out.println(string); // \"Hello #101\"\n  }\n  ```\n  \n  ```java\n  // Binding via annotations\n  public static class MyModule extends AbstractModule {\n      @Provides\n      int number() {\n          return 101;\n      }\n  \n      @Provides\n      String string(int number) {\n          return \"Hello #\" + number;\n      }\n  }\n  \n  public static void main(String[] args) {\n      Injector injector = Injector.of(new MyModule());\n  \n      String string = injector.getInstance(String.class);\n  \n      System.out.println(string); // \"Hello #101\"\n  }\n  ```\n\n* **Boot** - Production-ready tools for running and monitoring an ActiveJ application. Concurrent control of services lifecycle \n  based on their dependencies. Various service monitoring utilities with JMX and Zabbix support. ([Launcher](https://activej.io/boot/launcher),\n  [Service Graph](https://activej.io/boot/servicegraph), [JMX](https://github.com/activej/activej/tree/master/boot-jmx),\n  [Triggers](https://github.com/activej/activej/tree/master/boot-triggers))\n\n  ```java\n  public class MyLauncher extends Launcher {\n      @Inject\n      String message;\n  \n      @Provides\n      String message() {\n          return \"Hello, world!\";\n      }\n  \n      @Override\n      protected void run() {\n          System.out.println(message);\n      }\n  \n      public static void main(String[] args) throws Exception {\n          Launcher launcher = new MyLauncher();\n          launcher.launch(args);\n      }\n  }\n  ```\n\n* **Bytecode manipulation**\n    * **ActiveJ Codegen** - Dynamic bytecode generator for classes and methods on top of [ObjectWeb ASM](https://asm.ow2.io/)\n      library. Abstracts the complexity of direct bytecode manipulation and allows you to create custom classes on the fly\n      using Lisp-like AST expressions. ([ActiveJ Codegen](https://activej.io/codegen))\n\n      ```java\n      // Manually implemented method\n      public class MyCounter implements Counter { \n          @Override\n          public int countSum() {\n              int sum = 0;\n              for (int i = 0; i \u003c 100; i++) {\n                  sum += i;\n              }\n              return sum;\n          }\n      }\n      ```\n      \n      ```java\n      // The same method generated via ActiveJ Codegen \n      public static void main(String[] args) {\n          DefiningClassLoader classLoader = DefiningClassLoader.create();\n      \n          Counter counter = ClassGenerator.builder(Counter.class)\n              .withMethod(\"countSum\",\n                  let(value(0), sum -\u003e\n                      sequence(\n                          iterate(\n                              value(0),\n                              value(100),\n                              i -\u003e set(sum, add(sum, i))),\n                          sum\n                      )))\n              .build()\n              .generateClassAndCreateInstance(classLoader);\n      \n          System.out.println(counter.countSum()); // 4950\n      }\n      ```\n\n    * **ActiveJ Serializer** - [Fast](https://github.com/activej/jvm-serializers) and space-efficient serializers created with bytecode engineering.\n      Introduces schema-free approach for best performance. ([ActiveJ Serializer](https://activej.io/serializer))\n      \n      ```java\n      // A class to be serialized\n      public class User {\n          private final int id;\n          private final String name;\n      \n          public User(@Deserialize(\"id\") int id, @Deserialize(\"name\") String name) {\n              this.id = id;\n              this.name = name;\n          }\n      \n          @Serialize\n          public int getId() {\n              return id;\n          }\n      \n          @Serialize\n          public String getName() {\n              return name;\n          }\n      }\n      ```\n\n      ```java\n      // Serialization and deserialization\n      public static void main(String[] args) {\n          BinarySerializer\u003cUser\u003e userSerializer = SerializerFactory.defaultInstance()\n              .create(User.class);\n      \n          User john = new User(1, \"John\");\n      \n          byte[] buffer = new byte[100];\n          userSerializer.encode(buffer, 0, john);\n      \n          User decoded = userSerializer.decode(buffer, 0);\n      \n          System.out.println(decoded.id);   // 1\n          System.out.println(decoded.name); // John\n      }\n      ```\n\n      ```java\n      // Serialization of Java records\n      @SerializeRecord\n      public record User(int id, String name) {\n      }\n      ```\n      \n      ```java\n      // StreamCodec usage example\n      public static void main(String[] args) throws IOException {\n          StreamCodec\u003cUser\u003e userStreamCodec = StreamCodec.create(User::new,\n              User::getId, StreamCodecs.ofVarInt(),\n              User::getName, StreamCodecs.ofString()\n          );\n      \n          List\u003cUser\u003e users = List.of(\n              new User(1, \"John\"),\n              new User(2, \"Sarah\"),\n              new User(3, \"Ben\")\n          );\n      \n          ByteArrayOutputStream baos = new ByteArrayOutputStream();\n          try (StreamOutput streamOutput = StreamOutput.create(baos)) {\n              for (User user : users) {\n                  userStreamCodec.encode(streamOutput, user);\n              }\n          }\n      \n          ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());\n          try (StreamInput streamInput = StreamInput.create(bais)) {\n              while (!streamInput.isEndOfStream()) {\n                  User decoded = userStreamCodec.decode(streamInput);\n                  System.out.println(decoded.getId() + \" \" + decoded.getName());\n              }\n          }\n      }\n      ```\n      \n    * **ActiveJ Specializer** - Innovative technology to improve class performance at runtime by automatically\n      converting class instances into specialized static classes and class instance fields into baked-in static\n      fields. Provides a wide variety of JVM optimizations for static classes that are impossible otherwise: dead code\n      elimination, aggressive inlining of methods and static\n      constants. ([ActiveJ Specializer](https://activej.io/specializer))\n\n      ```java\n      // Operators\n      public record IdentityOperator() implements IntUnaryOperator {\n          @Override\n          public int applyAsInt(int operand) {\n              return operand;\n          }\n      }\n      \n      public record ConstOperator(int value) implements IntUnaryOperator {\n          @Override\n          public int applyAsInt(int operand) {\n              return value;\n          }\n      }\n      \n      public record SumOperator(IntUnaryOperator left, IntUnaryOperator right) implements IntUnaryOperator {\n          @Override\n          public int applyAsInt(int operand) {\n              return left.applyAsInt(operand) + right.applyAsInt(operand);\n          }\n      }\n      \n      public record ProductOperator(IntUnaryOperator left, IntUnaryOperator right) implements IntUnaryOperator {\n          @Override\n          public int applyAsInt(int operand) {\n              return left.applyAsInt(operand) * right.applyAsInt(operand);\n          }\n      }\n      ```\n\n      ```java\n      // Expression specialization\n      public static void main(String[] args) {\n          // ((x + 10) * (-5)) + 33\n          IntUnaryOperator expression = new SumOperator(\n              new ProductOperator(\n                  new ConstOperator(-5),\n                  new SumOperator(\n                      new ConstOperator(10),\n                      new IdentityOperator()\n                  )\n              ),\n              new ConstOperator(33)\n          );\n      \n          Specializer specializer = Specializer.create();\n          expression = specializer.specialize(expression);\n      \n          System.out.println(expression.applyAsInt(0));  // -17\n      }\n      ```\n\n* **Cloud components**\n    * **ActiveJ FS** - Asynchronous abstraction over the file system for building efficient, scalable local or remote file\n      storages that support data redundancy, rebalancing, and resharding.\n      ([ActiveJ FS](https://activej.io/fs))\n\n      ```java\n      public static void main(String[] args) throws IOException {\n          Eventloop eventloop = Eventloop.builder()\n              .withCurrentThread()\n              .build();\n      \n          HttpClient httpClient = HttpClient.create(eventloop);\n      \n          ExecutorService executor = Executors.newCachedThreadPool();\n      \n          Path directory = Files.createTempDirectory(\"fs\");\n      \n          FileSystem fileSystem = FileSystem.create(eventloop, executor, directory);\n      \n          String filename = \"file.txt\";\n      \n          fileSystem.start()\n                  // Upload\n                  .then(() -\u003e fileSystem.upload(filename))\n                  .then(consumer -\u003e httpClient.request(HttpRequest.get(\"http://localhost:8080\").build())\n                      .then(response -\u003e response.loadBody())\n                      .then(body -\u003e ChannelSuppliers.ofValue(body).streamTo(consumer)))\n      \n                  // Download\n                  .then(() -\u003e fileSystem.download(filename))\n                  .then(supplier -\u003e supplier.streamTo(ChannelConsumers.ofConsumer(byteBuf -\u003e\n                      System.out.println(byteBuf.asString(StandardCharsets.UTF_8)))))\n      \n                  // Cleanup\n                  .whenComplete(executor::shutdown);\n      \n          eventloop.run();\n      }\n      ```\n\n    * **ActiveJ RPC** - High-performance binary client-server protocol. Allows building distributed, sharded, and\n      fault-tolerant microservice applications. ([ActiveJ RPC](https://activej.io/rpc))\n\n      ```java\n      // Server\n      public static void main(String[] args) throws IOException {\n          Eventloop eventloop = Eventloop.create();\n      \n          RpcServer server = RpcServer.builder(eventloop)\n              .withMessageTypes(String.class)\n              .withHandler(String.class, name -\u003e Promise.of(\"Hello, \" + name))\n              .withListenPort(9000)\n              .build();\n      \n          server.listen();\n      \n          eventloop.run();\n      }\n      ```\n\n      ```java\n      // Client\n      public static void main(String[] args) {\n          Eventloop eventloop = Eventloop.create();\n      \n          RpcClient client = RpcClient.builder(eventloop)\n              .withStrategy(RpcStrategies.server(new InetSocketAddress(9000)))\n              .withMessageTypes(String.class)\n              .build();\n      \n          client.start()\n              .then(() -\u003e client.sendRequest(\"John\"))\n              .whenResult(response -\u003e System.out.println(response)) // \"Hello, John\"\n              .whenComplete(client::stop);\n      \n          eventloop.run();\n      }\n      ```\n\n    * Various extra services:\n      [ActiveJ CRDT](https://github.com/activej/activej/tree/master/extra/cloud-crdt),\n      [Redis client](https://github.com/activej/activej/tree/master/extra/cloud-redis),\n      [Memcache](https://github.com/activej/activej/tree/master/extra/cloud-memcache),\n      [OLAP Cube](https://github.com/activej/activej/tree/master/extra/cloud-lsmt-cube),\n      [Dataflow](https://github.com/activej/activej/tree/master/extra/cloud-dataflow)\n\n## Quick start\n\nPaste this snippet into your terminal...\n\n```\nmvn archetype:generate -DarchetypeGroupId=io.activej -DarchetypeArtifactId=archetype-http -DarchetypeVersion=6.0-beta2\n```\n\n... and open the project in your favorite IDE. Then build the application and run it. Open your browser\non [localhost:8080](http://localhost:8080)\nto see the \"Hello World\" message.\n\n#### Full-featured embedded web application server with Dependency Injection:\n\n```java\npublic final class HttpHelloWorldExample extends HttpServerLauncher {\n    @Provides\n    AsyncServlet servlet() {\n        return request -\u003e HttpResponse.ok200()\n            .withPlainText(\"Hello, World!\")\n            .toPromise();\n    }\n\n    public static void main(String[] args) throws Exception {\n        Launcher launcher = new HttpHelloWorldExample();\n        launcher.launch(args);\n    }\n}\n```\n\nSome technical details about the example above:\n\n- *The JAR file size is only 1.4 MB. By comparison, the minimum size of a Spring web application is about 17 MB*.\n- *The cold start time is 0.65 sec.*\n- *The [ActiveJ Inject](https://activej.io/inject) DI library used is 5.5 times faster than Guice and hundreds\n  of times faster than Spring.*\n\nTo learn more about ActiveJ, please visit https://activej.io or follow our\n5-minute [getting-started guide](https://activej.io/tutorials/getting-started).\n\nExamples of using the ActiveJ platform and all ActiveJ libraries can be found\nin the [`examples`](https://github.com/activej/activej/tree/master/examples) module.\n\n**Release notes for ActiveJ can be found [here](https://activej.io/blog)**","funding_links":[],"categories":["Service Toolkits","开发框架"],"sub_categories":["Java VM"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factivej%2Factivej","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Factivej%2Factivej","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factivej%2Factivej/lists"}