Giter Site home page Giter Site logo

activej / activej Goto Github PK

View Code? Open in Web Editor NEW
817.0 27.0 71.0 15.04 MB

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

Home Page: https://activej.io

License: Apache License 2.0

Dockerfile 0.01% Java 99.58% HTML 0.09% Shell 0.01% JavaScript 0.02% CSS 0.01% Svelte 0.29%
java framework web dependency-injection serializer code-generation async microservice rpc high-performance

activej's Introduction

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 decoded = userStreamCodec.decode(streamInput);
                  System.out.println(decoded.getId() + " " + decoded.getName());
              }
          }
      }
    • ActiveJ Specializer - Innovative technology to improve class performance at runtime by automatically converting class instances into specialized static classes and class instance fields into baked-in static fields. Provides a wide variety of JVM optimizations for static classes that are impossible otherwise: dead code elimination, aggressive inlining of methods and static constants. (ActiveJ Specializer)

      // Operators
      public record IdentityOperator() implements IntUnaryOperator {
          @Override
          public int applyAsInt(int operand) {
              return operand;
          }
      }
      
      public record ConstOperator(int value) implements IntUnaryOperator {
          @Override
          public int applyAsInt(int operand) {
              return value;
          }
      }
      
      public record SumOperator(IntUnaryOperator left, IntUnaryOperator right) implements IntUnaryOperator {
          @Override
          public int applyAsInt(int operand) {
              return left.applyAsInt(operand) + right.applyAsInt(operand);
          }
      }
      
      public record ProductOperator(IntUnaryOperator left, IntUnaryOperator right) implements IntUnaryOperator {
          @Override
          public int applyAsInt(int operand) {
              return left.applyAsInt(operand) * right.applyAsInt(operand);
          }
      }
      // Expression specialization
      public static void main(String[] args) {
          // ((x + 10) * (-5)) + 33
          IntUnaryOperator expression = new SumOperator(
              new ProductOperator(
                  new ConstOperator(-5),
                  new SumOperator(
                      new ConstOperator(10),
                      new IdentityOperator()
                  )
              ),
              new ConstOperator(33)
          );
      
          Specializer specializer = Specializer.create();
          expression = specializer.specialize(expression);
      
          System.out.println(expression.applyAsInt(0));  // -17
      }
  • Cloud components

    • ActiveJ FS - Asynchronous abstraction over the file system for building efficient, scalable local or remote file storages that support data redundancy, rebalancing, and resharding. (ActiveJ FS)

      public static void main(String[] args) throws IOException {
          Eventloop eventloop = Eventloop.builder()
              .withCurrentThread()
              .build();
      
          HttpClient httpClient = HttpClient.create(eventloop);
      
          ExecutorService executor = Executors.newCachedThreadPool();
      
          Path directory = Files.createTempDirectory("fs");
      
          FileSystem fileSystem = FileSystem.create(eventloop, executor, directory);
      
          String filename = "file.txt";
      
          fileSystem.start()
                  // Upload
                  .then(() -> fileSystem.upload(filename))
                  .then(consumer -> httpClient.request(HttpRequest.get("http://localhost:8080").build())
                      .then(response -> response.loadBody())
                      .then(body -> ChannelSuppliers.ofValue(body).streamTo(consumer)))
      
                  // Download
                  .then(() -> fileSystem.download(filename))
                  .then(supplier -> supplier.streamTo(ChannelConsumers.ofConsumer(byteBuf ->
                      System.out.println(byteBuf.asString(StandardCharsets.UTF_8)))))
      
                  // Cleanup
                  .whenComplete(executor::shutdown);
      
          eventloop.run();
      }
    • ActiveJ RPC - High-performance binary client-server protocol. Allows building distributed, sharded, and fault-tolerant microservice applications. (ActiveJ RPC)

      // Server
      public static void main(String[] args) throws IOException {
          Eventloop eventloop = Eventloop.create();
      
          RpcServer server = RpcServer.builder(eventloop)
              .withMessageTypes(String.class)
              .withHandler(String.class, name -> Promise.of("Hello, " + name))
              .withListenPort(9000)
              .build();
      
          server.listen();
      
          eventloop.run();
      }
      // Client
      public static void main(String[] args) {
          Eventloop eventloop = Eventloop.create();
      
          RpcClient client = RpcClient.builder(eventloop)
              .withStrategy(RpcStrategies.server(new InetSocketAddress(9000)))
              .withMessageTypes(String.class)
              .build();
      
          client.start()
              .then(() -> client.sendRequest("John"))
              .whenResult(response -> System.out.println(response)) // "Hello, John"
              .whenComplete(client::stop);
      
          eventloop.run();
      }
    • Various extra services: ActiveJ CRDT, Redis client, Memcache, OLAP Cube, Dataflow

