Search in sources :

Example 31 with SocketChannelContext

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

use of com.generallycloud.baseio.component.SocketChannelContext 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)

Example 33 with SocketChannelContext

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

the class ProtobaseApplicationContextEnricher method enrich.

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

Example 34 with SocketChannelContext

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

the class SystemStopServerServlet method accept.

@Override
public void accept(SocketSession session, Future future) throws Exception {
    SocketChannelContext context = session.getContext();
    future.write("server is stopping");
    session.flush(future);
    new Thread(new StopServer(context)).start();
}
Also used : SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext)

Example 35 with SocketChannelContext

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

the class Http2ProtocolDecoder method decode.

@Override
public ChannelFuture decode(SocketChannel channel, ByteBuf buffer) throws IOException {
    Http2SocketSession http2UnsafeSession = (Http2SocketSession) channel.getSession();
    SocketChannelContext context = channel.getContext();
    if (http2UnsafeSession.isPrefaceRead()) {
        return new Http2PrefaceFuture(context, allocate(channel, PROTOCOL_PREFACE_HEADER));
    }
    return new Http2FrameHeaderImpl(channel, allocate(channel, PROTOCOL_HEADER));
}
Also used : Http2FrameHeaderImpl(com.generallycloud.baseio.codec.http2.future.Http2FrameHeaderImpl) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) Http2PrefaceFuture(com.generallycloud.baseio.codec.http2.future.Http2PrefaceFuture)

Aggregations

SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)65 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)55 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)55 LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)54 SocketChannelConnector (com.generallycloud.baseio.connector.SocketChannelConnector)40 SocketSession (com.generallycloud.baseio.component.SocketSession)36 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)20 SimpleIoEventHandle (com.generallycloud.baseio.container.SimpleIoEventHandle)20 ProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture)17 SocketChannelAcceptor (com.generallycloud.baseio.acceptor.SocketChannelAcceptor)12 FixedLengthProtocolFactory (com.generallycloud.baseio.codec.fixedlength.FixedLengthProtocolFactory)12 FixedLengthFuture (com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFuture)8 ProtobaseFutureImpl (com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl)8 FixedLengthFutureImpl (com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFutureImpl)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