enkan

Enkan(円環) is a microframework implementing a middleware pattern like ring or connect.

CircleCI

Concept

Minimal

Ease of development

Ease of operation

Requirements

Middleware

Middleware is an implementation of filters and chains.

Components

In Enkan, component is an object manages lifecycle of stateful objects.

Using enkan and kotowari, the following will be your code

public class ExampleController {
    @Inject
    private TemplateEngineComponent templateEngine;

    @Inject
    private DomaDaoProvider daoProvider;

    public HttpResponse index(ExampleForm form) {
        CustomerDao customerDao = daoProvider.get(CustomerDao.class);
        Customer customer = customerDao.selectById(form.getId());
        return templateEngine.render("example",
                "customer", customer);
    }
}

Get started

Add sonatype snapshots repository to your pom.xml

  <repositories>
    <repository>
      <id>sonatype-snapshot</id>
      <url>http://oss.sonatype.org/content/repositories/snapshots</url>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>

Manual

EnkanSystem

The Enkan system consist of components. A component is a singleton instance that shares data between requests.

EnkanSystem.of(
    "doma", new DomaProvider(),
    "flyway", new FlywayMigration(),
    "template", new FreemarkerComponent(),
    "datasource", new HikariCPComponent(OptionMap.of("uri", "jdbc:h2:mem:test")),
    "app", new ApplicationComponent("kotowari.example.MyApplicationFactory"),
    "http", builder(new JettyComponent())
        .set(JettyComponent::setPort, Env.getInt("PORT", 3000))
        .build()
).relationships(
    component("http").using("app"),
    component("app").using("template", "doma", "datasource"),
    component("doma").using("datasource"),
    component("flyway").using("datasource")
);

Application

An application has a stack of middlewares. A middleware is a single instance. By use method, the middleware is used by application.

app.use(ANY("/secret"), new AuthenticateMiddleware());

REPL

Enkan system is operated by a REPL interface.

Enkan REPL can attach to a running process.

enkan> /connect 35677
Connected to server (port = 35677)

If you use Java9 or higher, you can use JShellRepl. It's so great experience!!

enkan> /connect 64815
Connected to server (port = 64815)
enkan> system
EnkanSystem {
  "datasource":   #HikariCPComponent {
    "jdbcUrl": "jdbc:h2:mem:test",
    "username": "null",
    "dependencies": []
  },
  "flyway":   [email protected],
  "doma":   #DomaProvider {
    "dependencies": ["flyway", "datasource"]
  },
  "jwt":   [email protected],
  "jackson":   #JacksonBeansConverter {
    "dependencies": []
  },
  "template":   [email protected],
  "app":   #ApplicationComponent {
    "application": "null",
    "factoryClassName": "net.unit8.rascaloid.RascaloidApplicationFactory",
    "dependencies": ["template", "doma", "jackson", "datasource", "jwt"]
  },
  "http":   [email protected]
}

enkan> system.getComponent("doma")
#DomaProvider {
  "dependencies": ["flyway", "datasource"]
}

Kotowari

Kotowari is a web routing framework on Enkan.

It provides a rails-like syntax for routing definition.

Routes routes = Routes.define(r -> {
    r.get("/").to(ExampleController.class, "index");
    r.get("/m1").to(ExampleController.class, "method1");
    r.get("/m2").to(ExampleController.class, "method2");
    r.get("/m3").to(ExampleController.class, "method3");
    r.get("/m4").to(ExampleController.class, "method4");
    r.post("/login").to(LoginController.class, "login");
    r.resource(CustomerController.class);
}).compile();

Get started

kotowari-archetype is very useful at starting point.

% bash <(curl -L https://raw.githubusercontent.com/kawasima/kotowari-archetype/master/kotowari.sh)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2051  100  2051    0     0   5962      0 --:--:-- --:--:-- --:--:--  5944

╔═╗┌┐┌┬┌─┌─┐┌┐┌ ┬ ╦╔═┌─┐┌┬┐┌─┐┬ ┬┌─┐┬─┐┬
║╣ │││├┴┐├─┤│││┌┼─╠╩╗│ │ │ │ ││││├─┤├┬┘│
╚═╝┘└┘┴ ┴┴ ┴┘└┘└┘ ╩ ╩└─┘ ┴ └─┘└┴┘┴ ┴┴└─┴

Which web server component do you use?:
1) undertow
2) jetty
3) No thank you
#?

License

Copyright © 2016-2018 kawasima

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.