Search in sources :

Example 1 with ParamedProtobaseProtocolFactory

use of com.generallycloud.baseio.codec.protobase.ParamedProtobaseProtocolFactory in project baseio by generallycloud.

the class TestBrowser method main.

public static void main(String[] args) throws Exception {
    String queueName = "qName";
    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 ParamedProtobaseProtocolFactory());
    context.addSessionEventListener(new LoggerSocketSEListener());
    FixedSession session = new FixedSession(connector.connect());
    session.login("admin", "admin100");
    MessageBrowser browser = new DefaultMessageBrowser(session);
    Message message = browser.browser(queueName);
    System.out.println("message:" + message);
    int size = browser.size();
    System.out.println("size:" + size);
    boolean isOnline = browser.isOnline(queueName);
    System.out.println("isOnline:" + isOnline);
    connector.close();
}
Also used : SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) Message(com.generallycloud.baseio.container.jms.Message) 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) DefaultMessageBrowser(com.generallycloud.baseio.container.jms.client.impl.DefaultMessageBrowser) MessageBrowser(com.generallycloud.baseio.container.jms.client.MessageBrowser) DefaultMessageBrowser(com.generallycloud.baseio.container.jms.client.impl.DefaultMessageBrowser) ParamedProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ParamedProtobaseProtocolFactory)

Example 2 with ParamedProtobaseProtocolFactory

use of com.generallycloud.baseio.codec.protobase.ParamedProtobaseProtocolFactory in project baseio by generallycloud.

the class TestListener method main.

public static void main(String[] args) throws Exception {
    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 ParamedProtobaseProtocolFactory());
    context.addSessionEventListener(new LoggerSocketSEListener());
    FixedSession session = new FixedSession(connector.connect());
    session.login("admin", "admin100");
    MessageConsumer consumer = new DefaultMessageConsumer(session);
    long old = System.currentTimeMillis();
    consumer.receive(new OnMessage() {

        @Override
        public void onReceive(Message message) {
            System.out.println(message);
        }
    });
    System.out.println("Time:" + (System.currentTimeMillis() - old));
    ThreadUtil.sleep(1500000);
    CloseUtil.close(connector);
}
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) ParamedProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ParamedProtobaseProtocolFactory)

Example 3 with ParamedProtobaseProtocolFactory

use of com.generallycloud.baseio.codec.protobase.ParamedProtobaseProtocolFactory 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 4 with ParamedProtobaseProtocolFactory

use of com.generallycloud.baseio.codec.protobase.ParamedProtobaseProtocolFactory in project baseio by generallycloud.

the class Test404 method main.

public static void main(String[] args) throws Exception {
    String serviceKey = "22";
    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 ParamedProtobaseProtocolFactory());
    context.addSessionEventListener(new LoggerSocketSEListener());
    FixedSession session = new FixedSession(connector.connect());
    ProtobaseFuture future = session.request(serviceKey, null);
    System.out.println(future.getReadText());
    Future future1 = new ProtobaseFutureImpl(connector.getContext()).setPING();
    session.getSession().flush(future1);
    CloseUtil.close(connector);
}
Also used : 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) ProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl) FixedSession(com.generallycloud.baseio.container.FixedSession) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) Future(com.generallycloud.baseio.protocol.Future) SimpleIoEventHandle(com.generallycloud.baseio.container.SimpleIoEventHandle) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) ParamedProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ParamedProtobaseProtocolFactory) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 5 with ParamedProtobaseProtocolFactory

use of com.generallycloud.baseio.codec.protobase.ParamedProtobaseProtocolFactory in project baseio by generallycloud.

the class TestPublish 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 ParamedProtobaseProtocolFactory());
    context.addSessionEventListener(new LoggerSocketSEListener());
    FixedSession session = new FixedSession(connector.connect());
    session.login("admin", "admin100");
    MessageProducer producer = new DefaultMessageProducer(session);
    TextMessage message = new TextMessage("msgId", "qName", "你好!");
    producer.publish(message);
    connector.close();
}
Also used : 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) DefaultMessageProducer(com.generallycloud.baseio.container.jms.client.impl.DefaultMessageProducer) MessageProducer(com.generallycloud.baseio.container.jms.client.MessageProducer) SimpleIoEventHandle(com.generallycloud.baseio.container.SimpleIoEventHandle) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) ParamedProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ParamedProtobaseProtocolFactory) TextMessage(com.generallycloud.baseio.container.jms.TextMessage) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Aggregations

ParamedProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ParamedProtobaseProtocolFactory)6 LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)6 SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)6 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)5 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)5 SocketChannelConnector (com.generallycloud.baseio.connector.SocketChannelConnector)5 FixedSession (com.generallycloud.baseio.container.FixedSession)5 SimpleIoEventHandle (com.generallycloud.baseio.container.SimpleIoEventHandle)5 Message (com.generallycloud.baseio.container.jms.Message)2 TextMessage (com.generallycloud.baseio.container.jms.TextMessage)2 MessageProducer (com.generallycloud.baseio.container.jms.client.MessageProducer)2 DefaultMessageProducer (com.generallycloud.baseio.container.jms.client.impl.DefaultMessageProducer)2 ParamedProtobaseBeatFutureFactory (com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseBeatFutureFactory)1 ProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture)1 ProtobaseFutureImpl (com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl)1 BlackIPFilter (com.generallycloud.baseio.container.BlackIPFilter)1 MapMessage (com.generallycloud.baseio.container.jms.MapMessage)1 MessageBrowser (com.generallycloud.baseio.container.jms.client.MessageBrowser)1 MessageConsumer (com.generallycloud.baseio.container.jms.client.MessageConsumer)1 OnMessage (com.generallycloud.baseio.container.jms.client.OnMessage)1