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);
}
}
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();
}
}
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));
}
}
}
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();
}
}
}
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();
}
}
Aggregations