Skip to content
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
72 changes: 6 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
This package should be divided in two.

### http

First one is to map http call to Globs as follow:

Given an URLParameter, QueryParameter and HeaderType GlobType

```

httpServerRegister = new HttpServerRegister("TestServer/1.1");

bootstrap = ServerBootstrap.bootstrap(); // from apache httpcomponents.
bootstrap = AsyncServerBootstrap.bootstrap().setIOReactorConfig(config);

final HttpServerRegister httpServerRegister = new HttpServerRegister("EstablishmentServer/0.1");

httpServerRegister.register("/test/{id}/TOTO/{subId}", URLParameter.TYPE)
.get(QueryParameter.TYPE, (body, url, queryParameters, header) -> {
Expand All @@ -22,62 +18,6 @@ httpServerRegister.register("/test/{id}/TOTO/{subId}", URLParameter.TYPE)
.withHeaderType(HeaderType.TYPE)
;

httpServerRegister.startAndWaitForStartup(bootstrap);


```

### etcd

The second part is about etcd (from google)
It expose an interface to publish Glob and to register for changes on Glob using etcd. It is usefull to propagate
configuration or low change state to/from microservice. (I do not used it to cache data like with a Redis)

It use the annotation PathIndex_ to create the key from the globs ().
The first part of the key is the name of the GlobType.
It is then possible to listen for all changes on a GlobType or a sub part of the key (in the given order : is is not
possible to listen for only the last part of a key)

The value can be a json serialisation or a binary serialisation using Globs-bin-serialisation (so only if all field have
the FieldNumber_ annotation)

```
Client client = Client.builder().endpoints(ETCD).build();

SharedDataAccess etcDSharedDataAccess = EtcDSharedDataAccess.createBin(client);

CompletableFuture<Glob> done = new CompletableFuture<>();
etcDSharedDataAccess.listen(Data1.TYPE, new SharedDataAccess.Listener() {
public void put(Glob glob) {
try {
etcDSharedDataAccess.get(glob.getType(), glob).join();
done.complete(glob);
} catch (Exception e) {
done.complete(null);
}
}

public void delete(Glob glob) {

}
}, Data1.TYPE.instantiate()
.set(Data1.shop, "mg.the-oz.com")
.set(Data1.workerName, "w1")
.set(Data1.num, 1));

MutableGlob data = Data1.TYPE.instantiate()
.set(Data1.shop, "mg.the-oz.com")
.set(Data1.workerName, "w1")
.set(Data1.num, 1)
.set(Data1.someData, "blabla");

// publish data.
etcDSharedDataAccess.register(data)
.get(1, TimeUnit.MINUTES);

final Glob join = done.join();
Assert.assertNotNull(join);
Assert.assertEquals("blabla", join.get(Data1.someData));
etcDSharedDataAccess.end();
```

GlobHttpApacheBuilder globHttpApacheBuilder = new GlobHttpApacheBuilder(httpServerRegister);
Server serverInstance = globHttpApacheBuilder.startAndWaitForStartup(bootstrap, 0);
server = serverInstance.getServer();
31 changes: 11 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<description>Globs library used to expose an http api and etcd using globs</description>
<url>https://globsframework.org</url>
<groupId>org.globsframework</groupId>
<packaging>jar</packaging>
<artifactId>globs-http</artifactId>
<name>Generic Lightweight ObjectS http</name>
<version>4.1.1</version>
<version>4.3-SNAPSHOT</version>

<developers>
<developer>
Expand Down Expand Up @@ -36,8 +35,11 @@
</repositories>

<scm>
<connection>scm:git:git@github.com:globsframework/globs-http</connection>
<developerConnection>scm:git:git@github.com:globsframework/globs-http</developerConnection>
<url>https://github.com/globsframework/globs-http</url>
</scm>
<tag>HEAD</tag>
</scm>

<profiles>
<profile>
Expand Down Expand Up @@ -127,21 +129,10 @@
</build>

<dependencies>
<dependency>
<groupId>io.etcd</groupId>
<artifactId>jetcd-core</artifactId>
<version>0.8.5</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.globsframework</groupId>
<artifactId>globs</artifactId>
<version>4.1.1</version>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>org.globsframework</groupId>
Expand All @@ -151,20 +142,20 @@
<dependency>
<groupId>org.globsframework</groupId>
<artifactId>globs-bin-serialisation</artifactId>
<version>4.1.1</version>
<version>4.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents.core5/httpcore5 -->
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5</artifactId>
<version>5.3.3</version>
<version>5.3.4</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents.core5/httpcore5 -->
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5-h2</artifactId>
<version>5.3.3</version>
<version>5.3.4</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents.client5/httpclient5 -->
Expand Down Expand Up @@ -246,7 +237,7 @@
<dependency>
<groupId>org.globsframework</groupId>
<artifactId>globs</artifactId>
<version>4.1-SNAPSHOT</version>
<version>4.2.0</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import java.util.Arrays;

class DefaultUrlMatcher {
public class DefaultUrlMatcher {


public static UrlMatcher create(GlobType globType, String fullUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
import org.apache.hc.core5.http.nio.ResponseChannel;
import org.apache.hc.core5.http.protocol.HttpContext;

interface GlobHttpRequestHandlerFactory {
public interface GlobHttpRequestHandlerFactory {
GlobHttpRequestHandler create(HttpRequest request, EntityDetails entityDetails, ResponseChannel responseChannel, HttpContext context);
}
2 changes: 1 addition & 1 deletion src/main/java/org/globsframework/http/HttpOp.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.globsframework.http;

enum HttpOp {
public enum HttpOp {
post, put, patch, delete, get, option
}
56 changes: 25 additions & 31 deletions src/main/java/org/globsframework/http/HttpOutputData.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,41 @@

import java.io.InputStream;

public interface HttpOutputData {

boolean isGlob();

Glob getGlob();
public sealed interface HttpOutputData permits HttpOutputData.GlobHttpOutputData, HttpOutputData.KnownSizeStreamHttpOutputData {

record SizedStream(InputStream stream, long size) {}
SizedStream getStream();


static HttpOutputData asGlob(Glob glob) {
return new HttpOutputData() {
public boolean isGlob() {
return true;
}
return new GlobHttpOutputData(glob);
}

public Glob getGlob() {
return glob;
}
static HttpOutputData asStream(InputStream data, long size) {
return new KnownSizeStreamHttpOutputData(data, size);
}

public SizedStream getStream() {
return null;
}
final class GlobHttpOutputData implements HttpOutputData {
private final Glob glob;

};
}
public GlobHttpOutputData(Glob glob) {
this.glob = glob;
}

static HttpOutputData asStream(InputStream data, long size) {
return new HttpOutputData() {
public boolean isGlob() {
return false;
}
public Glob getGlob() {
return glob;
}
}

public Glob getGlob() {
return null;
}
final class KnownSizeStreamHttpOutputData implements HttpOutputData {
private final InputStream data;
private final long size;

public SizedStream getStream() {
return new SizedStream(data, size);
}
public KnownSizeStreamHttpOutputData(InputStream data, long size) {
this.data = data;
this.size = size;
}

};
public SizedStream getStream() {
return new SizedStream(data, size);
}
}
}
Loading