{
26 | Class extends ElasticActor> getActorClass();
27 |
28 | void postCreate(ActorRef actorRef,T actorState);
29 |
30 | void postActivate(ActorRef actorRef,T actorState, @Nullable String previousVersion);
31 |
32 | void prePassivate(ActorRef actorRef,T actorState);
33 |
34 | void preDestroy(ActorRef actorRef,T actorState);
35 | }
36 |
--------------------------------------------------------------------------------
/main/spi/src/main/java/org/elasticsoftware/elasticactors/cluster/ClusterService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.cluster;
19 |
20 | /**
21 | * @author Joost van de Wijgerd
22 | */
23 | public interface ClusterService {
24 | void reportReady() throws Exception;
25 |
26 | void reportPlannedShutdown();
27 |
28 | void addEventListener(ClusterEventListener eventListener);
29 |
30 | void removeEventListener(ClusterEventListener eventListener);
31 |
32 | void sendMessage(String memberToken, byte[] message) throws Exception;
33 |
34 | void setClusterMessageHandler(ClusterMessageHandler clusterMessageHandler);
35 | }
36 |
--------------------------------------------------------------------------------
/main/core/src/main/java/org/elasticsoftware/elasticactors/util/concurrent/disruptor/ThreadBoundEventWrapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.util.concurrent.disruptor;
19 |
20 | import org.elasticsoftware.elasticactors.util.concurrent.ThreadBoundEvent;
21 |
22 | /**
23 | * @author Joost van de Wijgerd
24 | */
25 | public final class ThreadBoundEventWrapper {
26 | private ThreadBoundEvent wrappedEvent;
27 |
28 | public ThreadBoundEvent getWrappedEvent() {
29 | return wrappedEvent;
30 | }
31 |
32 | public void setWrappedEvent(ThreadBoundEvent wrappedEvent) {
33 | this.wrappedEvent = wrappedEvent;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/main/core/src/main/java/org/elasticsoftware/elasticactors/util/concurrent/ThreadBoundExecutor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.util.concurrent;
19 |
20 | /**
21 | * ThreadBoundExecutor
22 | *
23 | *
24 | * A thread bound executor guarantees that a runnable executed on the executor that has the same key
25 | * will always be executed by the same thread.
26 | *
27 | * @param The type of the key
28 | * @author Joost van de Wijgerd
29 | */
30 | public interface ThreadBoundExecutor> {
31 |
32 | void execute(T runnable);
33 |
34 | void shutdown();
35 |
36 | int getThreadCount();
37 |
38 | void init();
39 | }
40 |
--------------------------------------------------------------------------------
/main/elasticactors-kafka/src/main/java/org/elasticsoftware/elasticactors/kafka/InternalActorContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.kafka;
19 |
20 | import org.elasticsoftware.elasticactors.ActorContext;
21 | import org.elasticsoftware.elasticactors.ActorContextHolder;
22 |
23 | /**
24 | * @author Joost van de Wijgerd
25 | */
26 | final class InternalActorContext extends ActorContextHolder {
27 |
28 | private InternalActorContext() {
29 | super();
30 | }
31 |
32 | static void setContext(ActorContext context) {
33 | threadContext.set(context);
34 | }
35 |
36 | static void clearContext() {
37 | threadContext.remove();
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/main/base/src/main/java/org/elasticsoftware/elasticactors/base/state/StringState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.base.state;
19 |
20 | import com.fasterxml.jackson.annotation.JsonCreator;
21 | import com.fasterxml.jackson.annotation.JsonProperty;
22 |
23 | /**
24 | * @author Joost van de Wijgerd
25 | */
26 | public final class StringState extends JacksonActorState {
27 | private final String stringBody;
28 |
29 | @JsonCreator
30 | public StringState(@JsonProperty("stringBody") String stringBody) {
31 | this.stringBody = stringBody;
32 | }
33 |
34 | @JsonProperty("stringBody")
35 | public String getStringBody() {
36 | return stringBody;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/main/core/src/main/java/org/elasticsoftware/elasticactors/cluster/metrics/MicrometerTagCustomizer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.cluster.metrics;
19 |
20 | import io.micrometer.core.instrument.Tags;
21 | import jakarta.annotation.Nonnull;
22 |
23 | /**
24 | * Type used to customize tags for the various metrics in the Elastic Actors framework
25 | */
26 | public interface MicrometerTagCustomizer {
27 |
28 | /**
29 | * Provides a set of tags for using with the provided component.
30 | * @param component the name of the component for which to get tags.
31 | * @return the tags for the component.
32 | */
33 | @Nonnull
34 | Tags get(@Nonnull String component);
35 | }
36 |
--------------------------------------------------------------------------------
/main/spi/src/main/java/org/elasticsoftware/elasticactors/cluster/ActorSystemEventListenerRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.cluster;
19 |
20 | import org.elasticsoftware.elasticactors.ActorRef;
21 | import org.elasticsoftware.elasticactors.ShardKey;
22 |
23 | import java.util.List;
24 |
25 | /**
26 | * @author Joost van de Wijgerd
27 | */
28 | public interface ActorSystemEventListenerRepository {
29 | void create(ShardKey shardKey, ActorSystemEvent event, ActorSystemEventListener listener);
30 |
31 | void delete(ShardKey shardKey, ActorSystemEvent event, ActorRef listenerId);
32 |
33 | List getAll(ShardKey shardKey, ActorSystemEvent event);
34 | }
35 |
--------------------------------------------------------------------------------
/main/spi/src/main/java/org/elasticsoftware/elasticactors/serialization/SerializationAccessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.serialization;
19 |
20 | public interface SerializationAccessor {
21 |
22 | /**
23 | * Return the serializer for the given message type
24 | *
25 | * @param messageClass
26 | * @param
27 | * @return
28 | */
29 | MessageSerializer getSerializer(Class messageClass);
30 |
31 | /**
32 | * Return the deserializer for the give message type
33 | *
34 | * @param messageClass
35 | * @param
36 | * @return
37 | */
38 | MessageDeserializer getDeserializer(Class messageClass);
39 | }
40 |
--------------------------------------------------------------------------------
/main/elasticactors-kafka/src/main/java/org/elasticsoftware/elasticactors/kafka/state/InMemoryPeristentActorStoreFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.kafka.state;
19 |
20 | import org.elasticsoftware.elasticactors.ShardKey;
21 | import org.elasticsoftware.elasticactors.serialization.Deserializer;
22 | import org.elasticsoftware.elasticactors.state.PersistentActor;
23 |
24 | public final class InMemoryPeristentActorStoreFactory implements PersistentActorStoreFactory {
25 | @Override
26 | public PersistentActorStore create(ShardKey shardKey, Deserializer> deserializer) {
27 | return new InMemoryPersistentActorStore(shardKey, deserializer);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/main/elasticactors-kafka/src/main/java/org/elasticsoftware/elasticactors/kafka/ManagedActorContainer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.kafka;
19 |
20 | import com.google.common.cache.Cache;
21 | import org.elasticsoftware.elasticactors.ActorRef;
22 | import org.elasticsoftware.elasticactors.state.PersistentActor;
23 |
24 | public interface ManagedActorContainer {
25 | PersistentActor getPersistentActor(ActorRef actorRef);
26 |
27 | void persistActor(PersistentActor persistentActor);
28 |
29 | void deleteActor(PersistentActor persistentActor);
30 |
31 | boolean containsKey(ActorRef actorRef);
32 |
33 | K getKey();
34 |
35 | Cache> getActorCache();
36 | }
37 |
--------------------------------------------------------------------------------
/main/core/src/main/protobuf/elasticactors.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package org.elasticsoftware.elasticactors.serialization.protobuf;
4 |
5 |
6 | option optimize_for = SPEED;
7 |
8 | // WARNING:
9 | // you must not change the tag numbers of any existing fields.
10 | // you must not add or delete any required fields.
11 | // you may delete optional or repeated fields.
12 | // you may add new optional or repeated fields but you must use fresh tag numbers (i.e. tag numbers that were never
13 | // used in this protocol buffer, not even by deleted fields).
14 |
15 | message ActorSystemEventListener {
16 | optional string actorId = 1;
17 | optional string messageClass = 2;
18 | optional bytes message = 3;
19 | optional string messageQueueAffinityKey = 4;
20 | }
21 |
22 | message PersistentActor {
23 | optional string actorRef = 1;
24 | optional string actorClass = 2;
25 | optional string actorSystemVersion = 3;
26 | optional bytes state = 4;
27 | optional string shardKey = 5;
28 | repeated Subscriber subscribers = 6;
29 | repeated Subscription subscriptions = 7;
30 | }
31 |
32 | message Subscriber {
33 | optional string subscriberRef = 1;
34 | optional string messageName = 2;
35 | optional uint64 leases = 3;
36 | }
37 |
38 | message Subscription {
39 | optional string publisherRef = 1;
40 | optional string messageName = 2;
41 | optional bool cancelled = 3;
42 | }
--------------------------------------------------------------------------------
/main/elasticactors-kafka/src/main/java/org/elasticsoftware/elasticactors/kafka/cluster/InternalSubscriberContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.kafka.cluster;
19 |
20 | import org.elasticsoftware.elasticactors.SubscriberContext;
21 | import org.elasticsoftware.elasticactors.SubscriberContextHolder;
22 |
23 | /**
24 | * @author Joost van de Wijgerd
25 | */
26 | final class InternalSubscriberContext extends SubscriberContextHolder {
27 | private InternalSubscriberContext() {
28 | super();
29 | }
30 |
31 | static void setContext(SubscriberContext context) {
32 | threadContext.set(context);
33 | }
34 |
35 | static void clearContext() {
36 | threadContext.remove();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/main/runtime/src/main/java/org/elasticsoftware/elasticactors/cluster/HashingNodeSelectorFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.cluster;
19 |
20 | import org.elasticsoftware.elasticactors.PhysicalNode;
21 | import org.elasticsoftware.elasticactors.messaging.Hasher;
22 |
23 | import java.util.List;
24 |
25 | /**
26 | * @author Joost van de Wijgerd
27 | */
28 | public final class HashingNodeSelectorFactory implements NodeSelectorFactory {
29 | @Override
30 | public NodeSelector create(Hasher hasher, List nodes) {
31 | return new HashingNodeSelector(hasher, nodes);
32 | }
33 |
34 | @Override
35 | public void start() throws Exception {
36 | // nothing to do
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/main/test/src/test/java/org/elasticsoftware/elasticactors/test/common/GetActorName.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.test.common;
19 |
20 | import org.elasticsoftware.elasticactors.base.serialization.JacksonSerializationFramework;
21 | import org.elasticsoftware.elasticactors.serialization.Message;
22 |
23 | import static org.elasticsoftware.elasticactors.serialization.Message.LogFeature.CONTENTS;
24 | import static org.elasticsoftware.elasticactors.serialization.Message.LogFeature.TIMING;
25 |
26 | @Message(
27 | serializationFramework = JacksonSerializationFramework.class,
28 | immutable = true,
29 | logBodyOnError = true,
30 | logOnReceive = {TIMING, CONTENTS})
31 | public class GetActorName {
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/main/core/src/main/java/org/elasticsoftware/elasticactors/util/concurrent/WrapperThreadBoundRunnable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.util.concurrent;
19 |
20 | import jakarta.annotation.Nonnull;
21 |
22 | public interface WrapperThreadBoundRunnable extends ThreadBoundRunnable {
23 |
24 | @Nonnull
25 | ThreadBoundRunnable getWrappedRunnable();
26 |
27 | @Nonnull
28 | default ThreadBoundRunnable unwrap() {
29 | ThreadBoundRunnable unwrapped = getWrappedRunnable();
30 | while (unwrapped instanceof WrapperThreadBoundRunnable) {
31 | unwrapped = ((WrapperThreadBoundRunnable) unwrapped).getWrappedRunnable();
32 | }
33 | return unwrapped;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/main/elasticactors-kafka-testapp/src/config/system.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2013 - 2025 The Original Authors
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 | #
17 |
18 | jwt.sharedSecret=7bc13c0080ee11e3baa70800200c9a66
19 | jwt.audience=local.getbux.com
20 | #ea.node.port=9090
21 | ea.node.config.location=classpath:config.yaml
22 | ea.cluster=kafkatest.local.getbux.com
23 | ea.cluster.discovery.nodes=tcp://localhost:9090,tcp://localhost:9091,tcp://localhost:9092
24 | ea.nodeCache.maximumSize=1024
25 | ea.shardCache.maximumSize=10240
26 | ea.actorRefCache.maximumSize=10240
27 | ea.shardThreads.workerCount=1
28 | ea.persistentActorRepository.compressionThreshold=2048
29 | ea.base.useAfterburner=true
30 | ea.kafka.bootstrapServers=192.168.99.100:32400,192.168.99.100:32401,192.168.99.100:32402
31 | #ea.kafka.persistentActorStore.factoryClass=ChronicleMapPersistentActorStoreFactory
--------------------------------------------------------------------------------
/main/messaging/src/main/java/org/elasticsoftware/elasticactors/messaging/internal/MessageQueueBoundPayload.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.messaging.internal;
19 |
20 | import jakarta.annotation.Nullable;
21 |
22 | /**
23 | * This interface is used to allow messages sent to a container to still be hashed to
24 | * the same queue as the messages to specific actors, when using multiple queues per container.
25 | *
26 | * e.g. a CreateActorMessage message has to go to the same broker and/or in-memory queue as the
27 | * messages that are to be sent to the actor that was created, so it can be processed first.
28 | */
29 | interface MessageQueueBoundPayload {
30 |
31 | @Nullable
32 | String getMessageQueueAffinityKey();
33 | }
34 |
--------------------------------------------------------------------------------
/main/base/src/main/java/org/elasticsoftware/elasticactors/base/serialization/JacksonActorRefSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.base.serialization;
19 |
20 | import com.fasterxml.jackson.core.JsonGenerator;
21 | import com.fasterxml.jackson.databind.JsonSerializer;
22 | import com.fasterxml.jackson.databind.SerializerProvider;
23 | import org.elasticsoftware.elasticactors.ActorRef;
24 |
25 | import java.io.IOException;
26 |
27 | /**
28 | *
29 | */
30 | public final class JacksonActorRefSerializer extends JsonSerializer {
31 | @Override
32 | public void serialize(ActorRef value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
33 | jgen.writeString(value.toString());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/main/core/src/main/java/org/elasticsoftware/elasticactors/cluster/messaging/ShardReleasedMessage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.cluster.messaging;
19 |
20 | import java.io.Serializable;
21 |
22 | /**
23 | * @author Joost van de Wijgerd
24 | */
25 | public final class ShardReleasedMessage implements Serializable {
26 | private final String actorSystem;
27 | private final int shardId;
28 |
29 | public ShardReleasedMessage(String actorSystem, int shardId) {
30 | this.actorSystem = actorSystem;
31 | this.shardId = shardId;
32 | }
33 |
34 | public String getActorSystem() {
35 | return actorSystem;
36 | }
37 |
38 | public int getShardId() {
39 | return shardId;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/main/base/src/main/java/org/elasticsoftware/elasticactors/base/state/AliasActorState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.base.state;
19 |
20 | import com.fasterxml.jackson.annotation.JsonCreator;
21 | import com.fasterxml.jackson.annotation.JsonProperty;
22 | import org.elasticsoftware.elasticactors.ActorRef;
23 |
24 | /**
25 | * @author Joost van de Wijgerd
26 | */
27 | public final class AliasActorState extends JacksonActorState {
28 | private final ActorRef aliasedActor;
29 |
30 | @JsonCreator
31 | public AliasActorState(@JsonProperty("aliasedActor") ActorRef aliasedActor) {
32 | this.aliasedActor = aliasedActor;
33 | }
34 |
35 | public ActorRef getAliasedActor() {
36 | return aliasedActor;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/main/elasticactors-kafka/src/main/java/org/elasticsoftware/elasticactors/kafka/cluster/ActorLifecycleFunction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.kafka.cluster;
19 |
20 |
21 | import org.elasticsoftware.elasticactors.ActorRef;
22 | import org.elasticsoftware.elasticactors.ElasticActor;
23 | import org.elasticsoftware.elasticactors.cluster.InternalActorSystem;
24 | import org.elasticsoftware.elasticactors.messaging.InternalMessage;
25 | import org.elasticsoftware.elasticactors.state.PersistentActor;
26 |
27 | @FunctionalInterface
28 | public interface ActorLifecycleFunction {
29 | Boolean apply(InternalActorSystem actorSystem, PersistentActor persistentActor, ElasticActor receiver, ActorRef receiverRef, InternalMessage internalMessage);
30 | }
31 |
--------------------------------------------------------------------------------
/main/api/src/main/java/org/elasticsoftware/elasticactors/MessageDeliveryException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors;
19 |
20 | /**
21 | * @author Joost van de Wijgerd
22 | */
23 | public final class MessageDeliveryException extends RuntimeException {
24 | private final boolean recoverable;
25 |
26 | public MessageDeliveryException(String message,boolean recoverable) {
27 | super(message);
28 | this.recoverable = recoverable;
29 | }
30 |
31 | public MessageDeliveryException(String message, Throwable cause, boolean recoverable) {
32 | super(message, cause);
33 | this.recoverable = recoverable;
34 | }
35 |
36 | public boolean isRecoverable() {
37 | return recoverable;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/main/core/src/main/java/org/elasticsoftware/elasticactors/cluster/tasks/reactivestreams/InternalSubscriberContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.cluster.tasks.reactivestreams;
19 |
20 | import org.elasticsoftware.elasticactors.SubscriberContext;
21 | import org.elasticsoftware.elasticactors.SubscriberContextHolder;
22 |
23 | /**
24 | * @author Joost van de Wijgerd
25 | */
26 | public final class InternalSubscriberContext extends SubscriberContextHolder {
27 | private InternalSubscriberContext() {
28 | super();
29 | }
30 |
31 | static void setContext(SubscriberContext context) {
32 | threadContext.set(context);
33 | }
34 |
35 | static void clearContext() {
36 | threadContext.remove();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/main/spi/src/main/java/org/elasticsoftware/elasticactors/cluster/ShardAccessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.cluster;
19 |
20 | import org.elasticsoftware.elasticactors.ActorShard;
21 |
22 | /**
23 | * @author Joost van de Wijgerd
24 | */
25 | public interface ShardAccessor {
26 | /**
27 | * Return the {@link org.elasticsoftware.elasticactors.ActorShard} that belongs to the given path.
28 | *
29 | * @param actorPath
30 | * @return
31 | */
32 | ActorShard getShard(String actorPath);
33 |
34 | /**
35 | * Return an ActorShard with the given shardId
36 | *
37 | * @param shardId
38 | * @return
39 | */
40 | ActorShard getShard(int shardId);
41 |
42 | int getNumberOfShards();
43 | }
44 |
--------------------------------------------------------------------------------
/main/test/src/main/java/org/elasticsoftware/elasticactors/test/messaging/UnsupportedMessageQueueFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.test.messaging;
19 |
20 | import org.elasticsoftware.elasticactors.messaging.MessageHandler;
21 | import org.elasticsoftware.elasticactors.messaging.MessageQueue;
22 | import org.elasticsoftware.elasticactors.messaging.MessageQueueFactory;
23 |
24 | /**
25 | * @author Joost van de Wijgerd
26 | */
27 | public final class UnsupportedMessageQueueFactory implements MessageQueueFactory {
28 | @Override
29 | public MessageQueue create(String name, MessageHandler messageHandler) throws Exception {
30 | throw new UnsupportedOperationException("Remote Queues not supported in test mode");
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/main/elasticactors-kafka/src/main/java/org/elasticsoftware/elasticactors/kafka/KafkaTransactionContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 - 2025 The Original Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package org.elasticsoftware.elasticactors.kafka;
19 |
20 | import org.apache.kafka.clients.producer.KafkaProducer;
21 |
22 | public final class KafkaTransactionContext {
23 | private static final ThreadLocal> transactionalProducer = new ThreadLocal<>();
24 |
25 | static void setTransactionalProducer(KafkaProducer