Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Arc under shamrock repo #10

Merged
merged 3 commits into from
Sep 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ext/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# External projects

This directory contains independent standalone projects that can eventually split off from Shamrock.
4 changes: 4 additions & 0 deletions ext/arc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.project
.settings
.classpath
target
109 changes: 109 additions & 0 deletions ext/arc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Weld Arc - "CDI lite" Experiments

This repo contains a working prototype of something that could be called "CDI lite".
The goal is to verify whether it's feasible to implement a "reasonable" subset of CDI features with minimal runtime.
The target envs are JVM, GraalVM (both jvm and aot modes).

**NOTE:** Jandex built from master is needed to build this project: https://github.com/wildfly/jandex

## Goals

* Instant startup and low memory footprint (compared to Weld)
* As little reflection in runtime as possible
* Acceptable build time increase
* Stick with CDI API and CDI idioms where possible

## Architecture

Currently, we generate metadata classes bytecode (aka "factory" classes) using [Gizmo](https://github.com/protean-project/shamrock/tree/master/gizmo).
One of the drawbacks is that debugging is not that simple.
On the other hand, the logic in generated classes should be quite straightforward and the developer can always decompile the classes.

## Features and Limitations

:heavy_check_mark: - basic support implemented
:white_check_mark: - not implemented yet
:x: - not supported, no plan to support ATM

* Programming model
* :heavy_check_mark: Class beans
* :heavy_check_mark: `@PostConstruct` and `@PreDestroy` callbacks
* :white_check_mark: Lifecycle callbacks on superclasses
* :heavy_check_mark: Producer methods and fields
* :heavy_check_mark: Private members support
* :white_check_mark: Disposers
* :white_check_mark: Stereotypes
* Dependency injection
* :heavy_check_mark: Field, constructor and initializer injection
* :heavy_check_mark: Private injection fields
* :heavy_check_mark: Private constructors
* :white_check_mark: Private initializers
* :heavy_check_mark: Type-safe resolution
* :heavy_check_mark: Proper type-safe resolution rules at runtime; i.e. `ArcContainer.instance(Class<T>, Annotation...)`
* Scopes and Contexts:
* :heavy_check_mark: `@Dependent`
* :heavy_check_mark: `@Singleton`
* :heavy_check_mark: `@RequestScoped`
* :heavy_check_mark: `@ApplicationScoped`
* :x: other built-in scopes such as `@SessionScoped`
* :x: Custom scopes
* :heavy_check_mark: Client proxies
* Interceptors
* :heavy_check_mark: `@AroundInvoke`
* :heavy_check_mark: Lifecycle (`@PostConstruct`, `@PreDestroy`, `@AroundConstruct`)
* :white_check_mark: Transitive interceptor bindings
* :x: Interceptor methods on superclasses
* :white_check_mark: Events/observers
* :x: Decorators
* :x: Portable extensions
* :x: EL support
* :x: `BeanManager`
* :x: Specialization

## Modules

* `processor` - generates "bean" sources from a Jandex index
* `runtime` - classes needed at runtime
* `maven-plugin` - uses `processor` to generate sources and then compiles the sources
* `example` - a simple example; `target/generated-sources/java` contains the generated sources

## How to build

```bash
mvn clean install
```

## How to run the example

```bash
time java -jar example/target/arc-example-shaded.jar
```
And the results on my laptop:

```
real 0m0,133s
user 0m0,175s
sys 0m0,024s
```

### Native image

First build the image:

```bash
/opt/java/graalvm-ee-1.0.0-rc4/bin/native-image --verbose -jar target/arc-example-shaded.jar
```

Then run the example:

```bash
time ./arc-example-shaded
```

And the results on my laptop:

```
real 0m0,005s
user 0m0,000s
sys 0m0,005s
```
96 changes: 96 additions & 0 deletions ext/arc/example/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jboss.protean.arc</groupId>
<artifactId>arc-parent</artifactId>
<version>1.0.0.Alpha1-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

<artifactId>arc-example</artifactId>

<properties>
<version.smallrye-config>1.3.1</version.smallrye-config>
</properties>

<dependencies>

<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-config</artifactId>
<version>${version.smallrye-config}</version>
<exclusions>
<exclusion>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.jboss.protean.arc</groupId>
<artifactId>arc-runtime</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.jboss.protean.arc</groupId>
<artifactId>arc-maven-plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<dependenciesToScan>
<dependency>io.smallrye:smallrye-config</dependency>
<dependency>org.eclipse.microprofile.config:microprofile-config-api</dependency>
</dependenciesToScan>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>default</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>org.jboss.weld.arc.example.Main</Main-Class>
</manifestEntries>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
</transformers>
<shadedArtifactAttached>true</shadedArtifactAttached>
<finalName>arc-example-shaded</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.jboss.protean.arc.example;

import java.util.Collections;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;

import org.eclipse.microprofile.config.inject.ConfigProperty;

@Dependent
public class Bar {

private String name;

@ConfigProperty(name = "arc.example.surname", defaultValue = "Foo")
@Inject
String surname;

@PostConstruct
void init() {
this.name = "Lu";
}

@PreDestroy
void destroy() {
System.out.println("Destroy bar...");
}

public String getName() {
return name + " " + surname;
}

@ApplicationScoped
@Produces
List<Number> listOfNumbers() {
return Collections.emptyList();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.jboss.protean.arc.example;

import java.util.Arrays;
import java.util.List;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.inject.Inject;

@ApplicationScoped
public class Baz {

@MyQualifier(alpha = "1", bravo = "1")
@Inject
Foo foo;

@Inject
void setBar(Bar bar) {
}

public String pingFoo() {
return foo.ping();
}

@MyQualifier(bravo = "1")
@Produces
public List<String> listProducer(InjectionPoint injectionPoint) {
return Arrays.asList(injectionPoint.getType().toString());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.jboss.protean.arc.example;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class BazListProducerClient {

private List<String> list;

@Inject
public BazListProducerClient(@MyQualifier(alpha = "bang", bravo = "1") List<String> list) {
this.list = list;
}

public List<String> getList() {
return list;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.jboss.protean.arc.example;

import java.io.Serializable;

import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import javax.inject.Singleton;

@MyQualifier(alpha = "1", bravo = "1")
@Singleton
public class Foo implements Serializable {

private Bar bar;

@Inject
Instance<Bar> barInstance;

@Inject
Foo(Bar bar) {
this.bar = bar;
}

String ping() {
return bar.getName();
}

String lazyPing() {
return barInstance.isResolvable() ? barInstance.get().getName() : "NOK";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.jboss.protean.arc.example;

import java.util.UUID;

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;

@RequestScoped
public class FooRequest {

private Bar bar;

private String id;

@PostConstruct
void init() {
this.id = UUID.randomUUID().toString();
}

@Inject
void setBar(Bar bar) {
this.bar = bar;
}

String getId() {
return id;
}

String ping() {
return bar.getName();
}

}
Loading