Quick start

Paste this snippet into your terminal...

mvn archetype:generate -DarchetypeGroupId=io.activej -DarchetypeArtifactId=archetype-http -DarchetypeVersion=6.0-beta2

... and open the project in your favorite IDE. Then build the application and run it. Open your browser on localhost:8080 to see the "Hello World" message.

Full-featured embedded web application server with Dependency Injection:

public final class HttpHelloWorldExample extends HttpServerLauncher {
    @Provides
    AsyncServlet servlet() {
        return request -> HttpResponse.ok200()
            .withPlainText("Hello, World!")
            .toPromise();
    }

    public static void main(String[] args) throws Exception {
        Launcher launcher = new HttpHelloWorldExample();
        launcher.launch(args);
    }
}

Some technical details about the example above:

  • The JAR file size is only 1.4 MB. By comparison, the minimum size of a Spring web application is about 17 MB.
  • The cold start time is 0.65 sec.
  • The ActiveJ Inject DI library used is 5.5 times faster than Guice and hundreds of times faster than Spring.

To learn more about ActiveJ, please visit https://activej.io or follow our 5-minute getting-started guide.

Examples of using the ActiveJ platform and all ActiveJ libraries can be found in the examples module.

Release notes for ActiveJ can be found here

activej's People

Contributors

adamochayon avatar alphaqu avatar dependabot[bot] avatar dvolvach avatar eduard-vasinskyi avatar ewie avatar sirinath avatar valerialistratova avatar youmoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

activej's Issues

Additional Documentation

Can additional documentation be added for:

  • JMX,
  • Triggers,
  • Redis client,
  • Memcache,
  • Cloud Dataflow,
  • Util State,
  • ETL,
  • LSM Tree Aggregation,
  • LSM Tree OLAP Cube,
  • Multi Log,
  • OT,
  • etc.

Framing Package

Is this available framing packet option? like split by length of header?

activej-bytebuf 4.0-rc1 error in pom.xml

I can't download activej-bytebuf 4.0-rc1, below is my setting in pm.xml

 <dependency>
            <groupId>io.activej</groupId>
            <artifactId>activej-bytebuf</artifactId>
            <version>4.0-rc1</version>
        </dependency>

'activej-di' is still '1.0-rc1' on Maven Central Published on 05 Jun 2020

activej-di is still 1.0-rc1 on Maven Central. I am wondering if this in intentional of accidental where 1.0 was missed?

The other artefact has:

  • 1.0-rc1 published on 05 Jun 2020
  • 1.0-rc2 published on 09 Jun 2020
  • 1.0 published on 12 Jun 2020

In the case these are missing artefacts can they be published?

Release Notes

Is it possible to publish a release note with new versions on what changed and what is new?

Question: Multi Threaded Routing Module Servelet

How do you create a multi-threaded routing module servelet so all available CPU cores are utilised?

Also in the routing module servelet how do you make a distinction on what type of request is made when the method is not provided? Within this context how can parameters be accessed?

Introduce a Module with a Fast Detachable ThreadLocal Implementation

Netty has a FastThreadLocal implementation. Can a similar but faster thread local implementation be added to ActiveJ?

The ThreadLocal can have primitive specialisations to avoid boxing.

Following usages can be replaced once introduced: https://github.com/activej/activej/search?q=ThreadLocal

Also ThreadLocalRandom can be replaced: https://github.com/activej/activej/search?q=ThreadLocalRandom

Also see:

BosGroup and WorkerGroup

i know In netty to launch TCP server we just configure BootstrapServer and passed BossGroup (To receive connection) and WorkerGroup(To process event, like read data, write data), howto archive that in activej... and howto set how manu eventloop in boosGroup and in WorkerGroup

