Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Akkapres
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
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
Dag Østgulen Heradstveit
Akkapres
Commits
7ef6e719
Commit
7ef6e719
authored
Jun 15, 2015
by
Dag Østgulen Heradstveit
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added simple router example
parent
8eefb568
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
5 deletions
+78
-5
.idea/vcs.xml
.idea/vcs.xml
+1
-1
src/main/scala/no/nsd/akkapres/AkkaPres.scala
src/main/scala/no/nsd/akkapres/AkkaPres.scala
+2
-4
src/main/scala/no/nsd/akkapres/router/MessageActor.scala
src/main/scala/no/nsd/akkapres/router/MessageActor.scala
+19
-0
src/main/scala/no/nsd/akkapres/router/MessageRouterActor.scala
...ain/scala/no/nsd/akkapres/router/MessageRouterActor.scala
+46
-0
src/test/scala/no/nsd/akkapres/counter/CounterRouterActoTest.scala
...scala/no/nsd/akkapres/counter/CounterRouterActoTest.scala
+10
-0
No files found.
.idea/vcs.xml
View file @
7ef6e719
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"VcsDirectoryMappings"
>
<mapping
directory=
"
"
vcs=
"
"
/>
<mapping
directory=
"
$PROJECT_DIR$"
vcs=
"Git
"
/>
</component>
</project>
\ No newline at end of file
src/main/scala/no/nsd/akkapres/AkkaPres.scala
View file @
7ef6e719
package
no.nsd.akkapres
import
akka.actor.
{
Props
,
ActorSystem
}
import
akka.actor.
{
ActorSystem
,
Props
}
import
no.nsd.akkapres.counter.CounterActor
import
no.nsd.akkapres.greeting.GreeterResponseActor
import
scala.concurrent.duration._
/**
* Where you would start an actual application.
*
...
...
@@ -15,5 +13,5 @@ import scala.concurrent.duration._
object
AkkaPres
extends
App
{
implicit
val
system
=
ActorSystem
(
"akkapres"
)
system
.
actorOf
(
Props
(
classOf
[
GreeterResponseActor
]),
"greeter"
)
system
.
actorOf
(
Props
(
classOf
[
CounterActor
]
,
1
second
),
"counter"
)
system
.
actorOf
(
Props
(
classOf
[
CounterActor
]),
"counter"
)
}
src/main/scala/no/nsd/akkapres/router/MessageActor.scala
0 → 100644
View file @
7ef6e719
package
no.nsd.akkapres.router
import
akka.actor.
{
ActorLogging
,
Actor
}
case
class
Message
(
content
:
String
)
class
MessageActor
extends
Actor
with
ActorLogging
{
def
receive
=
{
case
m
:
Message
=>
log
.
info
(
m
.
content
)
sender
()
!
m
.
content
case
_
=>
log
.
info
(
"Unable to handle it."
)
}
}
\ No newline at end of file
src/main/scala/no/nsd/akkapres/router/MessageRouterActor.scala
0 → 100644
View file @
7ef6e719
package
no.nsd.akkapres.router
import
akka.actor._
import
akka.routing.
{
ActorRefRoutee
,
RoundRobinRoutingLogic
,
Router
}
/**
* @author Dag Østgulen Heradstveit
*/
class
MessageRouterActor
(
routeeSize
:
Int
)
extends
Actor
with
ActorLogging
{
var
router
=
{
val
routees
=
Vector
.
fill
(
routeeSize
)
{
val
routee
=
context
.
actorOf
(
Props
[
MessageActor
])
context
watch
routee
ActorRefRoutee
(
routee
)
}
Router
(
RoundRobinRoutingLogic
(),
routees
)
}
def
receive
=
{
case
m
:
Message
=>
router
.
route
(
m
,
sender
())
case
_
=>
log
.
info
(
"Empty message"
)
case
Terminated
(
actor
)
=>
router
=
router
.
removeRoutee
(
actor
)
val
routee
=
context
.
actorOf
(
Props
[
MessageActor
])
context
watch
routee
router
=
router
.
addRoutee
(
routee
)
log
.
info
(
"Terminated"
)
}
}
object
MessageRouter
extends
App
{
val
routeeSize
=
5
implicit
val
system
=
ActorSystem
(
"akkapres"
)
val
a
=
system
.
actorOf
(
Props
(
classOf
[
MessageRouterActor
],
routeeSize
),
"message-router"
)
for
(
x
<-
1
to
routeeSize
*
routeeSize
*
100000
){
a
!
Message
(
"This is our message to any actor in the router."
)
}
}
src/test/scala/no/nsd/akkapres/counter/CounterRouterActoTest.scala
0 → 100644
View file @
7ef6e719
package
no.nsd.akkapres.counter
import
akka.actor.ActorSystem
import
akka.testkit.
{
ImplicitSender
,
TestKit
}
import
org.scalatest.
{
BeforeAndAfter
,
Matchers
,
FlatSpecLike
}
class
CounterRouterActorTest
(
_system
:
ActorSystem
)
extends
TestKit
(
_system
)
with
ImplicitSender
with
FlatSpecLike
with
Matchers
with
BeforeAndAfter
{
}
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