-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(*): add ligning talk with example code
- Loading branch information
Showing
26 changed files
with
920 additions
and
392 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="module" module-name="playground" /> | ||
</component> | ||
</module> |
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,12 @@ | ||
#!/bin/bash | ||
|
||
echo -e "\nHINT: Be sure to compile project with IDEA first\n" | ||
|
||
echo -e "=== RetrieveModuleInfo" | ||
java -modulepath ../target/production/playground:../target/production/playground-dependent \ | ||
-m anothermodule/de.exxcellent.anothermodule.RetrieveModuleInfo | ||
|
||
|
||
echo -e "\n\n=== TestJigsawSPI" | ||
java -modulepath ../target/production/playground:../target/production/playground-dependent \ | ||
-m anothermodule/de.exxcellent.anothermodule.TestJigsawSPI |
40 changes: 40 additions & 0 deletions
40
playground-dependent/src/main/java/de/exxcellent/anothermodule/RetrieveModuleInfo.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,40 @@ | ||
package de.exxcellent.anothermodule; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.lang.module.ModuleDescriptor; | ||
import static java.lang.System.out; | ||
|
||
public class RetrieveModuleInfo { | ||
|
||
/** | ||
* Show module infos | ||
*/ | ||
public static void main(String[] args) throws IOException { | ||
ModuleDescriptor descriptor = RetrieveModuleInfo.class.getModule().getDescriptor(); | ||
|
||
if (descriptor == null) { | ||
out.println("JVM started without '-mp' option. Trying to load module-info manually..."); | ||
descriptor = readModuleDescriptorFromBytecode(); | ||
} | ||
|
||
printModule(descriptor); | ||
} | ||
|
||
static void printModule(ModuleDescriptor descriptor) { | ||
out.println("Module " + descriptor.name()); | ||
descriptor.exports().forEach( | ||
export -> out.println("\texports " + export.source()) | ||
); | ||
descriptor.requires().forEach( | ||
requires -> out.println("\trequires " + requires.name() + " " + requires.modifiers()) | ||
); | ||
} | ||
|
||
static ModuleDescriptor readModuleDescriptorFromBytecode() throws IOException { | ||
InputStream moduleInfo = RetrieveModuleInfo.class.getClassLoader().getResourceAsStream("module-info.class"); | ||
return ModuleDescriptor.read(moduleInfo); | ||
} | ||
|
||
|
||
} |
12 changes: 12 additions & 0 deletions
12
playground-dependent/src/main/java/de/exxcellent/anothermodule/TestJigsawSPI.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,12 @@ | ||
package de.exxcellent.anothermodule; | ||
|
||
import de.exxcellent.java9.jigsaw.BillingService; | ||
import static java.lang.System.out; | ||
|
||
public class TestJigsawSPI { | ||
|
||
public static void main(String[] args) { | ||
BillingService s = BillingService.getInstance(); | ||
out.println(s.takeMoney()); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
playground-dependent/src/main/java/de/exxcellent/anothermodule/TestModuleEncapuslation.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,17 @@ | ||
package de.exxcellent.anothermodule; | ||
|
||
import de.exxcellent.java9.collections.ImmutableCollections; | ||
|
||
/** | ||
* Test module encapsulation | ||
*/ | ||
public class TestModuleEncapuslation { | ||
|
||
public static void main(String[] args) { | ||
ImmutableCollections.main(args); | ||
|
||
// Would break, as it is not exported. Though it's public! | ||
// de.exxcellent.java9.util.InputStreamExample.main(args); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
playground-dependent/src/main/java/de/exxcellent/anothermodule/module-info.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,8 @@ | ||
module anothermodule { | ||
exports de.exxcellent.anothermodule; | ||
requires de.exxcellent.java9; | ||
|
||
// Provide Service instance (SPI with Jigsaw modules) | ||
provides de.exxcellent.java9.jigsaw.spi.BillingServiceProvider | ||
with de.exxcellent.anothermodule.spi.MastercardBillingServiceProvider; | ||
} |
11 changes: 11 additions & 0 deletions
11
...und-dependent/src/main/java/de/exxcellent/anothermodule/spi/MastercardBillingService.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,11 @@ | ||
package de.exxcellent.anothermodule.spi; | ||
|
||
import de.exxcellent.java9.jigsaw.BillingService; | ||
|
||
class MastercardBillingService extends BillingService { | ||
|
||
@Override | ||
public String takeMoney() { | ||
return "Mastercard billed the money!"; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...ndent/src/main/java/de/exxcellent/anothermodule/spi/MastercardBillingServiceProvider.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,12 @@ | ||
package de.exxcellent.anothermodule.spi; | ||
|
||
import de.exxcellent.java9.jigsaw.BillingService; | ||
import de.exxcellent.java9.jigsaw.spi.BillingServiceProvider; | ||
|
||
public class MastercardBillingServiceProvider extends BillingServiceProvider { | ||
|
||
@Override | ||
public BillingService buildBillingService() { | ||
return new MastercardBillingService(); | ||
} | ||
} |
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
Empty file.
31 changes: 31 additions & 0 deletions
31
playground/src/main/java/de/exxcellent/java9/collections/ImmutableCollections.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,31 @@ | ||
package de.exxcellent.java9.collections; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import static java.lang.System.*; | ||
|
||
public class ImmutableCollections { | ||
|
||
/** | ||
* Create immutable collections on the fly. | ||
* They do not accept {@code null} or duplicate entries (Set/Map) | ||
*/ | ||
public static void main(String args[]) { | ||
List<Integer> listOfNumbers = List.of(1, 2, 3, 4, 5/*, null*/); | ||
out.println(listOfNumbers); | ||
|
||
Set<Integer> setOfNumbers = Set.of(1, 2, 3, 4, 5/*, 1*/); | ||
out.println(setOfNumbers); | ||
|
||
Map<String, String> mapOfString = Map.of("key1", "value1", "key2", "value2"); | ||
out.println(mapOfString); | ||
|
||
Map<String, String> moreMapOfString = Map.ofEntries( | ||
Map.entry("key1", "value1"), | ||
Map.entry("key2", "value2")/*, | ||
Map.entry("key1", "value3")*/ | ||
); | ||
out.println(moreMapOfString); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
playground/src/main/java/de/exxcellent/java9/http/HttpClientExample.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,25 @@ | ||
package de.exxcellent.java9.http; | ||
|
||
import java.net.URI; | ||
import java.net.http.HttpClient; | ||
import java.net.http.HttpResponse; | ||
import static java.lang.System.out; | ||
|
||
public class HttpClientExample { | ||
|
||
/** | ||
* The HTTP API functions asynchronously & synchronously. In asynchronous mode, | ||
* work is done on the threads supplied by the client's ExecutorService. | ||
*/ | ||
public static void main(String[] args) throws Exception{ | ||
HttpClient.getDefault() | ||
.request(URI.create("https://www.exxcellent.de")) | ||
.GET() | ||
.responseAsync() // CompletableFuture :D | ||
.thenAccept(httpResponse -> | ||
out.println(httpResponse.body(HttpResponse.asString())) | ||
); | ||
|
||
Thread.sleep(999); // Give worker thread some time. | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
playground/src/main/java/de/exxcellent/java9/jigsaw/BillingService.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,28 @@ | ||
package de.exxcellent.java9.jigsaw; | ||
|
||
import java.util.Iterator; | ||
import java.util.ServiceLoader; | ||
import de.exxcellent.java9.jigsaw.spi.BillingServiceProvider; | ||
|
||
public abstract class BillingService { | ||
|
||
protected BillingService() { | ||
} | ||
|
||
public static BillingService getInstance() { | ||
// Java SPI to find the instance | ||
ServiceLoader<BillingServiceProvider> sl = ServiceLoader.load(BillingServiceProvider.class); | ||
|
||
// Fetch first provider implementation | ||
Iterator<BillingServiceProvider> providerIterator = sl.iterator(); | ||
if (!providerIterator.hasNext()) { | ||
throw new RuntimeException("No service providers found!"); | ||
} | ||
|
||
BillingServiceProvider provider = providerIterator.next(); | ||
|
||
return provider.buildBillingService(); | ||
} | ||
|
||
public abstract String takeMoney(); | ||
} |
8 changes: 8 additions & 0 deletions
8
playground/src/main/java/de/exxcellent/java9/jigsaw/spi/BillingServiceProvider.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,8 @@ | ||
package de.exxcellent.java9.jigsaw.spi; | ||
|
||
import de.exxcellent.java9.jigsaw.BillingService; | ||
|
||
public abstract class BillingServiceProvider { | ||
|
||
public abstract BillingService buildBillingService(); | ||
} |
12 changes: 12 additions & 0 deletions
12
playground/src/main/java/de/exxcellent/java9/module-info.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,12 @@ | ||
module de.exxcellent.java9 { | ||
exports de.exxcellent.java9.collections; | ||
|
||
// Depend on an offficial JDK modules | ||
// full list see http://cr.openjdk.java.net/~mr/jigsaw/ea/module-summary.html | ||
requires java.httpclient; | ||
|
||
// Service example (SPI with Jigsaw modules) | ||
exports de.exxcellent.java9.jigsaw; | ||
exports de.exxcellent.java9.jigsaw.spi; | ||
uses de.exxcellent.java9.jigsaw.spi.BillingServiceProvider; | ||
} |
Oops, something went wrong.