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
f2e3753e
Commit
f2e3753e
authored
Apr 23, 2012
by
neverlord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
consistent atom names
parent
467f3367
Changes
21
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
339 additions
and
221 deletions
+339
-221
benchmarks/PingPong.scala
benchmarks/PingPong.scala
+69
-0
benchmarks/scala_test.sh
benchmarks/scala_test.sh
+2
-1
cppa.files
cppa.files
+1
-0
cppa/abstract_actor.hpp
cppa/abstract_actor.hpp
+3
-3
cppa/actor.hpp
cppa/actor.hpp
+1
-1
cppa/actor_proxy.hpp
cppa/actor_proxy.hpp
+2
-2
cppa/any_tuple.hpp
cppa/any_tuple.hpp
+7
-1
cppa/cppa.hpp
cppa/cppa.hpp
+1
-1
cppa/detail/abstract_scheduled_actor.hpp
cppa/detail/abstract_scheduled_actor.hpp
+1
-1
cppa/detail/buffer.hpp
cppa/detail/buffer.hpp
+9
-6
src/actor_proxy.cpp
src/actor_proxy.cpp
+5
-5
src/actor_proxy_cache.cpp
src/actor_proxy_cache.cpp
+1
-1
src/converted_thread_context.cpp
src/converted_thread_context.cpp
+1
-1
src/cppa.cpp
src/cppa.cpp
+1
-1
src/mailman.cpp
src/mailman.cpp
+1
-1
src/post_office.cpp
src/post_office.cpp
+150
-143
unit_testing/main.cpp
unit_testing/main.cpp
+27
-8
unit_testing/ping_pong.cpp
unit_testing/ping_pong.cpp
+28
-15
unit_testing/ping_pong.hpp
unit_testing/ping_pong.hpp
+3
-2
unit_testing/test__remote_actor.cpp
unit_testing/test__remote_actor.cpp
+4
-2
unit_testing/test__spawn.cpp
unit_testing/test__spawn.cpp
+22
-26
No files found.
benchmarks/PingPong.scala
0 → 100644
View file @
f2e3753e
import
scala.actors.Actor
import
scala.actors.Actor._
import
akka.actor.Actor.actorOf
import
akka.actor.Actor.remote
import
Console.println
case
object
KickOff
case
class
Ping
(
value
:
Int
)
case
class
Pong
(
value
:
Int
)
object
global
{
val
latch
=
new
java
.
util
.
concurrent
.
CountDownLatch
(
1
)
}
class
PingActor
(
pong
:
akka.actor.ActorRef
)
extends
akka
.
actor
.
Actor
{
def
receive
=
{
case
Pong
(
1000
)
=>
{
//println("Received final pong")
global
.
latch
.
countDown
self
.
exit
}
case
Pong
(
value
:
Int
)
=>
{
//println("Received Pong(" + value + ")")
self
.
reply
(
Ping
(
value
))
}
case
KickOff
=>
{
pong
!
Ping
(
0
)
}
}
}
class
PongActor
extends
akka
.
actor
.
Actor
{
def
receive
=
{
case
Ping
(
value
:
Int
)
=>
{
//println("Received Ping(" + value + ")")
self
.
reply
(
Pong
(
value
+
1
))
}
}
}
object
pingApp
{
def
main
(
args
:
Array
[
String
])
=
{
if
(
args
.
size
!=
2
)
{
println
(
"usage: pingApp (host) (port)"
)
println
(
" (connects to pong-service of (host) on given port)"
)
System
.
exit
(
1
)
}
val
pong
=
remote
.
actorFor
(
"pong-service"
,
args
(
0
),
args
(
1
).
toInt
)
val
myPing
=
actorOf
(
new
PingActor
(
pong
)).
start
remote
.
start
(
"localhost"
,
64002
).
register
(
"ping-service"
,
myPing
)
myPing
!
KickOff
global
.
latch
.
await
remote
.
shutdown
System
.
exit
(
0
)
}
}
object
pongApp
{
def
main
(
args
:
Array
[
String
])
=
{
if
(
args
.
size
!=
1
)
{
println
(
"usage: pongApp (port)"
)
println
(
" (binds pong-service to given port)"
)
System
.
exit
(
1
)
}
val
myPong
=
actorOf
(
new
PongActor
).
start
remote
.
start
(
"localhost"
,
args
(
0
).
toInt
)
.
register
(
"pong-service"
,
myPong
)
}
}
benchmarks/scala_test.sh
View file @
f2e3753e
#!/bin/bash
#export JAVA_OPTS="-Xmx1024"
#echo "scala -cp /home/neverlord/akka-microkernel-1.2/lib/akka/akka-actor-1.2.jar $@" | ./exec.sh
echo
"scala -cp /home/neverlord/akka-microkernel-1.2/lib/akka/akka-actor-1.2.jar
$@
"
| ./exec.sh
JARS
=
/home/neverlord/akka-microkernel-1.2/lib/akka/activation-1.1.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/akka-actor-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/akka-actor-tests-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/akka-amqp-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/akka-beanstalk-mailbox-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/akka-camel-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/akka-camel-typed-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/akka-dispatcher-extras-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/akka-file-mailbox-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/akka-http-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/akka-kernel-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/akka-mailboxes-common-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/akka-redis-mailbox-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/akka-remote-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/akka-scalaz-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/akka-slf4j-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/akka-spring-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/akka-stm-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/akka-testkit-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/akka-typed-actor-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/amqp-client-2.5.0.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/aopalliance-1.0.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/asm-3.1.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/aspectwerkz-2.2.3.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/beanstalk_client-1.4.5.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/camel-core-2.7.0.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/commons-cli-1.1.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/commons-codec-1.4.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/commons-io-2.0.1.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/commons-logging-1.1.1.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/commons-management-1.0.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/commons-pool-1.5.5.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/dispatch-json_2.9.0-0.8.1.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/guice-all-2.0.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/h2-lzf-1.0.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/hawtdispatch-1.1.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/hawtdispatch-scala-1.1.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jackson-core-asl-1.8.0.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jackson-mapper-asl-1.8.0.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jaxb-api-2.1.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jaxb-impl-2.1.12.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jersey-core-1.3.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jersey-json-1.3.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jersey-scala-1.3.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jersey-server-1.3.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jettison-1.1.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jetty-continuation-7.4.0.v20110414.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jetty-http-7.4.0.v20110414.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jetty-io-7.4.0.v20110414.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jetty-security-7.4.0.v20110414.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jetty-server-7.4.0.v20110414.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jetty-servlet-7.4.0.v20110414.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jetty-util-7.4.0.v20110414.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jetty-xml-7.4.0.v20110414.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jsr250-api-1.0.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jsr311-api-1.1.1.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/jsr311-api-1.1.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/junit-4.8.1.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/log4j-1.2.16.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/multiverse-alpha-0.6.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/netty-3.2.5.Final.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/objenesis-1.2.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/protobuf-java-2.4.1.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/redisclient_2.9.0-2.3.1.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/scalaz-core_2.9.0-1-6.0.1.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/servlet-api-2.5.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/sjson_2.9.0-0.11.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/slf4j-api-1.5.8.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/slf4j-api-1.6.0.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/slf4j-log4j12-1.5.8.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/spring-aop-3.0.5.RELEASE.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/spring-asm-3.0.5.RELEASE.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/spring-beans-3.0.5.RELEASE.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/spring-context-3.0.5.RELEASE.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/spring-core-3.0.5.RELEASE.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/spring-expression-3.0.5.RELEASE.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/stax-api-1.0.1.jar:/home/neverlord/akka-microkernel-1.2/lib/akka/stax-api-1.0-2.jar
echo
"scala -cp
$JARS
$@
"
| ./exec.sh
cppa.files
View file @
f2e3753e
...
...
@@ -269,3 +269,4 @@ cppa/detail/recursive_queue_node.hpp
cppa/detail/scheduled_actor_dummy.hpp
cppa/detail/nestable_receive_actor.hpp
cppa/detail/filter_result.hpp
benchmarks/PingPong.scala
cppa/abstract_actor.hpp
View file @
f2e3753e
...
...
@@ -159,7 +159,7 @@ class abstract_actor : public Base
// send exit message without lock
if
(
reason
!=
exit_reason
::
not_exited
)
{
other
->
enqueue
(
this
,
make_cow_tuple
(
atom
(
"
:Exit
"
),
reason
));
other
->
enqueue
(
this
,
make_cow_tuple
(
atom
(
"
EXIT
"
),
reason
));
}
return
false
;
}
...
...
@@ -246,7 +246,7 @@ class abstract_actor : public Base
// send exit messages
for
(
actor_ptr
&
aptr
:
mlinks
)
{
aptr
->
enqueue
(
this
,
make_cow_tuple
(
atom
(
"
:Exit
"
),
reason
));
aptr
->
enqueue
(
this
,
make_cow_tuple
(
atom
(
"
EXIT
"
),
reason
));
}
for
(
attachable_ptr
&
ptr
:
mattachables
)
{
...
...
@@ -262,7 +262,7 @@ class abstract_actor : public Base
// send exit message if already exited
if
(
exited
())
{
other
->
enqueue
(
this
,
make_cow_tuple
(
atom
(
"
:Exit
"
),
other
->
enqueue
(
this
,
make_cow_tuple
(
atom
(
"
EXIT
"
),
m_exit_reason
.
load
()));
}
// add link if not already linked to other
...
...
cppa/actor.hpp
View file @
f2e3753e
...
...
@@ -157,7 +157,7 @@ class actor : public channel
void
link_to
(
intrusive_ptr
<
actor
>&&
other
);
/**
* @copydoc unlink_from(intrusive_ptr<actor>&)
* @copydoc
:
unlink_from(intrusive_ptr<actor>&)
*/
void
unlink_from
(
intrusive_ptr
<
actor
>&&
other
);
...
...
cppa/actor_proxy.hpp
View file @
f2e3753e
...
...
@@ -58,13 +58,13 @@ class actor_proxy : public abstract_actor<actor>
void
link_to
(
intrusive_ptr
<
actor
>&
other
);
// do not cause to send this actor an "
:Unlink
" message
// do not cause to send this actor an "
UNLINK
" message
// to the "original" remote actor
void
local_link_to
(
intrusive_ptr
<
actor
>&
other
);
void
unlink_from
(
intrusive_ptr
<
actor
>&
other
);
// do not cause to send this actor an "
:Unlink
" message
// do not cause to send this actor an "
UNLINK
" message
// to the "original" remote actor
void
local_unlink_from
(
intrusive_ptr
<
actor
>&
other
);
...
...
cppa/any_tuple.hpp
View file @
f2e3753e
...
...
@@ -33,9 +33,9 @@
#include <type_traits>
#include "cppa/cow_tuple.hpp"
#include "cppa/config.hpp"
#include "cppa/cow_ptr.hpp"
#include "cppa/cow_tuple.hpp"
#include "cppa/util/rm_ref.hpp"
#include "cppa/util/is_iterable.hpp"
...
...
@@ -273,6 +273,12 @@ inline bool operator!=(any_tuple const& lhs, any_tuple const& rhs)
return
!
(
lhs
==
rhs
);
}
template
<
typename
...
Args
>
inline
any_tuple
make_any_tuple
(
Args
&&
...
args
)
{
return
make_cow_tuple
(
std
::
forward
<
Args
>
(
args
)...);
}
}
// namespace cppa
#endif // ANY_TUPLE_HPP
cppa/cppa.hpp
View file @
f2e3753e
...
...
@@ -455,7 +455,7 @@ void unlink(actor_ptr& lhs, actor_ptr& rhs);
* @ingroup ActorManagement
* @brief Adds a unidirectional @p monitor to @p whom.
* @note Each calls to @p monitor creates a new, independent monitor.
* @pre The calling actor receives a "
:Down
" message from @p whom when
* @pre The calling actor receives a "
DOWN
" message from @p whom when
* it terminates.
*/
void
monitor
(
actor_ptr
&
whom
);
...
...
cppa/detail/abstract_scheduled_actor.hpp
View file @
f2e3753e
...
...
@@ -68,7 +68,7 @@ class abstract_scheduled_actor : public abstract_actor<scheduled_actor>
{
auto
v0
=
*
reinterpret_cast
<
const
atom_value
*>
(
msg
.
at
(
0
));
auto
v1
=
*
reinterpret_cast
<
const
std
::
uint32_t
*>
(
msg
.
at
(
1
));
if
(
v0
==
atom
(
"
:Exit
"
))
if
(
v0
==
atom
(
"
EXIT
"
))
{
if
(
this
->
m_trap_exit
==
false
)
{
...
...
cppa/detail/buffer.hpp
View file @
f2e3753e
...
...
@@ -174,12 +174,16 @@ class buffer
return
m_data
;
}
inline
bool
full
()
{
return
remaining
()
==
0
;
}
bool
append_from_file_descriptor
(
int
fd
,
bool
throw_on_error
=
false
)
{
auto
_this
=
this
;
auto
fun
=
[
_this
,
fd
]()
->
int
auto
fun
=
[
=
]()
->
int
{
return
::
read
(
fd
,
_this
->
wr_ptr
(),
_
this
->
remaining
());
return
::
read
(
fd
,
this
->
wr_ptr
(),
this
->
remaining
());
};
return
append_impl
(
fun
,
throw_on_error
);
}
...
...
@@ -187,10 +191,9 @@ class buffer
bool
append_from
(
native_socket_type
sfd
,
int
rdflags
,
bool
throw_on_error
=
false
)
{
auto
_this
=
this
;
auto
fun
=
[
_this
,
sfd
,
rdflags
]()
->
int
auto
fun
=
[
=
]()
->
int
{
return
::
recv
(
sfd
,
_this
->
wr_ptr
(),
_
this
->
remaining
(),
rdflags
);
return
::
recv
(
sfd
,
this
->
wr_ptr
(),
this
->
remaining
(),
rdflags
);
};
return
append_impl
(
fun
,
throw_on_error
);
}
...
...
src/actor_proxy.cpp
View file @
f2e3753e
...
...
@@ -64,7 +64,7 @@ void actor_proxy::enqueue(actor* sender, any_tuple msg)
{
if
(
msg
.
size
()
==
2
&&
*
(
msg
.
type_at
(
0
))
==
typeid
(
atom_value
)
&&
msg
.
get_as
<
atom_value
>
(
0
)
==
atom
(
"
:KillProxy
"
)
&&
msg
.
get_as
<
atom_value
>
(
0
)
==
atom
(
"
KILL_PROXY
"
)
&&
*
(
msg
.
type_at
(
1
))
==
typeid
(
std
::
uint32_t
))
{
cleanup
(
msg
.
get_as
<
std
::
uint32_t
>
(
1
));
...
...
@@ -80,7 +80,7 @@ void actor_proxy::link_to(intrusive_ptr<actor>& other)
// causes remote actor to link to (proxy of) other
forward_message
(
parent_process_ptr
(),
other
.
get
(),
make_cow_tuple
(
atom
(
"
:Link
"
),
other
));
make_cow_tuple
(
atom
(
"
LINK
"
),
other
));
}
}
...
...
@@ -96,7 +96,7 @@ void actor_proxy::unlink_from(intrusive_ptr<actor>& other)
// causes remote actor to unlink from (proxy of) other
forward_message
(
parent_process_ptr
(),
other
.
get
(),
make_cow_tuple
(
atom
(
"
:Unlink
"
),
other
));
make_cow_tuple
(
atom
(
"
UNLINK
"
),
other
));
}
}
...
...
@@ -113,7 +113,7 @@ bool actor_proxy::establish_backlink(intrusive_ptr<actor>& other)
// causes remote actor to unlink from (proxy of) other
forward_message
(
parent_process_ptr
(),
other
.
get
(),
make_cow_tuple
(
atom
(
"
:Link
"
),
other
));
make_cow_tuple
(
atom
(
"
LINK
"
),
other
));
}
return
result
;
}
...
...
@@ -125,7 +125,7 @@ bool actor_proxy::remove_backlink(intrusive_ptr<actor>& other)
{
forward_message
(
parent_process_ptr
(),
nullptr
,
make_cow_tuple
(
atom
(
"
:Unlink
"
),
actor_ptr
(
this
)));
make_cow_tuple
(
atom
(
"
UNLINK
"
),
actor_ptr
(
this
)));
}
return
result
;
}
...
...
src/actor_proxy_cache.cpp
View file @
f2e3753e
...
...
@@ -79,7 +79,7 @@ actor_proxy_ptr actor_proxy_cache::get(const key_tuple& key)
m_proxies
.
insert
(
std
::
make_pair
(
key
,
result
));
if
(
m_new_cb
)
m_new_cb
(
result
);
// insert to m_proxies
//result->enqueue(message(result, nullptr, atom("
:Monitor
")));
//result->enqueue(message(result, nullptr, atom("
MONITOR
")));
return
result
;
}
...
...
src/converted_thread_context.cpp
View file @
f2e3753e
...
...
@@ -42,7 +42,7 @@
namespace
cppa
{
namespace
detail
{
converted_thread_context
::
converted_thread_context
()
:
m_exit_msg_pattern
(
atom
(
"
:Exit
"
))
:
m_exit_msg_pattern
(
atom
(
"
EXIT
"
))
{
}
...
...
src/cppa.cpp
View file @
f2e3753e
...
...
@@ -45,7 +45,7 @@ class observer : public cppa::attachable
void
actor_exited
(
std
::
uint32_t
reason
)
{
using
namespace
cppa
;
send
(
m_client
,
atom
(
"
:Down
"
),
actor_ptr
(
self
),
reason
);
send
(
m_client
,
atom
(
"
DOWN
"
),
actor_ptr
(
self
),
reason
);
}
bool
matches
(
const
cppa
::
attachable
::
token
&
match_token
)
...
...
src/mailman.cpp
View file @
f2e3753e
...
...
@@ -41,7 +41,7 @@
std::cout << "[process id: " \
<< cppa::process_information::get()->process_id() \
<< "] " << arg << std::endl
//
*/
*/
#define DEBUG(unused) ((void) 0)
...
...
src/post_office.cpp
View file @
f2e3753e
This diff is collapsed.
Click to expand it.
unit_testing/main.cpp
View file @
f2e3753e
...
...
@@ -13,12 +13,13 @@
#include <iostream>
#include "test.hpp"
#include "ping_pong.hpp"
#include "cppa/cppa.hpp"
#include "cppa/cow_tuple.hpp"
#include "cppa/match.hpp"
#include "cppa/config.hpp"
#include "cppa/anything.hpp"
#include "cppa/cow_tuple.hpp"
#include "cppa/detail/demangle.hpp"
#include "cppa/uniform_type_info.hpp"
#include "cppa/process_information.hpp"
...
...
@@ -148,21 +149,40 @@ int main(int argc, char** argv)
/*
auto nao = remote_actor("192.168.1.148", 12000);
send(nao, atom("speak"), "
i am an actor! s
eriously!");
send(nao, atom("speak"), "
I am an actor! S
eriously!");
return 0;
*/
auto
args
=
get_kv_pairs
(
argc
,
argv
);
match_each
(
args
)
(
on
(
"run"
,
val
<
std
::
string
>
)
>>
[
&
](
std
::
string
const
&
what
)
on
(
"run"
,
"remote_actor"
)
>>
[
&
](
)
{
if
(
what
==
"remote_actor"
)
test__remote_actor
(
argv
[
0
],
true
,
args
);
exit
(
0
);
},
on
(
"run_ping"
,
arg_match
)
>>
[
&
](
std
::
string
const
&
num_pings
)
{
auto
ping_actor
=
spawn
(
ping
,
std
::
stoi
(
num_pings
));
std
::
uint16_t
port
=
4242
;
bool
success
=
false
;
do
{
test__remote_actor
(
argv
[
0
],
true
,
args
);
exit
(
0
);
try
{
publish
(
ping_actor
,
port
);
success
=
true
;
}
catch
(
bind_failure
&
)
{
// try next port
++
port
;
}
}
while
(
!
success
);
cout
<<
"port is "
<<
port
<<
endl
;
await_all_others_done
();
exit
(
0
);
},
on
(
"scheduler"
,
val
<
std
::
string
>
)
>>
[](
std
::
string
const
&
sched
)
{
...
...
@@ -185,7 +205,6 @@ int main(int argc, char** argv)
);
std
::
cout
<<
std
::
boolalpha
;
size_t
errors
=
0
;
//print_node_id();
RUN_TEST
(
test__ripemd_160
);
RUN_TEST
(
test__primitive_variant
);
...
...
unit_testing/ping_pong.cpp
View file @
f2e3753e
...
...
@@ -5,46 +5,59 @@
#include "cppa/cppa.hpp"
#include "cppa/to_string.hpp"
namespace
{
in
t
s_pongs
=
0
;
}
namespace
{
size_
t
s_pongs
=
0
;
}
using
std
::
cout
;
using
std
::
endl
;
using
namespace
cppa
;
in
t
pongs
()
size_
t
pongs
()
{
return
s_pongs
;
}
void
ping
()
void
ping
(
size_t
num_pings
)
{
s_pongs
=
0
;
receive_loop
do_receive
(
on
<
atom
(
"pong"
),
int
>
()
>>
[](
int
value
)
on
<
atom
(
"pong"
),
int
>
()
>>
[
&
](
int
value
)
{
//cout << to_string(self->last_dequeued()) << endl;
if
(
++
s_pongs
==
num_pings
)
{
reply
(
atom
(
"EXIT"
),
exit_reason
::
user_defined
);
}
else
{
reply
(
atom
(
"ping"
),
value
);
}
},
others
()
>>
[]()
{
++
s_pongs
;
reply
(
atom
(
"ping"
),
value
+
1
)
;
cout
<<
__FILE__
<<
" line "
<<
__LINE__
<<
": "
<<
to_string
(
self
->
last_dequeued
())
<<
endl
;
}
);
)
.
until
(
gref
(
s_pongs
)
==
num_pings
);
cout
<<
"ping is done"
<<
endl
;
}
void
pong
(
actor_ptr
ping_actor
)
{
self
->
link_to
(
ping_actor
);
// kickoff
send
(
ping_actor
,
atom
(
"pong"
),
0
);
receive_loop
(
on
(
atom
(
"ping"
),
9
)
>>
[]()
{
// terminate with non-normal exit reason
// to force ping actor to quit
self
->
quit
(
exit_reason
::
user_defined
);
},
on
<
atom
(
"ping"
),
int
>
()
>>
[](
int
value
)
{
//cout << to_string(self->last_dequeued()) << endl;
reply
(
atom
(
"pong"
),
value
+
1
);
},
others
()
>>
[]()
{
cout
<<
__FILE__
<<
" line "
<<
__LINE__
<<
": "
<<
to_string
(
self
->
last_dequeued
())
<<
endl
;
}
);
}
unit_testing/ping_pong.hpp
View file @
f2e3753e
...
...
@@ -3,10 +3,11 @@
#include "cppa/actor.hpp"
void
ping
();
void
ping
(
size_t
num_pings
);
void
pong
(
cppa
::
actor_ptr
ping_actor
);
// returns the number of messages ping received
in
t
pongs
();
size_
t
pongs
();
#endif // PING_PONG_HPP
unit_testing/test__remote_actor.cpp
View file @
f2e3753e
...
...
@@ -43,7 +43,7 @@ size_t test__remote_actor(char const* app_path, bool is_client,
return
0
;
}
CPPA_TEST
(
test__remote_actor
);
auto
ping_actor
=
spawn
(
ping
);
auto
ping_actor
=
spawn
(
ping
,
10
);
std
::
uint16_t
port
=
4242
;
bool
success
=
false
;
do
...
...
@@ -74,7 +74,9 @@ size_t test__remote_actor(char const* app_path, bool is_client,
}
});
await_all_others_done
();
CPPA_CHECK_EQUAL
(
pongs
(),
5
);
CPPA_CHECK_EQUAL
(
10
,
pongs
());
// kill pong actor
// wait until separate process (in sep. thread) finished execution
child
.
join
();
return
CPPA_TEST_RESULT
;
...
...
unit_testing/test__spawn.cpp
View file @
f2e3753e
...
...
@@ -331,7 +331,7 @@ std::string behavior_test(actor_ptr et)
throw
std
::
runtime_error
(
testee_name
+
" does not reply"
);
}
);
send
(
et
,
atom
(
"
:Exit
"
),
exit_reason
::
user_defined
);
send
(
et
,
atom
(
"
EXIT
"
),
exit_reason
::
user_defined
);
await_all_others_done
();
return
result
;
}
...
...
@@ -395,61 +395,57 @@ size_t test__spawn()
{
link
(
my_link
,
spawn
(
new
event_testee
));
}
send
(
my_link
,
atom
(
"
:Exit
"
),
exit_reason
::
user_defined
);
send
(
my_link
,
atom
(
"
EXIT
"
),
exit_reason
::
user_defined
);
await_all_others_done
();
auto
report_unexpected
=
[
&
]()
{
cerr
<<
"unexpected message: "
<<
to_string
(
self
->
last_dequeued
())
<<
endl
;
CPPA_CHECK
(
false
);
};
self
->
trap_exit
(
true
);
auto
pong_actor
=
spawn
(
pong
,
spawn
(
ping
));
auto
ping_actor
=
spawn
(
ping
,
10
);
auto
pong_actor
=
spawn
(
pong
,
ping_actor
);
monitor
(
pong_actor
);
monitor
(
ping_actor
);
self
->
link_to
(
pong_actor
);
int
i
=
0
;
int
flags
=
0
;
future_send
(
self
,
std
::
chrono
::
seconds
(
1
),
atom
(
"FooBar"
));
// wait for
:Down and :Exit
messages of pong
receive_for
(
i
,
3
)
// wait for
DOWN and EXIT
messages of pong
receive_for
(
i
,
4
)
(
on
<
atom
(
"
:Exit
"
),
std
::
uint32_t
>
()
>>
[
&
](
std
::
uint32_t
reason
)
on
<
atom
(
"
EXIT
"
),
std
::
uint32_t
>
()
>>
[
&
](
std
::
uint32_t
reason
)
{
CPPA_CHECK_EQUAL
(
reason
,
exit_reason
::
user_defined
);
//CPPA_CHECK_EQUAL(who,
pong_actor);
CPPA_CHECK
(
self
->
last_sender
()
==
pong_actor
);
flags
|=
0x01
;
},
on
<
atom
(
"
:Down
"
),
actor_ptr
,
std
::
uint32_t
>
()
>>
[
&
](
const
actor_ptr
&
who
,
std
::
uint32_t
reason
)
on
<
atom
(
"
DOWN
"
),
actor_ptr
,
std
::
uint32_t
>
()
>>
[
&
](
const
actor_ptr
&
who
,
std
::
uint32_t
reason
)
{
CPPA_CHECK_EQUAL
(
reason
,
exit_reason
::
user_defined
);
if
(
who
==
pong_actor
)
{
flags
|=
0x02
;
CPPA_CHECK_EQUAL
(
reason
,
exit_reason
::
user_defined
);
}
else
if
(
who
==
ping_actor
)
{
flags
|=
0x04
;
CPPA_CHECK_EQUAL
(
reason
,
exit_reason
::
normal
);
}
},
on
<
atom
(
"FooBar"
)
>
()
>>
[
&
]()
{
flags
|=
0x0
4
;
flags
|=
0x0
8
;
},
others
()
>>
[
&
]()
{
report_unexpected
();
CPPA_CHECK
(
false
);
CPPA_ERROR
(
"unexpected message: "
<<
to_string
(
self
->
last_dequeued
()));
},
after
(
std
::
chrono
::
seconds
(
5
))
>>
[
&
]()
{
cout
<<
"!!! TIMEOUT !!!"
<<
endl
;
CPPA_CHECK
(
false
);
CPPA_ERROR
(
"timeout in file "
<<
__FILE__
<<
" in line "
<<
__LINE__
);
}
);
// wait for termination of all spawned actors
await_all_others_done
();
CPPA_CHECK_EQUAL
(
flags
,
0x07
);
CPPA_CHECK_EQUAL
(
0x0F
,
flags
);
// verify pong messages
CPPA_CHECK_EQUAL
(
pongs
(),
5
);
await_all_others_done
();
CPPA_CHECK_EQUAL
(
10
,
pongs
());
return
CPPA_TEST_RESULT
;
}
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