Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
f4dfa77f
Commit
f4dfa77f
authored
Jun 27, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adhere to coding conventions
parent
93f87bf4
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
92 additions
and
99 deletions
+92
-99
libcaf_core/caf/proxy_registry.hpp
libcaf_core/caf/proxy_registry.hpp
+4
-4
libcaf_core/src/proxy_registry.cpp
libcaf_core/src/proxy_registry.cpp
+7
-8
libcaf_io/src/basp_broker.cpp
libcaf_io/src/basp_broker.cpp
+53
-52
libcaf_io/src/instance.cpp
libcaf_io/src/instance.cpp
+4
-3
libcaf_io/src/message_queue.cpp
libcaf_io/src/message_queue.cpp
+1
-3
libcaf_io/src/worker.cpp
libcaf_io/src/worker.cpp
+5
-5
libcaf_io/test/message_queue.cpp
libcaf_io/test/message_queue.cpp
+10
-14
libcaf_io/test/worker.cpp
libcaf_io/test/worker.cpp
+8
-10
No files found.
libcaf_core/caf/proxy_registry.hpp
View file @
f4dfa77f
...
...
@@ -18,17 +18,17 @@
#pragma once
#include <mutex>
#include <utility>
#include <functional>
#include <mutex>
#include <unordered_map>
#include <utility>
#include "caf/fwd.hpp"
#include "caf/node_id.hpp"
#include "caf/actor_addr.hpp"
#include "caf/actor_cast.hpp"
#include "caf/actor_proxy.hpp"
#include "caf/exit_reason.hpp"
#include "caf/fwd.hpp"
#include "caf/node_id.hpp"
namespace
caf
{
...
...
libcaf_core/src/proxy_registry.cpp
View file @
f4dfa77f
...
...
@@ -16,18 +16,18 @@
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include <utility>
#include <algorithm>
#include <utility>
#include "caf/node_id.hpp"
#include "caf/actor_addr.hpp"
#include "caf/serializer.hpp"
#include "caf/actor_system.hpp"
#include "caf/deserializer.hpp"
#include "caf/node_id.hpp"
#include "caf/proxy_registry.hpp"
#include "caf/serializer.hpp"
#include "caf/logger.hpp"
#include "caf/actor_registry.hpp"
#include "caf/logger.hpp"
namespace
caf
{
...
...
@@ -36,8 +36,7 @@ proxy_registry::backend::~backend() {
}
proxy_registry
::
proxy_registry
(
actor_system
&
sys
,
backend
&
be
)
:
system_
(
sys
),
backend_
(
be
)
{
:
system_
(
sys
),
backend_
(
be
)
{
// nop
}
...
...
@@ -46,7 +45,7 @@ proxy_registry::~proxy_registry() {
}
size_t
proxy_registry
::
count_proxies
(
const
node_id
&
node
)
const
{
std
::
unique_lock
<
std
::
mutex
>
guard
{
mtx_
};
std
::
unique_lock
<
std
::
mutex
>
guard
{
mtx_
};
auto
i
=
proxies_
.
find
(
node
);
return
i
!=
proxies_
.
end
()
?
i
->
second
.
size
()
:
0
;
}
...
...
libcaf_io/src/basp_broker.cpp
View file @
f4dfa77f
...
...
@@ -121,6 +121,7 @@ behavior basp_broker::make_behavior() {
send
(
this
,
tick_atom
::
value
,
heartbeat_interval
);
}
return
{
// received from underlying broker implementation
[
=
](
new_data_msg
&
msg
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
msg
.
handle
));
...
...
@@ -144,11 +145,11 @@ behavior basp_broker::make_behavior() {
[
=
](
forward_atom
,
strong_actor_ptr
&
src
,
const
std
::
vector
<
strong_actor_ptr
>&
fwd_stack
,
strong_actor_ptr
&
dest
,
message_id
mid
,
const
message
&
msg
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
src
)
<<
CAF_ARG
(
dest
)
<<
CAF_ARG
(
mid
)
<<
CAF_ARG
(
msg
));
CAF_LOG_TRACE
(
CAF_ARG
(
src
)
<<
CAF_ARG
(
dest
)
<<
CAF_ARG
(
mid
)
<<
CAF_ARG
(
msg
));
if
(
!
dest
||
system
().
node
()
==
dest
->
node
())
{
CAF_LOG_WARNING
(
"cannot forward to invalid or local actor:"
<<
CAF_ARG
(
dest
));
CAF_LOG_WARNING
(
"cannot forward to invalid or local actor:"
<<
CAF_ARG
(
dest
));
return
;
}
if
(
src
&&
system
().
node
()
==
src
->
node
())
...
...
@@ -167,14 +168,13 @@ behavior basp_broker::make_behavior() {
if
(
cme
==
nullptr
||
cme
->
sender
==
nullptr
)
return
sec
::
invalid_argument
;
CAF_LOG_TRACE
(
CAF_ARG2
(
"sender"
,
cme
->
sender
)
<<
", "
<<
CAF_ARG
(
dest_node
)
<<
", "
<<
CAF_ARG
(
dest_name
)
<<
", "
<<
CAF_ARG
(
dest_node
)
<<
", "
<<
CAF_ARG
(
dest_name
)
<<
", "
<<
CAF_ARG
(
msg
));
auto
&
sender
=
cme
->
sender
;
if
(
system
().
node
()
==
sender
->
node
())
system
().
registry
().
put
(
sender
->
id
(),
sender
);
if
(
!
instance
.
dispatch
(
context
(),
sender
,
cme
->
stages
,
dest_node
,
static_cast
<
uint64_t
>
(
dest_name
),
if
(
!
instance
.
dispatch
(
context
(),
sender
,
cme
->
stages
,
dest_node
,
static_cast
<
uint64_t
>
(
dest_name
),
basp
::
header
::
named_receiver_flag
,
cme
->
mid
,
msg
))
{
detail
::
sync_request_bouncer
srb
{
exit_reason
::
remote_link_unreachable
};
...
...
@@ -198,8 +198,8 @@ behavior basp_broker::make_behavior() {
CAF_LOG_DEBUG
(
"write monitor_message:"
<<
CAF_ARG
(
proxy
));
// tell remote side we are monitoring this actor now
auto
hdl
=
route
->
hdl
;
instance
.
write_monitor_message
(
context
(),
get_buffer
(
hdl
),
proxy
->
node
(),
proxy
->
id
());
instance
.
write_monitor_message
(
context
(),
get_buffer
(
hdl
),
proxy
->
node
(),
proxy
->
id
());
flush
(
hdl
);
},
// received from underlying broker implementation
...
...
@@ -214,11 +214,11 @@ behavior basp_broker::make_behavior() {
// received from underlying broker implementation
[
=
](
const
connection_closed_msg
&
msg
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
msg
.
handle
));
// We might still have pending messages from this connection. To
make
//
sure there's no BASP worker deserializing a message, we are sending
//
us a message through the queue. This message gets delivered only
//
after all received messages up to this point were deserialized
// and delivered.
// We might still have pending messages from this connection. To
//
make sure there's no BASP worker deserializing a message, we are
//
sending us a message through the queue. This message gets
//
delivered only after all received messages up to this point were
//
deserialized
and delivered.
auto
&
q
=
instance
.
queue
();
auto
msg_id
=
q
.
new_id
();
q
.
push
(
context
(),
msg_id
,
ctrl
(),
...
...
@@ -245,8 +245,8 @@ behavior basp_broker::make_behavior() {
// received from middleman actor
[
=
](
publish_atom
,
doorman_ptr
&
ptr
,
uint16_t
port
,
const
strong_actor_ptr
&
whom
,
std
::
set
<
std
::
string
>&
sigs
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
ptr
)
<<
CAF_ARG
(
port
)
<<
CAF_ARG
(
whom
)
<<
CAF_ARG
(
sigs
));
CAF_LOG_TRACE
(
CAF_ARG
(
ptr
)
<<
CAF_ARG
(
port
)
<<
CAF_ARG
(
whom
)
<<
CAF_ARG
(
sigs
));
CAF_ASSERT
(
ptr
!=
nullptr
);
add_doorman
(
std
::
move
(
ptr
));
if
(
whom
)
...
...
@@ -284,8 +284,7 @@ behavior basp_broker::make_behavior() {
[
&
](
const
strong_actor_ptr
&
,
uint16_t
x
)
->
error
{
close
(
hdl_by_port
(
x
));
return
none
;
}
);
});
if
(
instance
.
remove_published_actor
(
whom
,
port
,
&
cb
)
==
0
)
return
sec
::
no_actor_published_at_port
;
return
unit
;
...
...
@@ -293,8 +292,8 @@ behavior basp_broker::make_behavior() {
[
=
](
close_atom
,
uint16_t
port
)
->
result
<
void
>
{
if
(
port
==
0
)
return
sec
::
cannot_close_invalid_port
;
// It is well-defined behavior to not have an actor published here,
hence
// the result can be ignored safely.
// It is well-defined behavior to not have an actor published here,
//
hence
the result can be ignored safely.
instance
.
remove_published_actor
(
port
,
nullptr
);
auto
res
=
close
(
hdl_by_port
(
port
));
if
(
res
)
...
...
@@ -314,8 +313,8 @@ behavior basp_broker::make_behavior() {
},
[
=
](
tick_atom
,
size_t
interval
)
{
instance
.
handle_heartbeat
(
context
());
delayed_send
(
this
,
std
::
chrono
::
milliseconds
{
interval
},
tick_atom
::
value
,
interval
);
delayed_send
(
this
,
std
::
chrono
::
milliseconds
{
interval
},
tick_atom
::
value
,
interval
);
}};
}
...
...
@@ -325,9 +324,8 @@ proxy_registry* basp_broker::proxy_registry_ptr() {
resumable
::
resume_result
basp_broker
::
resume
(
execution_unit
*
ctx
,
size_t
mt
)
{
ctx
->
proxy_registry_ptr
(
&
instance
.
proxies
());
auto
guard
=
detail
::
make_scope_guard
([
=
]
{
ctx
->
proxy_registry_ptr
(
nullptr
);
});
auto
guard
=
detail
::
make_scope_guard
(
[
=
]
{
ctx
->
proxy_registry_ptr
(
nullptr
);
});
return
super
::
resume
(
ctx
,
mt
);
}
...
...
@@ -348,8 +346,9 @@ strong_actor_ptr basp_broker::make_proxy(node_id nid, actor_id aid) {
// create proxy and add functor that will be called if we
// receive a basp::down_message
actor_config
cfg
;
auto
res
=
make_actor
<
forwarding_actor_proxy
,
strong_actor_ptr
>
(
aid
,
nid
,
&
(
system
()),
cfg
,
this
);
auto
res
=
make_actor
<
forwarding_actor_proxy
,
strong_actor_ptr
>
(
aid
,
nid
,
&
(
system
()),
cfg
,
this
);
strong_actor_ptr
selfptr
{
ctrl
()};
res
->
get
()
->
attach_functor
([
=
](
const
error
&
rsn
)
{
mm
->
backend
().
post
([
=
]
{
...
...
@@ -406,8 +405,8 @@ void basp_broker::send_basp_down_message(const node_id& nid, actor_id aid,
CAF_LOG_TRACE
(
CAF_ARG
(
nid
)
<<
CAF_ARG
(
aid
)
<<
CAF_ARG
(
rsn
));
auto
path
=
instance
.
tbl
().
lookup
(
nid
);
if
(
!
path
)
{
CAF_LOG_INFO
(
"cannot send exit message for proxy, no route to host:"
<<
CAF_ARG
(
nid
));
CAF_LOG_INFO
(
"cannot send exit message for proxy, no route to host:"
<<
CAF_ARG
(
nid
));
return
;
}
instance
.
write_down_message
(
context
(),
get_buffer
(
path
->
hdl
),
nid
,
aid
,
rsn
);
...
...
@@ -460,6 +459,7 @@ void basp_broker::learned_new_node(const node_id& nid) {
// skip messages until we receive the initial ok_atom
tself
->
set_default_handler
(
skip
);
return
{
[
=
](
ok_atom
,
const
std
::
string
&
/* key == "info" */
,
const
strong_actor_ptr
&
config_serv
,
const
std
::
string
&
/* name */
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
config_serv
));
...
...
@@ -468,22 +468,19 @@ void basp_broker::learned_new_node(const node_id& nid) {
if
(
!
config_serv
)
return
;
tself
->
monitor
(
config_serv
);
tself
->
become
(
[
=
](
spawn_atom
,
std
::
string
&
type
,
message
&
args
)
tself
->
become
([
=
](
spawn_atom
,
std
::
string
&
type
,
message
&
args
)
->
delegated
<
strong_actor_ptr
,
std
::
set
<
std
::
string
>>
{
CAF_LOG_TRACE
(
CAF_ARG
(
type
)
<<
CAF_ARG
(
args
));
tself
->
delegate
(
actor_cast
<
actor
>
(
std
::
move
(
config_serv
)),
get_atom
::
value
,
std
::
move
(
type
),
std
::
move
(
args
));
get_atom
::
value
,
std
::
move
(
type
),
std
::
move
(
args
));
return
{};
}
);
});
},
after
(
std
::
chrono
::
minutes
(
5
))
>>
[
=
]
{
after
(
std
::
chrono
::
minutes
(
5
))
>>
[
=
]
{
CAF_LOG_INFO
(
"no spawn server found:"
<<
CAF_ARG
(
nid
));
tself
->
quit
();
}
};
}};
});
spawn_servers
.
emplace
(
nid
,
tmp
);
using
namespace
detail
;
...
...
@@ -536,8 +533,12 @@ void basp_broker::set_context(connection_handle hdl) {
auto
i
=
ctx
.
find
(
hdl
);
if
(
i
==
ctx
.
end
())
{
CAF_LOG_DEBUG
(
"create new BASP context:"
<<
CAF_ARG
(
hdl
));
basp
::
header
hdr
{
basp
::
message_type
::
server_handshake
,
0
,
0
,
0
,
invalid_actor_id
,
invalid_actor_id
};
basp
::
header
hdr
{
basp
::
message_type
::
server_handshake
,
0
,
0
,
0
,
invalid_actor_id
,
invalid_actor_id
};
i
=
ctx
.
emplace
(
hdl
,
basp
::
endpoint_context
{
basp
::
await_header
,
hdr
,
hdl
,
none
,
0
,
0
,
none
})
...
...
libcaf_io/src/instance.cpp
View file @
f4dfa77f
...
...
@@ -454,9 +454,10 @@ bool instance::handle(execution_unit* ctx, connection_handle hdl, header& hdr,
if
(
dest_node
==
this_node_
)
{
// Delay this message to make sure we don't skip in-flight messages.
auto
msg_id
=
queue_
.
new_id
();
auto
ptr
=
make_mailbox_element
(
nullptr
,
make_message_id
(),
{},
delete_atom
::
value
,
source_node
,
hdr
.
source_actor
,
std
::
move
(
fail_state
));
auto
ptr
=
make_mailbox_element
(
nullptr
,
make_message_id
(),
{},
delete_atom
::
value
,
source_node
,
hdr
.
source_actor
,
std
::
move
(
fail_state
));
queue_
.
push
(
callee_
.
current_execution_unit
(),
msg_id
,
callee_
.
this_actor
(),
std
::
move
(
ptr
));
}
else
{
...
...
libcaf_io/src/message_queue.cpp
View file @
f4dfa77f
...
...
@@ -58,9 +58,7 @@ void message_queue::push(execution_unit* ctx, uint64_t id,
return
;
}
// Get the insertion point.
auto
pred
=
[
&
](
const
actor_msg
&
x
)
{
return
x
.
id
>=
id
;
};
auto
pred
=
[
&
](
const
actor_msg
&
x
)
{
return
x
.
id
>=
id
;
};
pending
.
emplace
(
std
::
find_if
(
first
,
last
,
pred
),
actor_msg
{
id
,
std
::
move
(
receiver
),
std
::
move
(
content
)});
}
...
...
libcaf_io/src/worker.cpp
View file @
f4dfa77f
libcaf_io/test/message_queue.cpp
View file @
f4dfa77f
...
...
@@ -31,11 +31,9 @@ using namespace caf;
namespace
{
behavior
testee_impl
()
{
return
{
[](
ok_atom
,
int
)
{
return
{[](
ok_atom
,
int
)
{
// nop
}
};
}};
}
struct
fixture
:
test_coordinator_fixture
<>
{
...
...
@@ -59,8 +57,7 @@ struct fixture : test_coordinator_fixture<> {
}
};
}
// namespace <anonymous>
}
// namespace
CAF_TEST_FIXTURE_SCOPE
(
message_queue_tests
,
fixture
)
...
...
@@ -77,7 +74,7 @@ CAF_TEST(ascending IDs) {
CAF_CHECK_EQUAL
(
queue
.
next_undelivered
,
0u
);
}
CAF_TEST
(
push
order
0
-
1
-
2
)
{
CAF_TEST
(
push
order
0
-
1
-
2
)
{
acquire_ids
(
3
);
push
(
0
);
expect
((
ok_atom
,
int
),
from
(
self
).
to
(
testee
).
with
(
_
,
0
));
...
...
@@ -87,7 +84,7 @@ CAF_TEST(push order 0-1-2) {
expect
((
ok_atom
,
int
),
from
(
self
).
to
(
testee
).
with
(
_
,
2
));
}
CAF_TEST
(
push
order
0
-
2
-
1
)
{
CAF_TEST
(
push
order
0
-
2
-
1
)
{
acquire_ids
(
3
);
push
(
0
);
expect
((
ok_atom
,
int
),
from
(
self
).
to
(
testee
).
with
(
_
,
0
));
...
...
@@ -98,7 +95,7 @@ CAF_TEST(push order 0-2-1) {
expect
((
ok_atom
,
int
),
from
(
self
).
to
(
testee
).
with
(
_
,
2
));
}
CAF_TEST
(
push
order
1
-
0
-
2
)
{
CAF_TEST
(
push
order
1
-
0
-
2
)
{
acquire_ids
(
3
);
push
(
1
);
disallow
((
ok_atom
,
int
),
from
(
self
).
to
(
testee
));
...
...
@@ -109,8 +106,7 @@ CAF_TEST(push order 1-0-2) {
expect
((
ok_atom
,
int
),
from
(
self
).
to
(
testee
).
with
(
_
,
2
));
}
CAF_TEST
(
push
order
1
-
2
-
0
)
{
CAF_TEST
(
push
order
1
-
2
-
0
)
{
acquire_ids
(
3
);
push
(
1
);
disallow
((
ok_atom
,
int
),
from
(
self
).
to
(
testee
));
...
...
@@ -122,7 +118,7 @@ CAF_TEST(push order 1-2-0) {
expect
((
ok_atom
,
int
),
from
(
self
).
to
(
testee
).
with
(
_
,
2
));
}
CAF_TEST
(
push
order
2
-
0
-
1
)
{
CAF_TEST
(
push
order
2
-
0
-
1
)
{
acquire_ids
(
3
);
push
(
2
);
disallow
((
ok_atom
,
int
),
from
(
self
).
to
(
testee
));
...
...
@@ -133,7 +129,7 @@ CAF_TEST(push order 2-0-1) {
expect
((
ok_atom
,
int
),
from
(
self
).
to
(
testee
).
with
(
_
,
2
));
}
CAF_TEST
(
push
order
2
-
1
-
0
)
{
CAF_TEST
(
push
order
2
-
1
-
0
)
{
acquire_ids
(
3
);
push
(
2
);
disallow
((
ok_atom
,
int
),
from
(
self
).
to
(
testee
));
...
...
libcaf_io/test/worker.cpp
View file @
f4dfa77f
...
...
@@ -36,11 +36,9 @@ using namespace caf;
namespace
{
behavior
testee_impl
()
{
return
{
[](
ok_atom
)
{
return
{[](
ok_atom
)
{
// nop
}
};
}};
}
class
mock_actor_proxy
:
public
actor_proxy
{
...
...
@@ -61,7 +59,7 @@ public:
class
mock_proxy_registry_backend
:
public
proxy_registry
::
backend
{
public:
mock_proxy_registry_backend
(
actor_system
&
sys
)
:
sys_
(
sys
)
{
//nop
//
nop
}
strong_actor_ptr
make_proxy
(
node_id
nid
,
actor_id
aid
)
override
{
...
...
@@ -98,7 +96,7 @@ struct fixture : test_coordinator_fixture<> {
}
};
}
// namespace
<anonymous>
}
// namespace
CAF_TEST_FIXTURE_SCOPE
(
worker_tests
,
fixture
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment