-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
8 changed files
with
138 additions
and
24 deletions.
There are no files selected for viewing
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
74 changes: 74 additions & 0 deletions
74
src/test/java/com/snowcattle/game/excutor/event/asyncevent/AsyncNotifyEventTest.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,74 @@ | ||
package com.snowcattle.game.excutor.event.asyncevent; | ||
|
||
import com.snowcattle.game.excutor.event.CycleEvent; | ||
import com.snowcattle.game.excutor.event.EventBus; | ||
import com.snowcattle.game.excutor.event.EventParam; | ||
import com.snowcattle.game.excutor.event.async.IntegerUpdate; | ||
import com.snowcattle.game.excutor.event.impl.DispatchCreateEventListener; | ||
import com.snowcattle.game.excutor.event.impl.DispatchFinishEventListener; | ||
import com.snowcattle.game.excutor.event.impl.DispatchUpdateEventListener; | ||
import com.snowcattle.game.excutor.pool.UpdateEventExcutorService; | ||
import com.snowcattle.game.excutor.service.UpdateService; | ||
import com.snowcattle.game.excutor.thread.LockSupportEventDisptachThread; | ||
import com.snowcattle.game.excutor.utils.Constants; | ||
|
||
import java.util.Timer; | ||
import java.util.TimerTask; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.locks.LockSupport; | ||
|
||
/** | ||
* Created by jwp on 2017/3/28. | ||
*/ | ||
public class AsyncNotifyEventTest { | ||
public static void main(String[] args) throws Exception { | ||
testEvent(); | ||
} | ||
|
||
public static void testEvent() throws Exception { | ||
EventBus updateEventBus = new EventBus(); | ||
// int maxSize = 10000; | ||
// int corePoolSize = 100; | ||
int maxSize = 2; | ||
int corePoolSize = 2; | ||
long keepAliveTime = 60; | ||
TimeUnit timeUnit = TimeUnit.SECONDS; | ||
UpdateEventExcutorService updateEventExcutorService = new UpdateEventExcutorService(corePoolSize); | ||
int cycleSleepTime = 1000 / Constants.cycle.cycleSize; | ||
LockSupportEventDisptachThread dispatchThread = new LockSupportEventDisptachThread(updateEventBus, updateEventExcutorService | ||
, cycleSleepTime, cycleSleepTime*1000); | ||
updateEventExcutorService.setDispatchThread(dispatchThread); | ||
UpdateService updateService = new UpdateService(dispatchThread, updateEventExcutorService); | ||
updateEventBus.addEventListener(new DispatchCreateEventListener(dispatchThread, updateService)); | ||
updateEventBus.addEventListener(new DispatchUpdateEventListener(dispatchThread, updateService)); | ||
updateEventBus.addEventListener(new DispatchFinishEventListener(dispatchThread, updateService)); | ||
|
||
updateService.notifyStart(); | ||
// while (true) { | ||
// Thread.currentThread().sleep(100); | ||
// LockSupport.unpark(dispatchThread); | ||
// | ||
// LockSupport.park(dispatchThread); | ||
// updateService.notifyRun(); | ||
// break; | ||
// } | ||
|
||
|
||
for (long i = 0; i < maxSize; i++) { | ||
IntegerUpdate integerUpdate = new IntegerUpdate(i); | ||
EventParam<IntegerUpdate> param = new EventParam<IntegerUpdate>(integerUpdate); | ||
CycleEvent cycleEvent = new CycleEvent(Constants.EventTypeConstans.readyCreateEventType, integerUpdate.getId(), param); | ||
updateService.addReadyCreateEvent(cycleEvent); | ||
} | ||
|
||
|
||
// updateService.shutDown(); | ||
Timer timer = new Timer(); | ||
timer.schedule(new NotifyTask(updateService), 0, 10); | ||
while (true) { | ||
Thread.currentThread().sleep(100); | ||
updateService.toString(); | ||
} | ||
} | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
src/test/java/com/snowcattle/game/excutor/event/asyncevent/NotifyTask.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,22 @@ | ||
package com.snowcattle.game.excutor.event.asyncevent; | ||
|
||
import com.snowcattle.game.excutor.service.UpdateService; | ||
|
||
import java.util.TimerTask; | ||
|
||
/** | ||
* Created by jwp on 2017/3/28. | ||
*/ | ||
class NotifyTask extends TimerTask { | ||
|
||
private UpdateService updateService; | ||
|
||
public NotifyTask(UpdateService updateService) { | ||
this.updateService = updateService; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
updateService.notifyRun(); | ||
} | ||
} |