From fd5c3094f63d54e8dca96f67250d677409070ba0 Mon Sep 17 00:00:00 2001 From: Ankit Mahato Date: Sun, 1 Sep 2024 23:47:36 +0530 Subject: [PATCH] fix: Added Readme.md to use the clients --- .github/workflows/publish_jar.yaml | 48 ++++++++++++ .gitignore | 9 +-- clients/java/README.md | 69 ++++++++++++++++++ .../main/cac_client/CACClientException.class | Bin 0 -> 368 bytes .../main/cac_client/CacClient$RustLib.class | Bin 0 -> 915 bytes .../bin/main/cac_client/CacClient.class | Bin 0 -> 4949 bytes .../cac-client/bin/main/example/Demo.class | Bin 0 -> 4482 bytes clients/java/cac-client/build.gradle | 48 ++++++------ .../java/cac-client/gradle/libs.versions.toml | 10 --- .../{settings.gradle.kts => settings.gradle} | 2 +- .../java/cac_client/CACClientException.java | 7 ++ .../java/{CAC => cac_client}/CacClient.java | 13 ++-- .../{CAC/Client.java => example/Demo.java} | 16 ++-- .../exp-client/bin/main/example/Demo.class | Bin 0 -> 4636 bytes .../main/exp_client/EXPClientException.class | Bin 0 -> 368 bytes .../ExperimentationClient$RustLib.class | Bin 0 -> 909 bytes .../exp_client/ExperimentationClient.class | Bin 0 -> 4940 bytes clients/java/exp-client/build.gradle | 30 ++++++-- .../{settings.gradle.kts => settings.gradle} | 2 +- .../{CAC/Client.java => example/Demo.java} | 18 ++--- .../java/exp_client/EXPClientException.java | 7 ++ .../ExperimentationClient.java | 11 ++- 22 files changed, 212 insertions(+), 78 deletions(-) create mode 100644 .github/workflows/publish_jar.yaml create mode 100644 clients/java/cac-client/bin/main/cac_client/CACClientException.class create mode 100644 clients/java/cac-client/bin/main/cac_client/CacClient$RustLib.class create mode 100644 clients/java/cac-client/bin/main/cac_client/CacClient.class create mode 100644 clients/java/cac-client/bin/main/example/Demo.class delete mode 100644 clients/java/cac-client/gradle/libs.versions.toml rename clients/java/cac-client/{settings.gradle.kts => settings.gradle} (93%) create mode 100644 clients/java/cac-client/src/main/java/cac_client/CACClientException.java rename clients/java/cac-client/src/main/java/{CAC => cac_client}/CacClient.java (92%) rename clients/java/cac-client/src/main/java/{CAC/Client.java => example/Demo.java} (87%) create mode 100644 clients/java/exp-client/bin/main/example/Demo.class create mode 100644 clients/java/exp-client/bin/main/exp_client/EXPClientException.class create mode 100644 clients/java/exp-client/bin/main/exp_client/ExperimentationClient$RustLib.class create mode 100644 clients/java/exp-client/bin/main/exp_client/ExperimentationClient.class rename clients/java/exp-client/{settings.gradle.kts => settings.gradle} (93%) rename clients/java/exp-client/src/main/java/{CAC/Client.java => example/Demo.java} (90%) create mode 100644 clients/java/exp-client/src/main/java/exp_client/EXPClientException.java rename clients/java/exp-client/src/main/java/{CAC => exp_client}/ExperimentationClient.java (91%) diff --git a/.github/workflows/publish_jar.yaml b/.github/workflows/publish_jar.yaml new file mode 100644 index 000000000..70630dab7 --- /dev/null +++ b/.github/workflows/publish_jar.yaml @@ -0,0 +1,48 @@ +# 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: + pull_request: + +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 build + ./gradlew publish + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish exp client + run: | + cd clients/java/exp-client + ./gradlew build + ./gradlew publish + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index bc5abd1fb..ebb8f467b 100644 --- a/.gitignore +++ b/.gitignore @@ -36,8 +36,7 @@ test_logs .pre-commit-config.yaml .cargo -#java client -clients/java/cac-client/.gradle -clients/java/cac-client/build -clients/java/exp-client/.gradle -clients/java/exp-client/build \ No newline at end of file +#gradle files +.gradle +build +.java~ diff --git a/clients/java/README.md b/clients/java/README.md index 972ee7966..675ed9aa5 100644 --- a/clients/java/README.md +++ b/clients/java/README.md @@ -19,9 +19,78 @@ 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() + // maven { + // url = uri('https://your-repo-url/maven') // if using a remote repository + // } +} + +dependencies { + implementation 'com.github.jnr:jnr-ffi:2.2.16' + implementation 'com.github.jnr:jffi:1.3.13' + implementation 'cac-client:CacClient:1.0.0' + implementation 'exp-client:ExpClient:1.0.0' +} + +application { + mainClassName = 'Client' // main class name +} +``` + +Client.java +``` +import cac_client.CacClient; +import exp_client.ExperimentationClient; +import cac_client.CACClientException; +import exp_client.EXPClientException; + +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 ``` \ No newline at end of file diff --git a/clients/java/cac-client/bin/main/cac_client/CACClientException.class b/clients/java/cac-client/bin/main/cac_client/CACClientException.class new file mode 100644 index 0000000000000000000000000000000000000000..6390e14ee6c43242f9ae65e08b3bbdda1493335a GIT binary patch literal 368 zcmaKn&q~8U5XQfWX`->(T2W6T-uwgR0V;(W^c1{QdX??E#F2C($yR(VPl5*@z=ski ztLUNN4h-{~{bu&tkI%Pv02dg<2nhRH>04d0u`bQVS>~(DXKfxGS2jjS*nUt?DlL^Q z(%%b0bk3IDh_G{%{|P3pW?Kx8r-U%8?o5IetaZ^rMCj#g&GlkFGxd#{m4-0LE3L|@ zs=4K#X6Wv@AspoYIvWz=xoH|z_&rMw2+5>c)Y@Ee`_kU>-_F_@9D>ARdq_fjN{)p_ p2qb{$l{u{qWl7h@pO03{_0$BDc#ndOvABc8OzH>`O_i zXLr=31MJ!~I^&bsW(Y>A>X(e&6t+vA4g*}0qcIfX53yZKg$VF!D)dF=c8&Nn*!3sV39 literal 0 HcmV?d00001 diff --git a/clients/java/cac-client/bin/main/cac_client/CacClient.class b/clients/java/cac-client/bin/main/cac_client/CacClient.class new file mode 100644 index 0000000000000000000000000000000000000000..adc51668715a0df77138cc27701bf3c8943d523f GIT binary patch literal 4949 zcmb_g`Bxj)75)aafEY|7Z^2+kacmbXgj~la1X3qhhJqu63>epO95P4)j4d?EXs}Hk zr|G`A`<8BL(=A=nmN>0ra2xlh`keetIX(T}d!q$Or}gRSFTH^5Oh|HZqi!N zurJwY-GON}Kdd3}w3WBq6B?R(dgnCw5_Z-Mp&4yDf@o<$yM|E3MGHDK?3y{79-U54 z%}mTrOr_?N6DQ}>BeUZnJdEu@gts7?Su48cijE!F$-S0L*UVqhaHuC)0X^e7R(@%? zxBgQrJ?_@=2s#PRUS(iAm62t~(_G|oscEbXhsjfyj&8BX?iJ&*nXvO2!#!uY%N!M5 zBkvYN*oR0Ek80R1x8CYP$79$}-U`BNF3*h`A)IT$0cPS--sxXlwEA<_f@3&q{RP8a z7Qr9V@e%ZBXe*j-+OZ3!z-6s$K|IV@Zs)$s(5Q4=|O`|n9p;u~&-h5;RZ z1T=Ict-P69U0E=lSz{qb2;roiF>-T;V~Ka~qt9Koiqus@tx}_H9@8mfMY^cdPQ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ULc2O2tYv$*Iq%_^jVV^m*O%qBt)r;`0LcE@f#%*1B8Bc}8}z zIARD(@_mVIbayUinQY)}vs&JBn8s{BP3i75+jv_Y=gCS-dPbrLk-dEY#8<08pq@7a z3Z7T+^>Q8i2O+cT%m*iY*wSYwvwGJSf!;gs+XQL@zNO;Z^0bZlJ@!CAro*|c?in#e zB(bC8PQlF>drf(lh{&r+zl4rGV~^u_d5^>%HM|)on~&l}{7}IU1iF^MHSIa)w2=rZ zf%Qlr_v#tXanH(L{*u6j%1&I;4mKRt?W|?wyV8zxx{#}L^i-f$weZl{oKZ);GF5dN zbZLteFF@m_XACqq;Zhhs7U<(GKnqGp%ka1)Pqcg?li@)-Rj{nH{iSP-HZqvhL=->8 z6$O_CI%`l!`*~t?`cxT%pW){M%V(EF01&x)+hVhC(2YWkDDQ(Ji zW;JBpJWEGSTj!Nx63*0rzR#o=N zzZwMX!e93q=Z9REo>HeANZ>!`dGi>tZNp8mW#)~%g1@pY)DWW{;T615)uyU&FVzNn zcTgQHWnSHQ^8`Zt#ZLi_3f~fZ3O*Zqt|EMyKb9fNQBH$BZaGIaP~dX~-=eZ}Qo_Xz zac)FyF%fHi{0drQYl~=?&-Hv>$A+U8uB7xae`R_5-ku`%B}05|4_(990uEJAw}*r%;&8H2 zYBVn3XvuC%vWbSZ{iXB3yCYIJ-(v8~6zo@I?I?I4dJ7gB zO9BPk6?{m_kEheNn50gYS{ddx%g-x=`OIQB87#Fmu9bgn_%fd7Gs3wG_zHbq#fawcRoars ztV8G)4HB7)3hz%u;QTQKUyCX&QQ5vrF=nYPcWduqVBfriwo+in7VsTEu*+0r*I|n( zlQ!mqvYs-H#y8N=M&B*jej>gL=SnW{uOY)kn*70cxydqo58vl=5Bc&VD!+_haHfb~ pV!?mE?vKCr$5;LFH~#oLfBb_#{>dM2;xF7so<*af{|6yzlH33Q literal 0 HcmV?d00001 diff --git a/clients/java/cac-client/build.gradle b/clients/java/cac-client/build.gradle index 826e56986..955951fc0 100644 --- a/clients/java/cac-client/build.gradle +++ b/clients/java/cac-client/build.gradle @@ -1,42 +1,42 @@ plugins { id 'java-library' id 'maven-publish' + id 'java' + id 'application' } +group 'superposition' +version '1.0.1' + repositories { - mavenLocal() 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 } -// Task to create a fat JAR -tasks.register('fatJar', Jar) { - archiveClassifier.set('fat') - from sourceSets.main.output - dependsOn configurations.runtimeClasspath - from { - configurations.runtimeClasspath.findAll { it.name.endsWith('jar') }.collect { zipTree(it) } - } - manifest { - attributes 'Main-Class': 'CAC.Client' - } - duplicatesStrategy = DuplicatesStrategy.EXCLUDE -} - -// Make the fatJar task run as part of the build -build.dependsOn fatJar - -group = 'com.yourdomain' -version = '1.0-SNAPSHOT' - publishing { - publications { - mavenJava(MavenPublication) { - from components.java + // publications { + // myLib(MavenPublication) { + // from (components.java) + // artifactId = 'CacClient' + // } + // } + repositories { + maven { + name = "GitHubPackages" + url = uri('https://maven.pkg.github.com/juspay/superposition') + credentials { + username = "Superposition Bot" + password = System.getenv("GITHUB_TOKEN") + } } } +} + +application { + mainClassName = 'example.Demo' } \ No newline at end of file diff --git a/clients/java/cac-client/gradle/libs.versions.toml b/clients/java/cac-client/gradle/libs.versions.toml deleted file mode 100644 index dec9eee15..000000000 --- a/clients/java/cac-client/gradle/libs.versions.toml +++ /dev/null @@ -1,10 +0,0 @@ -# This file was generated by the Gradle 'init' task. -# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format - -[versions] -guava = "33.1.0-jre" -junit-jupiter = "5.10.2" - -[libraries] -guava = { module = "com.google.guava:guava", version.ref = "guava" } -junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" } diff --git a/clients/java/cac-client/settings.gradle.kts b/clients/java/cac-client/settings.gradle similarity index 93% rename from clients/java/cac-client/settings.gradle.kts rename to clients/java/cac-client/settings.gradle index 5af1ed093..6f4099e1a 100644 --- a/clients/java/cac-client/settings.gradle.kts +++ b/clients/java/cac-client/settings.gradle @@ -10,4 +10,4 @@ plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" } -rootProject.name = "superposition" +rootProject.name = 'cac-client' diff --git a/clients/java/cac-client/src/main/java/cac_client/CACClientException.java b/clients/java/cac-client/src/main/java/cac_client/CACClientException.java new file mode 100644 index 000000000..420200a5a --- /dev/null +++ b/clients/java/cac-client/src/main/java/cac_client/CACClientException.java @@ -0,0 +1,7 @@ +package cac_client; + +public class CACClientException extends Exception { + public CACClientException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/clients/java/cac-client/src/main/java/CAC/CacClient.java b/clients/java/cac-client/src/main/java/cac_client/CacClient.java similarity index 92% rename from clients/java/cac-client/src/main/java/CAC/CacClient.java rename to clients/java/cac-client/src/main/java/cac_client/CacClient.java index 559de8a89..3a8ac76eb 100644 --- a/clients/java/cac-client/src/main/java/CAC/CacClient.java +++ b/clients/java/cac-client/src/main/java/cac_client/CacClient.java @@ -1,4 +1,4 @@ -package CAC; +package cac_client; import java.io.IOException; @@ -31,18 +31,19 @@ public interface RustLib { public static RustLib rustLib; - public CacClient(String libraryPath, String libraryName) { + public CacClient() { + String libraryName = "cac_client"; + String libraryPath = System.getenv("SUPERPOSITION_LIB_PATH"); + System.out.println("libraryPath" + libraryPath); System.setProperty("jnr.ffi.library.path", libraryPath); - - // Load the Rust library CacClient.rustLib = LibraryLoader.create(RustLib.class).load(libraryName); } - public int cacNewClient(String tenant, long updateFrequency, String hostName) throws IOException { + public int cacNewClient(String tenant, long updateFrequency, String hostName) throws CACClientException { int result = rustLib.cac_new_client(tenant, updateFrequency, hostName); if (result > 0) { String errorMessage = rustLib.cac_last_error_message(); - throw new IOException("Failed to create new CAC client: " + errorMessage); + throw new CACClientException("Failed to create new CAC client: " + errorMessage); } return result; } diff --git a/clients/java/cac-client/src/main/java/CAC/Client.java b/clients/java/cac-client/src/main/java/example/Demo.java similarity index 87% rename from clients/java/cac-client/src/main/java/CAC/Client.java rename to clients/java/cac-client/src/main/java/example/Demo.java index 00d57e747..16c267838 100644 --- a/clients/java/cac-client/src/main/java/CAC/Client.java +++ b/clients/java/cac-client/src/main/java/example/Demo.java @@ -1,32 +1,26 @@ -package CAC; - -import java.io.File; +package example; import java.io.IOException; import java.util.concurrent.CountDownLatch; +import cac_client.CacClient; import jnr.ffi.Pointer; -public class Client { +public class Demo { private static void callCacClient() { - String dylib = "cac_client"; - File currentDir = new File(System.getProperty("user.dir")); - String libraryPath = currentDir.getParentFile().getParentFile().getParentFile() + "/target/debug"; String tenant = "dev"; - System.out.println("------------------------------------------"); - System.out.println("CAC Client"); System.out.println("---------------------"); - CacClient wrapper = new CacClient(libraryPath, dylib); + CacClient wrapper = new CacClient(); int newClient; try { newClient = wrapper.cacNewClient(tenant, 1, "http://localhost:8080"); System.out.println("New client created successfully. Client ID: " + newClient); - } catch (IOException e) { + } catch (cac_client.CACClientException e) { System.err.println(e.getMessage()); } diff --git a/clients/java/exp-client/bin/main/example/Demo.class b/clients/java/exp-client/bin/main/example/Demo.class new file mode 100644 index 0000000000000000000000000000000000000000..b810ba504c9df3c964932cc67344c2669b5ab02b GIT binary patch literal 4636 zcmcIoS#%TE8U8MoJ(3u}me~|Y7|aqc*dhrHt_?I`Lv66Ji@^lb0Ap!v4<5~^qY=hU z(sWDPbWOUXr27g@(+%1RDq7OC=|Y+=PdTUUdmnR7ANtaV((lelwuBVg({qXs_s;zH zzxRIs_b>O3Uinwy27rC|lY%7zs&QUVXDlPpZ=@XsA%VuT`Z+ye>GpJDWb&+$^aL7q znYQWe5vXfz8y5)mIVmHGIz&{|qd{QBkZBu-bLmOLJ*rPyhCpn{N$S?P?wazwC=7Ws zW>#SNQ2Cy{0&%KZ`_E?#*GwC>r+cPj_gN+%!)WBDDdSuOF|1V3Tmf%vKI<826|1nC zT278gR}J~-O(!wxnzlFQxrUzZ4P&jq>f3hEf-R!B3+olE6KJk6RmI)7M?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kS(nf9FK7bD; zPFAspf;%wGZ}ywnZ$H1@KLFgK9l|4=@O=7|=9-O-`;YfMSM}#9PpvLY2%m89s@_zb zE0e{47lhzO8*RIU!}DY%7}`>staC9U_`TwpBWz%+i3S2fE767rv&opt2Q|)_&`yd} z;G rDAa`~0R)#{fSG^}~PuK0X0Bz*d9_fi6Ad$xtgYK0bQL$*Nm^m0o4$FhqBLjh#PN zg9uXs3pesk##)+Dd^xzGp%<8E0-qSVFIkwfd;Tx2@2xVU{j++gcglRBIJHDob%(2s zjnh=cSD7-N?0)a}i_D08mAKm=)2r1AtON}$olnTx%qF+woE(urr_1?OL#5MKrd)6@ zuogI+m)0kFrZu;ejPq;hnPsWT2Rq&fHHBlD=UNTrKvQxjt&)bv_Osq*-AlizpRJ15 z@tRz!=sMw0xj83r@)7E~Sd-R|N-I^GSHV(mh;CMyc5F;BpI4rC>YkeP+Wl;7hjgqo z4|e^i>gvCH+$%OFFn4MU*+X8dBNt&qV4DTsy<~x?yk&vu3v&J>bG{`YFv&jz(B=dG zgcgcJk1!o@2JL{em<#y1jDNv=_+G%*fZwnfuv6j^mYH!9EBu_mD%J{qR^qO(*_y%k H5MO@=UDpxI literal 0 HcmV?d00001 diff --git a/clients/java/exp-client/bin/main/exp_client/ExperimentationClient.class b/clients/java/exp-client/bin/main/exp_client/ExperimentationClient.class new file mode 100644 index 0000000000000000000000000000000000000000..f0d7766dc2aa63be483572d927a2ceedc5c79684 GIT binary patch literal 4940 zcmb_g`Bxj)75)Y!4T!-c@>Y!PDh_tQEOHy$Ng%Nc6arMpvV|e8lgfiMz!)*3%nTU1 zCEfQn-P0{?x}{6nI!T~)x<@EG>Z$=A9HMFO{3^Q-J_q*Ty?tM@E^Ix0q z0vN`oiUtL7W38CY6->kO5~FKH!!eins(YqwjmS|IAq5Xz*H`sKLAMqX7v`=TIZuJ= zthip%oKtWzxs#2~Oa9tH1(Bys%k<7EXzc2qQ4kuj^F|bnXwjgesR^wL4$xdRjsRX0 z+BlcFo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$7Y|L{!hzmR90G3RNbJ$xyEr}@>%NPgp4<4q-_iXx z&b&oS4S0gjqqGJbW1o7IZ=GnxakS$E;=JD`(1j;C8~1(SDGcySWn~ZIX(DLlo@e;h z!1r@F&%Ynye28B|#0$JZ%))x&7S8m<+d~@|3FB;dfA}>V=FkSl6bwY(!O)fV$R;L% zJNU@G{oyycrBQ-AKm$Mz_V8A^7kxN_e!iWOpw3A;5&z>C8d@A@DiLQ|3dl}}4z#8?vWE)UPj_>0sq8X4r4)`m}KB9pS1#`&N zSbmq03(1@nmV1wEARod&s6BMQiv93An7z^--o&C{-@JFSJ#-t_2g2=P5viYrL(c5EU6U6)XVagLrx=y;R?J;az2kJe^Uv~m6Sufl{3zvyL7z4adE12{~Nx=vzGt> literal 0 HcmV?d00001 diff --git a/clients/java/exp-client/build.gradle b/clients/java/exp-client/build.gradle index 6cfbdcd13..3bf9b0f2b 100644 --- a/clients/java/exp-client/build.gradle +++ b/clients/java/exp-client/build.gradle @@ -1,8 +1,13 @@ plugins { + id 'java-library' + id 'maven-publish' id 'java' id 'application' } +group 'superposition' +version '1.0.1' + repositories { mavenCentral() } @@ -10,13 +15,28 @@ repositories { dependencies { implementation 'com.github.jnr:jnr-ffi:2.2.16' implementation 'com.github.jnr:jffi:1.3.13' + // Add other dependencies your library needs } -application { - mainClassName = 'CAC.Client' +publishing { + // publications { + // myLib(MavenPublication) { + // from (components.java) + // artifactId = 'ExpClient' + // } + // } + repositories { + maven { + name = "GitHubPackages" + url = uri('https://maven.pkg.github.com/juspay/superposition') + credentials { + username = "Superposition Bot" + password = System.getenv("GITHUB_TOKEN") + } + } + } } -run { - standardInput = System.in +application { + mainClassName = 'example.Demo' } - diff --git a/clients/java/exp-client/settings.gradle.kts b/clients/java/exp-client/settings.gradle similarity index 93% rename from clients/java/exp-client/settings.gradle.kts rename to clients/java/exp-client/settings.gradle index 5af1ed093..178e02524 100644 --- a/clients/java/exp-client/settings.gradle.kts +++ b/clients/java/exp-client/settings.gradle @@ -10,4 +10,4 @@ plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" } -rootProject.name = "superposition" +rootProject.name = "exp-client" diff --git a/clients/java/exp-client/src/main/java/CAC/Client.java b/clients/java/exp-client/src/main/java/example/Demo.java similarity index 90% rename from clients/java/exp-client/src/main/java/CAC/Client.java rename to clients/java/exp-client/src/main/java/example/Demo.java index b32e7007b..20f56fbd8 100644 --- a/clients/java/exp-client/src/main/java/CAC/Client.java +++ b/clients/java/exp-client/src/main/java/example/Demo.java @@ -1,32 +1,28 @@ -package CAC; +package example; -import java.io.File; import java.io.IOException; import java.util.concurrent.CountDownLatch; +import exp_client.EXPClientException; +import exp_client.ExperimentationClient; import jnr.ffi.Pointer; -public class Client { +public class Demo { private static void callExperimentationClient() { - String dylib = "experimentation_client"; - File currentDir = new File(System.getProperty("user.dir")); - String libraryPath = currentDir.getParentFile().getParentFile().getParentFile() + "/target/debug"; String tenant = "dev"; - - System.out.println("------------------------------------------"); - + System.out.println("Experimentation Client"); System.out.println("---------------------"); - ExperimentationClient wrapper = new ExperimentationClient(libraryPath, dylib); + ExperimentationClient wrapper = new ExperimentationClient(); int newClient; try { newClient = wrapper.exptNewClient(tenant, 1, "http://localhost:8080"); System.out.println("New Experimentation client created successfully. Client ID: " + newClient); - } catch (IOException e) { + } catch (EXPClientException e) { System.err.println(e.getMessage()); } diff --git a/clients/java/exp-client/src/main/java/exp_client/EXPClientException.java b/clients/java/exp-client/src/main/java/exp_client/EXPClientException.java new file mode 100644 index 000000000..a27bce4d7 --- /dev/null +++ b/clients/java/exp-client/src/main/java/exp_client/EXPClientException.java @@ -0,0 +1,7 @@ +package exp_client; + +public class EXPClientException extends Exception { + public EXPClientException(String message) { + super(message); + } +} diff --git a/clients/java/exp-client/src/main/java/CAC/ExperimentationClient.java b/clients/java/exp-client/src/main/java/exp_client/ExperimentationClient.java similarity index 91% rename from clients/java/exp-client/src/main/java/CAC/ExperimentationClient.java rename to clients/java/exp-client/src/main/java/exp_client/ExperimentationClient.java index ebb1b651e..1ae50a80a 100644 --- a/clients/java/exp-client/src/main/java/CAC/ExperimentationClient.java +++ b/clients/java/exp-client/src/main/java/exp_client/ExperimentationClient.java @@ -1,4 +1,4 @@ -package CAC; +package exp_client; import java.io.IOException; @@ -31,16 +31,19 @@ public interface RustLib { public static RustLib rustLib; - public ExperimentationClient(String libraryPath, String libraryName) { + public ExperimentationClient() { + String libraryName = "experimentation_client"; + String libraryPath = System.getenv("SUPERPOSITION_LIB_PATH"); + System.out.println("libraryPath" + libraryPath); System.setProperty("jnr.ffi.library.path", libraryPath); ExperimentationClient.rustLib = LibraryLoader.create(RustLib.class).load(libraryName); } - public int exptNewClient(String tenant, long updateFrequency, String hostName) throws IOException { + public int exptNewClient(String tenant, long updateFrequency, String hostName) throws EXPClientException { int result = rustLib.expt_new_client(tenant, updateFrequency, hostName); if (result > 0) { String errorMessage = rustLib.expt_last_error_message(); - throw new IOException("Failed to create new Experimentation client: " + errorMessage); + throw new EXPClientException("Failed to create new Experimentation client: " + errorMessage); } return result; }