-
Notifications
You must be signed in to change notification settings - Fork 18
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
[Client] Java client #198
Merged
Merged
[Client] Java client #198
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3fcec85
feat: java client
64ad8cd
fix: Removed unnecessary files
558a6b3
fix: more cleanups
b5839f0
feat: Add expt client wrapper
80fbd04
fix: add experiment client implementation
174eede
fix: Added README.md
9366013
fix: separated cac-client and exp-client
220bd0a
fix: separated cac-client and exp-client
fc941e8
fix: make it a lib
1c4f269
fix: Added Readme.md to use the clients
6a73495
fix: yaml file
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,45 @@ | ||
# This workflow uses actions that are not certified by GitHub. | ||
# They are provided by a third-party and are governed by | ||
# separate terms of service, privacy policy, and support | ||
# documentation. | ||
|
||
# GitHub recommends pinning actions to a commit SHA. | ||
# To get a newer version, you will need to update the SHA. | ||
# You can also reference a tag or branch, but the action may change without warning. | ||
|
||
name: Publish java client to GitHub Packages | ||
|
||
on: workflow_dispatch | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: java setup | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '11' | ||
distribution: 'corretto' | ||
|
||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 | ||
|
||
- name: Publish cac client | ||
run: | | ||
cd clients/java/cac-client | ||
./gradlew publish --console=rich | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Publish exp client | ||
run: | | ||
cd clients/java/exp-client | ||
./gradlew publish --console=rich | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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 |
---|---|---|
|
@@ -34,4 +34,9 @@ test_logs | |
.cargo | ||
# pre-commit config | ||
.pre-commit-config.yaml | ||
.cargo | ||
.cargo | ||
|
||
#gradle files | ||
.gradle | ||
build | ||
.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,102 @@ | ||
# JAVA Client | ||
|
||
## Prerequisites | ||
|
||
- Java JDK | ||
- Gradle 7.0 or later | ||
|
||
## Building the Project | ||
|
||
To build the project, run: | ||
``` | ||
./gradlew build | ||
``` | ||
|
||
## Running the Application | ||
|
||
To run the application: | ||
``` | ||
./gradlew run | ||
``` | ||
|
||
## Publishing the clients locally and using it | ||
|
||
Publish cac-client | ||
``` | ||
cd clients/java/cac-client | ||
./gradlew publishToMavenLocal | ||
``` | ||
|
||
Publish exp-client | ||
``` | ||
cd clients/java/exp-client | ||
./gradlew publishToMavenLocal | ||
``` | ||
|
||
### Use the clients in another project | ||
|
||
build.gradle | ||
``` | ||
plugins { | ||
id 'java' | ||
id 'application' | ||
} | ||
|
||
repositories { | ||
// mavenLocal() // if using local Maven repository | ||
mavenCentral() // It's good to have this as a fallback | ||
maven { | ||
name = "GitHubPackages" | ||
url = uri("https://maven.pkg.github.com/juspay/superposition") | ||
credentials { | ||
username = System.getenv("GITHUB_USERNAME") | ||
password = System.getenv("GITHUB_TOKEN") | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation 'com.github.jnr:jnr-ffi:2.2.16' | ||
implementation 'com.github.jnr:jffi:1.3.13' | ||
implementation 'juspay.superposition:cac-client:0.0.1' | ||
implementation 'juspay.superposition:exp-client:0.0.1' | ||
} | ||
|
||
application { | ||
mainClassName = 'Client' // main class name | ||
} | ||
``` | ||
|
||
Client.java | ||
``` | ||
import cac_client.CacClient; | ||
import exp_client.ExperimentationClient; | ||
import cac_client.CACClientException; | ||
import exp_client.EXPClientException; | ||
import java.util.concurrent.CountDownLatch; | ||
|
||
public class Client { | ||
public static void main(String[] args) { | ||
CountDownLatch latch = new CountDownLatch(1); | ||
try { | ||
CacClient cac_wrapper = new CacClient(); | ||
// Use cac-client's functions | ||
ExperimentationClient exp_wrapper = new ExperimentationClient(); | ||
// Use exp-client's functions | ||
latch.await(); // This will keep the main thread alive | ||
} catch (InterruptedException e) { | ||
System.err.println("Main thread interrupted: " + e.getMessage()); | ||
} finally { | ||
System.out.println("Application stopped."); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## If having issues | ||
Try exporting these | ||
``` | ||
export SUPERPOSITION_LIB_PATH=".../superposition/target/debug" | ||
export PATH=$JAVA_HOME/bin:$PATH | ||
export JAVA_HOME=/opt/homebrew/opt/openjdk | ||
``` |
Binary file added
BIN
+368 Bytes
clients/java/cac-client/bin/main/cac_client/CACClientException.class
Binary file not shown.
Binary file added
BIN
+915 Bytes
clients/java/cac-client/bin/main/cac_client/CacClient$RustLib.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,41 @@ | ||
plugins { | ||
id 'java-library' | ||
id 'maven-publish' | ||
id 'java' | ||
id 'application' | ||
} | ||
|
||
group 'juspay.superposition' | ||
version '0.0.1' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'com.github.jnr:jnr-ffi:2.2.16' | ||
implementation 'com.github.jnr:jffi:1.3.13' | ||
// Add other dependencies your library needs | ||
} | ||
|
||
publishing { | ||
publications { | ||
myLib(MavenPublication) { | ||
from (components.java) | ||
} | ||
} | ||
repositories { | ||
maven { | ||
name = "GitHubPackages" | ||
url = uri('https://maven.pkg.github.com/juspay/superposition') | ||
credentials { | ||
username = System.getenv("GITHUB_ACTOR") | ||
password = System.getenv("GITHUB_TOKEN") | ||
} | ||
} | ||
} | ||
} | ||
|
||
application { | ||
mainClassName = 'example.Demo' | ||
} |
Binary file not shown.
7 changes: 7 additions & 0 deletions
7
clients/java/cac-client/gradle/wrapper/gradle-wrapper.properties
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,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add documentation on how to add this to a separate project?