Search in sources :

Example 1 with RESMessage

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);
    }
}
Also used : RESMessage(com.generallycloud.baseio.container.RESMessage)

Example 2 with RESMessage

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);
}
Also used : RESMessage(com.generallycloud.baseio.container.RESMessage)

Example 3 with RESMessage

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);
}
Also used : RESMessage(com.generallycloud.baseio.container.RESMessage)

Example 4 with RESMessage

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);
}
Also used : LoginCenter(com.generallycloud.baseio.container.LoginCenter) RESMessage(com.generallycloud.baseio.container.RESMessage) ParametersFuture(com.generallycloud.baseio.protocol.ParametersFuture)

Example 5 with RESMessage

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);
    }
}
Also used : ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) MQException(com.generallycloud.baseio.container.jms.MQException) RESMessage(com.generallycloud.baseio.container.RESMessage) IOException(java.io.IOException) WaiterOnFuture(com.generallycloud.baseio.container.WaiterOnFuture)

Aggregations

RESMessage (com.generallycloud.baseio.container.RESMessage)5 ProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture)1 LoginCenter (com.generallycloud.baseio.container.LoginCenter)1 WaiterOnFuture (com.generallycloud.baseio.container.WaiterOnFuture)1 MQException (com.generallycloud.baseio.container.jms.MQException)1 ParametersFuture (com.generallycloud.baseio.protocol.ParametersFuture)1 IOException (java.io.IOException)1