-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. add actor tick schedule and refactor some code of akka
- Loading branch information
Showing
19 changed files
with
443 additions
and
25 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
common/src/main/java/com/toocol/common/akka/ActorAddTicker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.toocol.common.akka; | ||
|
||
import akka.actor.ActorRef; | ||
import lombok.AllArgsConstructor; | ||
|
||
/** | ||
* @author :JoeZane (joezane.cn@gmail.com) | ||
* @date: 2022/7/23 0:31 | ||
* @version: 0.0.1 | ||
*/ | ||
@AllArgsConstructor | ||
public class ActorAddTicker { | ||
|
||
public final ActorRef ticker; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.toocol.common.akka; | ||
|
||
/** | ||
* @author ZhaoZhe (joezane.cn@gmail.com) | ||
* @date 2022/7/21 20:27 | ||
*/ | ||
public enum ActorCreate { | ||
of | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
common/src/main/java/com/toocol/common/akka/ActorTick.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.toocol.common.akka; | ||
|
||
/** | ||
* @author :JoeZane (joezane.cn@gmail.com) | ||
* @date: 2022/7/22 23:07 | ||
* @version: 0.0.1 | ||
*/ | ||
public enum ActorTick { | ||
of | ||
} |
35 changes: 35 additions & 0 deletions
35
common/src/main/java/com/toocol/common/akka/ActorTickScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.toocol.common.akka; | ||
|
||
import akka.actor.AbstractActor; | ||
import akka.actor.ActorRef; | ||
import akka.japi.pf.ReceiveBuilder; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author :JoeZane (joezane.cn@gmail.com) | ||
* @date: 2022/7/23 0:22 | ||
* @version: 0.0.1 | ||
*/ | ||
public class ActorTickScheduler extends AbstractActor { | ||
|
||
private final List<ActorRef> tickList = new ArrayList<>(); | ||
|
||
@Override | ||
public Receive createReceive() { | ||
return ReceiveBuilder.create() | ||
.match(ActorAddTicker.class, actorAddTicker -> addTicker(actorAddTicker.ticker)) | ||
.match(ActorTick.class, tick -> tick()) | ||
.build(); | ||
} | ||
|
||
protected void addTicker(ActorRef ticker) { | ||
tickList.add(ticker); | ||
} | ||
|
||
private void tick() { | ||
tickList.forEach(actorRef -> actorRef.tell(ActorTick.of, ActorRef.noSender())); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
common/src/main/java/com/toocol/common/akka/IActorTicker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.toocol.common.akka; | ||
|
||
/** | ||
* Perform some tasks periodically(per second). | ||
* Only support the actor in akka system. | ||
* | ||
* @author :JoeZane (joezane.cn@gmail.com) | ||
* @date: 2022/7/22 22:51 | ||
* @version: 0.0.1 | ||
*/ | ||
public interface IActorTicker { | ||
|
||
void tick(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.