Skip to content

Commit f1ac90c

Browse files
committed
recipes: quarkus works
1 parent 461f5e5 commit f1ac90c

File tree

22 files changed

+833
-190
lines changed

22 files changed

+833
-190
lines changed

recipes/java-recipes/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ subprojects {
3434
}
3535

3636
dependencies {
37-
implementation(rootProject.projects.shared.domain)
3837
compileOnly(libs.lombok)
3938
annotationProcessor(libs.lombok)
4039
}

recipes/java-recipes/quarkus-basic-recipe/build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
alias(libs.plugins.quarkus)
33
id("org.jetbrains.kotlin.plugin.allopen") version libs.versions.kotlin
4+
java
45
}
56

67
allOpen {
@@ -22,12 +23,12 @@ dependencies {
2223
implementation(libs.quarkus.rest)
2324
implementation(libs.quarkus.arc)
2425
implementation(libs.quarkus.kotlin)
25-
implementation(libs.couchbase.client)
2626
implementation(libs.logback.classic)
2727
implementation(libs.slf4j.api)
2828
implementation(libs.kotlinx.reactor)
2929
implementation(libs.kotlinx.core)
30-
implementation(projects.shared.application)
30+
// Removed shared.application to avoid IDE launcher classpath issues
31+
// implementation(projects.shared.application)
3132
}
3233

3334
dependencies {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.trendyol.stove.recipes.quarkus;
2+
3+
import jakarta.enterprise.context.ApplicationScoped;
4+
5+
@ApplicationScoped
6+
public class EnglishGreetingService implements GreetingService {
7+
@Override
8+
public String greet(String name) {
9+
return "Hello, " + name + "!";
10+
}
11+
12+
@Override
13+
public String getLanguage() {
14+
return "English";
15+
}
16+
}

recipes/java-recipes/quarkus-basic-recipe/src/main/java/com/trendyol/stove/recipes/quarkus/GreetingResource.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.trendyol.stove.recipes.quarkus;
22

3+
import jakarta.enterprise.inject.Instance;
34
import jakarta.inject.Inject;
45
import jakarta.ws.rs.GET;
56
import jakarta.ws.rs.Path;
@@ -11,9 +12,26 @@ public class GreetingResource {
1112

1213
@Inject HelloService helloService;
1314

15+
// Inject all GreetingService implementations to ensure they're registered
16+
@Inject Instance<GreetingService> greetingServices;
17+
18+
// Inject repository to prevent dead code elimination
19+
@Inject ItemRepository itemRepository;
20+
1421
@GET
1522
@Produces(MediaType.TEXT_PLAIN)
1623
public String hello() {
1724
return helloService.hello();
1825
}
26+
27+
@GET
28+
@Path("/greetings")
29+
@Produces(MediaType.TEXT_PLAIN)
30+
public String greetings() {
31+
StringBuilder sb = new StringBuilder();
32+
for (GreetingService gs : greetingServices) {
33+
sb.append(gs.getLanguage()).append(": ").append(gs.greet("World")).append("\n");
34+
}
35+
return sb.toString();
36+
}
1937
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.trendyol.stove.recipes.quarkus;
2+
3+
/**
4+
* Interface for greeting services - demonstrates multiple implementations pattern.
5+
*/
6+
public interface GreetingService {
7+
String greet(String name);
8+
String getLanguage();
9+
}
10+
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package com.trendyol.stove.recipes.quarkus;
22

3-
import jakarta.inject.Singleton;
4-
5-
@Singleton
6-
public class HelloService {
7-
public String hello() {
8-
return "Hello from Quarkus Service";
9-
}
3+
/**
4+
* Interface for HelloService - using interfaces is a CDI best practice
5+
* and enables type-safe testing through dynamic proxies.
6+
*/
7+
public interface HelloService {
8+
String hello();
109
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.trendyol.stove.recipes.quarkus;
2+
3+
import jakarta.inject.Singleton;
4+
5+
@Singleton
6+
public class HelloServiceImpl implements HelloService {
7+
@Override
8+
public String hello() {
9+
return "Hello from Quarkus Service";
10+
}
11+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.trendyol.stove.recipes.quarkus;
2+
3+
import jakarta.enterprise.context.ApplicationScoped;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import java.util.Map;
7+
import java.util.concurrent.ConcurrentHashMap;
8+
9+
@ApplicationScoped
10+
public class InMemoryItemRepository implements ItemRepository {
11+
12+
private final Map<String, String> items = new ConcurrentHashMap<>();
13+
14+
@Override
15+
public void add(String id, String name) {
16+
items.put(id, name);
17+
}
18+
19+
@Override
20+
public void addItem(Item item) {
21+
items.put(item.getId(), item.getName());
22+
}
23+
24+
@Override
25+
public String getById(String id) {
26+
return items.get(id);
27+
}
28+
29+
@Override
30+
public Item getItemById(String id) {
31+
String name = items.get(id);
32+
return name != null ? new Item(id, name) : null;
33+
}
34+
35+
@Override
36+
public List<String> getAllIds() {
37+
return new ArrayList<>(items.keySet());
38+
}
39+
40+
@Override
41+
public void clear() {
42+
items.clear();
43+
}
44+
45+
@Override
46+
public int count() {
47+
return items.size();
48+
}
49+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.trendyol.stove.recipes.quarkus;
2+
3+
/**
4+
* Simple item class to demonstrate classloader limitations.
5+
*/
6+
public class Item {
7+
private final String id;
8+
private final String name;
9+
10+
public Item(String id, String name) {
11+
this.id = id;
12+
this.name = name;
13+
}
14+
15+
public String getId() {
16+
return id;
17+
}
18+
19+
public String getName() {
20+
return name;
21+
}
22+
23+
@Override
24+
public String toString() {
25+
return "Item{id='" + id + "', name='" + name + "'}";
26+
}
27+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.trendyol.stove.recipes.quarkus;
2+
3+
import java.util.List;
4+
5+
/**
6+
* Simple repository interface for testing cross-classloader interactions.
7+
*/
8+
public interface ItemRepository {
9+
void add(String id, String name);
10+
void addItem(Item item); // Takes complex object - will fail across classloaders!
11+
String getById(String id);
12+
Item getItemById(String id); // Returns complex object
13+
List<String> getAllIds();
14+
void clear();
15+
int count();
16+
}

0 commit comments

Comments
 (0)