Search in sources :

Example 26 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, Collection<EzySession> recipients, boolean encrypted, boolean immediate, EzyTransportType transportType) {
    boolean success = false;
    EzyResponseApi responseApi = server.getResponseApi();
    EzyArray data = response.serialize();
    EzySimplePackage pack = newPackage(data, encrypted, transportType);
    pack.addRecipients(recipients);
    try {
        responseApi.response(pack, immediate);
        success = true;
    } catch (Exception e) {
        logger.error("send data: {}, to client: {} error", pack.getData(), getRecipientsNames(recipients), e);
    } finally {
        pack.release();
    }
    boolean debug = server.getSettings().isDebug();
    if (debug && success && !ignoredLogCommands.contains(response.getCommand())) {
        logger.debug("send to: {} data: {}", getRecipientsNames(recipients), data);
    }
}
Also used : EzySimplePackage(com.tvd12.ezyfoxserver.socket.EzySimplePackage) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi)

Example 27 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, EzySession recipient, EzyTransportType transportType) {
    EzyStreamingApi streamingApi = server.getStreamingApi();
    EzySimpleBytesPackage pack = newPackage(bytes, transportType);
    pack.addRecipient(recipient);
    try {
        streamingApi.response(pack);
    } catch (Exception e) {
        logger.warn("send {} bytes {}, to client: {} error", bytes.length, recipient.getName(), e);
    } finally {
        pack.release();
    }
}
Also used : EzyStreamingApi(com.tvd12.ezyfoxserver.api.EzyStreamingApi) EzySimpleBytesPackage(com.tvd12.ezyfoxserver.socket.EzySimpleBytesPackage)

Example 28 with EzySession

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

the class EzyAbstractResponseApi method normalResponse.

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

Example 29 with EzySession

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

the class EzySocketRequestHandler method handleEvent.

@Override
public void handleEvent() {
    EzySocketRequest request = null;
    try {
        EzySession session = sessionTicketsQueue.take();
        EzyRequestQueue requestQueue = getRequestQueue(session);
        // noinspection SynchronizationOnLocalVariableOrMethodParameter
        synchronized (requestQueue) {
            request = requestQueue.take();
            if (requestQueue.size() > 0) {
                sessionTicketsQueue.add(session);
            }
        }
        processRequest(request);
    } catch (InterruptedException e) {
        logger.info("{}-request-handler thread interrupted", getRequestType());
    } catch (Throwable throwable) {
        logger.warn("problems in {}-request-handler", getRequestType(), throwable);
    } finally {
        if (request != null) {
            request.release();
        }
    }
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession)

Example 30 with EzySession

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

the class EzySocketStreamHandler method processStream.

private void processStream(EzySocketStream stream) throws Exception {
    try {
        byte[] bytes = stream.getBytes();
        EzySession session = stream.getSession();
        EzySocketDataHandlerGroup handlerGroup = getDataHandlerGroup(session);
        if (handlerGroup != null) {
            handlerGroup.fireStreamBytesReceived(bytes);
        } else {
            logger.warn("has no handler group with session: {}, drop: {} bytes", session, bytes.length);
        }
    } finally {
        stream.release();
    }
}
Also used : 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