Search in sources :

Example 86 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class EzySendResponseImpl method execute.

@Override
public void execute(EzyResponse response, EzySession recipient, boolean encrypted, boolean immediate, EzyTransportType transportType) {
    boolean success = false;
    EzyResponseApi responseApi = server.getResponseApi();
    EzyArray data = response.serialize();
    EzySimplePackage pack = newPackage(data, encrypted, transportType);
    pack.addRecipient(recipient);
    try {
        responseApi.response(pack, immediate);
        success = true;
    } catch (Exception e) {
        logger.error("send data: {}, to client: {} error", pack.getData(), recipient.getName(), e);
    } finally {
        pack.release();
    }
    boolean debug = server.getSettings().isDebug();
    if (debug && success && !ignoredLogCommands.contains(response.getCommand())) {
        logger.debug("send to: {} data: {}", recipient.getName(), data);
    }
}
Also used : EzySimplePackage(com.tvd12.ezyfoxserver.socket.EzySimplePackage) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi)

Example 87 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class EzyStreamBytesImpl method execute.

@Override
public void execute(byte[] bytes, Collection<EzySession> recipients, EzyTransportType transportType) {
    EzyStreamingApi streamingApi = server.getStreamingApi();
    EzySimpleBytesPackage pack = newPackage(bytes, transportType);
    pack.addRecipients(recipients);
    try {
        streamingApi.response(pack);
    } catch (Exception e) {
        logger.warn("send: {} bytes, to client: {} error", bytes.length, getRecipientsNames(recipients), e);
    } finally {
        pack.release();
    }
}
Also used : EzyStreamingApi(com.tvd12.ezyfoxserver.api.EzyStreamingApi) EzySimpleBytesPackage(com.tvd12.ezyfoxserver.socket.EzySimpleBytesPackage)

Example 88 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class EzyAppSendResponseImpl method execute.

@Override
public void execute(EzyData data, EzySession recipient, boolean encrypted, EzyTransportType transportType) {
    EzyResponse response = newResponse(data);
    serverContext.send(response, recipient, encrypted, transportType);
}
Also used : EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse)

Example 89 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class EzyCloseSessionImpl method doSendToClients.

protected void doSendToClients(EzySession session, EzyConstant reason) {
    EzyResponse response = newResponse(reason);
    context.sendNow(response, session);
}
Also used : EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse)

Example 90 with EzySession

use of com.tvd12.ezyfoxserver.entity.EzySession in project ezyfox-server by youngmonkeys.

the class EzyAbstractResponseApi method secureResponse.

protected final void secureResponse(EzyPackage pack, boolean immediate) throws Exception {
    EzyConstant connectionType = getConnectionType();
    Collection<EzySession> recipients = pack.getRecipients(connectionType);
    if (recipients.isEmpty()) {
        return;
    }
    byte[] messageContent = dataToMessageContent(pack.getData());
    if (immediate) {
        for (EzySession session : recipients) {
            byte[] bytes = encryptMessageContent(messageContent, session.getSessionKey());
            session.sendNow(createPacket(bytes, pack));
        }
    } else {
        for (EzySession session : recipients) {
            byte[] bytes = encryptMessageContent(messageContent, session.getSessionKey());
            session.send(createPacket(bytes, pack));
        }
    }
}
Also used : EzyConstant(com.tvd12.ezyfox.constant.EzyConstant) EzySession(com.tvd12.ezyfoxserver.entity.EzySession)

Aggregations

EzySession (com.tvd12.ezyfoxserver.entity.EzySession)112 Test (org.testng.annotations.Test)92 EzyArray (com.tvd12.ezyfox.entity.EzyArray)33 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)26 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)25 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)25 BaseTest (com.tvd12.test.base.BaseTest)25 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)15 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)14 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)13 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)13 EzySimpleLoginRequest (com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest)13 EzyLoginController (com.tvd12.ezyfoxserver.controller.EzyLoginController)12 EzySimpleSettings (com.tvd12.ezyfoxserver.setting.EzySimpleSettings)11 EzySendResponseImpl (com.tvd12.ezyfoxserver.command.impl.EzySendResponseImpl)8 EzyHandshakeController (com.tvd12.ezyfoxserver.controller.EzyHandshakeController)8 EzyHandshakeParams (com.tvd12.ezyfoxserver.request.EzyHandshakeParams)8 EzySimpleResponse (com.tvd12.ezyfoxserver.response.EzySimpleResponse)8 GreetResponse (com.tvd12.ezyfoxserver.support.test.data.GreetResponse)8 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)8