Skip to content

Commit 5bb5164

Browse files
Renaming components -> services (#287)
1 parent 18538d6 commit 5bb5164

File tree

61 files changed

+627
-656
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+627
-656
lines changed

examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ You can modify the class to run setting `-PmainClass=<FQCN>`, for example, in or
3838
./gradlew :examples:run -PmainClass=my.restate.sdk.examples.CounterKtKt
3939
```
4040

41-
## Invoking the counter bindableComponent
41+
## Invoking the Counter
4242

4343
If you want to invoke the counter virtual object via curl:
4444

sdk-api-gen-common/src/main/java/dev/restate/sdk/gen/model/Handler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public Handler validateAndBuild() {
9292
if (handlerNameLowercase.startsWith("restate")
9393
|| handlerNameLowercase.startsWith("openapi")) {
9494
throw new IllegalArgumentException(
95-
"A component name cannot start with `restate` or `openapi`");
95+
"A service name cannot start with `restate` or `openapi`");
9696
}
9797

9898
return new Handler(

sdk-api-gen-common/src/main/java/dev/restate/sdk/gen/model/Component.java renamed to sdk-api-gen-common/src/main/java/dev/restate/sdk/gen/model/Service.java

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@
88
// https://github.com/restatedev/sdk-java/blob/main/LICENSE
99
package dev.restate.sdk.gen.model;
1010

11-
import dev.restate.sdk.common.ComponentType;
11+
import dev.restate.sdk.common.ServiceType;
1212
import java.util.ArrayList;
1313
import java.util.Collection;
1414
import java.util.List;
1515
import java.util.Objects;
1616

17-
public class Component {
17+
public class Service {
1818

1919
private final CharSequence targetPkg;
2020
private final CharSequence targetFqcn;
21-
private final String componentName;
22-
private final ComponentType componentType;
21+
private final String serviceName;
22+
private final ServiceType serviceType;
2323
private final List<Handler> handlers;
2424

25-
public Component(
25+
public Service(
2626
CharSequence targetPkg,
2727
CharSequence targetFqcn,
28-
String componentName,
29-
ComponentType componentType,
28+
String serviceName,
29+
ServiceType serviceType,
3030
List<Handler> handlers) {
3131
this.targetPkg = targetPkg;
3232
this.targetFqcn = targetFqcn;
33-
this.componentName = componentName;
33+
this.serviceName = serviceName;
3434

35-
this.componentType = componentType;
35+
this.serviceType = serviceType;
3636
this.handlers = handlers;
3737
}
3838

@@ -44,23 +44,23 @@ public CharSequence getTargetFqcn() {
4444
return this.targetFqcn;
4545
}
4646

47-
public String getFullyQualifiedComponentName() {
48-
return this.componentName;
47+
public String getFullyQualifiedServiceName() {
48+
return this.serviceName;
4949
}
5050

51-
public String getSimpleComponentName() {
52-
return this.componentName.substring(this.componentName.lastIndexOf('.') + 1);
51+
public String getSimpleServiceName() {
52+
return this.serviceName.substring(this.serviceName.lastIndexOf('.') + 1);
5353
}
5454

5555
public CharSequence getGeneratedClassFqcnPrefix() {
5656
if (this.targetPkg == null || this.targetPkg.length() == 0) {
57-
return getSimpleComponentName();
57+
return getSimpleServiceName();
5858
}
59-
return this.targetPkg + "." + getSimpleComponentName();
59+
return this.targetPkg + "." + getSimpleServiceName();
6060
}
6161

62-
public ComponentType getComponentType() {
63-
return componentType;
62+
public ServiceType getServiceType() {
63+
return serviceType;
6464
}
6565

6666
public List<Handler> getMethods() {
@@ -74,8 +74,8 @@ public static Builder builder() {
7474
public static class Builder {
7575
private CharSequence targetPkg;
7676
private CharSequence targetFqcn;
77-
private String componentName;
78-
private ComponentType componentType;
77+
private String serviceName;
78+
private ServiceType serviceType;
7979
private final List<Handler> handlers = new ArrayList<>();
8080

8181
public Builder withTargetPkg(CharSequence targetPkg) {
@@ -88,13 +88,13 @@ public Builder withTargetFqcn(CharSequence targetFqcn) {
8888
return this;
8989
}
9090

91-
public Builder withComponentName(String componentName) {
92-
this.componentName = componentName;
91+
public Builder withServiceName(String serviceName) {
92+
this.serviceName = serviceName;
9393
return this;
9494
}
9595

96-
public Builder withComponentType(ComponentType componentType) {
97-
this.componentType = componentType;
96+
public Builder withServiceType(ServiceType serviceType) {
97+
this.serviceType = serviceType;
9898
return this;
9999
}
100100

@@ -116,39 +116,39 @@ public CharSequence getTargetFqcn() {
116116
return targetFqcn;
117117
}
118118

119-
public String getComponentName() {
120-
return componentName;
119+
public String getServiceName() {
120+
return serviceName;
121121
}
122122

123-
public ComponentType getComponentType() {
124-
return componentType;
123+
public ServiceType getServiceType() {
124+
return serviceType;
125125
}
126126

127127
public List<Handler> getHandlers() {
128128
return handlers;
129129
}
130130

131-
public Component validateAndBuild() {
132-
String componentNameLowercase = componentName.toLowerCase();
133-
if (componentNameLowercase.startsWith("restate")
134-
|| componentNameLowercase.startsWith("openapi")) {
131+
public Service validateAndBuild() {
132+
String serviceNameLowercase = serviceName.toLowerCase();
133+
if (serviceNameLowercase.startsWith("restate")
134+
|| serviceNameLowercase.startsWith("openapi")) {
135135
throw new IllegalArgumentException(
136-
"A component name cannot start with `restate` or `openapi`");
136+
"A service name cannot start with `restate` or `openapi`");
137137
}
138138

139-
if (componentType.equals(ComponentType.WORKFLOW)) {
139+
if (serviceType.equals(ServiceType.WORKFLOW)) {
140140
if (handlers.stream().filter(m -> m.getHandlerType().equals(HandlerType.WORKFLOW)).count()
141141
!= 1) {
142142
throw new IllegalArgumentException(
143143
"Workflow services must have exactly one method annotated as @Workflow");
144144
}
145145
}
146146

147-
return new Component(
147+
return new Service(
148148
Objects.requireNonNull(targetPkg),
149149
Objects.requireNonNull(targetFqcn),
150-
Objects.requireNonNull(componentName),
151-
Objects.requireNonNull(componentType),
150+
Objects.requireNonNull(serviceName),
151+
Objects.requireNonNull(serviceType),
152152
handlers);
153153
}
154154
}

sdk-api-gen-common/src/main/java/dev/restate/sdk/gen/template/HandlebarsTemplateEngine.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
import com.github.jknack.handlebars.context.FieldValueResolver;
1515
import com.github.jknack.handlebars.helper.StringHelpers;
1616
import com.github.jknack.handlebars.io.TemplateLoader;
17-
import dev.restate.sdk.common.ComponentType;
17+
import dev.restate.sdk.common.ServiceType;
1818
import dev.restate.sdk.common.function.ThrowingFunction;
19-
import dev.restate.sdk.gen.model.Component;
2019
import dev.restate.sdk.gen.model.Handler;
2120
import dev.restate.sdk.gen.model.HandlerType;
21+
import dev.restate.sdk.gen.model.Service;
2222
import java.io.IOException;
2323
import java.io.Writer;
2424
import java.util.List;
@@ -29,13 +29,13 @@
2929
public class HandlebarsTemplateEngine {
3030

3131
private final String baseTemplateName;
32-
private final Map<ComponentType, Template> templates;
32+
private final Map<ServiceType, Template> templates;
3333
private final Set<String> handlerNamesToPrefix;
3434

3535
public HandlebarsTemplateEngine(
3636
String baseTemplateName,
3737
TemplateLoader templateLoader,
38-
Map<ComponentType, String> templates,
38+
Map<ServiceType, String> templates,
3939
Set<String> handlerNamesToPrefix) {
4040
this.baseTemplateName = baseTemplateName;
4141
this.handlerNamesToPrefix = handlerNamesToPrefix;
@@ -62,16 +62,16 @@ public HandlebarsTemplateEngine(
6262
}));
6363
}
6464

65-
public void generate(ThrowingFunction<String, Writer> createFile, Component component)
65+
public void generate(ThrowingFunction<String, Writer> createFile, Service service)
6666
throws Throwable {
67-
String fileName = component.getGeneratedClassFqcnPrefix() + this.baseTemplateName;
67+
String fileName = service.getGeneratedClassFqcnPrefix() + this.baseTemplateName;
6868
try (Writer out = createFile.apply(fileName)) {
6969
this.templates
70-
.get(component.getComponentType())
70+
.get(service.getServiceType())
7171
.apply(
7272
Context.newBuilder(
73-
new ComponentTemplateModel(
74-
component, this.baseTemplateName, this.handlerNamesToPrefix))
73+
new ServiceTemplateModel(
74+
service, this.baseTemplateName, this.handlerNamesToPrefix))
7575
.resolver(FieldValueResolver.INSTANCE)
7676
.build(),
7777
out);
@@ -80,30 +80,30 @@ public void generate(ThrowingFunction<String, Writer> createFile, Component comp
8080

8181
// --- classes to interact with the handlebars template
8282

83-
static class ComponentTemplateModel {
83+
static class ServiceTemplateModel {
8484
public final String originalClassPkg;
8585
public final String originalClassFqcn;
8686
public final String generatedClassSimpleNamePrefix;
8787
public final String generatedClassSimpleName;
88-
public final String componentName;
89-
public final String componentType;
88+
public final String serviceName;
89+
public final String serviceType;
9090
public final boolean isWorkflow;
9191
public final boolean isObject;
9292
public final boolean isService;
9393
public final List<HandlerTemplateModel> handlers;
9494

95-
private ComponentTemplateModel(
96-
Component inner, String baseTemplateName, Set<String> handlerNamesToPrefix) {
95+
private ServiceTemplateModel(
96+
Service inner, String baseTemplateName, Set<String> handlerNamesToPrefix) {
9797
this.originalClassPkg = inner.getTargetPkg().toString();
9898
this.originalClassFqcn = inner.getTargetFqcn().toString();
99-
this.generatedClassSimpleNamePrefix = inner.getSimpleComponentName();
99+
this.generatedClassSimpleNamePrefix = inner.getSimpleServiceName();
100100
this.generatedClassSimpleName = this.generatedClassSimpleNamePrefix + baseTemplateName;
101-
this.componentName = inner.getFullyQualifiedComponentName();
101+
this.serviceName = inner.getFullyQualifiedServiceName();
102102

103-
this.componentType = inner.getComponentType().toString();
104-
this.isWorkflow = inner.getComponentType() == ComponentType.WORKFLOW;
105-
this.isObject = inner.getComponentType() == ComponentType.VIRTUAL_OBJECT;
106-
this.isService = inner.getComponentType() == ComponentType.SERVICE;
103+
this.serviceType = inner.getServiceType().toString();
104+
this.isWorkflow = inner.getServiceType() == ServiceType.WORKFLOW;
105+
this.isObject = inner.getServiceType() == ServiceType.VIRTUAL_OBJECT;
106+
this.isService = inner.getServiceType() == ServiceType.SERVICE;
107107

108108
this.handlers =
109109
inner.getMethods().stream()

0 commit comments

Comments
 (0)