Search in sources :

Example 1 with CmdResponse

use of com.generallycloud.baseio.container.jms.cmd.CmdResponse in project baseio by generallycloud.

the class ExitExecutable method exec.

@Override
public CmdResponse exec(CommandContext context, HashMap<String, String> params) {
    CmdResponse response = new CmdResponse();
    ChannelConnector connector = getClientConnector(context);
    if (connector == null) {
        response.setResponse("请先登录!");
        return response;
    }
    // FIXME logout
    // connector.logout();
    CloseUtil.close(connector);
    setMessageBrowser(context, null);
    setClientConnector(context, null);
    response.setContinue(false);
    response.setResponse("系统退出!");
    return response;
}
Also used : CmdResponse(com.generallycloud.baseio.container.jms.cmd.CmdResponse) ChannelConnector(com.generallycloud.baseio.connector.ChannelConnector)

Example 2 with CmdResponse

use of com.generallycloud.baseio.container.jms.cmd.CmdResponse in project baseio by generallycloud.

the class BrowserExecutable method exec.

@Override
public CmdResponse exec(CommandContext context, HashMap<String, String> params) {
    CmdResponse response = new CmdResponse();
    MessageBrowser browser = getMessageBrowser(context);
    if (browser == null) {
        response.setResponse("请先登录!");
        return response;
    }
    String messageId = params.get("-mid");
    if (StringUtil.isNullOrBlank(messageId)) {
        response.setResponse("参数不正确!\n" + "example:\n" + "browser -mid:mid");
        return response;
    }
    try {
        Message message = browser.browser(messageId);
        if (message == null) {
            response.setResponse("没有此id的消息!");
        } else {
            response.setResponse(message.toString());
        }
    } catch (Exception e) {
        logger.debug(e);
    }
    return response;
}
Also used : Message(com.generallycloud.baseio.container.jms.Message) CmdResponse(com.generallycloud.baseio.container.jms.cmd.CmdResponse) MessageBrowser(com.generallycloud.baseio.container.jms.client.MessageBrowser)

Example 3 with CmdResponse

use of com.generallycloud.baseio.container.jms.cmd.CmdResponse in project baseio by generallycloud.

the class DisconnectExecutable method exec.

@Override
public CmdResponse exec(CommandContext context, HashMap<String, String> params) {
    CmdResponse response = new CmdResponse();
    ChannelConnector connector = getClientConnector(context);
    if (connector == null) {
        response.setResponse("请先登录!");
        return response;
    }
    // FXIME logout
    // connector.logout();
    CloseUtil.close(connector);
    setMessageBrowser(context, null);
    setClientConnector(context, null);
    response.setResponse("已断开连接!");
    return response;
}
Also used : CmdResponse(com.generallycloud.baseio.container.jms.cmd.CmdResponse) ChannelConnector(com.generallycloud.baseio.connector.ChannelConnector)

Example 4 with CmdResponse

use of com.generallycloud.baseio.container.jms.cmd.CmdResponse in project baseio by generallycloud.

the class ConnectExecutable method exec.

@Override
public CmdResponse exec(CommandContext context, HashMap<String, String> params) {
    CmdResponse response = new CmdResponse();
    SocketChannelConnector connector = getClientConnector(context);
    if (connector != null) {
        response.setResponse("已登录。");
        return response;
    }
    String username = params.get("-un");
    String password = params.get("-p");
    String host = params.get("-host");
    String port = params.get("-port");
    if (StringUtil.isNullOrBlank(username) || StringUtil.isNullOrBlank(password) || StringUtil.isNullOrBlank(host) || StringUtil.isNullOrBlank(port)) {
        response.setResponse("参数不正确!\n" + "example:\n" + "connect -host:localhost -port:8300 -un:admin -p:admin100");
        return response;
    }
    try {
        NioSocketChannelContext baseContext = new NioSocketChannelContext(new ServerConfiguration(Integer.parseInt(port)));
        connector = new SocketChannelConnector(baseContext);
        SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
        baseContext.setIoEventHandleAdaptor(eventHandle);
        baseContext.addSessionEventListener(new LoggerSocketSEListener());
        FixedSession session = new FixedSession(connector.connect());
        // FIXME denglu cuowu
        session.login(username, password);
        MessageBrowser browser = new DefaultMessageBrowser(session);
        response.setResponse("连接成功!");
        setClientConnector(context, connector);
        setMessageBrowser(context, browser);
    } catch (Exception e) {
        setClientConnector(context, null);
        setMessageBrowser(context, null);
        response.setResponse(e.getMessage());
        // debug
        logger.debug(e);
    }
    return response;
}
Also used : SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) CmdResponse(com.generallycloud.baseio.container.jms.cmd.CmdResponse) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) FixedSession(com.generallycloud.baseio.container.FixedSession) MessageBrowser(com.generallycloud.baseio.container.jms.client.MessageBrowser) DefaultMessageBrowser(com.generallycloud.baseio.container.jms.client.impl.DefaultMessageBrowser) DefaultMessageBrowser(com.generallycloud.baseio.container.jms.client.impl.DefaultMessageBrowser) SimpleIoEventHandle(com.generallycloud.baseio.container.SimpleIoEventHandle) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 5 with CmdResponse

use of com.generallycloud.baseio.container.jms.cmd.CmdResponse in project baseio by generallycloud.

the class HelpExecutable method exec.

@Override
public CmdResponse exec(CommandContext context, HashMap<String, String> params) {
    CmdResponse response = new CmdResponse();
    response.setResponse("请尝试:" + context.getCommandKeys());
    return response;
}
Also used : CmdResponse(com.generallycloud.baseio.container.jms.cmd.CmdResponse)

Aggregations

CmdResponse (com.generallycloud.baseio.container.jms.cmd.CmdResponse)6 MessageBrowser (com.generallycloud.baseio.container.jms.client.MessageBrowser)3 ChannelConnector (com.generallycloud.baseio.connector.ChannelConnector)2 LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)1 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)1 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)1 SocketChannelConnector (com.generallycloud.baseio.connector.SocketChannelConnector)1 FixedSession (com.generallycloud.baseio.container.FixedSession)1 SimpleIoEventHandle (com.generallycloud.baseio.container.SimpleIoEventHandle)1 Message (com.generallycloud.baseio.container.jms.Message)1 DefaultMessageBrowser (com.generallycloud.baseio.container.jms.client.impl.DefaultMessageBrowser)1