Search in sources :

Example 21 with LoggerSocketSEListener

use of com.generallycloud.baseio.component.LoggerSocketSEListener in project baseio by generallycloud.

the class TestGetPhoneNO method main.

public static void main(String[] args) throws Exception {
    String serviceKey = "TestGetPhoneNOServlet";
    LoggerFactory.configure();
    SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
    ServerConfiguration configuration = new ServerConfiguration(8300);
    SocketChannelContext context = new NioSocketChannelContext(configuration);
    SocketChannelConnector connector = new SocketChannelConnector(context);
    context.setIoEventHandleAdaptor(eventHandle);
    context.setProtocolFactory(new ProtobaseProtocolFactory());
    context.addSessionEventListener(new LoggerSocketSEListener());
    connector.getContext().setProtocolFactory(new ProtobaseProtocolFactory());
    FixedSession session = new FixedSession(connector.connect());
    ProtobaseFuture future = session.request(serviceKey, null);
    System.out.println(future.getReadText());
    CloseUtil.close(connector);
}
Also used : ProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory) SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) FixedSession(com.generallycloud.baseio.container.FixedSession) SimpleIoEventHandle(com.generallycloud.baseio.container.SimpleIoEventHandle) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 22 with LoggerSocketSEListener

use of com.generallycloud.baseio.component.LoggerSocketSEListener in project baseio by generallycloud.

the class TestSessionDisconnect method main.

public static void main(String[] args) throws Exception {
    String serviceName = "TestSessionDisconnectServlet";
    String param = "ttt";
    LoggerFactory.configure();
    SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
    ServerConfiguration configuration = new ServerConfiguration(8300);
    SocketChannelContext context = new NioSocketChannelContext(configuration);
    SocketChannelConnector connector = new SocketChannelConnector(context);
    context.setIoEventHandleAdaptor(eventHandle);
    context.setProtocolFactory(new ProtobaseProtocolFactory());
    context.addSessionEventListener(new LoggerSocketSEListener());
    FixedSession session = new FixedSession(connector.connect());
    session.login("admin", "admin100");
    ProtobaseFuture future = session.request(serviceName, param);
    System.out.println(future.getReadText());
    session.listen(serviceName, new OnFuture() {

        @Override
        public void onResponse(SocketSession session, Future future) {
            ProtobaseFuture f = (ProtobaseFuture) future;
            System.out.println(f.getReadText());
        }
    });
    session.write(serviceName, param);
    ThreadUtil.sleep(9999);
    CloseUtil.close(connector);
}
Also used : SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) OnFuture(com.generallycloud.baseio.container.OnFuture) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) FixedSession(com.generallycloud.baseio.container.FixedSession) SimpleIoEventHandle(com.generallycloud.baseio.container.SimpleIoEventHandle) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) ProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) SocketSession(com.generallycloud.baseio.component.SocketSession) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) Future(com.generallycloud.baseio.protocol.Future) OnFuture(com.generallycloud.baseio.container.OnFuture)

Example 23 with LoggerSocketSEListener

use of com.generallycloud.baseio.component.LoggerSocketSEListener in project baseio by generallycloud.

the class TestSimple method main.

public static void main(String[] args) throws Exception {
    String serviceKey = "/test-simple";
    String param = "ttt";
    IoEventHandleAdaptor eventHandle = new IoEventHandleAdaptor() {

        @Override
        public void accept(SocketSession session, Future future) throws Exception {
            System.out.println("________________________" + future.getReadText());
        }
    };
    SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(18300));
    SocketChannelConnector connector = new SocketChannelConnector(context);
    context.setProtocolFactory(new ProtobaseProtocolFactory());
    context.addSessionEventListener(new LoggerSocketSEListener());
    context.setIoEventHandleAdaptor(eventHandle);
    SocketSession session = connector.connect();
    ProtobaseFuture f = new ProtobaseFutureImpl(connector.getContext(), serviceKey);
    f.write(param);
    session.flush(f);
    ThreadUtil.sleep(500);
    CloseUtil.close(connector);
}
Also used : ProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory) SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) SocketSession(com.generallycloud.baseio.component.SocketSession) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) IoEventHandleAdaptor(com.generallycloud.baseio.component.IoEventHandleAdaptor) ProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) Future(com.generallycloud.baseio.protocol.Future) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 24 with LoggerSocketSEListener

use of com.generallycloud.baseio.component.LoggerSocketSEListener 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 25 with LoggerSocketSEListener

use of com.generallycloud.baseio.component.LoggerSocketSEListener in project baseio by generallycloud.

the class HttpApplicationContextEnricher method enrich.

@Override
public void enrich(ApplicationContext context) {
    SocketChannelContext channelContext = context.getChannelContext();
    context.setServiceFilter(new FutureAcceptorHttpFilter());
    context.setExceptionCaughtHandle(new HttpExceptionCaughtHandle());
    // FIXME 重复的
    Set<String> blackIPs = context.getBlackIPs();
    if (blackIPs != null && !blackIPs.isEmpty()) {
        channelContext.addSessionEventListener(new BlackIPFilter(blackIPs));
    }
    channelContext.setBeatFutureFactory(new WebSocketBeatFutureFactory());
    channelContext.addSessionEventListener(new LoggerSocketSEListener());
    channelContext.addSessionIdleEventListener(new SocketSessionAliveSEListener());
    channelContext.setProtocolFactory(new ServerHTTPProtocolFactory());
}
Also used : LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) SocketSessionAliveSEListener(com.generallycloud.baseio.component.SocketSessionAliveSEListener) BlackIPFilter(com.generallycloud.baseio.container.BlackIPFilter) FutureAcceptorHttpFilter(com.generallycloud.baseio.container.http11.service.FutureAcceptorHttpFilter) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) ServerHTTPProtocolFactory(com.generallycloud.baseio.codec.http11.ServerHTTPProtocolFactory) WebSocketBeatFutureFactory(com.generallycloud.baseio.codec.http11.future.WebSocketBeatFutureFactory)

Aggregations

LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)55 SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)54 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)53 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)51 SocketChannelConnector (com.generallycloud.baseio.connector.SocketChannelConnector)41 SocketSession (com.generallycloud.baseio.component.SocketSession)35 Future (com.generallycloud.baseio.protocol.Future)33 IoEventHandleAdaptor (com.generallycloud.baseio.component.IoEventHandleAdaptor)29 ProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory)27 FixedSession (com.generallycloud.baseio.container.FixedSession)21 SimpleIoEventHandle (com.generallycloud.baseio.container.SimpleIoEventHandle)21 ProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture)16 FixedLengthProtocolFactory (com.generallycloud.baseio.codec.fixedlength.FixedLengthProtocolFactory)12 SocketChannelAcceptor (com.generallycloud.baseio.acceptor.SocketChannelAcceptor)11 FixedLengthFuture (com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFuture)8 FixedLengthFutureImpl (com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFutureImpl)7 ProtobaseFutureImpl (com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl)7 ParamedProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ParamedProtobaseProtocolFactory)6 MessageConsumer (com.generallycloud.baseio.container.jms.client.MessageConsumer)6 DefaultMessageConsumer (com.generallycloud.baseio.container.jms.client.impl.DefaultMessageConsumer)6