Search in sources :

Example 1 with EzyEvent

use of com.tvd12.ezyfoxserver.event.EzyEvent in project ezyfox-server by youngmonkeys.

the class EzyBroadcastAppsEventImplTest method newAppContext.

private EzyAppContext newAppContext(String appName, EzyEvent event2) {
    EzyAppContext appContext = mock(EzyAppContext.class);
    EzyApplication app = mock(EzyApplication.class);
    when(appContext.getApp()).thenReturn(app);
    EzySimpleAppSetting setting = new EzySimpleAppSetting();
    setting.setName(appName);
    when(app.getSetting()).thenReturn(setting);
    EzyAppUserManager appUserManager = EzyAppUserManagerImpl.builder().appName(appName).maxUsers(99).build();
    when(app.getUserManager()).thenReturn(appUserManager);
    EzySimpleUser user = new EzySimpleUser();
    user.setName("user" + appName);
    appUserManager.addUser(user);
    doThrow(new IllegalStateException()).when(appContext).handleEvent(EzyEventType.SERVER_INITIALIZING, event2);
    return appContext;
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext)

Example 2 with EzyEvent

use of com.tvd12.ezyfoxserver.event.EzyEvent in project ezyfox-server by youngmonkeys.

the class EzyBroadcastAppsEventImplTest method test.

@Test
public void test() {
    EzyEvent event2 = new EzySimpleServerInitializingEvent();
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    List<EzyAppContext> appContexts = Lists.newArrayList(newAppContext("1", event2), newAppContext("2", event2), newAppContext("3", event2));
    when(zoneContext.getAppContexts()).thenReturn(appContexts);
    EzyZone zone = mock(EzyZone.class);
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    zoneSetting.setName("test");
    when(zone.getSetting()).thenReturn(zoneSetting);
    when(zoneContext.getZone()).thenReturn(zone);
    EzyBroadcastAppsEventImpl cmd = new EzyBroadcastAppsEventImpl(zoneContext);
    EzyEvent event = new EzySimpleServerInitializingEvent();
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, true);
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, false);
    EzySimpleUser user = new EzySimpleUser();
    user.setName("user1");
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, user, true);
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, "user1", true);
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event2, true);
}
Also used : EzySimpleServerInitializingEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerInitializingEvent) EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyEvent(com.tvd12.ezyfoxserver.event.EzyEvent) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyBroadcastAppsEventImpl(com.tvd12.ezyfoxserver.command.impl.EzyBroadcastAppsEventImpl) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 3 with EzyEvent

use of com.tvd12.ezyfoxserver.event.EzyEvent in project ezyfox-server by youngmonkeys.

the class EzySimpleDataHandler method notifySessionRemoved.

protected void notifySessionRemoved(EzyConstant reason) {
    if (zoneContext != null) {
        EzyEvent event = newSessionRemovedEvent(reason);
        notifyAppsSessionRemoved(event);
        notifyPluginsSessionRemoved(event);
    }
}
Also used : EzyEvent(com.tvd12.ezyfoxserver.event.EzyEvent)

Example 4 with EzyEvent

use of com.tvd12.ezyfoxserver.event.EzyEvent in project ezyfox-server by youngmonkeys.

the class EzySimpleAppUserDelegate method handleUserRemovedEvent.

protected void handleUserRemovedEvent(EzyUser user, EzyConstant reason) {
    EzyEvent event = new EzySimpleUserRemovedEvent(user, reason);
    appContext.handleEvent(EzyEventType.USER_REMOVED, event);
}
Also used : EzyEvent(com.tvd12.ezyfoxserver.event.EzyEvent) EzySimpleUserRemovedEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserRemovedEvent)

Example 5 with EzyEvent

use of com.tvd12.ezyfoxserver.event.EzyEvent in project ezyfox-server-android-client by youngmonkeys.

the class EzySocketClient method reconnect.

public boolean reconnect() {
    EzySocketStatus status = socketStatuses.last();
    if (!isSocketReconnectable(status)) {
        EzyLogger.warn("socket is not in a reconnectable status");
        return false;
    }
    int maxReconnectCount = reconnectConfig.getMaxReconnectCount();
    if (reconnectCount >= maxReconnectCount)
        return false;
    socketStatuses.push(EzySocketStatus.RECONNECTING);
    int reconnectSleepTime = reconnectConfig.getReconnectPeriod();
    connect0(reconnectSleepTime);
    reconnectCount++;
    EzyLogger.info("try reconnect to server: " + reconnectCount + ", wating time: " + reconnectSleepTime);
    EzyEvent tryConnectEvent = new EzyTryConnectEvent(reconnectCount);
    socketEventQueue.addEvent(tryConnectEvent);
    return true;
}
Also used : EzyEvent(com.tvd12.ezyfoxserver.client.event.EzyEvent) EzySocketStatus(com.tvd12.ezyfoxserver.client.constant.EzySocketStatus) EzyTryConnectEvent(com.tvd12.ezyfoxserver.client.event.EzyTryConnectEvent)

Aggregations

EzyEvent (com.tvd12.ezyfoxserver.event.EzyEvent)4 EzyEvent (com.tvd12.ezyfoxserver.client.event.EzyEvent)3 EzySocketStatus (com.tvd12.ezyfoxserver.client.constant.EzySocketStatus)2 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)2 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)2 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)1 EzyZone (com.tvd12.ezyfoxserver.EzyZone)1 EzyConnectionFailureEvent (com.tvd12.ezyfoxserver.client.event.EzyConnectionFailureEvent)1 EzyConnectionSuccessEvent (com.tvd12.ezyfoxserver.client.event.EzyConnectionSuccessEvent)1 EzyDisconnectionEvent (com.tvd12.ezyfoxserver.client.event.EzyDisconnectionEvent)1 EzyEventType (com.tvd12.ezyfoxserver.client.event.EzyEventType)1 EzyTryConnectEvent (com.tvd12.ezyfoxserver.client.event.EzyTryConnectEvent)1 EzyBroadcastAppsEventImpl (com.tvd12.ezyfoxserver.command.impl.EzyBroadcastAppsEventImpl)1 EzyPluginContext (com.tvd12.ezyfoxserver.context.EzyPluginContext)1 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)1 EzySimpleServerInitializingEvent (com.tvd12.ezyfoxserver.event.EzySimpleServerInitializingEvent)1 EzySimpleServerReadyEvent (com.tvd12.ezyfoxserver.event.EzySimpleServerReadyEvent)1 EzySimpleUserRemovedEvent (com.tvd12.ezyfoxserver.event.EzySimpleUserRemovedEvent)1 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)1 EzySimpleZoneSetting (com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting)1