Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,64 @@ object ModelBuilder {
/**
* Type argument for generic replicated data types with type parameters.
*/
case class TypeArgument(fqn: FullyQualifiedName)
sealed trait TypeArgument

object TypeArgument {
def apply(name: String, proto: PackageNaming): TypeArgument = {
if (name.nonEmpty && name.charAt(0).isLower) ScalarTypeArgument(ScalarType(name))
else MessageTypeArgument(FullyQualifiedName(name, proto))
}
}

/**
* Type argument for Protobuf message types.
*/
case class MessageTypeArgument(fqn: FullyQualifiedName) extends TypeArgument

/**
* Type argument for Protobuf scalar types.
*/
case class ScalarTypeArgument(scalar: ScalarType) extends TypeArgument

sealed trait ScalarType

object ScalarType {
case object Double extends ScalarType
case object Float extends ScalarType
case object Int32 extends ScalarType
case object Int64 extends ScalarType
case object UInt32 extends ScalarType
case object UInt64 extends ScalarType
case object SInt32 extends ScalarType
case object SInt64 extends ScalarType
case object Fixed32 extends ScalarType
case object Fixed64 extends ScalarType
case object SFixed32 extends ScalarType
case object SFixed64 extends ScalarType
case object Bool extends ScalarType
case object String extends ScalarType
case object Bytes extends ScalarType
case object Unknown extends ScalarType

def apply(protoType: String): ScalarType = protoType match {
case "double" => Double
case "float" => Float
case "int32" => Int32
case "int64" => Int64
case "uint32" => UInt32
case "uint64" => UInt64
case "sint32" => SInt32
case "sint64" => SInt64
case "fixed32" => Fixed32
case "fixed64" => Fixed64
case "sfixed32" => SFixed32
case "sfixed64" => SFixed64
case "bool" => Bool
case "string" => String
case "bytes" => Bytes
case _ => Unknown
}
}

/**
* A Service backed by Akka Serverless; either an Action, View or Entity
Expand Down Expand Up @@ -363,24 +420,24 @@ object ModelBuilder {
case ReplicatedDataCase.REPLICATED_COUNTER =>
Some(ReplicatedCounter)
case ReplicatedDataCase.REPLICATED_REGISTER =>
val value = TypeArgument(FullyQualifiedName(rawEntity.getReplicatedRegister.getValue, protoReference))
val value = TypeArgument(rawEntity.getReplicatedRegister.getValue, protoReference)
Some(ReplicatedRegister(value))
case ReplicatedDataCase.REPLICATED_SET =>
val element = TypeArgument(FullyQualifiedName(rawEntity.getReplicatedSet.getElement, protoReference))
val element = TypeArgument(rawEntity.getReplicatedSet.getElement, protoReference)
Some(ReplicatedSet(element))
case ReplicatedDataCase.REPLICATED_MAP =>
val key = TypeArgument(FullyQualifiedName(rawEntity.getReplicatedMap.getKey, protoReference))
val key = TypeArgument(rawEntity.getReplicatedMap.getKey, protoReference)
Some(ReplicatedMap(key))
case ReplicatedDataCase.REPLICATED_COUNTER_MAP =>
val key = TypeArgument(FullyQualifiedName(rawEntity.getReplicatedCounterMap.getKey, protoReference))
val key = TypeArgument(rawEntity.getReplicatedCounterMap.getKey, protoReference)
Some(ReplicatedCounterMap(key))
case ReplicatedDataCase.REPLICATED_REGISTER_MAP =>
val key = TypeArgument(FullyQualifiedName(rawEntity.getReplicatedRegisterMap.getKey, protoReference))
val value = TypeArgument(FullyQualifiedName(rawEntity.getReplicatedRegisterMap.getValue, protoReference))
val key = TypeArgument(rawEntity.getReplicatedRegisterMap.getKey, protoReference)
val value = TypeArgument(rawEntity.getReplicatedRegisterMap.getValue, protoReference)
Some(ReplicatedRegisterMap(key, value))
case ReplicatedDataCase.REPLICATED_MULTI_MAP =>
val key = TypeArgument(FullyQualifiedName(rawEntity.getReplicatedMultiMap.getKey, protoReference))
val value = TypeArgument(FullyQualifiedName(rawEntity.getReplicatedMultiMap.getValue, protoReference))
val key = TypeArgument(rawEntity.getReplicatedMultiMap.getKey, protoReference)
val value = TypeArgument(rawEntity.getReplicatedMultiMap.getValue, protoReference)
Some(ReplicatedMultiMap(key, value))
case ReplicatedDataCase.REPLICATED_VOTE =>
Some(ReplicatedVote)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class ModelBuilderSuite extends munit.FunSuite {
val entity = ModelBuilder.ReplicatedEntity(
FullyQualifiedName("ShoppingCart", domainProto),
"shopping-cart",
ModelBuilder.ReplicatedCounterMap(ModelBuilder.TypeArgument(FullyQualifiedName("Product", domainProto))))
ModelBuilder.ReplicatedCounterMap(ModelBuilder.TypeArgument("Product", domainProto)))

assertEquals(model.entities, Map(entity.fqn.fullQualifiedName -> entity))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,15 @@ service CounterMapService {
rpc Get(GetValue) returns (CurrentValue);
rpc GetAll(GetAllValues) returns (CurrentValues);
}

service ScalarCounterMapService {
option (akkaserverless.service) = {
type: SERVICE_TYPE_ENTITY
component: "com.example.replicated.countermap.domain.SomeScalarCounterMap"
};

rpc Increase(IncreaseValue) returns (google.protobuf.Empty);
rpc Decrease(DecreaseValue) returns (google.protobuf.Empty);
rpc Get(GetValue) returns (CurrentValue);
rpc GetAll(GetAllValues) returns (CurrentValues);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2021 Lightbend Inc.
//
// 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 com.example.replicated.countermap.domain;

import "akkaserverless/annotations.proto";

option java_outer_classname = "SomeScalarCounterMapDomain";

option (akkaserverless.file).replicated_entity = {
name: "SomeScalarCounterMap"
entity_type: "some-scalar-counter-map"
replicated_counter_map: {
key: "int64"
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,17 @@ service MapService {
rpc RemoveBaz(RemoveBazValue) returns (google.protobuf.Empty);
rpc Get(GetValues) returns (CurrentValues);
}

service ScalarMapService {
option (akkaserverless.service) = {
type: SERVICE_TYPE_ENTITY
component: "com.example.replicated.map.domain.SomeScalarMap"
};

rpc IncreaseFoo(IncreaseFooValue) returns (google.protobuf.Empty);
rpc DecreaseFoo(DecreaseFooValue) returns (google.protobuf.Empty);
rpc SetBar(SetBarValue) returns (google.protobuf.Empty);
rpc AddBaz(AddBazValue) returns (google.protobuf.Empty);
rpc RemoveBaz(RemoveBazValue) returns (google.protobuf.Empty);
rpc Get(GetValues) returns (CurrentValues);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2021 Lightbend Inc.
//
// 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 com.example.replicated.map.domain;

import "akkaserverless/annotations.proto";

option java_outer_classname = "SomeScalarMapDomain";

option (akkaserverless.file).replicated_entity = {
name: "SomeScalarMap"
entity_type: "some-scalar-map"
replicated_map: {
key: "string"
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,15 @@ service MultiMapService {
rpc Get(GetValues) returns (CurrentValues);
rpc GetAll(GetAllValues) returns (AllCurrentValues);
}

service ScalarMultiMapService {
option (akkaserverless.service) = {
type: SERVICE_TYPE_ENTITY
component: "com.example.replicated.multimap.domain.SomeScalarMultiMap"
};

rpc Put(PutValue) returns (google.protobuf.Empty);
rpc Remove(RemoveValue) returns (google.protobuf.Empty);
rpc Get(GetValues) returns (CurrentValues);
rpc GetAll(GetAllValues) returns (AllCurrentValues);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2021 Lightbend Inc.
//
// 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 com.example.replicated.multimap.domain;

import "akkaserverless/annotations.proto";

option java_outer_classname = "SomeScalarMultiMapDomain";

option (akkaserverless.file).replicated_entity = {
name: "SomeScalarMultiMap"
entity_type: "some-scalar-multi-map"
replicated_multi_map: {
key: "string"
value: "double"
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,13 @@ service RegisterService {
rpc Set(SetValue) returns (google.protobuf.Empty);
rpc Get(GetValue) returns (CurrentValue);
}

service ScalarRegisterService {
option (akkaserverless.service) = {
type: SERVICE_TYPE_ENTITY
component: "com.example.replicated.register.domain.SomeScalarRegister"
};

rpc Set(SetValue) returns (google.protobuf.Empty);
rpc Get(GetValue) returns (CurrentValue);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2021 Lightbend Inc.
//
// 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 com.example.replicated.register.domain;

import "akkaserverless/annotations.proto";

option java_outer_classname = "SomeScalarRegisterDomain";

option (akkaserverless.file).replicated_entity = {
name: "SomeScalarRegister"
entity_type: "some-scalar-register"
replicated_register: {
value: "bytes"
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,14 @@ service RegisterMapService {
rpc Get(GetValue) returns (CurrentValue);
rpc GetAll(GetAllValues) returns (CurrentValues);
}

service ScalarRegisterMapService {
option (akkaserverless.service) = {
type: SERVICE_TYPE_ENTITY
component: "com.example.replicated.registermap.domain.SomeScalarRegisterMap"
};

rpc Set(SetValue) returns (google.protobuf.Empty);
rpc Get(GetValue) returns (CurrentValue);
rpc GetAll(GetAllValues) returns (CurrentValues);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2021 Lightbend Inc.
//
// 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 com.example.replicated.registermap.domain;

import "akkaserverless/annotations.proto";

option java_outer_classname = "SomeScalarRegisterMapDomain";

option (akkaserverless.file).replicated_entity = {
name: "SomeScalarRegisterMap"
entity_type: "some-scalar-register-map"
replicated_register_map: {
key: "sint32"
value: "string"
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,14 @@ service SetService {
rpc Remove(RemoveElement) returns (google.protobuf.Empty);
rpc Get(GetElements) returns (CurrentElements);
}

service ScalarSetService {
option (akkaserverless.service) = {
type: SERVICE_TYPE_ENTITY
component: "com.example.replicated.set.domain.SomeScalarSet"
};

rpc Add(AddElement) returns (google.protobuf.Empty);
rpc Remove(RemoveElement) returns (google.protobuf.Empty);
rpc Get(GetElements) returns (CurrentElements);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2021 Lightbend Inc.
//
// 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 com.example.replicated.set.domain;

import "akkaserverless/annotations.proto";

option java_outer_classname = "SomeScalarSetDomain";

option (akkaserverless.file).replicated_entity = {
name: "SomeScalarSet"
entity_type: "some-scalar-set"
replicated_set: {
element: "string"
}
};
Loading