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);
}
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());
}
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());
}
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();
}
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));
}
Aggregations