Ability to Instrument Existing Classes

Can we have the ability to instrument existing classes? e.g.

rebase("AClass")
.field("a").initilise(instentiate("MyObj").param(1).at(0).of(int.class))
.method("f").body(statements(call(self().field("a").method("x").params(args(0))), origin().method("f").params(args(0)))))

Introduce a field a and initialise it with constructor taking an int and call its method x in method f followed by the original implementation of f.

Instrumentation can happen at:

  • selected or all classes at runtime
  • selected or all classes at load time
  • selected or all classes in a Jar file
  • selected or all before Jar file packing

To find what classes to instrument one can use something like ClassGraph

Should call ByteBuf.recycle() after read data?

Should we recycle after read incoming data

 public static ByteBufsDecoder<ByteBuf> customDecoder(int maxSize) {

        return bufs -> {

            if (bufs.remainingBytes() < 5) {
                return null;
            }

            int length = 2 + 2; //header tail
            if (bufs.peekByte(0) == 0x78 && bufs.peekByte(1) == 0x78) {
                length += 1 + bufs.peekByte(2);
            } else if (bufs.peekByte(0) == 0x79 && bufs.peekByte(1) == 0x79) {
                length += 2 + bufs.peekByte(2);
            }

            if (bufs.remainingBytes() < length) {
                return null;
            }
            //ByteBuf temp = ByteBufPool.allocate(length);
            //bufs.drainTo(temp);
            //return temp;
            return bufs.takeExactSize(length);
        };
    }

Main App

 public static void main(String[] args) throws Exception {
        Eventloop eventloop = Eventloop.create().withCurrentThread();
        SimpleServer server = SimpleServer.create(eventloop, new Consumer<AsyncTcpSocket>() {
            @Override
            public void accept(AsyncTcpSocket socket) {
                
                // readData(socket);
                BinaryChannelSupplier
                        .of(ChannelSupplier.ofSocket(socket))
                        .decodeStream(customDecoder(1024))
                        .streamTo(ChannelConsumer.ofConsumer((data) -> {
                            //read data....
                            //should i call data.recycle() after read data?

                            data.recycle(); // Is this right?
                        }));
            }
        });
        server.withListenPort(PORT);
        server.listen();

        System.out.println("Server is running");
        System.out.println("You can connect from telnet with command: telnet localhost 9922 or by running csp.TcpClientExample");

        eventloop.run();
    }

"To make everything consistent, ActiveJ relies on the concept of ‘ownership’ (like in Rust language) - after allocation, the components pass a byteBuf from one to another, until the last ‘owner’ recycles it to ByteBufPool."

after read data? should call ByteBuf.recycle()? how about when client disconnect, shoudl activej recycle all buf have been used?

Websocket Not working

Iam really new with activej need help, i try to run websocket pong server

{
    @Provides
    AsyncServlet servlet() {
       
        return RoutingServlet.create()
                .mapWebSocket("/", webSocket -> webSocket.readMessage()
                .whenResult(message -> System.out.println("Received:" + message.getText()))
                .then(() -> webSocket.writeMessage(Message.text("Pong")))
                .whenComplete(webSocket::close));
    }
    //[END EXAMPLE]

    public static void main(String[] args) throws Exception {
        args = new String[]{"ws://localhost:7070/websocket"};
        WebsocketServer launcher = new WebsocketServer();       
        launcher.launch(args);
    }
}

and got error messages

Exception in thread "main" io.activej.inject.binding.DIException: Unsatisfied dependencies detected:
	key AsyncServlet required to make:
		- AsyncHttpServer at object com.pusatgps.main.WebsocketServer@188715b5, provider method HttpServerLauncher.server(HttpServerLauncher.java:0)


