Search in sources :

Example 16 with SocketChannelContext

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

the class TestListenerPower method main.

public static void main(String[] args) throws Exception {
    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");
    MessageConsumer consumer = new DefaultMessageConsumer(session);
    long old = System.currentTimeMillis();
    OnMessage onMessage = new OnMessage() {

        @Override
        public void onReceive(Message message) {
            System.out.println(message);
        }
    };
    for (int i = 0; i < 10000; i++) {
        consumer.receive(onMessage);
    }
    System.out.println("Time:" + (System.currentTimeMillis() - old));
    connector.close();
}
Also used : SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) DefaultMessageConsumer(com.generallycloud.baseio.container.jms.client.impl.DefaultMessageConsumer) MessageConsumer(com.generallycloud.baseio.container.jms.client.MessageConsumer) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) OnMessage(com.generallycloud.baseio.container.jms.client.OnMessage) Message(com.generallycloud.baseio.container.jms.Message) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) FixedSession(com.generallycloud.baseio.container.FixedSession) DefaultMessageConsumer(com.generallycloud.baseio.container.jms.client.impl.DefaultMessageConsumer) OnMessage(com.generallycloud.baseio.container.jms.client.OnMessage) 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)

Example 17 with SocketChannelContext

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

the class TestTellerByteMessage method main.

public static void main(String[] args) throws Exception {
    SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
    SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(8300));
    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");
    MessageProducer producer = new DefaultMessageProducer(session);
    TextByteMessage message = new TextByteMessage("msgId", "uuid", "============", "你好!".getBytes(session.getContext().getEncoding()));
    long old = System.currentTimeMillis();
    for (int i = 0; i < 5; i++) {
        producer.offer(message);
    }
    System.out.println("Time:" + (System.currentTimeMillis() - old));
    connector.close();
}
Also used : TextByteMessage(com.generallycloud.baseio.container.jms.TextByteMessage) SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) DefaultMessageProducer(com.generallycloud.baseio.container.jms.client.impl.DefaultMessageProducer) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) 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) ProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory) DefaultMessageProducer(com.generallycloud.baseio.container.jms.client.impl.DefaultMessageProducer) MessageProducer(com.generallycloud.baseio.container.jms.client.MessageProducer)

Example 18 with SocketChannelContext

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

the class RTPServerDPAcceptor method execute.

@Override
protected void execute(DatagramSession dSession, DatagramRequest request) {
    String serviceName = request.getFutureName();
    if (BIND_SESSION.equals(serviceName)) {
        Parameters parameters = request.getParameters();
        ApplicationContext context = ApplicationContext.getInstance();
        LoginCenter loginCenter = AuthorityContext.getInstance().getLoginCenter();
        if (!loginCenter.isValidate(parameters)) {
            return;
        }
        // FIXME udp
        SocketChannelContext channelContext = context.getChannelContext();
        SocketSessionManager sessionManager = channelContext.getSessionManager();
        // Session session = factory.getSession(username);
        SocketSession session = null;
        if (session == null) {
            return;
        }
        // session.setDatagramChannel(channel); //FIXME udp
        ProtobaseFuture future = new ProtobaseFutureImpl(session.getContext(), BIND_SESSION_CALLBACK);
        logger.debug("___________________bind___session___{}", session);
        future.write("1");
        session.flush(future);
    } else {
        logger.debug(">>>> {}", request.getFutureName());
    }
}
Also used : ApplicationContext(com.generallycloud.baseio.container.ApplicationContext) Parameters(com.generallycloud.baseio.component.Parameters) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) SocketSession(com.generallycloud.baseio.component.SocketSession) SocketSessionManager(com.generallycloud.baseio.component.SocketSessionManager) LoginCenter(com.generallycloud.baseio.container.LoginCenter) ProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext)

Example 19 with SocketChannelContext

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

the class WebSocketSEListener method sessionClosed.

@Override
public void sessionClosed(SocketSession session) {
    if (!WebSocketProtocolFactory.PROTOCOL_ID.equals(session.getProtocolId())) {
        return;
    }
    SocketChannelContext context = session.getContext();
    WebSocketFutureImpl future = new WebSocketFutureImpl(context);
    future.setType(WebSocketProtocolDecoder.TYPE_CLOSE);
    future.setServiceName(session);
    try {
        context.getForeReadFutureAcceptor().accept(session, future);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    super.sessionClosed(session);
}
Also used : SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext)

Example 20 with SocketChannelContext

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

the class BalanceServerBootStrap method getBalanceReverseChannelContext.

private SocketChannelContext getBalanceReverseChannelContext(BalanceContext balanceContext, ServerConfiguration configuration, ProtocolFactory protocolFactory) {
    SocketChannelContext context = new NioSocketChannelContext(configuration);
    // SocketChannelContext context = new AioSocketChannelContext(configuration);
    context.setIoEventHandleAdaptor(balanceContext.getBalanceReverseAcceptorHandler());
    context.addSessionEventListener(balanceContext.getBalanceReverseAcceptorSEListener());
    context.setProtocolFactory(protocolFactory);
    context.setBeatFutureFactory(balanceReverseBeatFutureFactory);
    if (balanceReverseSessionEventListeners != null) {
        addSessionEventListener2Context(context, balanceReverseSessionEventListeners);
    }
    if (balanceReverseSessionIdleEventListeners != null) {
        addSessionIdleEventListener2Context(context, balanceReverseSessionIdleEventListeners);
    }
    return context;
}
Also used : NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

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