Skip to content

Commit

Permalink
update java std version
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriano Santos committed Aug 23, 2024
1 parent 3605944 commit e98281d
Show file tree
Hide file tree
Showing 33 changed files with 67,868 additions and 2,842 deletions.
4 changes: 2 additions & 2 deletions java-std/{{cookiecutter.app_name}}/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

<!-- Lib versions -->
<!-- TODO: Remove this line when update java sdk lib to v1.4.2 -->
<!-- <spawn.sdk.version>{{ cookiecutter.spawn_sdk_version }}</spawn.sdk.version> -->
<spawn.sdk.version>v1.3.1</spawn.sdk.version>
<spawn.sdk.version>{{ cookiecutter.spawn_sdk_version }}</spawn.sdk.version>
<!-- <spawn.sdk.version>v1.3.1</spawn.sdk.version> -->
<protobuf.version>4.27.2</protobuf.version>
<gson.version>2.11.0</gson.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void main(String[] args) throws SpawnException {

spawnSystem.start();

log.info("Actor running and ready to connection at ports [{}]", cfg.userFunctionPort);
log.info("Actor running and ready to accept connections at port [{}]", cfg.userFunctionPort);
}

public record Config(String startupDelaySeconds,
Expand All @@ -58,7 +58,7 @@ public static Config createDefaultConfig() {
String userFunctionHost = System.getenv("USER_FUNCTION_HOST") != null ? System.getenv("USER_FUNCTION_HOST")
: "localhost";
String userFunctionPort = System.getenv("USER_FUNCTION_PORT") != null ? System.getenv("USER_FUNCTION_PORT")
: "8091";
: "8090";
String spawnProxyHost = System.getenv("SPAWN_PROXY_HOST") != null ? System.getenv("SPAWN_PROXY_HOST")
: "localhost";
String spawnProxyPort = System.getenv("SPAWN_PROXY_PORT") != null ? System.getenv("SPAWN_PROXY_PORT")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package io.eigr.spawn.java.actors;

import domain.actors.GetRequest;
import domain.actors.GetResponse;
import domain.actors.PostalCodeState;
import domain.actors.PostalCodeStatus;
import io.eigr.spawn.api.actors.ActorContext;
import io.eigr.spawn.api.actors.StatefulActor;
import io.eigr.spawn.api.actors.Value;
import io.eigr.spawn.api.actors.behaviors.ActorBehavior;
import io.eigr.spawn.api.actors.behaviors.BehaviorCtx;
import io.eigr.spawn.api.actors.behaviors.UnNamedActorBehavior;
import io.eigr.spawn.internal.ActionBindings;

import io.eigr.spawn.java.domain.DomainProto;
import io.eigr.spawn.java.service.PostalCodeService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -20,7 +21,7 @@
import static io.eigr.spawn.api.actors.behaviors.ActorBehavior.action;
import static io.eigr.spawn.api.actors.behaviors.ActorBehavior.name;

public final class PostalCodeActor implements StatefulActor<DomainProto.PostalCodeState> {
public final class PostalCodeActor implements StatefulActor<PostalCodeState> {
private static final Logger log = LoggerFactory.getLogger(PostalCodeActor.class);

private PostalCodeService postalCodeService;
Expand All @@ -30,16 +31,16 @@ public ActorBehavior configure(BehaviorCtx behaviorCtx) {
this.postalCodeService = behaviorCtx.getInjector().getInstance(PostalCodeService.class);
return new UnNamedActorBehavior(
name("PostalCode"),
action("GetPostalCodeData", ActionBindings.of(DomainProto.GetRequest.class, this::getPostalCodeData)));
action("GetPostalCodeData", ActionBindings.of(GetRequest.class, this::getPostalCodeData)));
}

private Value getPostalCodeData(ActorContext<DomainProto.PostalCodeState> context, DomainProto.GetRequest msg) {
private Value getPostalCodeData(ActorContext<PostalCodeState> context, GetRequest msg) {
log.debug("Received invocation. Message: '{}'. Context: '{}'.", msg, context);

Optional<DomainProto.PostalCodeState> currentState = context.getState();
Optional<PostalCodeState> currentState = context.getState();

// Return current state if available and not unknown
if (currentState.isPresent() && currentState.get().getStatus() != DomainProto.PostalCodeStatus.UNKNOWN) {
if (currentState.isPresent() && currentState.get().getStatus() != PostalCodeStatus.UNKNOWN) {
return createValueWithStateAndResponse(currentState.get());
}

Expand All @@ -48,28 +49,28 @@ private Value getPostalCodeData(ActorContext<DomainProto.PostalCodeState> contex

// If postal code data found, build state and response
if (!postalCodeData.isEmpty()) {
DomainProto.PostalCodeState newState = buildPostalCodeState(msg.getCode(), postalCodeData,
DomainProto.PostalCodeStatus.FOUND);
PostalCodeState newState = buildPostalCodeState(msg.getCode(), postalCodeData,
PostalCodeStatus.FOUND);
return createValueWithStateAndResponse(newState);
}

// Default case: return unknown state
DomainProto.PostalCodeState unknownState = DomainProto.PostalCodeState.newBuilder()
.setStatus(DomainProto.PostalCodeStatus.UNKNOWN)
PostalCodeState unknownState = PostalCodeState.newBuilder()
.setStatus(PostalCodeStatus.UNKNOWN)
.build();
return createValueWithStateAndResponse(unknownState);
}

private Value createValueWithStateAndResponse(DomainProto.PostalCodeState state) {
DomainProto.GetResponse response = DomainProto.GetResponse.newBuilder()
private Value createValueWithStateAndResponse(PostalCodeState state) {
GetResponse response = GetResponse.newBuilder()
.setPostalCode(state)
.build();
return Value.at().state(state).response(response).reply();
}

private DomainProto.PostalCodeState buildPostalCodeState(String code, Map<String, String> data,
DomainProto.PostalCodeStatus status) {
return DomainProto.PostalCodeState.newBuilder()
private PostalCodeState buildPostalCodeState(String code, Map<String, String> data,
PostalCodeStatus status) {
return PostalCodeState.newBuilder()
.setCode(code)
.setCity(data.get("localidade"))
.setState(data.get("uf"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.eigr.spawn.java.actors;

import domain.actors.GetRequest;
import io.eigr.spawn.api.ActorIdentity;
import io.eigr.spawn.api.ActorRef;
import io.eigr.spawn.api.Spawn;
Expand All @@ -12,10 +13,7 @@
import io.eigr.spawn.api.actors.workflows.Forward;
import io.eigr.spawn.api.exceptions.ActorCreationException;
import io.eigr.spawn.internal.ActionBindings;

import io.eigr.spawn.java.domain.DomainProto;
import io.eigr.spawn.java.service.ViaCepService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -32,16 +30,16 @@ public ActorBehavior configure(BehaviorCtx behaviorCtx) {
this.postalCodeService = behaviorCtx.getInjector().getInstance(ViaCepService.class);
return new NamedActorBehavior(
name("Router"),
action("GetPostalCode", ActionBindings.of(DomainProto.GetRequest.class, this::getPostalCodeData))
action("GetPostalCode", ActionBindings.of(GetRequest.class, this::getPostalCodeData))
);
}

private Value getPostalCodeData(ActorContext<?> context, DomainProto.GetRequest msg) {
private Value getPostalCodeData(ActorContext<?> context, GetRequest msg) {
log.debug("Received invocation. Message: '{}'.", msg, context);
try {
Spawn spawn = context.getSpawnSystem();
ActorRef actorRef = context.getSpawnSystem()
.createActorRef(ActorIdentity.of(spawn.getSystem(), msg.getCode(), "PostalCode"));
.createActorRef(ActorIdentity.of(spawn.getSystem(), msg.getCode(), "PostalCode", true));

return Value.at()
.flow(Forward.to(actorRef, "GetPostalCodeData"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
syntax = "proto3";

package domain.actors;

import "google/api/annotations.proto";
import "eigr/functions/protocol/actors/extensions.proto";

option java_package = "domain.actors";
option java_outer_classname = "ActorsProto";

enum PostalCodeStatus {
UNKNOWN = 0;
CREATED = 1;
NOT_FOUND = 2;
FOUND = 3;
}

message PostalCodeState {
string code = 1;
PostalCodeStatus status = 2;
string country = 3;
string street = 4;
string state = 5;
string city = 6;
}

message GetRequest {
string code = 1 [(.eigr.functions.protocol.actors.actor_id) = true];
}

message GetResponse { PostalCodeState postal_code = 1; }

// Router Actor
service Router {
rpc GetPostalCode(GetRequest) returns (GetResponse) {
option (google.api.http) = {
get: "/v1/postalcode/{code}",
body: "*"
};
}
}

// PostalCode Actor
service PostalCode {
rpc GetPostalCodeData(GetRequest) returns (GetResponse) {
option (google.api.http) = {
get : "/v1/internal/postalcodes/{code}"
};
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
syntax = "proto3";

package eigr.functions.protocol.actors;

import "google/protobuf/descriptor.proto";

extend google.protobuf.FieldOptions {
bool actor_id = 9999;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package google.api;

import "google/api/http.proto";
import "google/protobuf/descriptor.proto";

option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations";
option java_multiple_files = true;
option java_outer_classname = "AnnotationsProto";
option java_package = "com.google.api";
option objc_class_prefix = "GAPI";

extend google.protobuf.MethodOptions {
// See `HttpRule`.
HttpRule http = 72295728;
}
Loading

0 comments on commit e98281d

Please sign in to comment.