` ``

how to resolve above error, and get websocket server working, my target web socket running on ws://localhost:7070/websocket?

ByteBuf read unsigned value?

after learn ByteBuf class, i can't find function to read unsigned value like:
buf.getUnsignedByte()
buf.getUnsignedShort();
buf.getUnsignedInt()
... etc

or this not available yet?

Http 307/308

Please add HTTP 307/308 support to the HTTP server. ActiveJ http will move closer to rfc7231 and rfc7538 respectively. We found the required changes to be so minimal that is not worth a fork.

Thank you.

Support Web Services

Can web services supported with parity in functionality with JAX-WS, Spring, Axis2, CXF, etc. with annotation based configuration.

A possible list of technologies to support:

  • SOAP
  • WSDL
  • MTOM
  • XML-RPC
  • JSON
  • JSON-RPC
  • XML
  • XML-RPC
  • OData
  • REST
  • Binary protocols:
    • SBE
    • MsgPacket
    • etc.
  • IPC framework
  • P2P framework
  • IoT framework
    • MQTT
    • etc.
  • Browser communication
    • WebSocket
    • Server-Sent Events
    • WebRTC
    • etc.
  • etc.

[Question] Redis Client

Hi,
Thank you for this excellent product/project.
We are having much fun with it.

Could you please point us to a tutorial on how on one might create a Redis, or redis-like (connector) client?
We could take a wack at it but comparing your SSE demo code to our embarassing attempt to implement SSE without guidance tells us to ask for "professional help:)" Thank you for that code gist.

Generally, we are looking to leverage ActiveJ for for interactions with Redis and PostgreSQL (JDBC). Any tutorial about creating this type of connectors with ActiveJ would be welcome.

Thanks again for a clean and awesome project.
Yes, we are using ActiveJ!

MultipartFormData Handle

any tutorial to handle MultipartFormData? i need decode multiple Fields and File in multithread?, what exactly decoder to handle it?

ActiveFS questions

Thank you for releasing ActiveJ family of products!
I am trying to assess ActiveFS for a distributed file system that can run under a database server and provide seamless database replication. I am comparing Active FS possible solution to Aeron + Dokan Java implementation and have these questions:

  1. Does ActveFS support low level block operations (like update Nth block in an existing remote file). This is essential for building distributed file systems. It seems ActiveFS supports only very limited high-level file operations (commands)

  2. How does ActiveFS coordinate the the consistent updates to a distributed file? Aeron provides Raft protocol clustering where there is always a Master and Replicas , and new master can be elected in case of failure. How is ActiveFS P2P doing this?

  3. The ActiveFS examples only show single client-server interactions. Are there example for cluster-wide operations?

  4. Aeron is extremely efficient by utilizing UDP level broadcasting in the cluster. It goes to extreme care to avoid Java GC overhead and use of "lock-free" structures to avoid threading issues. How does ActiveFS compare - HTTP is not very efficient transmission protocol and not good for broadcasting?

Launcher Command Line and Arguments Description

What are the arguments passed to a launcher?

Can the description of this be added to the documentation?

Also, how do you override the number of workers on a multi-threaded launcher to a specific number or the numbers of cores on the system? Can this also be added to documentation?

[core-serialiser] Is serialisation of Optional values supported?

Is serialisation of Optional values supported?

I can see some references to supporting optional values in the codebase -- such as BinarySerializers.ofOptional -- but a naive attempt to serialise an optional value fails with:

Exception in thread "main" java.lang.IllegalArgumentException: Method not found: <init> []
	at io.activej.codegen.Context.findMethod(Context.java:387)
	at io.activej.codegen.Context.invokeConstructor(Context.java:324)
	at io.activej.codegen.Context.invokeConstructor(Context.java:318)
	at io.activej.codegen.expression.ExpressionConstructor.load(ExpressionConstructor.java:40)
	at io.activej.codegen.expression.ExpressionLet.load(ExpressionLet.java:34)
	at io.activej.codegen.expression.ExpressionSequence.load(ExpressionSequence.java:44)
	at io.activej.codegen.expression.ExpressionLet.load(ExpressionLet.java:34)
	at io.activej.codegen.expression.ExpressionSequence.load(ExpressionSequence.java:44)
	at io.activej.codegen.ClassBuilder.defineNewClass(ClassBuilder.java:380)
	at io.activej.codegen.ClassBuilder.build(ClassBuilder.java:293)
	at io.activej.codegen.ClassBuilder.buildClassAndCreateNewInstance(ClassBuilder.java:447)
	at io.activej.serializer.SerializerBuilder.buildImpl(SerializerBuilder.java:854)
	at io.activej.serializer.SerializerBuilder.build(SerializerBuilder.java:316)
	at io.activej.serializer.SerializerBuilder.build(SerializerBuilder.java:310)

This uses:

  public static class OptionalTest
  {
    @Serialize(order = 0)
    public final Optional<String> optional;

    public OptionalTest(@Deserialize("optional") final Optional<String> optional)
    {
      this.optional = optional;
    }
  }

and

    final OptionalTest optionalTest = new OptionalTest(Optional.of("hello, world"));
    final BinarySerializer<OptionalTest> serializer =
        SerializerBuilder.create()
            .build(OptionalTest.class);

    final StreamOutput stream = StreamOutput.create(new ByteArrayOutputStream());
    serializer.encode(stream.getBinaryOutput(), optionalTest);

How do we serialise Optional values?

Better APIs and Modules to Implement Security, Authentication and Authorisation

For web-facing deployments security is paramount, hence it is a requirement to protect the deployments against hackers. For this is it possible to implement security, authentication and authorisation which might include:

  • OAuth (Facebook, Twitter, Google, etc)
  • SAML
  • CAS
  • OpenID Connect
  • OpenID
  • JWT
  • Kerberos
  • etc.
    with authorization mechanisms:
  • Roles/permissions
  • Anonymous/remember-me/(fully) authenticated
  • CORS
  • CSRF
  • HTTP Security Headers
  • etc.
    either internally or integrating with an existing framework.

This issue was initially raised in a different form at DataKernal: softindex/datakernel#20

User More Faster Project Dependencies

I noticed the following dependencies

  • RocksDB
  • Gson
  • HPPC
  • etc.

Also wondering if Logback can be changed to Log4J2 as this claimed to be more performant. Also, consider ZeroLog.

IMDB (https://github.com/lmdbjava/lmdbjava) is noted to be more performant than RocksDB: https://github.com/lmdbjava/benchmarks/blob/master/results/20160710/README.md

Also might be worth considerin: https://github.com/castortech/mdbxjni

Also, https://github.com/ngs-doo/dsl-json seems to be more performant, than Gson, according to: https://github.com/fabienrenaud/java-json-benchmark. Also, noteworthy: https://github.com/RuedigerMoeller/fast-serialization.

For binary serialisation: https://github.com/real-logic/simple-binary-encoding, https://chronoxor.github.io/FastBinaryEncoding/, http://cbor.io/, https://arrow.apache.org/. Binary benchmarks: https://speice.io/2019/09/binary-format-shootout.html

Also following are some benchmarks on primitive collections: https://github.com/austinv11/Long-Map-Benchmarks, https://ivanursul.com/articles/java/collections-performance.html, http://java-performance.info/hashmap-overview-jdk-fastutil-goldman-sachs-hppc-koloboke-trove-january-2015/. It may be worthwhile to see if HPPC is the best to use.

Make ByteBuff more efficient: Use of Unsafe.putXXX, Unsafe.getXXX maybe more efficient

Customize Port and address

I am sorry, mybe this easy but i can't find example howto set parameter like port, SSL Port, SSLContext

public final class BlockingServletExample extends HttpServerLauncher {
	@Provides
	Executor executor() {
		return newCachedThreadPool();
	}

	//[START EXAMPLE]
	@Provides
	AsyncServlet servlet(Executor executor) {
		return RoutingServlet.create()
				.map("/", request -> HttpResponse.ok200()
						.withHtml("<a href='hardWork'>Do hard work</a>"))
				.map("/hardWork", AsyncServlet.ofBlocking(executor, request -> {
					Thread.sleep(2000); //Hard work
					return HttpResponse.ok200()
							.withHtml("Hard work is done");
				}));
	}
	//[END EXAMPLE]

	public static void main(String[] args) throws Exception {
		Injector.useSpecializer();

		Launcher launcher = new BlockingServletExample();
		launcher.launch(args);
	}
}

Question: What does @Eager attribute do?

I have encondeted @Eager in the following example:

	@Provides
	@Eager
	AsyncHttpServer server(Eventloop eventloop, AsyncServlet servlet) {
		return AsyncHttpServer.create(eventloop, servlet).withListenPort(PORT);
	}

I have not seen this else were any other HTTP example. What does the @Eager do?

Is it possible to have a documentation page on all ActiveJ attributes?

ActiveSpecializer links to ActiveCRDT

I believe ActiveSpecializer links to the wrong link which is the ActiveCRDT page.

image

So there should be descriptions and links to:

  • ActiveSpecializer (description present but wrong link) and
  • ActiveCRDT (no description present and ActiveSpecializer incorrectly links to this section)

links in the frontpage.

CodeGen API Simplification

I believe the codegen API can be simplified. E.g.

.withMethod("setIdAndName", sequence(
				set(property(self(), "id"), arg(0)),
				set(property(self(), "name"), arg(1))))

can become

.method("setIdAndName").args("id", "name").of(int.class, String.class).body(statements(assign("this.id", "this.name").to("id", "name")))

or

.method("setIdAndName").body(assign("this.id", "this.name").to("id", "name"))

as Person defines the arguments and types this is implied.

Similarly

.withField("id", int.class)
...
.withMethod("getId", property(self(), "id"))

can become

.getter("id", int.class)

Also,

.withMethod("hashOfPojo", hash(property(arg(0), "id"), property(arg(0), "name")))

can become

.method("hashOfPojo").args("personPojo").of("ExamplePojo").returning(int.class).body(statements(returning(hash("personPojo.id", "personPojo.name"))))

or

.method("hashOfPojo").body(returning(hash("personPojo.id", "personPojo.name")))

as Person defines the arguments

etc.

Basically,

  • add shortcuts to all JavaBeans specific constructs
  • Use builder pattern and fluent API
  • a simple way to access arguments, fields, etc.
  • a simple way to set fields and return values

getPathParameter not give me value

Why getPathParameter not give me value but paramete string like id_user=1

 @Provides
    AsyncServlet createServlet() {
        return RoutingServlet.create()
                .map(HttpMethod.POST,"/vehicle/list/:id_user",r->{
                    String id_user="";
                    try{
                        id_user=r.getPathParameter("id_user");
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }
                    return HttpResponse.ok200().withPlainText("Value = "+ id_user);
                });
    }

when i send http://localhost:8080/vehicle/list/id_user=1

output

  Value = id_user=1

My expectation is Value = 1

Own Collections Framework as Module

Can ActiveJ add own collection framework. ActiveJ seams to use JDK collections but could benefit from own collection framework.

To keep things simple and fast they may not need to implement the Java Collection API.

Some pointers to existing implementations which can be studied and benchmark against:

Queues:

Maps:

Trees:

Weak:

Primitive Specialised:

Misc:

Integrate Website and Blog to Utterances

Can you integrate your website and blog into Utterances so anybody can comment on every page and also any issues are on GitHub if they are actionable.

Also, it would be good to have the blog on GitHub also with an edit in GitHub link so the community can contribute to making small corrections. Also, integrate with Utterances for comments and issues.

[Question] Mime types and favicon.ico

We are testing ActiveJ with some of our users and we're getting 404s and wrong content-type on some files but favicon.ico is particularly sturborn. We are trying to have the same look, feel and bugs with our current application.

We added a StaticServlet to handle static content, that was when we noticed that the artifacts were served with a content-type of application/octet-stream. We tried to use io.activej.http.ContentTypes but the types are incomplete for our use case and, unfortunately, the class is final.

Therefore, starting with a copy of io.activej.http.ContentTypes and armed with ideas from java2s, we created a contentTypeResolver attaching it toStaticServlet withContentTypeResolver. We started getting the right content-type but our resolver is not called for favicon.ico no matter what we do even though other files (css, js, and fonts) seem to be processed properly.

Neither,
RoutingServlet.create() .map(GET, "/", StaticServlet.ofClassPath(executor, "static/").withIndexHtml()) .map(GET, "/favicon.ico", StaticServlet.ofClassPath(executor, "static/favicon.ico").withContentTypeResolver(...) ...
nor
RoutingServlet.create() .map(GET, "/", StaticServlet.ofClassPath(executor, "static/").withContentTypeResolver().withIndexHtml() ...) .map(GET, "/favicon.ico", StaticServlet.ofClassPath(executor, "static/favicon.ico") is working

Junior developer question
Do we have to do anything special with favicon.ico? We are getting the right content-type and 200 with other files (css, js, fonts, etc.) but always 404 with favicon.ico.

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.