/baseio

An io framework project based on java nio

Primary LanguageJavaApache License 2.0Apache-2.0

BaseIO Project

License Maven central Website

BaseIO is an io framework which can build network project fast, it based on java nio, it is popular with Developers because of simple and easy of use APIs and high-performance.

Features

  • easy to support reconnect (easy to support heart beat)
  • simple application container
  • simple hot deploy , eg: https://www.generallycloud.com/system-redeploy
  • support deploy http , micro service (depend on your protocol)
  • easy to supprot load balance, known:
  • virtual node based on hash
  • loop balance node
  • support component extend, known:
  • simple mq service, offer msg, poll msg
  • simple rtp service, for real time voice/video
  • simple invoke limit, for limit inovke times in unit time
  • support protocol extend, known:
  • Redis protocol, for detail {baseio-test}
  • Protobuf protocol, for detail {baseio-test}
  • LineBased protocol, for detail {baseio-test}
  • FixedLength protocol, for detail {baseio-test}
  • HTTP1.1 protocol, for detail: https://www.generallycloud.com/
  • WebSocket protocol, for detail: https://www.generallycloud.com/web-socket/chat/index.html
  • Protobase(custom) support text and binay and text binay mixed transfer, for detail {baseio-test}
  • load test
  • over 320K QPS (Socket,I7-4790,Win10)
  • over 200K QPS (Http1.1,I7-4790,Win10)  ab load test

Quick Start

  • Maven Dependency
  <dependency>
  	<groupId>com.generallycloud</groupId>
  	<artifactId>baseio-all</artifactId>
  	<version>3.1.8-Alpha2</version>
  </dependency>  
  • A simple server:

      public static void main(String[] args) throws Exception {
    
      	IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
    
      		@Override
      		public void accept(SocketSession session, ReadFuture future) throws Exception {
      			future.write("yes server already accept your message:");
      			future.write(future.getReadText());
      			session.flush(future);
      		}
      	};
      	
      	SocketChannelContext context = new SocketChannelContextImpl(new ServerConfiguration(18300));
      	
      	SocketChannelAcceptor acceptor = new SocketChannelAcceptor(context);
      	
      	context.addSessionEventListener(new LoggerSocketSEListener());
      	
      	context.setIoEventHandleAdaptor(eventHandleAdaptor);
      	
      	context.setProtocolFactory(new FixedLengthProtocolFactory());
    
      	acceptor.bind();
      }
  • A simple client:

      public static void main(String[] args) throws Exception {
    
      	IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
    
      		@Override
      		public void accept(SocketSession session, ReadFuture future) throws Exception {
      			System.out.println();
      			System.out.println("____________________"+future.getReadText());
      			System.out.println();
      		}
      	};
      	
      	SocketChannelContext context = new SocketChannelContextImpl(new ServerConfiguration("localhost", 18300));
    
      	SocketChannelConnector connector = new SocketChannelConnector(context);
    
      	context.setIoEventHandleAdaptor(eventHandleAdaptor);
      	
      	context.addSessionEventListener(new LoggerSocketSEListener());
    
      	context.setProtocolFactory(new FixedLengthProtocolFactory());
      	
      	SocketSession session = connector.connect();
    
      	FixedLengthReadFuture future = new FixedLengthReadFutureImpl(context);
    
      	future.write("hello server!");
    
      	session.flush(future);
      	
      	ThreadUtil.sleep(100);
    
      	CloseUtil.close(connector);
      }

more samples {baseio-test}

Sample at website:

License

BaseIO is released under the Apache License 2.0.

For learn more, join this QQ group, more java technique can talk at there.

  • QQ group NO: 540637859
  • Join by click this link: img
  • Scan QR code:
    image