use of com.generallycloud.baseio.container.RESMessage in project baseio by generallycloud.
the class MQTransactionServlet method doAccept.
@Override
public void doAccept(SocketSession session, ParamedProtobaseFuture future, MQSessionAttachment attachment) throws Exception {
String action = future.getReadText();
TransactionSection section = attachment.getTransactionSection();
if ("begin".equals(action)) {
RESMessage message = null;
if (section == null) {
section = new TransactionSection(getMQContext());
attachment.setTransactionSection(section);
message = RESMessage.SUCCESS;
} else {
message = MQRESMessage.R_TRANSACTION_BEGINED;
}
future.write(message.toString());
session.flush(future);
} else if ("commit".equals(action)) {
RESMessage message = null;
if (section == null) {
message = MQRESMessage.R_TRANSACTION_NOT_BEGIN;
} else {
if (section.commit()) {
message = RESMessage.SUCCESS;
} else {
message = MQRESMessage.R_TRANSACTION_NOT_BEGIN;
}
attachment.setTransactionSection(null);
}
future.write(message.toString());
session.flush(future);
} else if ("rollback".equals(action)) {
RESMessage message = null;
if (section == null) {
message = MQRESMessage.R_TRANSACTION_NOT_BEGIN;
} else {
if (section.rollback()) {
message = RESMessage.SUCCESS;
} else {
message = MQRESMessage.R_TRANSACTION_NOT_BEGIN;
}
attachment.setTransactionSection(null);
}
future.write(message.toString());
session.flush(future);
} else // else if("complete".equals(action)){
// RESMessage message = RESMessage.R_SUCCESS;
// attachment.setTpl_message(null);
// response.write(message.toString());
// response.flush();
//
// }
{
future.write(MQRESMessage.R_CMD_NOT_FOUND.toString());
session.flush(future);
}
}
use of com.generallycloud.baseio.container.RESMessage in project baseio by generallycloud.
the class TestDownloadServlet method fileNotFound.
private void fileNotFound(SocketSession session, ProtobaseFuture future, String msg) throws IOException {
RESMessage message = new RESMessage(404, msg);
future.write(message.toString());
session.flush(future);
}
use of com.generallycloud.baseio.container.RESMessage in project baseio by generallycloud.
the class FutureAcceptorServiceFilter method accept404.
protected void accept404(SocketSession session, NamedFuture future, String serviceName) throws IOException {
logger.info("service name [{}] not found", serviceName);
RESMessage message = new RESMessage(404, "service name not found :" + serviceName);
flush(session, future, message);
}
use of com.generallycloud.baseio.container.RESMessage in project baseio by generallycloud.
the class SystemAuthorityServlet method accept.
@Override
public void accept(SocketSession session, Future future) throws Exception {
LoginCenter loginCenter = AuthorityContext.getInstance().getLoginCenter();
ParametersFuture f = (ParametersFuture) future;
boolean login = loginCenter.login(session, f.getParameters());
RESMessage message = RESMessage.UNAUTH;
if (login) {
Authority authority = ApplicationContextUtil.getAuthority(session);
message = new RESMessage(0, authority, null);
}
future.write(message.toString());
session.flush(future);
}
use of com.generallycloud.baseio.container.RESMessage in project baseio by generallycloud.
the class DefaultMessageConsumer method transactionVal.
private boolean transactionVal(String action) throws MQException {
try {
WaiterOnFuture onReadFuture = new WaiterOnFuture();
session.listen(MQTransactionServlet.SERVICE_NAME, onReadFuture);
session.write(MQTransactionServlet.SERVICE_NAME, action);
if (onReadFuture.await(3000)) {
throw MQException.TIME_OUT;
}
ProtobaseFuture future = (ProtobaseFuture) onReadFuture.getReadFuture();
RESMessage message = RESMessageDecoder.decode(future.getReadText());
if (message.getCode() == 0) {
return true;
} else {
throw new MQException(message.getDescription());
}
} catch (IOException e) {
throw new MQException(e.getMessage(), e);
}
}
Aggregations