Skip to content

Package: MessageListenerAdapter

MessageListenerAdapter

nameinstructionbranchcomplexitylinemethod
MessageListenerAdapter(Object, Method, ExecutorWithPriority, ActorActivatorStats)
M: 43 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lambda$notify$0(DefaultCollaboration, Object)
M: 45 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
notify(Object)
M: 36 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * *********************************************************************************************************************
3: *
4: * TheseFoolishThings: Miscellaneous utilities
5: * http://tidalwave.it/projects/thesefoolishthings
6: *
7: * Copyright (C) 2009 - 2023 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/thesefoolishthings-src
23: * git clone https://github.com/tidalwave-it/thesefoolishthings-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.actor.impl;
28:
29: import java.lang.reflect.Method;
30: import javax.annotation.Nonnull;
31: import it.tidalwave.actor.annotation.Message;
32: import it.tidalwave.actor.spi.ActorActivatorStats;
33: import it.tidalwave.messagebus.MessageBus;
34: import lombok.RequiredArgsConstructor;
35: import lombok.extern.slf4j.Slf4j;
36:
37: /***********************************************************************************************************************
38: *
39: * @author Fabrizio Giudici
40: *
41: **********************************************************************************************************************/
42:•@RequiredArgsConstructor @Slf4j
43: class MessageListenerAdapter<Topic> implements MessageBus.Listener<Topic>
44: {
45: @Nonnull
46: private final Object owner;
47:
48: @Nonnull
49: private final Method method;
50:
51: @Nonnull
52: private final ExecutorWithPriority executor;
53:
54: @Nonnull
55: private final ActorActivatorStats stats;
56:
57: @Override
58: public void notify (@Nonnull final Topic message)
59: {
60: log.trace("notify({})", message);
61: final DefaultCollaboration collaboration = DefaultCollaboration.getCollaboration(message);
62: collaboration.registerPendingMessage(message);
63: stats.changePendingMessageCount(+1);
64:
65: final Runnable messageWorker = () ->
66: {
67: collaboration.bindToCurrentThread();
68: collaboration.unregisterPendingMessage(message);
69: stats.changePendingMessageCount(-1);
70:
71: try
72: {
73: stats.incrementInvocationCount();
74: method.invoke(owner, message);
75: }
76: catch (Throwable t)
77: {
78: stats.incrementInvocationErrorCount();
79: log.error("Error calling {} with {}", method, message.getClass());
80: log.error("", t);
81: }
82: finally
83: {
84: stats.incrementSuccessfulInvocationCount();
85: collaboration.unbindFromCurrentThread();
86: }
87: };
88:
89:• if (message.getClass().getAnnotation(Message.class).outOfBand())
90: {
91: executor.executeWithPriority(messageWorker);
92: }
93: else
94: {
95: executor.execute(messageWorker);
96: }
97: }
98: }
99:
100: