Skip to content

Commit e61c307

Browse files
committed
feat: add context to Java runtime
1 parent 5becca6 commit e61c307

6 files changed

Lines changed: 19 additions & 13 deletions

File tree

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ ADD runtimes/go1-16 /workspace
4949
RUN chown -R 9653 /.cache /workspace
5050
WORKDIR /workspace
5151
USER 9653:9653
52+
RUN go build ./...
5253
ENTRYPOINT ./entrypoint.sh
5354

5455
FROM openjdk:16 AS java16
5556
ADD runtimes/java16 /workspace
5657
RUN chown -R 9653 /workspace
5758
WORKDIR /workspace
5859
USER 9653:9653
60+
RUN javac *.java
5961
ENTRYPOINT ./entrypoint.sh
6062

6163
FROM python:3.9-alpine AS python3-9

dsls/python/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
def str_presenter(dumper, data):
11-
if len(data.splitlines()) > 1 or '"' in data or "'" in data:
11+
if '\n' in data or '"' in data or "'" in data:
1212
return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='|')
1313
return dumper.represent_scalar('tag:yaml.org,2002:str', data)
1414

@@ -433,7 +433,7 @@ def dump(self):
433433

434434

435435
class KafkaSource(Source):
436-
def __init__(self, topic, name=None, retryPolicy=None):
436+
def __init__(self, topic, name=None, retryPolicy=None):
437437
super().__init__(name=name, retryPolicy=retryPolicy)
438438
self._topic = topic
439439

@@ -444,7 +444,7 @@ def dump(self):
444444

445445

446446
class STANSource(Source):
447-
def __init__(self, subject, name=None, retryPolicy=None):
447+
def __init__(self, subject, name=None, retryPolicy=None):
448448
super().__init__(name=name, retryPolicy=retryPolicy)
449449
self._subject = subject
450450

@@ -463,9 +463,9 @@ def http(name=None, retryPolicy=None):
463463
return HTTPSource(name=name, retryPolicy=retryPolicy)
464464

465465

466-
def kafka(topic, name=None, retryPolicy=None):
467-
return KafkaSource(topic, name=name, retryPolicy=retryPolicy)
466+
def kafka(topic, name=None, retryPolicy=None):
467+
return KafkaSource(topic, name=name, retryPolicy=retryPolicy)
468468

469469

470-
def stan(subject, name=None, retryPolicy=None):
470+
def stan(subject, name=None, retryPolicy=None):
471471
return STANSource(subject, name=name, retryPolicy=retryPolicy)

examples/104-java16-pipeline.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ def handler(msg):
1313
[Learn about handlers](../docs/HANDLERS.md)""")
1414
.step(
1515
(kafka('input-topic')
16-
.handler('main', code="""public class Handler {
17-
public static byte[] Handle(byte[] msg) throws Exception {
16+
.handler('main', code="""import java.util.Map;
17+
18+
public static byte[] Handle(byte[] msg, Map<String,String> context) throws Exception {
1819
return msg;
1920
}
2021
}""", runtime='java16')

examples/104-java16-pipeline.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ spec:
1212
steps:
1313
- handler:
1414
code: |-
15-
public class Handler {
16-
public static byte[] Handle(byte[] msg) throws Exception {
15+
import java.util.Map;
16+
17+
public static byte[] Handle(byte[] msg, Map<String,String> context) throws Exception {
1718
return msg;
1819
}
1920
}

runtimes/java16/Handler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import java.util.Map;
2+
13
public class Handler {
2-
public static byte[] Handle(byte[] msg) throws Exception {
4+
public static byte[] Handle(byte[] msg, Map<String,String> context) throws Exception {
35
var x = "hi " + new String(msg);
46
return x.getBytes();
57
}

runtimes/java16/Main.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import com.sun.net.httpserver.HttpServer;
2-
32
import java.io.ByteArrayOutputStream;
43
import java.io.InputStreamReader;
54
import java.net.InetSocketAddress;
@@ -9,6 +8,7 @@
98
import java.net.http.HttpResponse;
109
import java.nio.charset.StandardCharsets;
1110
import java.util.concurrent.Executors;
11+
import java.util.Collections;
1212

1313
public class Main {
1414
public static void main(String[] args) throws Exception {
@@ -25,7 +25,7 @@ public static void main(String[] args) throws Exception {
2525
}
2626
isr.close();
2727
try {
28-
var out = Handler.Handle(in.toByteArray());
28+
var out = Handler.Handle(in.toByteArray(), Collections.<String,String>emptyMap());
2929
if (out != null) {
3030
he.sendResponseHeaders(201, 0);
3131
try (var os = he.getResponseBody()) {

0 commit comments

Comments
 (0)