Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
834 additions
and
445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 HarperDB | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
rootProject.name = 'harperdb-sdk-java' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package io.harperdb; | ||
|
||
import io.harperdb.auth.Authorization; | ||
import io.harperdb.extras.Endpoint; | ||
import io.harperdb.extras.Payload; | ||
import io.harperdb.extras.Promise; | ||
import io.harperdb.http.Connector; | ||
import io.harperdb.http.Processor; | ||
import java.net.http.HttpClient; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse.BodyHandlers; | ||
import java.time.Duration; | ||
import static java.util.Objects.nonNull; | ||
|
||
/** | ||
* | ||
* @author denim2x <denim2x@cyberdude.com> | ||
*/ | ||
public final class AsyncConnector<R> implements Connector.Factory { | ||
|
||
Processor<R> processor; | ||
|
||
AsyncConnector(Processor<R> processor) { | ||
this.processor = processor; | ||
} | ||
|
||
public static <R> AsyncConnector<R> factory(Processor<R> processor) { | ||
if (nonNull(processor)) { | ||
return new AsyncConnector<>(processor); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public Connector create(Endpoint server, Authorization auth) { | ||
return new Impl<R>(server, auth); | ||
} | ||
|
||
public class Impl<R> extends Connector<Promise<R>> { | ||
|
||
protected final HttpClient client; | ||
|
||
protected Impl(Endpoint server, Authorization auth) { | ||
super(server, auth); | ||
client = HttpClient.newHttpClient(); | ||
} | ||
|
||
@Override | ||
public Promise<R> send(Payload op, Duration timeout) { | ||
return send(makeRequest(processor.export(op), timeout).build()); | ||
} | ||
|
||
protected Promise<R> send(HttpRequest req) { | ||
return Promise.create(client.sendAsync(req, BodyHandlers.ofString()), processor::process); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.harperdb; | ||
|
||
import io.harperdb.extras.Payload; | ||
import io.harperdb.http.Processor; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpRequest.BodyPublishers; | ||
import java.net.http.HttpResponse; | ||
import static java.util.Objects.nonNull; | ||
|
||
/** | ||
* | ||
* @author denim2x <denim2x@cyberdude.com> | ||
*/ | ||
public class DefaultProcessor implements Processor<Result> { | ||
|
||
@Override | ||
public HttpRequest.BodyPublisher export(Payload payload) { | ||
return BodyPublishers.ofString(payload.toJSON()); | ||
} | ||
|
||
@Override | ||
public Result process(HttpResponse res) { | ||
var result = Result.create(res); | ||
if (nonNull(result)) { | ||
|
||
} | ||
|
||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,43 @@ | ||
package io.harperdb; | ||
|
||
import io.harperdb.auth.Authorization; | ||
import io.harperdb.config.HarperDBConfig; | ||
import io.harperdb.extras.Connection; | ||
import io.harperdb.extras.Endpoint; | ||
import io.harperdb.http.Connector; | ||
|
||
public class HarperDB { | ||
public final class HarperDB extends Connection { | ||
|
||
private final HarperDBConfig config; | ||
private final Authorization auth; | ||
public static final int DEFAULT_PORT = 9925; | ||
static final Connector.Factory asyncConnectorFactory; | ||
|
||
private HarperDB(HarperDBConfig config, Authorization auth) { | ||
this.config = config; | ||
this.auth = auth; | ||
static { | ||
var processor = new DefaultProcessor(); | ||
asyncConnectorFactory = AsyncConnector.factory(processor); | ||
} | ||
|
||
public static HarperDB create(HarperDBConfig config, Authorization auth) { | ||
return new HarperDB(config, auth); | ||
public HarperDB() { | ||
this("localhost", DEFAULT_PORT); | ||
} | ||
|
||
public HarperDB(String host, int port) { | ||
withServer(host, port); | ||
} | ||
|
||
public HarperDB(Endpoint endpoint) { | ||
withServer(endpoint); | ||
} | ||
|
||
public HarperDB(Endpoint endpoint, Authorization auth) { | ||
this(endpoint); | ||
withAuthorization(auth); | ||
} | ||
|
||
public Connector connect() { | ||
return connect(asyncConnectorFactory); | ||
} | ||
|
||
public Connector connect(Connector.Factory factory) { | ||
return Connector.factory(factory).create(getServer(), getAuthorization()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.harperdb; | ||
|
||
import io.harperdb.extras.Payload; | ||
|
||
|
||
public class Operation extends Payload { | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.harperdb; | ||
|
||
import static java.util.Objects.nonNull; | ||
|
||
/** | ||
* | ||
* @author denim2x <denim2x@cyberdude.com> | ||
*/ | ||
public final class Result<S> { | ||
S source; | ||
|
||
Result(S source) { | ||
this.source = source; | ||
} | ||
|
||
public static <S> Result<S> create(S source) { | ||
if (nonNull(source)) { | ||
return new Result<>(source); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package io.harperdb.auth; | ||
|
||
public final class Authorization { | ||
|
||
public static BasicAuth basic() { | ||
return new BasicAuth(); | ||
} | ||
|
||
} | ||
package io.harperdb.auth; | ||
|
||
public interface Authorization { | ||
|
||
public String authorize(); | ||
|
||
public static BasicAuth basic() { | ||
return new BasicAuth(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
src/main/java/io/harperdb/config/ConfigParserException.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.