Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Duda committed Mar 17, 2019
2 parents 8146635 + 6b6981f commit b17aa8a
Show file tree
Hide file tree
Showing 11 changed files with 319 additions and 62 deletions.
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Find the official documentation [here](https://codingchili.github.io/chili-core/
## Quickstart

Using gradle
```$groovy
```groovy
repositories {
maven { url 'https://jitpack.io' }
}
Expand All @@ -20,7 +20,7 @@ dependencies {

Creating a new handler

```$java
```java
@Role(PUBLIC)
@Address("api")
public class MyHandler implements CoreHandler {
Expand All @@ -41,7 +41,7 @@ public class MyHandler implements CoreHandler {

Deploying a handler with the REST listener on port 8080 (default).

```$java
```java
public static void main(String[] args) {
ListenerSettings settings = new ListenerSettings()
.setPort(8080)
Expand All @@ -56,23 +56,27 @@ public static void main(String[] args) {
```

Start it up and check the service with
```$bash

```console
curl -v http://localhost:8080/api/list
```

## Building
To build chili-core clone this repository with **git**,
```

```console
git clone https://github.com/codingchili/chili-core.git
```

Builds project jars and run tests
```

```console
gradlew build
```

Note: when targeting java 9+ the following hacks are needed for Netty/Vert.x
```

```console
--add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/sun.net.dns=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/sun.nio.ch=ALL-UNNAMED
```

Expand All @@ -99,9 +103,9 @@ In order to achieve this it is much more invasive than the vertx toolkit.
The complete feature list may change during development.

##### Core
* Transport & protocol independent implementation
* Transport & storage independent implementations
* Logging system for data analysis and real time monitoring
* Authentication based on hmac tokens.
* Authentication based on signed tokens.
* A router for routing external connections into the clustered event bus.
* Statistics API that builds on top of the logging system
* Interchangeable storage options with indexing and query support
Expand Down
9 changes: 9 additions & 0 deletions core/main/java/com/codingchili/core/logging/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ public enum Level {

public String color;

/**
* Changes the default color of the log level to the given.
*
* @param color defined as an ANSI escape code.
*/
void setColor(String color) {
this.color = color;
}

Level(String color) {
this.color = color;
}
Expand Down
24 changes: 12 additions & 12 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Contains the server configuration.
## Configuration APIs
This section contains information on using the configuration API's.

```
```java
import com.codingchili.core.configuration.Configurable;

public class ConfigurationClass implements Configurable {
Expand All @@ -27,7 +27,7 @@ Here is another [example configuration model](https://github.com/codingchili/chi
### Loading configuration
Loading configuration from a file with the model/schema file `ConfigurationClass.class`.

```
```java
ConfigurationClass config = Configurations.get("path/to/configurable.yml", ConfigurationClass.class);
```

Expand All @@ -37,7 +37,7 @@ If the file does not exist it will be instantiated with the defaults in Configur

Configuration can also be loaded directly from memory into the `Configurations` manager. This is done with the following call.

```
```java
Configurations.put(ConfigurationClass.class);
```

Expand All @@ -46,7 +46,7 @@ Whenever configuration changes it will be reloaded in memory. Any configuration

If the call to `Configurations.get` is cached, an additional O(1) map lookup can be avoided - with the implication that changes to the configuration on disk will not be visible. To limit the time configuration is cached, or to always retrieve the latest copy from the cache a wrapper is recommended.

```
```java
public ConfigurationClass getMyConfiguration() {
// custom logic to cache the call goes here.
return Configurations.get("path/to/configurable.yaml", ConfigurationClass.class);
Expand All @@ -56,7 +56,7 @@ public ConfigurationClass getMyConfiguration() {
### Persisting configuration
Persisting configuration is easy, perform any changes to the configuration class in memory and call the save method on the configurable object.

```
```java
myConfiguration.fastMode = true;

// saves the configuration to disk, location is specified by the 'getPath' method.
Expand All @@ -81,7 +81,7 @@ To use a custom format a custom `com.codingchili.core.files.FileStore` needs to
The custom mapper needs to be registered on the `com.codingchili.core.files.ConfigurationFactory`.

This can be done with the following sample,
```
```java
ConfigurationFactory.add(new YamlFileStore());
```

Expand All @@ -93,7 +93,7 @@ The `ConfigurationFactory` may be combined with a `com.codingchili.core.files.Fi

Example of using the ConfigurationFactory with a FileWatcher

```
```java
// creates a FileWatcher on the given directory that checks the WatchService each 1500ms.
FileWatcher.builder(core)
.onDirectory('path/to/directory/')
Expand Down Expand Up @@ -140,7 +140,7 @@ The launcher configuration allows for configuration of the following properties
If there is no matching host and a block has not been explicitly specified a block named `default` will be deployed.

Sample configuration file
```
```yaml
version: CORE-1.0.5-PR
application: prototype
clustered: false
Expand Down Expand Up @@ -198,7 +198,7 @@ Controls internal security configuration.
|tokenttl|how long tokens generated from the `TokenFactory` are valid.|

Sample configuration
```
```yaml
dependencies:
service/[^/]*:
preshare:
Expand Down Expand Up @@ -247,7 +247,7 @@ Contains settings for storage implementations, these can be any of the included
It's up to the storage implementation to respect the `maxResults` and `minFeedbackChars` properties. The default storage implementations honor them.

Configuration for a specific plugin can be retrieved with
```
```java
RemoteStorage config = Configurations.storage(Plugin.class);
```

Expand All @@ -262,7 +262,7 @@ A remote storage configuration contains the following properties
|persistInterval|some implementations that support persistence will persist at this interval.|

Sample configuration
```
```yaml
storage:
com.codingchili.core.storage.ElasticMap:
host: localhost
Expand Down Expand Up @@ -296,7 +296,7 @@ It's possible to add custom implementations here. Either in the configuration fi

Adding a custom storage plugin,

```
```java
// RemoteStorage is the configuration, Class is a class that implements AsyncStorage<Value> where value extends `Storable`.
Configurations.storage().add(RemoteStorage, Class);
```
Expand Down
28 changes: 14 additions & 14 deletions docs/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Using the context directly is one way of deploying the services, handlers and li
## Context lifecycle
A context is required to deploy services, create a new context with

```$java
```java
CoreContext core = new SystemContext();
```

Expand Down Expand Up @@ -37,7 +37,7 @@ A clustered context will attempt to join the Hazelcast cluster configured in th
It's also possible to programmatically configure the hazelcast cluster using the `VertxOptions` in the `Configurations.system()` settings.

Example of a clustered context
```$java
```java
SystemContext.clustered(core -> {
// core is a clustered context here - deploy some services.
// the event bus is clustered and the Hazelcast distributed map available.
Expand All @@ -47,13 +47,13 @@ SystemContext.clustered(core -> {
##### Deploying
Deploying a service that may in turn issue more deployments.

```$java
```java
// deploys a service that may issue more deployments.
core.service(new CoreServiceImpl());
```

A small example that deploys a listener and a handler without any services.
```$java
```java
// deploys a HTTP listener on port 8080 that uses the
// BusForwarder to forward requests over the cluster.
core.listener(new RestListener()
Expand Down Expand Up @@ -82,15 +82,15 @@ A BusRouter can be used to dynamically determine the target address.
##### Undeploying

Undeploying a service, this operation is asynchronous.
```$java
```java
core.stop(deploymentId);
```
The stop method of the CoreDeployable will then be invoked, it is then up to the server to stop
any deployments it has made during it's lifetime. Usually deployments will live for the duration of the application.


Stopping the application, this will invoke the stop method of all core deployments.
```$java
```java
core.close(() -> {
// invoked when the close operation has succeeded.
});
Expand All @@ -101,7 +101,7 @@ core.close(() -> {
It's possible to use the following listeners to be notified when the context
lifecycle state changes.

```$java
```java
// listener invoked when the context shuts down.
ShutdownListener.subscribe(() -> {
// do something here.
Expand All @@ -119,13 +119,13 @@ The context contains some additional functionality listed here.

- Access to the asynchronous vert.x [FileSystem](https://vertx.io/docs/apidocs/io/vertx/core/file/FileSystem.html) implementation.

```$java
```java
FileSystem fs = core.fileSystem();
```

- Scheduling support

```$java
```java
core.periodic(() -> 100, "10xPoll", (id) -> {
// invoked every 100ms, the interval is a supplier that can be modified during runtime.

Expand All @@ -143,7 +143,7 @@ core.cancel(timerTask);

- Running blocking code

```$java
```java
// false indicates that scheduled blocking operations does not have to
// be executed in order. This parameter is optional and defaults to false.
core.blocking((future) -> {
Expand All @@ -160,15 +160,15 @@ core.blocking((future) -> {

- Retrieving a logger instance

```$java
```java
// use the name of the current class, or pass a specific class.
// see the chapter on logging for more information.
Logger logger = context.logger(getClass());
```

- Accessing the Vert.x event bus

```$java
```java
EventBus bus = core.bus();

// listens for incoming message on "address".
Expand All @@ -190,12 +190,12 @@ bus.send("address", message);

- Retrieving the underlying Vert.x instance

```$java
```java
core.vertx();
```

- Get the system settings

```$java
```java
SystemSettings system = core.system();
```
10 changes: 5 additions & 5 deletions docs/handlers.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ handler may register the API's of other handlers on it's protocol, as a proxy-ha
The dpeloyment of a handler requires at least a `CoreService`, see [listeners](listeners) for a set of listeners that
are included in the framework.

```$java
```java
// The address is used by the listener to determine where to mount the handler.
// the REST handler would mount this at "/cats" for example.
@Role(PUBLIC)
Expand Down Expand Up @@ -53,7 +53,7 @@ public class CatHandler implements CoreHandler {
To simplify dealing with request data we can wrap the request body in a model class. If we use
the `request.data()` only a JsonObject API will be available.

```$java
```java
public class CatRequest implements RequestWrapper() {
private Request request;

Expand All @@ -75,7 +75,7 @@ public class CatRequest implements RequestWrapper() {
```

**Another example of a minimal handler without request wrapping,**
```$java
```java
@Role(PUBLIC)
@Address("cats")
public class Cathandler implements CoreHandler {
Expand All @@ -96,15 +96,15 @@ public class Cathandler implements CoreHandler {

### Deploying a handler
Deploying a handler requires a running `SystemContext`, example
```$java
```java
core.handler(Cathandler::new);
```

When a handler is deployed using the `handler` method on the context the listener will always default to `ClusterListener`.

To deploy the handler on a specific listener the following can be used,

```$java
```java
core.listener(() -> new RestListener().handler(new CatHandler()));
```

Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ Recommended reading order
|yes|Handlers|Contains business logic and authentication.|[com.codingchili.core.listener](https://github.com/codingchili/chili-core/tree/master/core/main/java/com/codingchili/core/listener)
|yes|Protocol|Provides the mapping from routes in a handler to methods invoked by the listener.|[com.codingchili.core.protocol](https://github.com/codingchili/chili-core/tree/master/core/main/java/com/codingchili/core/protocol)
|yes|Configuration|The configuration subsystem and framework configuration.|[com.codingchili.core.configuration](https://github.com/codingchili/chili-core/tree/master/core/main/java/com/codingchili/core/configuration)
||Launcher|Provides additional features for deploying applications, optional.|[com.codingchili.core.context](https://github.com/codingchili/chili-core/tree/master/core/main/java/com/codingchili/core/context)
||Logging|Contains features for logging locally and remotely over the cluster.|[com.codingchili.core.logging](https://github.com/codingchili/chili-core/tree/master/core/main/java/com/codingchili/core/logging)
|yes|Launcher|Provides additional features for deploying applications, optional.|[com.codingchili.core.context](https://github.com/codingchili/chili-core/tree/master/core/main/java/com/codingchili/core/context)
|yes|Logging|Contains features for logging locally and remotely over the cluster.|[com.codingchili.core.logging](https://github.com/codingchili/chili-core/tree/master/core/main/java/com/codingchili/core/logging)
||Security|Security functionality such as keystores, hashing and token verification/signing.|[com.codingchili.core.security](https://github.com/codingchili/chili-core/tree/master/core/main/java/com/codingchili/core/security)
||Storage|The storage and query API's.|[com.codingchili.core.storage](https://github.com/codingchili/chili-core/tree/master/core/main/java/com/codingchili/core/storage)
||Benchmarking|The benchmarking API's.|[com.codingchili.core.benchmarking](https://github.com/codingchili/chili-core/tree/master/core/main/java/com/codingchili/core/benchmarking)
Expand Down
Loading

0 comments on commit b17aa8a

Please sign in to comment.