├── .gitignore ├── 001.png ├── 002.png ├── 003.png ├── EchoServer ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── org │ └── apache │ └── mina │ └── example │ └── echoserver │ ├── EchoProtocolHandler.java │ ├── Main.java │ ├── package.html │ └── ssl │ ├── BogusSslContextFactory.java │ ├── BogusTrustManagerFactory.java │ ├── SslServerSocketFactory.java │ ├── SslSocketFactory.java │ └── package.html ├── HaikuValidationServer ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── org │ └── apache │ └── mina │ └── example │ └── haiku │ ├── Haiku.java │ ├── HaikuValidationServer.java │ ├── HaikuValidator.java │ ├── HaikuValidatorIoHandler.java │ ├── InvalidHaikuException.java │ ├── PhraseUtilities.java │ └── ToHaikuIoFilter.java ├── Long_TCP_Client ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── org │ └── apache │ └── mina │ └── test │ └── LongTcpClient.java ├── Long_TCP_Server ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── org │ └── apache │ └── mina │ └── test │ ├── ClientKeepAliveMessageFactoryImp.java │ ├── ClientSessionHandler.java │ ├── KeepAliveMessageFactoryImp.java │ ├── LongTcpServer.java │ ├── ServerKeepAliveMessageFactoryImp.java │ └── ServerSessionHandler.java ├── MemMonClient ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── org │ └── apache │ └── mina │ └── example │ └── udp │ └── client │ └── MemMonClient.java ├── MemoryMonitor ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── org │ └── apache │ └── mina │ └── example │ └── udp │ ├── ClientPanel.java │ ├── MemoryMonitor.java │ └── MemoryMonitorHandler.java ├── NetCatClient ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── org │ └── apache │ └── mina │ └── example │ └── netcat │ ├── Main.java │ ├── NetCatProtocolHandler.java │ └── package.html ├── Proxyserver ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── org │ └── apache │ └── mina │ └── example │ └── proxy │ ├── AbstractProxyIoHandler.java │ ├── ClientToProxyIoHandler.java │ ├── Main.java │ ├── ServerToProxyIoHandler.java │ └── package.html ├── README.md ├── ReverserServer ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── org │ └── apache │ └── mina │ └── example │ └── reverser │ ├── Main.java │ ├── ReverseProtocolHandler.java │ └── package.html ├── SumUpClient ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── org │ └── apache │ └── mina │ └── example │ └── sumup │ ├── Client.java │ └── ClientSessionHandler.java ├── SumUpCommon ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── org │ └── apache │ └── mina │ └── example │ └── sumup │ ├── codec │ ├── AbstractMessageDecoder.java │ ├── AbstractMessageEncoder.java │ ├── AddMessageDecoder.java │ ├── AddMessageEncoder.java │ ├── Constants.java │ ├── ResultMessageDecoder.java │ ├── ResultMessageEncoder.java │ ├── SumUpProtocolCodecFactory.java │ └── package.html │ └── message │ ├── AbstractMessage.java │ ├── AddMessage.java │ ├── ResultMessage.java │ └── package.html ├── SumUpServer ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── org │ └── apache │ └── mina │ └── example │ └── sumup │ ├── Server.java │ └── ServerSessionHandler.java ├── TCPClient ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── org │ └── apache │ └── mina │ └── example │ └── tcp │ └── perf │ └── TcpClient.java ├── TCPServer ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── org │ └── apache │ └── mina │ └── example │ └── tcp │ └── perf │ └── TcpServer.java ├── TennisBall ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── org │ └── apache │ └── mina │ └── example │ └── tennis │ ├── Main.java │ ├── TennisBall.java │ ├── TennisPlayer.java │ └── package.html ├── TimeServer ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── org │ └── apache │ └── mina │ └── example │ └── gettingstarted │ └── timeserver │ ├── MinaTimeServer.java │ └── TimeServerHandler.java ├── UDPClient ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── org │ └── apache │ └── mina │ └── example │ └── udp │ └── perf │ └── UdpClient.java ├── UDPServer ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── org │ └── apache │ └── mina │ └── example │ └── udp │ └── perf │ └── UdpServer.java ├── android-client ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── neal │ │ └── minapush │ │ ├── activity │ │ └── MainActivity.java │ │ ├── applicaiton │ │ └── BaseApplication.java │ │ ├── push │ │ ├── ClientKeepAliveMessageFactoryImp.java │ │ ├── ClientPushMessage.java │ │ ├── ClientSessionHandler.java │ │ ├── Config.java │ │ ├── PushEventListener.java │ │ ├── PushManager.java │ │ ├── ServerKeepAliveMessageFactoryImp.java │ │ └── ServerPushMessage.java │ │ ├── service │ │ └── PushService.java │ │ └── util │ │ └── NetworkUtil.java │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── layout │ └── activity_main.xml │ └── values │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── common ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── org │ └── apache │ └── mina │ ├── core │ ├── IoUtil.java │ ├── RuntimeIoException.java │ ├── buffer │ │ ├── AbstractIoBuffer.java │ │ ├── BufferDataException.java │ │ ├── CachedBufferAllocator.java │ │ ├── IoBuffer.java │ │ ├── IoBufferAllocator.java │ │ ├── IoBufferHexDumper.java │ │ ├── IoBufferWrapper.java │ │ └── SimpleBufferAllocator.java │ ├── file │ │ ├── DefaultFileRegion.java │ │ ├── FileRegion.java │ │ └── FilenameFileRegion.java │ ├── filterchain │ │ ├── DefaultIoFilterChain.java │ │ ├── DefaultIoFilterChainBuilder.java │ │ ├── IoFilter.java │ │ ├── IoFilterAdapter.java │ │ ├── IoFilterChain.java │ │ ├── IoFilterChainBuilder.java │ │ ├── IoFilterEvent.java │ │ └── IoFilterLifeCycleException.java │ ├── future │ │ ├── CloseFuture.java │ │ ├── CompositeIoFuture.java │ │ ├── ConnectFuture.java │ │ ├── DefaultCloseFuture.java │ │ ├── DefaultConnectFuture.java │ │ ├── DefaultIoFuture.java │ │ ├── DefaultReadFuture.java │ │ ├── DefaultWriteFuture.java │ │ ├── IoFuture.java │ │ ├── IoFutureListener.java │ │ ├── ReadFuture.java │ │ └── WriteFuture.java │ ├── polling │ │ ├── AbstractPollingIoAcceptor.java │ │ ├── AbstractPollingIoConnector.java │ │ ├── AbstractPollingIoProcessor.java │ │ └── package.html │ ├── service │ │ ├── AbstractIoAcceptor.java │ │ ├── AbstractIoConnector.java │ │ ├── AbstractIoService.java │ │ ├── DefaultTransportMetadata.java │ │ ├── IoAcceptor.java │ │ ├── IoConnector.java │ │ ├── IoHandler.java │ │ ├── IoHandlerAdapter.java │ │ ├── IoProcessor.java │ │ ├── IoService.java │ │ ├── IoServiceListener.java │ │ ├── IoServiceListenerSupport.java │ │ ├── IoServiceStatistics.java │ │ ├── SimpleIoProcessorPool.java │ │ └── TransportMetadata.java │ ├── session │ │ ├── AbstractIoSession.java │ │ ├── AbstractIoSessionConfig.java │ │ ├── AttributeKey.java │ │ ├── DefaultIoSessionDataStructureFactory.java │ │ ├── DummySession.java │ │ ├── ExpiringSessionRecycler.java │ │ ├── IdleStatus.java │ │ ├── IdleStatusChecker.java │ │ ├── IoEvent.java │ │ ├── IoEventType.java │ │ ├── IoSession.java │ │ ├── IoSessionAttributeMap.java │ │ ├── IoSessionConfig.java │ │ ├── IoSessionDataStructureFactory.java │ │ ├── IoSessionInitializationException.java │ │ ├── IoSessionInitializer.java │ │ ├── IoSessionRecycler.java │ │ ├── SessionState.java │ │ └── UnknownMessageTypeException.java │ └── write │ │ ├── DefaultWriteRequest.java │ │ ├── NothingWrittenException.java │ │ ├── WriteException.java │ │ ├── WriteRequest.java │ │ ├── WriteRequestQueue.java │ │ ├── WriteRequestWrapper.java │ │ ├── WriteTimeoutException.java │ │ └── WriteToClosedSessionException.java │ ├── filter │ ├── buffer │ │ ├── BufferedWriteFilter.java │ │ └── IoBufferLazyInitializer.java │ ├── codec │ │ ├── AbstractProtocolDecoderOutput.java │ │ ├── AbstractProtocolEncoderOutput.java │ │ ├── CumulativeProtocolDecoder.java │ │ ├── ProtocolCodecException.java │ │ ├── ProtocolCodecFactory.java │ │ ├── ProtocolCodecFilter.java │ │ ├── ProtocolCodecSession.java │ │ ├── ProtocolDecoder.java │ │ ├── ProtocolDecoderAdapter.java │ │ ├── ProtocolDecoderException.java │ │ ├── ProtocolDecoderOutput.java │ │ ├── ProtocolEncoder.java │ │ ├── ProtocolEncoderAdapter.java │ │ ├── ProtocolEncoderException.java │ │ ├── ProtocolEncoderOutput.java │ │ ├── RecoverableProtocolDecoderException.java │ │ ├── SynchronizedProtocolDecoder.java │ │ ├── SynchronizedProtocolEncoder.java │ │ ├── demux │ │ │ ├── DemuxingProtocolCodecFactory.java │ │ │ ├── DemuxingProtocolDecoder.java │ │ │ ├── DemuxingProtocolEncoder.java │ │ │ ├── MessageDecoder.java │ │ │ ├── MessageDecoderAdapter.java │ │ │ ├── MessageDecoderFactory.java │ │ │ ├── MessageDecoderResult.java │ │ │ ├── MessageEncoder.java │ │ │ ├── MessageEncoderFactory.java │ │ │ └── package.html │ │ ├── package.html │ │ ├── prefixedstring │ │ │ ├── PrefixedStringCodecFactory.java │ │ │ ├── PrefixedStringDecoder.java │ │ │ └── PrefixedStringEncoder.java │ │ ├── serialization │ │ │ ├── ObjectSerializationCodecFactory.java │ │ │ ├── ObjectSerializationDecoder.java │ │ │ ├── ObjectSerializationEncoder.java │ │ │ ├── ObjectSerializationInputStream.java │ │ │ ├── ObjectSerializationOutputStream.java │ │ │ └── package.html │ │ ├── statemachine │ │ │ ├── ConsumeToCrLfDecodingState.java │ │ │ ├── ConsumeToDynamicTerminatorDecodingState.java │ │ │ ├── ConsumeToEndOfSessionDecodingState.java │ │ │ ├── ConsumeToLinearWhitespaceDecodingState.java │ │ │ ├── ConsumeToTerminatorDecodingState.java │ │ │ ├── CrLfDecodingState.java │ │ │ ├── DecodingState.java │ │ │ ├── DecodingStateMachine.java │ │ │ ├── DecodingStateProtocolDecoder.java │ │ │ ├── FixedLengthDecodingState.java │ │ │ ├── IntegerDecodingState.java │ │ │ ├── LinearWhitespaceSkippingState.java │ │ │ ├── ShortIntegerDecodingState.java │ │ │ ├── SingleByteDecodingState.java │ │ │ └── SkippingState.java │ │ └── textline │ │ │ ├── LineDelimiter.java │ │ │ ├── TextLineCodecFactory.java │ │ │ ├── TextLineDecoder.java │ │ │ ├── TextLineEncoder.java │ │ │ └── package.html │ ├── errorgenerating │ │ ├── ErrorGeneratingFilter.java │ │ └── package.html │ ├── executor │ │ ├── DefaultIoEventSizeEstimator.java │ │ ├── ExecutorFilter.java │ │ ├── IoEventQueueHandler.java │ │ ├── IoEventQueueThrottle.java │ │ ├── IoEventSizeEstimator.java │ │ ├── OrderedThreadPoolExecutor.java │ │ ├── UnorderedThreadPoolExecutor.java │ │ ├── WriteRequestFilter.java │ │ └── package.html │ ├── firewall │ │ ├── BlacklistFilter.java │ │ ├── ConnectionThrottleFilter.java │ │ ├── Subnet.java │ │ └── package.html │ ├── keepalive │ │ ├── KeepAliveFilter.java │ │ ├── KeepAliveMessageFactory.java │ │ ├── KeepAliveRequestTimeoutException.java │ │ ├── KeepAliveRequestTimeoutHandler.java │ │ └── package.html │ ├── logging │ │ ├── LogLevel.java │ │ ├── LoggingFilter.java │ │ ├── MdcInjectionFilter.java │ │ └── package.html │ ├── ssl │ │ ├── BogusTrustManagerFactory.java │ │ ├── KeyStoreFactory.java │ │ ├── SslContextFactory.java │ │ ├── SslFilter.java │ │ ├── SslHandler.java │ │ └── package.html │ ├── statistic │ │ ├── ProfilerTimerFilter.java │ │ └── package.html │ ├── stream │ │ ├── AbstractStreamWriteFilter.java │ │ ├── FileRegionWriteFilter.java │ │ ├── StreamWriteFilter.java │ │ └── package.html │ └── util │ │ ├── CommonEventFilter.java │ │ ├── NoopFilter.java │ │ ├── ReferenceCountingFilter.java │ │ ├── SessionAttributeInitializingFilter.java │ │ ├── WriteRequestFilter.java │ │ └── package.html │ ├── handler │ ├── chain │ │ ├── ChainedIoHandler.java │ │ ├── IoHandlerChain.java │ │ ├── IoHandlerCommand.java │ │ └── package.html │ ├── demux │ │ ├── DemuxingIoHandler.java │ │ ├── ExceptionHandler.java │ │ ├── MessageHandler.java │ │ └── package.html │ ├── multiton │ │ ├── SingleSessionIoHandler.java │ │ ├── SingleSessionIoHandlerAdapter.java │ │ ├── SingleSessionIoHandlerDelegate.java │ │ ├── SingleSessionIoHandlerFactory.java │ │ └── package.html │ ├── package.html │ └── stream │ │ ├── IoSessionInputStream.java │ │ ├── IoSessionOutputStream.java │ │ └── StreamIoHandler.java │ ├── proxy │ ├── AbstractProxyIoHandler.java │ ├── AbstractProxyLogicHandler.java │ ├── ProxyAuthException.java │ ├── ProxyConnector.java │ ├── ProxyLogicHandler.java │ ├── event │ │ ├── IoSessionEvent.java │ │ ├── IoSessionEventQueue.java │ │ └── IoSessionEventType.java │ ├── filter │ │ ├── ProxyFilter.java │ │ └── ProxyHandshakeIoBuffer.java │ ├── handlers │ │ ├── ProxyRequest.java │ │ ├── http │ │ │ ├── AbstractAuthLogicHandler.java │ │ │ ├── AbstractHttpLogicHandler.java │ │ │ ├── HttpAuthenticationMethods.java │ │ │ ├── HttpProxyConstants.java │ │ │ ├── HttpProxyRequest.java │ │ │ ├── HttpProxyResponse.java │ │ │ ├── HttpSmartProxyHandler.java │ │ │ ├── basic │ │ │ │ ├── HttpBasicAuthLogicHandler.java │ │ │ │ └── HttpNoAuthLogicHandler.java │ │ │ ├── digest │ │ │ │ ├── DigestUtilities.java │ │ │ │ └── HttpDigestAuthLogicHandler.java │ │ │ └── ntlm │ │ │ │ ├── HttpNTLMAuthLogicHandler.java │ │ │ │ ├── NTLMConstants.java │ │ │ │ ├── NTLMResponses.java │ │ │ │ └── NTLMUtilities.java │ │ └── socks │ │ │ ├── AbstractSocksLogicHandler.java │ │ │ ├── Socks4LogicHandler.java │ │ │ ├── Socks5LogicHandler.java │ │ │ ├── SocksProxyConstants.java │ │ │ └── SocksProxyRequest.java │ ├── session │ │ ├── ProxyIoSession.java │ │ └── ProxyIoSessionInitializer.java │ └── utils │ │ ├── ByteUtilities.java │ │ ├── IoBufferDecoder.java │ │ └── StringUtilities.java │ ├── test │ ├── ClientKeepAliveMessageFactoryImp.java │ ├── ClientSessionHandler.java │ ├── KeepAliveMessageFactoryImp.java │ ├── LongTcpServer.java │ ├── ServerKeepAliveMessageFactoryImp.java │ └── ServerSessionHandler.java │ ├── transport │ ├── socket │ │ ├── AbstractDatagramSessionConfig.java │ │ ├── AbstractSocketSessionConfig.java │ │ ├── DatagramAcceptor.java │ │ ├── DatagramConnector.java │ │ ├── DatagramSessionConfig.java │ │ ├── DefaultDatagramSessionConfig.java │ │ ├── DefaultSocketSessionConfig.java │ │ ├── SocketAcceptor.java │ │ ├── SocketConnector.java │ │ ├── SocketSessionConfig.java │ │ └── nio │ │ │ ├── NioDatagramAcceptor.java │ │ │ ├── NioDatagramConnector.java │ │ │ ├── NioDatagramSession.java │ │ │ ├── NioDatagramSessionConfig.java │ │ │ ├── NioProcessor.java │ │ │ ├── NioSession.java │ │ │ ├── NioSocketAcceptor.java │ │ │ ├── NioSocketConnector.java │ │ │ ├── NioSocketSession.java │ │ │ └── package.html │ └── vmpipe │ │ ├── DefaultVmPipeSessionConfig.java │ │ ├── VmPipe.java │ │ ├── VmPipeAcceptor.java │ │ ├── VmPipeAddress.java │ │ ├── VmPipeConnector.java │ │ ├── VmPipeFilterChain.java │ │ ├── VmPipeSession.java │ │ ├── VmPipeSessionConfig.java │ │ └── package.html │ └── util │ ├── AvailablePortFinder.java │ ├── Base64.java │ ├── CircularQueue.java │ ├── ConcurrentHashSet.java │ ├── CopyOnWriteMap.java │ ├── DefaultExceptionMonitor.java │ ├── ExceptionMonitor.java │ ├── ExpirationListener.java │ ├── ExpiringMap.java │ ├── IdentityHashSet.java │ ├── LazyInitializedCacheMap.java │ ├── LazyInitializer.java │ ├── Log4jXmlFormatter.java │ ├── MapBackedSet.java │ ├── NamePreservingRunnable.java │ ├── SynchronizedQueue.java │ ├── Transform.java │ ├── byteaccess │ ├── AbstractByteArray.java │ ├── BufferByteArray.java │ ├── ByteArray.java │ ├── ByteArrayFactory.java │ ├── ByteArrayList.java │ ├── ByteArrayPool.java │ ├── CompositeByteArray.java │ ├── CompositeByteArrayRelativeBase.java │ ├── CompositeByteArrayRelativeReader.java │ ├── CompositeByteArrayRelativeWriter.java │ ├── IoAbsoluteReader.java │ ├── IoAbsoluteWriter.java │ ├── IoRelativeReader.java │ ├── IoRelativeWriter.java │ └── SimpleByteArrayFactory.java │ └── package.html ├── gradle.properties ├── gradle └── wrapper │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### NetBeans template 3 | nbproject/private/ 4 | build/ 5 | nbbuild/ 6 | dist/ 7 | nbdist/ 8 | nbactions.xml 9 | nb-configuration.xml 10 | 11 | # Mac OS X Garbage 12 | .DS_Store 13 | Thumbs.db 14 | 15 | .idea/ 16 | 17 | ### Android Studio 18 | /jniLibs 19 | mobile/mobile.iml 20 | mobile/mobile.iml 21 | tv/tv.iml 22 | app/app.iml 23 | app/*.iml 24 | *.iml 25 | mobile/*.iml 26 | tv/*.iml 27 | .idea/workspace.xml 28 | .idea/libraries 29 | .idea/ 30 | .idea 31 | /build 32 | /captures 33 | ### Android template 34 | # Built application files 35 | *.apk 36 | *.ap_ 37 | /build 38 | /captures 39 | # Files for the Dalvik VM 40 | *.dex 41 | 42 | # Java class files 43 | *.class 44 | 45 | # Generated files 46 | bin/ 47 | gen/ 48 | 49 | # Gradle files 50 | .gradle/ 51 | 52 | # Local configuration file (sdk path, etc) 53 | local.properties 54 | 55 | # Proguard folder generated by Eclipse 56 | proguard/ 57 | 58 | # Log Files 59 | *.log 60 | 61 | 62 | ### Java template 63 | *.class 64 | 65 | # Mobile Tools for Java (J2ME) 66 | .mtj.tmp/ 67 | 68 | # Package Files # 69 | *.jar 70 | *.war 71 | *.ear 72 | 73 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 74 | hs_err_pid* 75 | 76 | 77 | ### Eclipse template 78 | *.pydevproject 79 | .metadata 80 | .gradle 81 | bin/ 82 | tmp/ 83 | *.tmp 84 | *.bak 85 | *.swp 86 | *~.nib 87 | .settings/ 88 | .loadpath 89 | /build 90 | /captures 91 | # External tool builders 92 | .externalToolBuilders/ 93 | 94 | # Locally stored "Eclipse launch configurations" 95 | *.launch 96 | 97 | # CDT-specific 98 | .cproject 99 | 100 | # PDT-specific 101 | .buildpath 102 | 103 | # sbteclipse plugin 104 | .target 105 | 106 | # TeXlipse plugin 107 | .texlipse 108 | 109 | # Android Studio 110 | *.iml 111 | 112 | # Keep external libs 113 | !app/libs/*.jar 114 | 115 | # script output 116 | check-dpi.txt* 117 | -------------------------------------------------------------------------------- /001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sddyljsx/tcp-long-connection-based-on-apache-mina/c82332d7e7543ff9d785bb40ee09c1b22846ffbd/001.png -------------------------------------------------------------------------------- /002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sddyljsx/tcp-long-connection-based-on-apache-mina/c82332d7e7543ff9d785bb40ee09c1b22846ffbd/002.png -------------------------------------------------------------------------------- /003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sddyljsx/tcp-long-connection-based-on-apache-mina/c82332d7e7543ff9d785bb40ee09c1b22846ffbd/003.png -------------------------------------------------------------------------------- /EchoServer/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /EchoServer/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /EchoServer/src/main/java/org/apache/mina/example/echoserver/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Echo server which demonstates low-level I/O layer and SSL support. 23 | 24 | 25 | -------------------------------------------------------------------------------- /EchoServer/src/main/java/org/apache/mina/example/echoserver/ssl/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | SSL support classes. 23 | 24 | 25 | -------------------------------------------------------------------------------- /HaikuValidationServer/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /HaikuValidationServer/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /HaikuValidationServer/src/main/java/org/apache/mina/example/haiku/Haiku.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.mina.example.haiku; 20 | 21 | import java.util.Arrays; 22 | 23 | /** 24 | * @author Apache MINA Project 25 | */ 26 | public class Haiku { 27 | private final String[] phrases; 28 | 29 | public Haiku(String... lines) { 30 | this.phrases = lines; 31 | if (null == lines || lines.length != 3) { 32 | throw new IllegalArgumentException("Must pass in 3 phrases of text"); 33 | } 34 | } 35 | 36 | public String[] getPhrases() { 37 | return phrases; 38 | } 39 | 40 | @Override 41 | public boolean equals(Object o) { 42 | if (this == o) 43 | return true; 44 | if (o == null || getClass() != o.getClass()) 45 | return false; 46 | 47 | Haiku haiku = (Haiku) o; 48 | 49 | return Arrays.equals(phrases, haiku.phrases); 50 | } 51 | 52 | @Override 53 | public int hashCode() { 54 | return Arrays.hashCode(phrases); 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return Arrays.toString(phrases); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /HaikuValidationServer/src/main/java/org/apache/mina/example/haiku/HaikuValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.mina.example.haiku; 20 | 21 | /** 22 | * @author Apache MINA Project 23 | */ 24 | public class HaikuValidator { 25 | private static final int[] SYLLABLE_COUNTS = { 5, 7, 5 }; 26 | 27 | public void validate(Haiku haiku) throws InvalidHaikuException { 28 | String[] phrases = haiku.getPhrases(); 29 | 30 | for (int i = 0; i < phrases.length; i++) { 31 | String phrase = phrases[i]; 32 | int count = PhraseUtilities.countSyllablesInPhrase(phrase); 33 | 34 | if (count != SYLLABLE_COUNTS[i]) { 35 | throw new InvalidHaikuException(i + 1, phrase, count, 36 | SYLLABLE_COUNTS[i]); 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /HaikuValidationServer/src/main/java/org/apache/mina/example/haiku/HaikuValidatorIoHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.mina.example.haiku; 20 | 21 | import org.apache.mina.core.service.IoHandlerAdapter; 22 | import org.apache.mina.core.session.IoSession; 23 | 24 | /** 25 | * @author Apache MINA Project 26 | */ 27 | 28 | public class HaikuValidatorIoHandler extends IoHandlerAdapter { 29 | 30 | private final HaikuValidator validator = new HaikuValidator(); 31 | 32 | @Override 33 | public void messageReceived(IoSession session, Object message) 34 | throws Exception { 35 | Haiku haiku = (Haiku) message; 36 | 37 | try { 38 | validator.validate(haiku); 39 | session.write("HAIKU!"); 40 | } catch (InvalidHaikuException e) { 41 | session.write("NOT A HAIKU: " + e.getMessage()); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /HaikuValidationServer/src/main/java/org/apache/mina/example/haiku/InvalidHaikuException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.mina.example.haiku; 20 | 21 | /** 22 | * @author Apache MINA Project 23 | */ 24 | public class InvalidHaikuException extends Exception { 25 | private static final long serialVersionUID = 34877739006797894L; 26 | 27 | private final int position; 28 | 29 | private final String phrase; 30 | 31 | private final int syllableCount; 32 | 33 | private final int expectedSyllableCount; 34 | 35 | public InvalidHaikuException(int position, String phrase, 36 | int syllableCount, int expectedSyllableCount) { 37 | super("phrase " + position + ", '" + phrase + "' had " + syllableCount 38 | + " syllables, not " + expectedSyllableCount); 39 | 40 | this.position = position; 41 | this.phrase = phrase; 42 | this.syllableCount = syllableCount; 43 | this.expectedSyllableCount = expectedSyllableCount; 44 | } 45 | 46 | public int getExpectedSyllableCount() { 47 | return expectedSyllableCount; 48 | } 49 | 50 | public String getPhrase() { 51 | return phrase; 52 | } 53 | 54 | public int getSyllableCount() { 55 | return syllableCount; 56 | } 57 | 58 | public int getPhrasePosition() { 59 | return position; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /HaikuValidationServer/src/main/java/org/apache/mina/example/haiku/ToHaikuIoFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.mina.example.haiku; 20 | 21 | import org.apache.mina.core.filterchain.IoFilterAdapter; 22 | import org.apache.mina.core.session.IoSession; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | /** 28 | * @author Apache MINA Project 29 | */ 30 | public class ToHaikuIoFilter extends IoFilterAdapter { 31 | 32 | @SuppressWarnings( { "unchecked" }) 33 | @Override 34 | public void messageReceived(NextFilter nextFilter, IoSession session, 35 | Object message) throws Exception { 36 | List phrases = (List) session.getAttribute("phrases"); 37 | 38 | if (null == phrases) { 39 | phrases = new ArrayList(); 40 | session.setAttribute("phrases", phrases); 41 | } 42 | 43 | phrases.add((String) message); 44 | 45 | if (phrases.size() == 3) { 46 | session.removeAttribute("phrases"); 47 | 48 | super.messageReceived(nextFilter, session, new Haiku(phrases 49 | .toArray(new String[3]))); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Long_TCP_Client/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Long_TCP_Client/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /Long_TCP_Client/src/main/java/org/apache/mina/test/LongTcpClient.java: -------------------------------------------------------------------------------- 1 | package org.apache.mina.test; 2 | 3 | import org.apache.mina.core.RuntimeIoException; 4 | import org.apache.mina.core.session.IdleStatus; 5 | import org.apache.mina.filter.codec.ProtocolCodecFilter; 6 | import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; 7 | import org.apache.mina.filter.keepalive.KeepAliveFilter; 8 | import org.apache.mina.filter.keepalive.KeepAliveRequestTimeoutHandler; 9 | import org.apache.mina.filter.logging.LoggingFilter; 10 | import org.apache.mina.transport.socket.nio.NioSocketConnector; 11 | 12 | import java.net.InetSocketAddress; 13 | 14 | public class LongTcpClient { 15 | private static final String HOSTNAME = "192.168.1.15"; 16 | 17 | private static final int PORT = 8081; 18 | 19 | private static final long CONNECT_TIMEOUT = 30*1000L; // 30 seconds 20 | 21 | 22 | public static void main(String[] args) throws Throwable { 23 | 24 | NioSocketConnector connector = new NioSocketConnector(); 25 | 26 | // Configure the service. 27 | connector.setConnectTimeoutMillis(CONNECT_TIMEOUT); 28 | connector.setHandler(new ClientSessionHandler()); 29 | //connector.getFilterChain().addLast( "codec", new ProtocolCodecFilter( new TextLineCodecFactory( Charset.forName( "UTF-8" )))); 30 | connector.getFilterChain().addLast( "codec", new ProtocolCodecFilter( new ObjectSerializationCodecFactory())); 31 | connector.getFilterChain().addLast("logger", new LoggingFilter()); 32 | connector.getFilterChain().addLast("keeplive", new KeepAliveFilter(new ClientKeepAliveMessageFactoryImp(), IdleStatus.READER_IDLE, KeepAliveRequestTimeoutHandler.DEAF_SPEAKER,10, 5)); 33 | 34 | try { 35 | connector.connect(new InetSocketAddress( 36 | HOSTNAME, PORT)); 37 | } catch (RuntimeIoException e) { 38 | System.err.println("Failed to connect."); 39 | e.printStackTrace(); 40 | 41 | } 42 | } 43 | 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Long_TCP_Server/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Long_TCP_Server/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /Long_TCP_Server/src/main/java/org/apache/mina/test/ClientKeepAliveMessageFactoryImp.java: -------------------------------------------------------------------------------- 1 | package org.apache.mina.test; 2 | 3 | import org.apache.mina.core.session.IoSession; 4 | import org.apache.mina.filter.keepalive.KeepAliveMessageFactory; 5 | 6 | public class ClientKeepAliveMessageFactoryImp implements KeepAliveMessageFactory{ 7 | 8 | @Override 9 | public boolean isRequest(IoSession session, Object message) { 10 | // TODO Auto-generated method stub 11 | if(message instanceof String && message.equals("ping")){ 12 | return true; 13 | } 14 | return false; 15 | } 16 | 17 | @Override 18 | public boolean isResponse(IoSession session, Object message) { 19 | // TODO Auto-generated method stub 20 | if(message instanceof String && message.equals("pong")){ 21 | return true; 22 | } 23 | return false; 24 | } 25 | 26 | @Override 27 | public Object getRequest(IoSession session) { 28 | // TODO Auto-generated method stub 29 | return "ping"; 30 | } 31 | 32 | @Override 33 | public Object getResponse(IoSession session, Object request) { 34 | // TODO Auto-generated method stub 35 | return null; 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /Long_TCP_Server/src/main/java/org/apache/mina/test/ClientSessionHandler.java: -------------------------------------------------------------------------------- 1 | package org.apache.mina.test; 2 | 3 | import org.apache.mina.core.service.IoHandlerAdapter; 4 | import org.apache.mina.core.session.IoSession; 5 | 6 | public class ClientSessionHandler extends IoHandlerAdapter{ 7 | 8 | @Override 9 | public void sessionOpened(IoSession session) throws Exception { 10 | // TODO Auto-generated method stub 11 | super.sessionOpened(session); 12 | session.write("hello"); 13 | } 14 | 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Long_TCP_Server/src/main/java/org/apache/mina/test/KeepAliveMessageFactoryImp.java: -------------------------------------------------------------------------------- 1 | package org.apache.mina.test; 2 | 3 | import org.apache.mina.core.session.IoSession; 4 | import org.apache.mina.filter.keepalive.KeepAliveMessageFactory; 5 | 6 | public class KeepAliveMessageFactoryImp implements KeepAliveMessageFactory{ 7 | 8 | @Override 9 | public boolean isRequest(IoSession session, Object message) { 10 | // TODO Auto-generated method stub 11 | if(message instanceof String && message.equals("ping")){ 12 | return true; 13 | } 14 | return false; 15 | } 16 | 17 | @Override 18 | public boolean isResponse(IoSession session, Object message) { 19 | // TODO Auto-generated method stub 20 | if(message instanceof String && message.equals("pong")){ 21 | return true; 22 | } 23 | return false; 24 | } 25 | 26 | @Override 27 | public Object getRequest(IoSession session) { 28 | // TODO Auto-generated method stub 29 | return "ping"; 30 | } 31 | 32 | @Override 33 | public Object getResponse(IoSession session, Object request) { 34 | // TODO Auto-generated method stub 35 | return "pong"; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Long_TCP_Server/src/main/java/org/apache/mina/test/LongTcpServer.java: -------------------------------------------------------------------------------- 1 | package org.apache.mina.test; 2 | 3 | import org.apache.mina.core.session.IdleStatus; 4 | import org.apache.mina.filter.codec.ProtocolCodecFilter; 5 | import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; 6 | import org.apache.mina.filter.keepalive.KeepAliveFilter; 7 | import org.apache.mina.filter.keepalive.KeepAliveRequestTimeoutHandler; 8 | import org.apache.mina.filter.logging.LoggingFilter; 9 | import org.apache.mina.transport.socket.nio.NioSocketAcceptor; 10 | 11 | import java.net.InetSocketAddress; 12 | 13 | public class LongTcpServer { 14 | private static final int SERVER_PORT = 8081; 15 | 16 | public static void main(String[] args) throws Throwable { 17 | NioSocketAcceptor acceptor = new NioSocketAcceptor(); 18 | //acceptor.getFilterChain().addLast( "codec", new ProtocolCodecFilter( new TextLineCodecFactory( Charset.forName( "UTF-8" )))); 19 | acceptor.getFilterChain().addLast( "codec", new ProtocolCodecFilter( new ObjectSerializationCodecFactory())); 20 | acceptor.getFilterChain().addLast("logger", new LoggingFilter()); 21 | acceptor.getFilterChain().addLast("keeplive", new KeepAliveFilter(new ServerKeepAliveMessageFactoryImp(), IdleStatus.READER_IDLE, KeepAliveRequestTimeoutHandler.CLOSE,10, 5)); 22 | 23 | acceptor.setHandler(new ServerSessionHandler()); 24 | acceptor.bind(new InetSocketAddress("192.168.1.15",SERVER_PORT)); 25 | System.out.println("Listening on port " + SERVER_PORT); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Long_TCP_Server/src/main/java/org/apache/mina/test/ServerKeepAliveMessageFactoryImp.java: -------------------------------------------------------------------------------- 1 | package org.apache.mina.test; 2 | 3 | import org.apache.mina.core.session.IoSession; 4 | import org.apache.mina.filter.keepalive.KeepAliveMessageFactory; 5 | 6 | public class ServerKeepAliveMessageFactoryImp implements KeepAliveMessageFactory{ 7 | 8 | @Override 9 | public boolean isRequest(IoSession session, Object message) { 10 | // TODO Auto-generated method stub 11 | if(message instanceof String && message.equals("ping")){ 12 | return true; 13 | } 14 | return false; 15 | } 16 | 17 | @Override 18 | public boolean isResponse(IoSession session, Object message) { 19 | // TODO Auto-generated method stub 20 | if(message instanceof String && message.equals("pong")){ 21 | return true; 22 | } 23 | return false; 24 | } 25 | 26 | @Override 27 | public Object getRequest(IoSession session) { 28 | // TODO Auto-generated method stub 29 | return null; 30 | } 31 | 32 | @Override 33 | public Object getResponse(IoSession session, Object request) { 34 | // TODO Auto-generated method stub 35 | return "pong"; 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /Long_TCP_Server/src/main/java/org/apache/mina/test/ServerSessionHandler.java: -------------------------------------------------------------------------------- 1 | package org.apache.mina.test; 2 | 3 | import org.apache.mina.core.service.IoHandlerAdapter; 4 | import org.apache.mina.core.session.IdleStatus; 5 | import org.apache.mina.core.session.IoSession; 6 | 7 | public class ServerSessionHandler extends IoHandlerAdapter{ 8 | 9 | @Override 10 | public void sessionCreated(IoSession session) throws Exception { 11 | // TODO Auto-generated method stub 12 | super.sessionCreated(session); 13 | } 14 | 15 | @Override 16 | public void sessionOpened(IoSession session) throws Exception { 17 | // TODO Auto-generated method stub 18 | super.sessionOpened(session); 19 | } 20 | 21 | @Override 22 | public void sessionClosed(IoSession session) throws Exception { 23 | // TODO Auto-generated method stub 24 | super.sessionClosed(session); 25 | } 26 | 27 | @Override 28 | public void sessionIdle(IoSession session, IdleStatus status) 29 | throws Exception { 30 | // TODO Auto-generated method stub 31 | super.sessionIdle(session, status); 32 | } 33 | 34 | @Override 35 | public void exceptionCaught(IoSession session, Throwable cause) 36 | throws Exception { 37 | // TODO Auto-generated method stub 38 | super.exceptionCaught(session, cause); 39 | } 40 | 41 | @Override 42 | public void messageReceived(IoSession session, Object message) 43 | throws Exception { 44 | // TODO Auto-generated method stub 45 | super.messageReceived(session, message); 46 | } 47 | 48 | @Override 49 | public void messageSent(IoSession session, Object message) throws Exception { 50 | // TODO Auto-generated method stub 51 | super.messageSent(session, message); 52 | } 53 | 54 | @Override 55 | public void inputClosed(IoSession session) throws Exception { 56 | // TODO Auto-generated method stub 57 | super.inputClosed(session); 58 | } 59 | 60 | 61 | 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /MemMonClient/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /MemMonClient/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /MemoryMonitor/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /MemoryMonitor/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /NetCatClient/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /NetCatClient/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /NetCatClient/src/main/java/org/apache/mina/example/netcat/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | NetCat client (Network + Unix cat command) which demonstates low-level I/O layer. 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Proxyserver/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Proxyserver/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /Proxyserver/src/main/java/org/apache/mina/example/proxy/ServerToProxyIoHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.example.proxy; 21 | 22 | /** 23 | * Handles the server to proxy part of the proxied connection. 24 | * 25 | * @author Apache MINA Project 26 | */ 27 | public class ServerToProxyIoHandler extends AbstractProxyIoHandler { 28 | } 29 | -------------------------------------------------------------------------------- /Proxyserver/src/main/java/org/apache/mina/example/proxy/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | A TCP/IP tunneling proxy example. 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TCP-long-connection-based-on-Apache-mina 2 | **基于Apache mina 的tcp长连接实现,可用于android客户端推送。** 3 | 4 | 项目将Apache的mina项目移植到了android平台。实现长连接的主要思想是使用了mina的KeepAliveFilter过滤器。 5 | 6 | acceptor.getFilterChain().addLast("keeplive", new KeepAliveFilter(new ServerKeepAliveMessageFactoryImp(), IdleStatus.READER_IDLE, KeepAliveRequestTimeoutHandler.CLOSE,10, 5)); 7 | 8 | 9 | Android客户端: 10 | 11 | 核心代码如下图所示,规定了长连接ping与pong信息的规则,以及网络参数配置信息。 12 | 13 | ![](https://github.com/sddyljsx/Android-tcp-long-connection-based-on-Apache-mina/blob/master/002.png?raw=true) 14 | 15 | 配置信息: 16 | 17 | /** 18 | * 服务器地址 19 | */ 20 | public static final String HOSTNAME = "192.168.1.15"; 21 | /** 22 | * 服务器端口号 23 | */ 24 | public static final int PORT = 8081; 25 | /** 26 | * 连接超时时间,30 seconds 27 | */ 28 | public static final long SOCKET_CONNECT_TIMEOUT = 30 * 1000L; 29 | /** 30 | * 长连接心跳包发送频率,10 seconds 31 | */ 32 | public static final int KEEP_ALIVE_TIME_INTERVAL = 10; 33 | /** 34 | * 长连接心跳包应答超时 35 | */ 36 | public static final int KEEP_ALIVE_RESPONSE_TIMEOUT = 5; 37 | /** 38 | * 心跳包 ping message 39 | */ 40 | public static final String PING_MESSAGE="ping"; 41 | /** 42 | * 心跳包 pong message 43 | */ 44 | public static final String PONG_MESSAGE="pong"; 45 | 程序启动后,PushService启动,并开始与服务器连接。 46 | 47 | **服务器端核心代码:** 48 | 49 | ![](https://github.com/sddyljsx/Android-tcp-long-connection-based-on-Apache-mina/blob/master/003.png?raw=true) 50 | 51 | 服务器与客户端的ping与pong信息要保持一致。服务器启动LongTcpServer即可。 52 | 53 | 在服务器可以看到日志信息: 54 | 55 | ![](https://github.com/sddyljsx/Android-tcp-long-connection-based-on-Apache-mina/blob/master/001.png?raw=true) 56 | 57 | 可以看到,成功建立了链接,并且每隔10秒都会受到ping信息,并发送pong信息应答。 58 | 59 | 60 | -------------------------------------------------------------------------------- /ReverserServer/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /ReverserServer/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /ReverserServer/src/main/java/org/apache/mina/example/reverser/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.example.reverser; 21 | 22 | import org.apache.mina.filter.codec.ProtocolCodecFilter; 23 | import org.apache.mina.filter.codec.textline.TextLineCodecFactory; 24 | import org.apache.mina.filter.logging.LoggingFilter; 25 | import org.apache.mina.transport.socket.nio.NioSocketAcceptor; 26 | 27 | import java.net.InetSocketAddress; 28 | import java.nio.charset.Charset; 29 | 30 | /** 31 | * (Entry point) Reverser server which reverses all text lines from 32 | * clients. 33 | * 34 | * @author Apache MINA Project 35 | */ 36 | public class Main { 37 | private static final int PORT = 8080; 38 | 39 | public static void main(String[] args) throws Exception { 40 | NioSocketAcceptor acceptor = new NioSocketAcceptor(); 41 | 42 | // Prepare the configuration 43 | acceptor.getFilterChain().addLast("logger", new LoggingFilter()); 44 | acceptor.getFilterChain().addLast( 45 | "codec", 46 | new ProtocolCodecFilter(new TextLineCodecFactory(Charset 47 | .forName("UTF-8")))); 48 | 49 | // Bind 50 | acceptor.setHandler(new ReverseProtocolHandler()); 51 | acceptor.bind(new InetSocketAddress(PORT)); 52 | 53 | System.out.println("Listening on port " + PORT); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /ReverserServer/src/main/java/org/apache/mina/example/reverser/ReverseProtocolHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.example.reverser; 21 | 22 | import org.apache.mina.core.service.IoHandler; 23 | import org.apache.mina.core.service.IoHandlerAdapter; 24 | import org.apache.mina.core.session.IoSession; 25 | 26 | /** 27 | * {@link IoHandler} implementation of reverser server protocol. 28 | * 29 | * @author Apache MINA Project 30 | */ 31 | public class ReverseProtocolHandler extends IoHandlerAdapter { 32 | @Override 33 | public void exceptionCaught(IoSession session, Throwable cause) { 34 | // Close connection when unexpected exception is caught. 35 | session.close(true); 36 | } 37 | 38 | @Override 39 | public void messageReceived(IoSession session, Object message) { 40 | // Reverse reveiced string 41 | String str = message.toString(); 42 | StringBuilder buf = new StringBuilder(str.length()); 43 | for (int i = str.length() - 1; i >= 0; i--) { 44 | buf.append(str.charAt(i)); 45 | } 46 | 47 | // and write it back. 48 | session.write(buf.toString()); 49 | } 50 | } -------------------------------------------------------------------------------- /ReverserServer/src/main/java/org/apache/mina/example/reverser/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Reverser server which reverses all text lines demonstating high-level protocol layer. 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /SumUpClient/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /SumUpClient/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /SumUpCommon/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /SumUpCommon/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /SumUpCommon/src/main/java/org/apache/mina/example/sumup/codec/AddMessageDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.example.sumup.codec; 21 | 22 | import org.apache.mina.core.buffer.IoBuffer; 23 | import org.apache.mina.core.session.IoSession; 24 | import org.apache.mina.example.sumup.message.AbstractMessage; 25 | import org.apache.mina.example.sumup.message.AddMessage; 26 | import org.apache.mina.filter.codec.ProtocolDecoderOutput; 27 | import org.apache.mina.filter.codec.demux.MessageDecoder; 28 | 29 | /** 30 | * A {@link MessageDecoder} that decodes {@link AddMessage}. 31 | * 32 | * @author Apache MINA Project 33 | */ 34 | public class AddMessageDecoder extends AbstractMessageDecoder { 35 | 36 | public AddMessageDecoder() { 37 | super(Constants.ADD); 38 | } 39 | 40 | @Override 41 | protected AbstractMessage decodeBody(IoSession session, IoBuffer in) { 42 | if (in.remaining() < Constants.ADD_BODY_LEN) { 43 | return null; 44 | } 45 | 46 | AddMessage m = new AddMessage(); 47 | m.setValue(in.getInt()); 48 | return m; 49 | } 50 | 51 | public void finishDecode(IoSession session, ProtocolDecoderOutput out) 52 | throws Exception { 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /SumUpCommon/src/main/java/org/apache/mina/example/sumup/codec/AddMessageEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.example.sumup.codec; 21 | 22 | import org.apache.mina.core.buffer.IoBuffer; 23 | import org.apache.mina.core.session.IoSession; 24 | import org.apache.mina.example.sumup.message.AddMessage; 25 | import org.apache.mina.filter.codec.demux.MessageEncoder; 26 | 27 | /** 28 | * A {@link MessageEncoder} that encodes {@link AddMessage}. 29 | * 30 | * @author Apache MINA Project 31 | */ 32 | public class AddMessageEncoder extends AbstractMessageEncoder { 33 | public AddMessageEncoder() { 34 | super(Constants.ADD); 35 | } 36 | 37 | @Override 38 | protected void encodeBody(IoSession session, T message, IoBuffer out) { 39 | out.putInt(message.getValue()); 40 | } 41 | 42 | public void dispose() throws Exception { 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /SumUpCommon/src/main/java/org/apache/mina/example/sumup/codec/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.example.sumup.codec; 21 | 22 | /** 23 | * Provides SumUp protocol constants. 24 | * 25 | * @author Apache MINA Project 26 | */ 27 | public class Constants { 28 | public static final int TYPE_LEN = 2; 29 | 30 | public static final int SEQUENCE_LEN = 4; 31 | 32 | public static final int HEADER_LEN = TYPE_LEN + SEQUENCE_LEN; 33 | 34 | public static final int BODY_LEN = 12; 35 | 36 | public static final int RESULT = 0; 37 | 38 | public static final int ADD = 1; 39 | 40 | public static final int RESULT_CODE_LEN = 2; 41 | 42 | public static final int RESULT_VALUE_LEN = 4; 43 | 44 | public static final int ADD_BODY_LEN = 4; 45 | 46 | public static final int RESULT_OK = 0; 47 | 48 | public static final int RESULT_ERROR = 1; 49 | 50 | private Constants() { 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /SumUpCommon/src/main/java/org/apache/mina/example/sumup/codec/ResultMessageEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.example.sumup.codec; 21 | 22 | import org.apache.mina.core.buffer.IoBuffer; 23 | import org.apache.mina.core.session.IoSession; 24 | import org.apache.mina.example.sumup.message.ResultMessage; 25 | import org.apache.mina.filter.codec.demux.MessageEncoder; 26 | 27 | /** 28 | * A {@link MessageEncoder} that encodes {@link ResultMessage}. 29 | * 30 | * @author Apache MINA Project 31 | */ 32 | public class ResultMessageEncoder extends AbstractMessageEncoder { 33 | public ResultMessageEncoder() { 34 | super(Constants.RESULT); 35 | } 36 | 37 | @Override 38 | protected void encodeBody(IoSession session, T message, IoBuffer out) { 39 | if (message.isOk()) { 40 | out.putShort((short) Constants.RESULT_OK); 41 | out.putInt(message.getValue()); 42 | } else { 43 | out.putShort((short) Constants.RESULT_ERROR); 44 | } 45 | } 46 | 47 | public void dispose() throws Exception { 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /SumUpCommon/src/main/java/org/apache/mina/example/sumup/codec/SumUpProtocolCodecFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.example.sumup.codec; 21 | 22 | import org.apache.mina.example.sumup.message.AddMessage; 23 | import org.apache.mina.example.sumup.message.ResultMessage; 24 | import org.apache.mina.filter.codec.ProtocolCodecFactory; 25 | import org.apache.mina.filter.codec.demux.DemuxingProtocolCodecFactory; 26 | 27 | /** 28 | * A {@link ProtocolCodecFactory} that provides a protocol codec for 29 | * SumUp protocol. 30 | * 31 | * @author Apache MINA Project 32 | */ 33 | public class SumUpProtocolCodecFactory extends DemuxingProtocolCodecFactory { 34 | 35 | public SumUpProtocolCodecFactory(boolean server) { 36 | if (server) { 37 | super.addMessageDecoder(AddMessageDecoder.class); 38 | super.addMessageEncoder(ResultMessage.class, ResultMessageEncoder.class); 39 | } else // Client 40 | { 41 | super.addMessageEncoder(AddMessage.class, AddMessageEncoder.class); 42 | super.addMessageDecoder(ResultMessageDecoder.class); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /SumUpCommon/src/main/java/org/apache/mina/example/sumup/codec/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Protocol codec implementation for SumUp protocol. 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /SumUpCommon/src/main/java/org/apache/mina/example/sumup/message/AbstractMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.example.sumup.message; 21 | 22 | import java.io.Serializable; 23 | 24 | /** 25 | * A base message for SumUp protocol messages. 26 | * 27 | * @author Apache MINA Project 28 | */ 29 | public abstract class AbstractMessage implements Serializable { 30 | private int sequence; 31 | 32 | public int getSequence() { 33 | return sequence; 34 | } 35 | 36 | public void setSequence(int sequence) { 37 | this.sequence = sequence; 38 | } 39 | } -------------------------------------------------------------------------------- /SumUpCommon/src/main/java/org/apache/mina/example/sumup/message/AddMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.example.sumup.message; 21 | 22 | /** 23 | * ADD message in SumUp protocol. 24 | * 25 | * @author Apache MINA Project 26 | */ 27 | public class AddMessage extends AbstractMessage { 28 | private static final long serialVersionUID = -940833727168119141L; 29 | 30 | private int value; 31 | 32 | public AddMessage() { 33 | } 34 | 35 | public int getValue() { 36 | return value; 37 | } 38 | 39 | public void setValue(int value) { 40 | this.value = value; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | // it is a good practice to create toString() method on message classes. 46 | return getSequence() + ":ADD(" + value + ')'; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /SumUpCommon/src/main/java/org/apache/mina/example/sumup/message/ResultMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.example.sumup.message; 21 | 22 | /** 23 | * RESULT message in SumUp protocol. 24 | * 25 | * @author Apache MINA Project 26 | */ 27 | public class ResultMessage extends AbstractMessage { 28 | private static final long serialVersionUID = 7371210248110219946L; 29 | 30 | private boolean ok; 31 | 32 | private int value; 33 | 34 | public ResultMessage() { 35 | } 36 | 37 | public boolean isOk() { 38 | return ok; 39 | } 40 | 41 | public void setOk(boolean ok) { 42 | this.ok = ok; 43 | } 44 | 45 | public int getValue() { 46 | return value; 47 | } 48 | 49 | public void setValue(int value) { 50 | this.value = value; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | if (ok) { 56 | return getSequence() + ":RESULT(" + value + ')'; 57 | } else { 58 | return getSequence() + ":RESULT(ERROR)"; 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /SumUpCommon/src/main/java/org/apache/mina/example/sumup/message/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Protocol mmessage classes for SumUp protocol. 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /SumUpServer/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /SumUpServer/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /TCPClient/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /TCPClient/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /TCPServer/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /TCPServer/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /TennisBall/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /TennisBall/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /TennisBall/src/main/java/org/apache/mina/example/tennis/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Two tennis players play a game which demonstates in-VM pipes. 23 | 24 | 25 | -------------------------------------------------------------------------------- /TimeServer/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /TimeServer/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /UDPClient/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /UDPClient/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /UDPServer/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /UDPServer/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /android-client/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /android-client/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 29 5 | buildToolsVersion "29.0.3" 6 | lintOptions { 7 | abortOnError false 8 | } 9 | defaultConfig { 10 | applicationId "neal.minapush" 11 | minSdkVersion 24 12 | targetSdkVersion 29 13 | versionCode 1 14 | versionName "1.0" 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | multiDexEnabled true 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | testImplementation 'junit:junit:4.12' 29 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 30 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 31 | // testImplementation 'junit:junit:4.12' 32 | // androidTestImplementation 'androidx.test.ext:junit:1.1.1' 33 | // androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 34 | implementation fileTree(dir: 'libs', include: ['*.jar']) 35 | implementation 'com.android.support:appcompat-v7:28.0.0' 36 | // implementation 'androidx.appcompat:appcompat:1.1.0' 37 | // implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.7' 38 | implementation group: 'org.slf4j', name: 'slf4j-android', version: '1.7.30' 39 | implementation group: 'org.apache.mina', name: 'mina-core', version: '2.1.3' 40 | } -------------------------------------------------------------------------------- /android-client/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /android-client/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /android-client/src/main/java/neal/minapush/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package neal.minapush.activity; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | 6 | import neal.minapush.R; 7 | 8 | public class MainActivity extends Activity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_main); 14 | System.out.println("activity start"+android.os.Process.myPid()+'-'+android.os.Process.myTid()); 15 | } 16 | 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /android-client/src/main/java/neal/minapush/applicaiton/BaseApplication.java: -------------------------------------------------------------------------------- 1 | package neal.minapush.applicaiton; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | 7 | import neal.minapush.service.PushService; 8 | 9 | /** 10 | * Created by neal on 2014/12/2. 11 | */ 12 | public class BaseApplication extends Application{ 13 | private static Context applicationContext; 14 | @Override 15 | public void onCreate() { 16 | super.onCreate(); 17 | System.out.println("app start"+android.os.Process.myPid()+'-'+android.os.Process.myTid()); 18 | applicationContext=getApplicationContext(); 19 | Intent intent=new Intent(this, PushService.class); 20 | startService(intent); 21 | } 22 | 23 | public static Context getAppContext(){ 24 | return applicationContext; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /android-client/src/main/java/neal/minapush/push/ClientKeepAliveMessageFactoryImp.java: -------------------------------------------------------------------------------- 1 | package neal.minapush.push; 2 | 3 | import org.apache.mina.core.session.IoSession; 4 | import org.apache.mina.filter.keepalive.KeepAliveMessageFactory; 5 | 6 | public class ClientKeepAliveMessageFactoryImp implements KeepAliveMessageFactory{ 7 | 8 | @Override 9 | public boolean isRequest(IoSession session, Object message) { 10 | if(message instanceof String && message.equals(Config.PING_MESSAGE)){ 11 | return true; 12 | } 13 | return false; 14 | } 15 | 16 | @Override 17 | public boolean isResponse(IoSession session, Object message) { 18 | if(message instanceof String && message.equals(Config.PONG_MESSAGE)){ 19 | return true; 20 | } 21 | return false; 22 | } 23 | 24 | @Override 25 | public Object getRequest(IoSession session) { 26 | return Config.PING_MESSAGE; 27 | } 28 | 29 | @Override 30 | public Object getResponse(IoSession session, Object request) { 31 | return null; 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /android-client/src/main/java/neal/minapush/push/ClientPushMessage.java: -------------------------------------------------------------------------------- 1 | package neal.minapush.push; 2 | 3 | /** 4 | * Created by neal on 2014/12/2. 5 | */ 6 | public class ClientPushMessage { 7 | } 8 | -------------------------------------------------------------------------------- /android-client/src/main/java/neal/minapush/push/Config.java: -------------------------------------------------------------------------------- 1 | package neal.minapush.push; 2 | 3 | /** 4 | * Created by neal on 2014/12/2. 5 | */ 6 | public class Config { 7 | /** 8 | * 服务器地址 9 | */ 10 | public static final String HOSTNAME = "192.168.1.15"; 11 | /** 12 | * 服务器端口号 13 | */ 14 | public static final int PORT = 8081; 15 | /** 16 | * 连接超时时间,30 seconds 17 | */ 18 | public static final long SOCKET_CONNECT_TIMEOUT = 30 * 1000L; 19 | /** 20 | * 长连接心跳包发送频率,10 seconds 21 | */ 22 | public static final int KEEP_ALIVE_TIME_INTERVAL = 10; 23 | /** 24 | * 长连接心跳包应答超时 25 | */ 26 | public static final int KEEP_ALIVE_RESPONSE_TIMEOUT = 5; 27 | /** 28 | * 心跳包 ping message 29 | */ 30 | public static final String PING_MESSAGE="ping"; 31 | /** 32 | * 心跳包 pong message 33 | */ 34 | public static final String PONG_MESSAGE="pong"; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /android-client/src/main/java/neal/minapush/push/PushEventListener.java: -------------------------------------------------------------------------------- 1 | package neal.minapush.push; 2 | 3 | /** 4 | * Created by neal on 2014/12/7. 5 | */ 6 | public interface PushEventListener { 7 | public abstract void onPushConnected(); 8 | public abstract void onPushExceptionCaught(); 9 | public abstract void onPushMessageSent(); 10 | public abstract void onPushMessageReceived(); 11 | public abstract void onPushDisConnected(); 12 | } 13 | -------------------------------------------------------------------------------- /android-client/src/main/java/neal/minapush/push/ServerKeepAliveMessageFactoryImp.java: -------------------------------------------------------------------------------- 1 | package neal.minapush.push; 2 | 3 | import org.apache.mina.core.session.IoSession; 4 | import org.apache.mina.filter.keepalive.KeepAliveMessageFactory; 5 | 6 | public class ServerKeepAliveMessageFactoryImp implements KeepAliveMessageFactory{ 7 | 8 | @Override 9 | public boolean isRequest(IoSession session, Object message) { 10 | if(message instanceof String && message.equals(Config.PING_MESSAGE)){ 11 | return true; 12 | } 13 | return false; 14 | } 15 | 16 | @Override 17 | public boolean isResponse(IoSession session, Object message) { 18 | if(message instanceof String && message.equals(Config.PONG_MESSAGE)){ 19 | return true; 20 | } 21 | return false; 22 | } 23 | 24 | @Override 25 | public Object getRequest(IoSession session) { 26 | return null; 27 | } 28 | 29 | @Override 30 | public Object getResponse(IoSession session, Object request) { 31 | return Config.PONG_MESSAGE; 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /android-client/src/main/java/neal/minapush/push/ServerPushMessage.java: -------------------------------------------------------------------------------- 1 | package neal.minapush.push; 2 | 3 | /** 4 | * Created by neal on 2014/12/2. 5 | */ 6 | public class ServerPushMessage { 7 | } 8 | -------------------------------------------------------------------------------- /android-client/src/main/java/neal/minapush/service/PushService.java: -------------------------------------------------------------------------------- 1 | package neal.minapush.service; 2 | 3 | import android.app.Service; 4 | import android.content.Intent; 5 | import android.os.IBinder; 6 | 7 | import neal.minapush.push.PushEventListener; 8 | import neal.minapush.push.PushManager; 9 | 10 | public class PushService extends Service{ 11 | 12 | PushManager pushManager=PushManager.getInstance(); 13 | 14 | @Override 15 | public void onCreate() { 16 | System.out.println("service start"+android.os.Process.myPid()+'-'+android.os.Process.myTid()); 17 | super.onCreate(); 18 | pushManager.openPush(); 19 | pushManager.setPushEventListener(new PushEventListener() { 20 | @Override 21 | public void onPushConnected() { 22 | System.out.println("service push open"+android.os.Process.myPid()+'-'+android.os.Process.myTid()); 23 | 24 | } 25 | 26 | @Override 27 | public void onPushExceptionCaught() { 28 | System.out.println("service push exception"+android.os.Process.myPid()+'-'+android.os.Process.myTid()); 29 | 30 | } 31 | 32 | @Override 33 | public void onPushMessageSent() { 34 | System.out.println("service push sent"+android.os.Process.myPid()+'-'+android.os.Process.myTid()); 35 | 36 | } 37 | 38 | @Override 39 | public void onPushMessageReceived() { 40 | 41 | } 42 | 43 | @Override 44 | public void onPushDisConnected() { 45 | System.out.println("service push close"+android.os.Process.myPid()+'-'+android.os.Process.myTid()); 46 | 47 | } 48 | }); 49 | 50 | System.out.println(pushManager.Connect()); 51 | } 52 | @Override 53 | public int onStartCommand(Intent intent, int flags, int startId) { 54 | System.out.println("service start command"+android.os.Process.myPid()+'-'+android.os.Process.myTid()); 55 | super.onStartCommand(intent, flags, startId); 56 | return START_STICKY; 57 | } 58 | @Override 59 | public IBinder onBind(Intent intent) { 60 | return null; 61 | } 62 | @Override 63 | public void onDestroy() { 64 | super.onDestroy(); 65 | pushManager.disConnect(); 66 | } 67 | 68 | 69 | } 70 | -------------------------------------------------------------------------------- /android-client/src/main/java/neal/minapush/util/NetworkUtil.java: -------------------------------------------------------------------------------- 1 | package neal.minapush.util; 2 | 3 | import android.content.Context; 4 | import android.net.ConnectivityManager; 5 | 6 | import neal.minapush.applicaiton.BaseApplication; 7 | 8 | /** 9 | * Created by neal on 2014/12/2. 10 | */ 11 | public class NetworkUtil { 12 | public static boolean isNetworkConnect(){ 13 | if(BaseApplication.getAppContext()==null){ 14 | return false; 15 | } 16 | ConnectivityManager connectivityManager= (ConnectivityManager)BaseApplication.getAppContext().getSystemService(Context.CONNECTIVITY_SERVICE); 17 | if(connectivityManager!=null) { 18 | if(connectivityManager.getActiveNetworkInfo()!=null && connectivityManager.getActiveNetworkInfo().isConnected()){ 19 | return true; 20 | } 21 | } 22 | return false; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /android-client/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sddyljsx/tcp-long-connection-based-on-apache-mina/c82332d7e7543ff9d785bb40ee09c1b22846ffbd/android-client/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android-client/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sddyljsx/tcp-long-connection-based-on-apache-mina/c82332d7e7543ff9d785bb40ee09c1b22846ffbd/android-client/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android-client/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sddyljsx/tcp-long-connection-based-on-apache-mina/c82332d7e7543ff9d785bb40ee09c1b22846ffbd/android-client/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android-client/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sddyljsx/tcp-long-connection-based-on-apache-mina/c82332d7e7543ff9d785bb40ee09c1b22846ffbd/android-client/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android-client/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /android-client/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 长连接 3 | 4 | -------------------------------------------------------------------------------- /android-client/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.3.72' 5 | repositories { 6 | mavenCentral() 7 | google() 8 | jcenter() 9 | maven { 10 | url "https://plugins.gradle.org/m2/" 11 | } 12 | } 13 | dependencies { 14 | classpath 'com.android.tools.build:gradle:3.6.3' 15 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 16 | // NOTE: Do not place your application dependencies here; they belong 17 | // in the individual module build.gradle files 18 | } 19 | } 20 | 21 | allprojects { 22 | repositories { 23 | mavenCentral() 24 | google() 25 | jcenter() 26 | maven { 27 | url "https://plugins.gradle.org/m2/" 28 | } 29 | } 30 | } 31 | 32 | task clean(type: Delete) { 33 | delete rootProject.buildDir 34 | } 35 | -------------------------------------------------------------------------------- /common/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /common/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Neo\Documents\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/core/RuntimeIoException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.core; 21 | 22 | import java.io.IOException; 23 | 24 | /** 25 | * A unchecked version of {@link IOException}. 26 | *

27 | * Please note that {@link RuntimeIoException} is different from 28 | * {@link IOException} in that doesn't trigger force session close, 29 | * while {@link IOException} forces disconnection. 30 | * 31 | * @author Apache MINA Project 32 | */ 33 | public class RuntimeIoException extends RuntimeException { 34 | private static final long serialVersionUID = 9029092241311939548L; 35 | 36 | public RuntimeIoException() { 37 | super(); 38 | } 39 | 40 | public RuntimeIoException(String message) { 41 | super(message); 42 | } 43 | 44 | public RuntimeIoException(String message, Throwable cause) { 45 | super(message, cause); 46 | } 47 | 48 | public RuntimeIoException(Throwable cause) { 49 | super(cause); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/core/buffer/BufferDataException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.core.buffer; 21 | 22 | /** 23 | * A {@link RuntimeException} which is thrown when the data the {@link IoBuffer} 24 | * contains is corrupt. 25 | * 26 | * @author Apache MINA Project 27 | * 28 | */ 29 | public class BufferDataException extends RuntimeException { 30 | private static final long serialVersionUID = -4138189188602563502L; 31 | 32 | public BufferDataException() { 33 | super(); 34 | } 35 | 36 | public BufferDataException(String message) { 37 | super(message); 38 | } 39 | 40 | public BufferDataException(String message, Throwable cause) { 41 | super(message, cause); 42 | } 43 | 44 | public BufferDataException(Throwable cause) { 45 | super(cause); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/core/buffer/IoBufferAllocator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.core.buffer; 21 | 22 | import java.nio.ByteBuffer; 23 | 24 | /** 25 | * Allocates {@link IoBuffer}s and manages them. Please implement this 26 | * interface if you need more advanced memory management scheme. 27 | * 28 | * @author Apache MINA Project 29 | */ 30 | public interface IoBufferAllocator { 31 | /** 32 | * Returns the buffer which is capable of the specified size. 33 | * 34 | * @param capacity the capacity of the buffer 35 | * @param direct true to get a direct buffer, 36 | * false to get a heap buffer. 37 | */ 38 | IoBuffer allocate(int capacity, boolean direct); 39 | 40 | /** 41 | * Returns the NIO buffer which is capable of the specified size. 42 | * 43 | * @param capacity the capacity of the buffer 44 | * @param direct true to get a direct buffer, 45 | * false to get a heap buffer. 46 | */ 47 | ByteBuffer allocateNioBuffer(int capacity, boolean direct); 48 | 49 | /** 50 | * Wraps the specified NIO {@link ByteBuffer} into MINA buffer. 51 | */ 52 | IoBuffer wrap(ByteBuffer nioBuffer); 53 | 54 | /** 55 | * Dispose of this allocator. 56 | */ 57 | void dispose(); 58 | } 59 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/core/file/FilenameFileRegion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.core.file; 21 | 22 | import java.io.File; 23 | import java.io.IOException; 24 | import java.nio.channels.FileChannel; 25 | 26 | /** 27 | * TODO Add documentation 28 | * 29 | * 30 | * @author The Apache MINA Project (dev@mina.apache.org) 31 | * @version $Rev$, $Date$ 32 | */ 33 | public class FilenameFileRegion extends DefaultFileRegion { 34 | 35 | private final File file; 36 | 37 | public FilenameFileRegion(File file, FileChannel channel) throws IOException { 38 | this(file, channel, 0, file.length()); 39 | } 40 | 41 | public FilenameFileRegion(File file, FileChannel channel, long position, long remainingBytes) { 42 | super(channel, position, remainingBytes); 43 | 44 | if (file == null) { 45 | throw new IllegalArgumentException("file can not be null"); 46 | } 47 | this.file = file; 48 | } 49 | 50 | public String getFilename() { 51 | return file.getAbsolutePath(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/core/filterchain/IoFilterChainBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.core.filterchain; 21 | 22 | import org.apache.mina.core.session.IoSession; 23 | 24 | /** 25 | * An interface that builds {@link IoFilterChain} in predefined way 26 | * when {@link IoSession} is created. You can extract common filter chain 27 | * modification logic to this interface. For example, to add a filter 28 | * to the chain, 29 | *

30 |  * public class MyFilterChainBuilder implements IoFilterChainBuilder {
31 |  *     public void buildFilterChain( IoFilterChain chain ) throws Exception {
32 |  *         chain.addLast( "myFilter", new MyFilter() );
33 |  *     }
34 |  * }
35 |  * 
36 | * 37 | * @author Apache MINA Project 38 | */ 39 | public interface IoFilterChainBuilder { 40 | /** 41 | * An implementation which does nothing. 42 | */ 43 | IoFilterChainBuilder NOOP = new IoFilterChainBuilder() { 44 | public void buildFilterChain(IoFilterChain chain) throws Exception { 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "NOOP"; 50 | } 51 | }; 52 | 53 | /** 54 | * Modifies the specified chain. 55 | */ 56 | void buildFilterChain(IoFilterChain chain) throws Exception; 57 | } 58 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/core/filterchain/IoFilterLifeCycleException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.core.filterchain; 21 | 22 | /** 23 | * A {@link RuntimeException} which is thrown when {@link IoFilter#init()} 24 | * or {@link IoFilter#onPostAdd(IoFilterChain, String, org.apache.mina.core.filterchain.IoFilter.NextFilter)} 25 | * failed. 26 | * 27 | * @author Apache MINA Project 28 | */ 29 | public class IoFilterLifeCycleException extends RuntimeException { 30 | private static final long serialVersionUID = -5542098881633506449L; 31 | 32 | public IoFilterLifeCycleException() { 33 | } 34 | 35 | public IoFilterLifeCycleException(String message) { 36 | super(message); 37 | } 38 | 39 | public IoFilterLifeCycleException(String message, Throwable cause) { 40 | super(message, cause); 41 | } 42 | 43 | public IoFilterLifeCycleException(Throwable cause) { 44 | super(cause); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/core/future/CloseFuture.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.core.future; 21 | 22 | /** 23 | * An {@link IoFuture} for asynchronous close requests. 24 | * 25 | *

Example

26 | *
27 |  * IoSession session = ...;
28 |  * CloseFuture future = session.close(true);
29 |  * // Wait until the connection is closed
30 |  * future.awaitUninterruptibly();
31 |  * // Now connection should be closed.
32 |  * assert future.isClosed();
33 |  * 
34 | * 35 | * @author Apache MINA Project 36 | */ 37 | public interface CloseFuture extends IoFuture { 38 | /** 39 | * Returns true if the close request is finished and the session is closed. 40 | */ 41 | boolean isClosed(); 42 | 43 | /** 44 | * Marks this future as closed and notifies all threads waiting for this 45 | * future. This method is invoked by MINA internally. Please do not call 46 | * this method directly. 47 | */ 48 | void setClosed(); 49 | 50 | CloseFuture await() throws InterruptedException; 51 | 52 | CloseFuture awaitUninterruptibly(); 53 | 54 | CloseFuture addListener(IoFutureListener listener); 55 | 56 | CloseFuture removeListener(IoFutureListener listener); 57 | } 58 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/core/future/IoFutureListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.core.future; 21 | 22 | import org.apache.mina.core.session.IoSession; 23 | 24 | import java.util.EventListener; 25 | 26 | /** 27 | * Something interested in being notified when the completion 28 | * of an asynchronous I/O operation : {@link IoFuture}. 29 | * 30 | * @author Apache MINA Project 31 | */ 32 | public interface IoFutureListener extends EventListener { 33 | /** 34 | * An {@link IoFutureListener} that closes the {@link IoSession} which is 35 | * associated with the specified {@link IoFuture}. 36 | */ 37 | static IoFutureListener CLOSE = new IoFutureListener() { 38 | public void operationComplete(IoFuture future) { 39 | future.getSession().close(true); 40 | } 41 | }; 42 | 43 | /** 44 | * Invoked when the operation associated with the {@link IoFuture} 45 | * has been completed even if you add the listener after the completion. 46 | * 47 | * @param future The source {@link IoFuture} which called this 48 | * callback. 49 | */ 50 | void operationComplete(F future); 51 | } -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/core/polling/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Base class for implementing transport based on active polling strategies like NIO select call, or any API 23 | based on I/O polling system calls (epoll, poll, select, kqueue, etc). Know implementations are org.apache.mina.transport.socket.nio 24 | and org.apache.mina.transport.socket.apr. 25 | 26 | 27 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/core/session/IoEventType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.core.session; 21 | 22 | /** 23 | * An {@link Enum} that represents the type of I/O events and requests. 24 | * Most users won't need to use this class. It is usually used by internal 25 | * components to store I/O events. 26 | * 27 | * @author Apache MINA Project 28 | */ 29 | public enum IoEventType { 30 | SESSION_CREATED, SESSION_OPENED, SESSION_CLOSED, MESSAGE_RECEIVED, MESSAGE_SENT, SESSION_IDLE, EXCEPTION_CAUGHT, WRITE, CLOSE, 31 | } 32 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/core/session/IoSessionDataStructureFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.core.session; 21 | 22 | import org.apache.mina.core.write.WriteRequest; 23 | import org.apache.mina.core.write.WriteRequestQueue; 24 | 25 | import java.util.Comparator; 26 | 27 | /** 28 | * Provides data structures to a newly created session. 29 | * 30 | * @author Apache MINA Project 31 | */ 32 | public interface IoSessionDataStructureFactory { 33 | /** 34 | * Returns an {@link IoSessionAttributeMap} which is going to be associated 35 | * with the specified session. Please note that the returned 36 | * implementation must be thread-safe. 37 | */ 38 | IoSessionAttributeMap getAttributeMap(IoSession session) throws Exception; 39 | 40 | /** 41 | * Returns an {@link WriteRequest} which is going to be associated with 42 | * the specified session. Please note that the returned 43 | * implementation must be thread-safe and robust enough to deal 44 | * with various messages types (even what you didn't expect at all), 45 | * especially when you are going to implement a priority queue which 46 | * involves {@link Comparator}. 47 | */ 48 | WriteRequestQueue getWriteRequestQueue(IoSession session) throws Exception; 49 | } 50 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/core/session/IoSessionInitializationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.core.session; 21 | 22 | /** 23 | * A {@link RuntimeException} that is thrown when the initialization of 24 | * an {@link IoSession} fails. 25 | * 26 | * @author Apache MINA Project 27 | */ 28 | public class IoSessionInitializationException extends RuntimeException { 29 | private static final long serialVersionUID = -1205810145763696189L; 30 | 31 | public IoSessionInitializationException() { 32 | super(); 33 | } 34 | 35 | public IoSessionInitializationException(String message, Throwable cause) { 36 | super(message, cause); 37 | } 38 | 39 | public IoSessionInitializationException(String message) { 40 | super(message); 41 | } 42 | 43 | public IoSessionInitializationException(Throwable cause) { 44 | super(cause); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/core/session/IoSessionInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.core.session; 21 | 22 | import org.apache.mina.core.future.IoFuture; 23 | 24 | /** 25 | * Defines a callback for obtaining the {@link IoSession} during 26 | * session initialization. 27 | * 28 | * @author Apache MINA Project 29 | */ 30 | public interface IoSessionInitializer { 31 | void initializeSession(IoSession session, T future); 32 | } 33 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/core/session/SessionState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.core.session; 21 | 22 | /** 23 | * The session state. A session can be in three different state : 24 | *
    25 | *
  • OPENING : The session has not been fully created
  • 26 | *
  • OPENED : The session is opened
  • 27 | *
  • CLOSING : The session is closing
  • 28 | *
29 | * 30 | * @author Apache MINA Project 31 | */ 32 | public enum SessionState { 33 | OPENING, OPENED, CLOSING 34 | } -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/core/session/UnknownMessageTypeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.core.session; 21 | 22 | /** 23 | * An exception that is thrown when the type of the message cannot be determined. 24 | * 25 | * @author Apache MINA Project 26 | */ 27 | public class UnknownMessageTypeException extends RuntimeException { 28 | private static final long serialVersionUID = 3257290227428047158L; 29 | 30 | public UnknownMessageTypeException() { 31 | // Do nothing 32 | } 33 | 34 | public UnknownMessageTypeException(String message, Throwable cause) { 35 | super(message, cause); 36 | } 37 | 38 | public UnknownMessageTypeException(String message) { 39 | super(message); 40 | } 41 | 42 | public UnknownMessageTypeException(Throwable cause) { 43 | super(cause); 44 | } 45 | } -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/core/write/WriteRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.core.write; 21 | 22 | import org.apache.mina.core.filterchain.IoFilter; 23 | import org.apache.mina.core.future.WriteFuture; 24 | import org.apache.mina.core.session.IoSession; 25 | 26 | import java.net.SocketAddress; 27 | 28 | /** 29 | * Represents write request fired by {@link IoSession#write(Object)}. 30 | * 31 | * @author Apache MINA Project 32 | */ 33 | public interface WriteRequest { 34 | /** 35 | * Returns the {@link WriteRequest} which was requested originally, 36 | * which is not transformed by any {@link IoFilter}. 37 | */ 38 | WriteRequest getOriginalRequest(); 39 | 40 | /** 41 | * Returns {@link WriteFuture} that is associated with this write request. 42 | */ 43 | WriteFuture getFuture(); 44 | 45 | /** 46 | * Returns a message object to be written. 47 | */ 48 | Object getMessage(); 49 | 50 | /** 51 | * Returns the destination of this write request. 52 | * 53 | * @return null for the default destination 54 | */ 55 | SocketAddress getDestination(); 56 | 57 | /** 58 | * Tells if the current message has been encoded 59 | * 60 | * @return true if the message has already been encoded 61 | */ 62 | boolean isEncoded(); 63 | } -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/buffer/IoBufferLazyInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.filter.buffer; 21 | 22 | import org.apache.mina.core.buffer.IoBuffer; 23 | import org.apache.mina.util.LazyInitializer; 24 | 25 | /** 26 | * An {@link LazyInitializer} implementation that initializes an 27 | * {@link IoBuffer} only when needed. 28 | * 29 | * @author Apache MINA Project 30 | * @since MINA 2.0.0-M2 31 | */ 32 | public class IoBufferLazyInitializer extends LazyInitializer { 33 | 34 | /** 35 | * The buffer size allocated for each new session's buffer. 36 | */ 37 | private int bufferSize; 38 | 39 | /** 40 | * Constructor which sets allocated buffer size to bufferSize. 41 | * 42 | * @param bufferSize the new buffer size 43 | */ 44 | public IoBufferLazyInitializer(int bufferSize) { 45 | this.bufferSize = bufferSize; 46 | } 47 | 48 | /** 49 | * {@inheritDoc} 50 | */ 51 | public IoBuffer init() { 52 | return IoBuffer.allocate(bufferSize); 53 | } 54 | } -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/codec/AbstractProtocolDecoderOutput.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.filter.codec; 21 | 22 | import java.util.LinkedList; 23 | import java.util.Queue; 24 | 25 | /** 26 | * A {@link ProtocolDecoderOutput} based on queue. 27 | * 28 | * @author Apache MINA Project 29 | */ 30 | public abstract class AbstractProtocolDecoderOutput implements ProtocolDecoderOutput { 31 | private final Queue messageQueue = new LinkedList(); 32 | 33 | public AbstractProtocolDecoderOutput() { 34 | // Do nothing 35 | } 36 | 37 | public Queue getMessageQueue() { 38 | return messageQueue; 39 | } 40 | 41 | public void write(Object message) { 42 | if (message == null) { 43 | throw new IllegalArgumentException("message"); 44 | } 45 | 46 | messageQueue.add(message); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/codec/ProtocolCodecException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.filter.codec; 21 | 22 | /** 23 | * An exception that is thrown when {@link ProtocolEncoder} or 24 | * {@link ProtocolDecoder} cannot understand or failed to validate 25 | * data to process. 26 | * 27 | * @author Apache MINA Project 28 | */ 29 | public class ProtocolCodecException extends Exception { 30 | private static final long serialVersionUID = 5939878548186330695L; 31 | 32 | /** 33 | * Constructs a new instance. 34 | */ 35 | public ProtocolCodecException() { 36 | // Do nothing 37 | } 38 | 39 | /** 40 | * Constructs a new instance with the specified message. 41 | */ 42 | public ProtocolCodecException(String message) { 43 | super(message); 44 | } 45 | 46 | /** 47 | * Constructs a new instance with the specified cause. 48 | */ 49 | public ProtocolCodecException(Throwable cause) { 50 | super(cause); 51 | } 52 | 53 | /** 54 | * Constructs a new instance with the specified message and the specified 55 | * cause. 56 | */ 57 | public ProtocolCodecException(String message, Throwable cause) { 58 | super(message, cause); 59 | } 60 | } -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.filter.codec; 21 | 22 | import org.apache.mina.core.session.IoSession; 23 | 24 | /** 25 | * Provides {@link ProtocolEncoder} and {@link ProtocolDecoder} which translates 26 | * binary or protocol specific data into message object and vice versa. 27 | *

28 | * Please refer to 29 | * ReverserProtocolProvider 30 | * example. 31 | * 32 | * @author Apache MINA Project 33 | */ 34 | public interface ProtocolCodecFactory { 35 | /** 36 | * Returns a new (or reusable) instance of {@link ProtocolEncoder} which 37 | * encodes message objects into binary or protocol-specific data. 38 | */ 39 | ProtocolEncoder getEncoder(IoSession session) throws Exception; 40 | 41 | /** 42 | * Returns a new (or reusable) instance of {@link ProtocolDecoder} which 43 | * decodes binary or protocol-specific data into message objects. 44 | */ 45 | ProtocolDecoder getDecoder(IoSession session) throws Exception; 46 | } -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/codec/ProtocolDecoderAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.filter.codec; 21 | 22 | import org.apache.mina.core.session.IoSession; 23 | 24 | /** 25 | * An abstract {@link ProtocolDecoder} implementation for those who don't need 26 | * {@link ProtocolDecoder#finishDecode(IoSession, ProtocolDecoderOutput)} nor 27 | * {@link ProtocolDecoder#dispose(IoSession)} method. 28 | * 29 | * @author Apache MINA Project 30 | */ 31 | public abstract class ProtocolDecoderAdapter implements ProtocolDecoder { 32 | 33 | /** 34 | * Override this method to deal with the closed connection. 35 | * The default implementation does nothing. 36 | */ 37 | public void finishDecode(IoSession session, ProtocolDecoderOutput out) throws Exception { 38 | // Do nothing 39 | } 40 | 41 | /** 42 | * Override this method to dispose all resources related with this decoder. 43 | * The default implementation does nothing. 44 | */ 45 | public void dispose(IoSession session) throws Exception { 46 | // Do nothing 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/codec/ProtocolDecoderOutput.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.filter.codec; 21 | 22 | import org.apache.mina.core.filterchain.IoFilter.NextFilter; 23 | import org.apache.mina.core.session.IoSession; 24 | 25 | /** 26 | * Callback for {@link ProtocolDecoder} to generate decoded messages. 27 | * {@link ProtocolDecoder} must call {@link #write(Object)} for each decoded 28 | * messages. 29 | * 30 | * @author Apache MINA Project 31 | */ 32 | public interface ProtocolDecoderOutput { 33 | /** 34 | * Callback for {@link ProtocolDecoder} to generate decoded messages. 35 | * {@link ProtocolDecoder} must call {@link #write(Object)} for each 36 | * decoded messages. 37 | * 38 | * @param message the decoded message 39 | */ 40 | void write(Object message); 41 | 42 | /** 43 | * Flushes all messages you wrote via {@link #write(Object)} to 44 | * the next filter. 45 | */ 46 | void flush(NextFilter nextFilter, IoSession session); 47 | } 48 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/codec/ProtocolEncoderAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.filter.codec; 21 | 22 | import org.apache.mina.core.session.IoSession; 23 | 24 | /** 25 | * An abstract {@link ProtocolEncoder} implementation for those who don't have any 26 | * resources to dispose. 27 | * 28 | * @author Apache MINA Project 29 | */ 30 | public abstract class ProtocolEncoderAdapter implements ProtocolEncoder { 31 | /** 32 | * Override this method dispose all resources related with this encoder. 33 | * The default implementation does nothing. 34 | */ 35 | public void dispose(IoSession session) throws Exception { 36 | // Do nothing 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/codec/ProtocolEncoderException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.filter.codec; 21 | 22 | /** 23 | * An exception that is thrown when {@link ProtocolEncoder} 24 | * cannot understand or failed to validate the specified message object. 25 | * 26 | * @author Apache MINA Project 27 | */ 28 | public class ProtocolEncoderException extends ProtocolCodecException { 29 | private static final long serialVersionUID = 8752989973624459604L; 30 | 31 | /** 32 | * Constructs a new instance. 33 | */ 34 | public ProtocolEncoderException() { 35 | // Do nothing 36 | } 37 | 38 | /** 39 | * Constructs a new instance with the specified message. 40 | */ 41 | public ProtocolEncoderException(String message) { 42 | super(message); 43 | } 44 | 45 | /** 46 | * Constructs a new instance with the specified cause. 47 | */ 48 | public ProtocolEncoderException(Throwable cause) { 49 | super(cause); 50 | } 51 | 52 | /** 53 | * Constructs a new instance with the specified message and the specified 54 | * cause. 55 | */ 56 | public ProtocolEncoderException(String message, Throwable cause) { 57 | super(message, cause); 58 | } 59 | } -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/codec/demux/MessageDecoderAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.filter.codec.demux; 21 | 22 | import org.apache.mina.core.session.IoSession; 23 | import org.apache.mina.filter.codec.ProtocolDecoderOutput; 24 | 25 | /** 26 | * An abstract {@link MessageDecoder} implementation for those who don't need to 27 | * implement {@link MessageDecoder#finishDecode(IoSession, ProtocolDecoderOutput)} 28 | * method. 29 | * 30 | * @author Apache MINA Project 31 | */ 32 | public abstract class MessageDecoderAdapter implements MessageDecoder { 33 | /** 34 | * Override this method to deal with the closed connection. 35 | * The default implementation does nothing. 36 | */ 37 | public void finishDecode(IoSession session, ProtocolDecoderOutput out) throws Exception { 38 | // Do nothing 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/codec/demux/MessageDecoderFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.filter.codec.demux; 21 | 22 | /** 23 | * A factory that creates a new instance of {@link MessageDecoder}. 24 | * 25 | * @author Apache MINA Project 26 | * 27 | * @see DemuxingProtocolDecoder 28 | */ 29 | public interface MessageDecoderFactory { 30 | /** 31 | * Creates a new message decoder. 32 | */ 33 | MessageDecoder getDecoder() throws Exception; 34 | } 35 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/codec/demux/MessageEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.filter.codec.demux; 21 | 22 | import org.apache.mina.core.buffer.IoBuffer; 23 | import org.apache.mina.core.session.IoSession; 24 | import org.apache.mina.filter.codec.ProtocolEncoderOutput; 25 | 26 | /** 27 | * Encodes a certain type of messages. 28 | *

29 | * We didn't provide any dispose method for {@link MessageEncoder} 30 | * because it can give you performance penalty in case you have a lot of 31 | * message types to handle. 32 | * 33 | * @author Apache MINA Project 34 | * 35 | * @see DemuxingProtocolEncoder 36 | * @see MessageEncoderFactory 37 | */ 38 | public interface MessageEncoder { 39 | /** 40 | * Encodes higher-level message objects into binary or protocol-specific data. 41 | * MINA invokes {@link #encode(IoSession, Object, ProtocolEncoderOutput)} 42 | * method with message which is popped from the session write queue, and then 43 | * the encoder implementation puts encoded {@link IoBuffer}s into 44 | * {@link ProtocolEncoderOutput}. 45 | * 46 | * @throws Exception if the message violated protocol specification 47 | */ 48 | void encode(IoSession session, T message, ProtocolEncoderOutput out) throws Exception; 49 | } 50 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/codec/demux/MessageEncoderFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.filter.codec.demux; 21 | 22 | /** 23 | * A factory that creates a new instance of {@link MessageEncoder}. 24 | * 25 | * @author Apache MINA Project 26 | * 27 | * @see DemuxingProtocolEncoder 28 | */ 29 | public interface MessageEncoderFactory { 30 | /** 31 | * Creates a new message encoder. 32 | */ 33 | MessageEncoder getEncoder() throws Exception; 34 | } 35 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/codec/demux/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Protocol codecs that helps you to implement even more complex protocols by 23 | splitting a codec into multiple sub-codecs. 24 | 25 | 26 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/codec/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Filter implementations that helps you to implement complex protocols 23 | via 'codec' concept. 24 | 25 | 26 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/codec/serialization/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Protocol codecs which uses Java object serilization and leads to rapid protocol 23 | implementation. 24 | 25 | 26 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/codec/statemachine/ConsumeToLinearWhitespaceDecodingState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.filter.codec.statemachine; 21 | 22 | /** 23 | * {@link DecodingState} which consumes all bytes until a space (0x20) or tab 24 | * (0x09) character is reached. The terminator is skipped. 25 | * 26 | * @author Apache MINA Project 27 | */ 28 | public abstract class ConsumeToLinearWhitespaceDecodingState extends ConsumeToDynamicTerminatorDecodingState { 29 | 30 | /** 31 | * @return true if the given byte is a space or a tab 32 | */ 33 | @Override 34 | protected boolean isTerminator(byte b) { 35 | return (b == ' ') || (b == '\t'); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/codec/statemachine/LinearWhitespaceSkippingState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.filter.codec.statemachine; 21 | 22 | /** 23 | * {@link DecodingState} which skips space (0x20) and tab (0x09) characters. 24 | * 25 | * @author Apache MINA Project 26 | */ 27 | public abstract class LinearWhitespaceSkippingState extends SkippingState { 28 | 29 | /** 30 | * {@inheritDoc} 31 | */ 32 | @Override 33 | protected boolean canSkip(byte b) { 34 | return b == 32 || b == 9; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/codec/textline/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | A protocol codec for text-based protocols. 23 | 24 | 25 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/errorgenerating/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | An IoFilter that provides flexible error generation facilities. 23 | 24 | 25 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/executor/IoEventSizeEstimator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.filter.executor; 21 | 22 | import org.apache.mina.core.session.IoEvent; 23 | 24 | /** 25 | * Estimates the amount of memory that the specified {@link IoEvent} occupies 26 | * in the current JVM. 27 | * 28 | * @author Apache MINA Project 29 | */ 30 | public interface IoEventSizeEstimator { 31 | /** 32 | * Estimate the IoEvent size in number of bytes 33 | * @param event The event we want to estimate the size of 34 | * @return The estimated size of this event 35 | */ 36 | int estimateSize(IoEvent event); 37 | } 38 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/executor/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | IoFilters that provide flexible thread model and event queue 23 | monitoring interface. 24 | 25 | 26 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/firewall/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Classes that implement IoFilter and provide host blocking and throttling. 23 | 24 | 25 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/keepalive/KeepAliveMessageFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.filter.keepalive; 21 | 22 | import org.apache.mina.core.session.IoSession; 23 | 24 | /** 25 | * Provides keep-alive messages to {@link KeepAliveFilter}. 26 | * 27 | * @author Apache MINA Project 28 | */ 29 | public interface KeepAliveMessageFactory { 30 | 31 | /** 32 | * Returns true if and only if the specified message is a 33 | * keep-alive request message. 34 | */ 35 | boolean isRequest(IoSession session, Object message); 36 | 37 | /** 38 | * Returns true if and only if the specified message is a 39 | * keep-alive response message; 40 | */ 41 | boolean isResponse(IoSession session, Object message); 42 | 43 | /** 44 | * Returns a (new) keep-alive request message. 45 | * Returns null if no request is required. 46 | */ 47 | Object getRequest(IoSession session); 48 | 49 | /** 50 | * Returns a (new) response message for the specified keep-alive request. 51 | * Returns null if no response is required. 52 | */ 53 | Object getResponse(IoSession session, Object request); 54 | } 55 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/keepalive/KeepAliveRequestTimeoutException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.filter.keepalive; 21 | 22 | /** 23 | * A {@link RuntimeException} which is thrown when a keep-alive response 24 | * message was not received within a certain timeout. 25 | * 26 | * @author Apache MINA Project 27 | */ 28 | public class KeepAliveRequestTimeoutException extends RuntimeException { 29 | 30 | private static final long serialVersionUID = -1985092764656546558L; 31 | 32 | public KeepAliveRequestTimeoutException() { 33 | super(); 34 | } 35 | 36 | public KeepAliveRequestTimeoutException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | 40 | public KeepAliveRequestTimeoutException(String message) { 41 | super(message); 42 | } 43 | 44 | public KeepAliveRequestTimeoutException(Throwable cause) { 45 | super(cause); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/keepalive/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | IoFilter that provides the ability for connections to remain open when data is not being transferred. 23 | 24 | 25 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/logging/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Classes that implement IoFilter and provide logging of the events and data that flows through a MINA-based system. 23 | 24 | 25 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/ssl/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Classes that implement IoFilter and provide Secure Sockets Layer functionality. 23 | 24 | 25 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/statistic/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Classes that implement IoFilter and provide the ability for filters to be timed on their performance. 23 | 24 | 25 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/stream/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Stream based IoFilter implementation. 23 | 24 | 25 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/util/NoopFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.filter.util; 21 | 22 | import org.apache.mina.core.filterchain.IoFilterAdapter; 23 | 24 | /** 25 | * A Noop filter. It does nothing, as all the method are already implemented 26 | * in the super class.
27 | * 28 | * This class is used by tests, when some faked filter is needed to test that the 29 | * chain is working properly when adding or removing a filter. 30 | * 31 | * @author Apache MINA Project 32 | */ 33 | public class NoopFilter extends IoFilterAdapter { 34 | /** 35 | * Default Constructor. 36 | */ 37 | public NoopFilter() { 38 | super(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/filter/util/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Utility classes for the MINA filtering portion of the library. 23 | 24 | 25 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/handler/chain/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | A handler implementation that helps you implement sequentially layered protocols 23 | using Chains of Responsibility pattern. 24 | 25 | 26 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/handler/demux/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | A handler implementation that helps you implement complex protocols 23 | by splitting messageReceived handlers into multiple sub-handlers. 24 | 25 | 26 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/handler/multiton/SingleSessionIoHandlerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.handler.multiton; 21 | 22 | import org.apache.mina.core.session.IoSession; 23 | 24 | /** 25 | * A factory that creates {@link SingleSessionIoHandler} to be used with one 26 | * particular session. 27 | * 28 | * @see SingleSessionIoHandler 29 | * 30 | * @author Apache MINA Project 31 | */ 32 | @Deprecated 33 | public interface SingleSessionIoHandlerFactory { 34 | 35 | /** 36 | * Returns a {@link SingleSessionIoHandler} for the given session. 37 | * 38 | * @param session the session for which a handler is requested 39 | */ 40 | SingleSessionIoHandler getHandler(IoSession session) throws Exception; 41 | } 42 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/handler/multiton/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Enables creating a handler per session instead of having one handler for many 23 | sessions, using 24 | Multiton pattern. 25 | 26 | 27 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/handler/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Useful IoHandler implementations. 23 | 24 | 25 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/proxy/ProxyAuthException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.proxy; 21 | 22 | import javax.security.sasl.SaslException; 23 | 24 | /** 25 | * ProxyAuthException.java - This class extends {@link SaslException} and represents an 26 | * authentication failure to the proxy. 27 | * 28 | * @author Apache MINA Project 29 | * @since MINA 2.0.0-M3 30 | */ 31 | public class ProxyAuthException extends SaslException { 32 | private static final long serialVersionUID = -6511596809517532988L; 33 | 34 | /** 35 | * @see SaslException#SaslException(String) 36 | */ 37 | public ProxyAuthException(String message) { 38 | super(message); 39 | } 40 | 41 | /** 42 | * @see SaslException#SaslException(String, Throwable) 43 | */ 44 | public ProxyAuthException(String message, Throwable ex) { 45 | super(message, ex); 46 | } 47 | } -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/proxy/event/IoSessionEventType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.proxy.event; 21 | 22 | /** 23 | * IoSessionEventType.java - Enumerates session event types. 24 | * 25 | * @author Apache MINA Project 26 | * @since MINA 2.0.0-M3 27 | */ 28 | public enum IoSessionEventType { 29 | CREATED(1), OPENED(2), IDLE(3), CLOSED(4); 30 | 31 | /** 32 | * The event type id. 33 | */ 34 | private final int id; 35 | 36 | private IoSessionEventType(int id) { 37 | this.id = id; 38 | } 39 | 40 | /** 41 | * Returns the event id. 42 | * 43 | * @return the event id 44 | */ 45 | public int getId() { 46 | return id; 47 | } 48 | 49 | /** 50 | * {@inheritDoc} 51 | */ 52 | @Override 53 | public String toString() { 54 | switch (this) { 55 | case CREATED: 56 | return "- CREATED event -"; 57 | case OPENED: 58 | return "- OPENED event -"; 59 | case IDLE: 60 | return "- IDLE event -"; 61 | case CLOSED: 62 | return "- CLOSED event -"; 63 | default: 64 | return "- Event Id=" + id + " -"; 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/proxy/filter/ProxyHandshakeIoBuffer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.proxy.filter; 21 | 22 | import org.apache.mina.core.buffer.IoBuffer; 23 | import org.apache.mina.core.buffer.IoBufferWrapper; 24 | 25 | /** 26 | * ProxyHandshakeIoBuffer.java - {@link IoBuffer} wrapper to indicate handshake 27 | * related messages which should not be passed upstream of the {@link ProxyFilter}. 28 | * 29 | * @author Apache MINA Project 30 | * @since MINA 2.0.0-M3 31 | */ 32 | public class ProxyHandshakeIoBuffer extends IoBufferWrapper { 33 | public ProxyHandshakeIoBuffer(final IoBuffer buf) { 34 | super(buf); 35 | } 36 | } -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/proxy/handlers/ProxyRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.proxy.handlers; 21 | 22 | import java.net.InetSocketAddress; 23 | 24 | /** 25 | * ProxyRequest.java - Abstract wrapper class for proxy requests. 26 | * 27 | * @author Apache MINA Project 28 | * @since MINA 2.0.0-M3 29 | */ 30 | public abstract class ProxyRequest { 31 | 32 | /** 33 | * The address of the request endpoint. 34 | */ 35 | private InetSocketAddress endpointAddress = null; 36 | 37 | /** 38 | * Implicit constructor. 39 | */ 40 | public ProxyRequest() { 41 | // Do nothing 42 | } 43 | 44 | /** 45 | * Basic constructor of a {@link ProxyRequest} that only sets the 46 | * address of the request endpoint. 47 | * 48 | * @param endpointAddress the address of the request endpoint. 49 | */ 50 | public ProxyRequest(final InetSocketAddress endpointAddress) { 51 | this.endpointAddress = endpointAddress; 52 | } 53 | 54 | /** 55 | * Returns the address of the request endpoint. 56 | * 57 | * @return the address of the request endpoint 58 | */ 59 | public InetSocketAddress getEndpointAddress() { 60 | return endpointAddress; 61 | } 62 | } -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/proxy/handlers/socks/AbstractSocksLogicHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.proxy.handlers.socks; 21 | 22 | import org.apache.mina.proxy.AbstractProxyLogicHandler; 23 | import org.apache.mina.proxy.session.ProxyIoSession; 24 | 25 | /** 26 | * AbstractSocksLogicHandler.java - Base class for SOCKS {@link AbstractProxyLogicHandler} 27 | * implementations. 28 | * 29 | * @author Apache MINA Project 30 | * @since MINA 2.0.0-M3 31 | */ 32 | public abstract class AbstractSocksLogicHandler extends AbstractProxyLogicHandler { 33 | 34 | /** 35 | * The request sent to the proxy. 36 | */ 37 | protected final SocksProxyRequest request; 38 | 39 | /** 40 | * Creates a new {@link AbstractSocksLogicHandler}. 41 | * 42 | * @param proxyIoSession the proxy session object 43 | */ 44 | public AbstractSocksLogicHandler(final ProxyIoSession proxyIoSession) { 45 | super(proxyIoSession); 46 | this.request = (SocksProxyRequest) proxyIoSession.getRequest(); 47 | } 48 | } -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/test/ClientKeepAliveMessageFactoryImp.java: -------------------------------------------------------------------------------- 1 | package org.apache.mina.test; 2 | 3 | import org.apache.mina.core.session.IoSession; 4 | import org.apache.mina.filter.keepalive.KeepAliveMessageFactory; 5 | 6 | public class ClientKeepAliveMessageFactoryImp implements KeepAliveMessageFactory { 7 | 8 | @Override 9 | public boolean isRequest(IoSession session, Object message) { 10 | // TODO Auto-generated method stub 11 | if (message instanceof String && message.equals("ping")) { 12 | return true; 13 | } 14 | return false; 15 | } 16 | 17 | @Override 18 | public boolean isResponse(IoSession session, Object message) { 19 | // TODO Auto-generated method stub 20 | if (message instanceof String && message.equals("pong")) { 21 | return true; 22 | } 23 | return false; 24 | } 25 | 26 | @Override 27 | public Object getRequest(IoSession session) { 28 | // TODO Auto-generated method stub 29 | return "ping"; 30 | } 31 | 32 | @Override 33 | public Object getResponse(IoSession session, Object request) { 34 | // TODO Auto-generated method stub 35 | return null; 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/test/ClientSessionHandler.java: -------------------------------------------------------------------------------- 1 | package org.apache.mina.test; 2 | 3 | import org.apache.mina.core.service.IoHandlerAdapter; 4 | import org.apache.mina.core.session.IoSession; 5 | 6 | public class ClientSessionHandler extends IoHandlerAdapter { 7 | 8 | @Override 9 | public void sessionOpened(IoSession session) throws Exception { 10 | // TODO Auto-generated method stub 11 | super.sessionOpened(session); 12 | session.write("hello"); 13 | } 14 | 15 | 16 | } 17 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/test/KeepAliveMessageFactoryImp.java: -------------------------------------------------------------------------------- 1 | package org.apache.mina.test; 2 | 3 | import org.apache.mina.core.session.IoSession; 4 | import org.apache.mina.filter.keepalive.KeepAliveMessageFactory; 5 | 6 | public class KeepAliveMessageFactoryImp implements KeepAliveMessageFactory { 7 | 8 | @Override 9 | public boolean isRequest(IoSession session, Object message) { 10 | // TODO Auto-generated method stub 11 | if (message instanceof String && message.equals("ping")) { 12 | return true; 13 | } 14 | return false; 15 | } 16 | 17 | @Override 18 | public boolean isResponse(IoSession session, Object message) { 19 | // TODO Auto-generated method stub 20 | if (message instanceof String && message.equals("pong")) { 21 | return true; 22 | } 23 | return false; 24 | } 25 | 26 | @Override 27 | public Object getRequest(IoSession session) { 28 | // TODO Auto-generated method stub 29 | return "ping"; 30 | } 31 | 32 | @Override 33 | public Object getResponse(IoSession session, Object request) { 34 | // TODO Auto-generated method stub 35 | return "pong"; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/test/LongTcpServer.java: -------------------------------------------------------------------------------- 1 | package org.apache.mina.test; 2 | 3 | import org.apache.mina.core.session.IdleStatus; 4 | import org.apache.mina.filter.codec.ProtocolCodecFilter; 5 | import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; 6 | import org.apache.mina.filter.keepalive.KeepAliveFilter; 7 | import org.apache.mina.filter.keepalive.KeepAliveRequestTimeoutHandler; 8 | import org.apache.mina.filter.logging.LoggingFilter; 9 | import org.apache.mina.transport.socket.nio.NioSocketAcceptor; 10 | 11 | import java.net.InetSocketAddress; 12 | 13 | public class LongTcpServer { 14 | private static final int SERVER_PORT = 8081; 15 | 16 | public static void main(String[] args) throws Throwable { 17 | NioSocketAcceptor acceptor = new NioSocketAcceptor(); 18 | //acceptor.getFilterChain().addLast( "codec", new ProtocolCodecFilter( new TextLineCodecFactory( Charset.forName( "UTF-8" )))); 19 | acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory())); 20 | acceptor.getFilterChain().addLast("logger", new LoggingFilter()); 21 | acceptor.getFilterChain().addLast("keeplive", new KeepAliveFilter(new ServerKeepAliveMessageFactoryImp(), IdleStatus.READER_IDLE, KeepAliveRequestTimeoutHandler.CLOSE, 10, 5)); 22 | 23 | acceptor.setHandler(new ServerSessionHandler()); 24 | acceptor.bind(new InetSocketAddress("192.168.1.15", SERVER_PORT)); 25 | System.out.println("Listening on port " + SERVER_PORT); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/test/ServerKeepAliveMessageFactoryImp.java: -------------------------------------------------------------------------------- 1 | package org.apache.mina.test; 2 | 3 | import org.apache.mina.core.session.IoSession; 4 | import org.apache.mina.filter.keepalive.KeepAliveMessageFactory; 5 | 6 | public class ServerKeepAliveMessageFactoryImp implements KeepAliveMessageFactory { 7 | 8 | @Override 9 | public boolean isRequest(IoSession session, Object message) { 10 | // TODO Auto-generated method stub 11 | if (message instanceof String && message.equals("ping")) { 12 | return true; 13 | } 14 | return false; 15 | } 16 | 17 | @Override 18 | public boolean isResponse(IoSession session, Object message) { 19 | // TODO Auto-generated method stub 20 | if (message instanceof String && message.equals("pong")) { 21 | return true; 22 | } 23 | return false; 24 | } 25 | 26 | @Override 27 | public Object getRequest(IoSession session) { 28 | // TODO Auto-generated method stub 29 | return null; 30 | } 31 | 32 | @Override 33 | public Object getResponse(IoSession session, Object request) { 34 | // TODO Auto-generated method stub 35 | return "pong"; 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/test/ServerSessionHandler.java: -------------------------------------------------------------------------------- 1 | package org.apache.mina.test; 2 | 3 | import org.apache.mina.core.service.IoHandlerAdapter; 4 | import org.apache.mina.core.session.IdleStatus; 5 | import org.apache.mina.core.session.IoSession; 6 | 7 | public class ServerSessionHandler extends IoHandlerAdapter { 8 | 9 | @Override 10 | public void sessionCreated(IoSession session) throws Exception { 11 | // TODO Auto-generated method stub 12 | super.sessionCreated(session); 13 | } 14 | 15 | @Override 16 | public void sessionOpened(IoSession session) throws Exception { 17 | // TODO Auto-generated method stub 18 | super.sessionOpened(session); 19 | } 20 | 21 | @Override 22 | public void sessionClosed(IoSession session) throws Exception { 23 | // TODO Auto-generated method stub 24 | super.sessionClosed(session); 25 | } 26 | 27 | @Override 28 | public void sessionIdle(IoSession session, IdleStatus status) 29 | throws Exception { 30 | // TODO Auto-generated method stub 31 | super.sessionIdle(session, status); 32 | } 33 | 34 | @Override 35 | public void exceptionCaught(IoSession session, Throwable cause) 36 | throws Exception { 37 | // TODO Auto-generated method stub 38 | super.exceptionCaught(session, cause); 39 | } 40 | 41 | @Override 42 | public void messageReceived(IoSession session, Object message) 43 | throws Exception { 44 | // TODO Auto-generated method stub 45 | super.messageReceived(session, message); 46 | } 47 | 48 | @Override 49 | public void messageSent(IoSession session, Object message) throws Exception { 50 | // TODO Auto-generated method stub 51 | super.messageSent(session, message); 52 | } 53 | 54 | @Override 55 | public void inputClosed(IoSession session) throws Exception { 56 | // TODO Auto-generated method stub 57 | super.inputClosed(session); 58 | } 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/transport/socket/DatagramConnector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.transport.socket; 21 | 22 | import org.apache.mina.core.service.IoConnector; 23 | 24 | import java.net.InetSocketAddress; 25 | 26 | /** 27 | * {@link IoConnector} for datagram transport (UDP/IP). 28 | * 29 | * @author Apache MINA Project 30 | */ 31 | public interface DatagramConnector extends IoConnector { 32 | /** 33 | * Returns the default remote InetSocketAddress to connect to when no argument 34 | * is specified in {@link #connect()} method. 35 | * This method overrides the {@link IoConnector#getDefaultRemoteAddress()} method. 36 | */ 37 | InetSocketAddress getDefaultRemoteAddress(); 38 | 39 | /** 40 | * Returns the default configuration of the new FatagramSessions created by 41 | * this connect service. 42 | */ 43 | DatagramSessionConfig getSessionConfig(); 44 | 45 | /** 46 | * Sets the default remote InetSocketAddress to connect to when no argument is 47 | * specified in {@link #connect()} method. 48 | * This method overrides the {@link IoConnector#setDefaultRemoteAddress(java.net.SocketAddress)} method. 49 | */ 50 | void setDefaultRemoteAddress(InetSocketAddress remoteAddress); 51 | } 52 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/transport/socket/SocketConnector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.transport.socket; 21 | 22 | import org.apache.mina.core.service.IoConnector; 23 | 24 | import java.net.InetSocketAddress; 25 | 26 | /** 27 | * {@link IoConnector} for socket transport (TCP/IP). 28 | * 29 | * @author Apache MINA Project 30 | */ 31 | public interface SocketConnector extends IoConnector { 32 | /** 33 | * Returns the default remote InetSocketAddress to connect to when no argument 34 | * is specified in {@link #connect()} method. 35 | * This method overrides the {@link IoConnector#getDefaultRemoteAddress()} method. 36 | */ 37 | InetSocketAddress getDefaultRemoteAddress(); 38 | 39 | /** 40 | * Returns the default configuration of the new SocketSessions created by 41 | * this connect service. 42 | */ 43 | SocketSessionConfig getSessionConfig(); 44 | 45 | /** 46 | * Sets the default remote InetSocketAddress to connect to when no argument is 47 | * specified in {@link #connect()} method. 48 | * This method overrides the {@link IoConnector#setDefaultRemoteAddress(java.net.SocketAddress)} method. 49 | */ 50 | void setDefaultRemoteAddress(InetSocketAddress remoteAddress); 51 | } -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/transport/socket/nio/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Socket (TCP/IP) and Datagram (UDP/IP) support based on Java 23 | NIO (New I/O) API. 24 | 25 |

Configuring the number of NIO selector loops

26 |

27 | You can specify the number of Socket I/O thread to utilize multi-processors 28 | efficiently by specifying the number of processing threads in the constructor. The default is 1 29 |

30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/transport/vmpipe/DefaultVmPipeSessionConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.transport.vmpipe; 21 | 22 | import org.apache.mina.core.session.AbstractIoSessionConfig; 23 | import org.apache.mina.core.session.IoSessionConfig; 24 | 25 | /** 26 | * A default implementation of {@link VmPipeSessionConfig}. 27 | * 28 | * @author Apache MINA Project 29 | */ 30 | class DefaultVmPipeSessionConfig extends AbstractIoSessionConfig implements VmPipeSessionConfig { 31 | DefaultVmPipeSessionConfig() { 32 | // Do nothing 33 | } 34 | 35 | @Override 36 | protected void doSetAll(IoSessionConfig config) { 37 | // Do nothing 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/transport/vmpipe/VmPipe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.transport.vmpipe; 21 | 22 | import org.apache.mina.core.service.IoHandler; 23 | import org.apache.mina.core.service.IoServiceListenerSupport; 24 | 25 | /** 26 | * TODO Add documentation 27 | * 28 | * @author Apache MINA Project 29 | */ 30 | class VmPipe { 31 | private final VmPipeAcceptor acceptor; 32 | 33 | private final VmPipeAddress address; 34 | 35 | private final IoHandler handler; 36 | 37 | private final IoServiceListenerSupport listeners; 38 | 39 | VmPipe(VmPipeAcceptor acceptor, VmPipeAddress address, IoHandler handler, IoServiceListenerSupport listeners) { 40 | this.acceptor = acceptor; 41 | this.address = address; 42 | this.handler = handler; 43 | this.listeners = listeners; 44 | } 45 | 46 | public VmPipeAcceptor getAcceptor() { 47 | return acceptor; 48 | } 49 | 50 | public VmPipeAddress getAddress() { 51 | return address; 52 | } 53 | 54 | public IoHandler getHandler() { 55 | return handler; 56 | } 57 | 58 | public IoServiceListenerSupport getListeners() { 59 | return listeners; 60 | } 61 | } -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/transport/vmpipe/VmPipeSessionConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.transport.vmpipe; 21 | 22 | import org.apache.mina.core.session.IoSessionConfig; 23 | 24 | /** 25 | * An {@link IoSessionConfig} for vmpipe transport type. 26 | * 27 | * @author Apache MINA Project 28 | */ 29 | public interface VmPipeSessionConfig extends IoSessionConfig { 30 | // Do nothing 31 | } 32 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/transport/vmpipe/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | In-VM pipe support which removes the overhead of local loopback communication. 23 | 24 |

What is 'in-VM pipe'?

25 |

26 | In-VM pipe is a direct event forwarding mechanism between two 27 | ProtocolHandlers in the 28 | same Java Virtual Machine. Using in-VM pipe, you can remove the overhead 29 | of encoding and decoding which is caused uselessly by local loopback 30 | network communication. Here are some useful situations possible: 31 |

    32 |
  • SMTP server and SPAM filtering server,
  • 33 |
  • web server and Servlet/JSP container.
  • 34 |
35 |

36 |

37 | Please refer to 38 | Tennis 39 | example. 40 |

41 | 42 | 43 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/util/ConcurrentHashSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.util; 21 | 22 | import java.util.Collection; 23 | import java.util.Set; 24 | import java.util.concurrent.ConcurrentHashMap; 25 | import java.util.concurrent.ConcurrentMap; 26 | 27 | /** 28 | * A {@link ConcurrentHashMap}-backed {@link Set}. 29 | * 30 | * @author Apache MINA Project 31 | */ 32 | public class ConcurrentHashSet extends MapBackedSet { 33 | 34 | private static final long serialVersionUID = 8518578988740277828L; 35 | 36 | public ConcurrentHashSet() { 37 | super(new ConcurrentHashMap()); 38 | } 39 | 40 | public ConcurrentHashSet(Collection c) { 41 | super(new ConcurrentHashMap(), c); 42 | } 43 | 44 | @Override 45 | public boolean add(E o) { 46 | Boolean answer = ((ConcurrentMap) map).putIfAbsent(o, Boolean.TRUE); 47 | return answer == null; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/util/DefaultExceptionMonitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.util; 21 | 22 | import org.apache.mina.core.service.IoService; 23 | import org.slf4j.Logger; 24 | import org.slf4j.LoggerFactory; 25 | 26 | /** 27 | * A default {@link ExceptionMonitor} implementation that logs uncaught 28 | * exceptions using {@link Logger}. 29 | *

30 | * All {@link IoService}s have this implementation as a default exception 31 | * monitor. 32 | * 33 | * @author Apache MINA Project 34 | */ 35 | public class DefaultExceptionMonitor extends ExceptionMonitor { 36 | private final static Logger LOGGER = LoggerFactory.getLogger(DefaultExceptionMonitor.class); 37 | 38 | /** 39 | * {@inheritDoc} 40 | */ 41 | @Override 42 | public void exceptionCaught(Throwable cause) { 43 | if (cause instanceof Error) { 44 | throw (Error) cause; 45 | } 46 | 47 | LOGGER.warn("Unexpected exception.", cause); 48 | } 49 | } -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/util/ExpirationListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.util; 21 | 22 | /** 23 | * A listener for expired object events. 24 | * 25 | * @author Apache MINA Project 26 | * TODO Make this a inner interface of ExpiringMap 27 | */ 28 | public interface ExpirationListener { 29 | void expired(E expiredObject); 30 | } 31 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/util/IdentityHashSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.util; 21 | 22 | import java.util.Collection; 23 | import java.util.IdentityHashMap; 24 | import java.util.Set; 25 | 26 | /** 27 | * An {@link IdentityHashMap}-backed {@link Set}. 28 | * 29 | * @author Apache MINA Project 30 | */ 31 | public class IdentityHashSet extends MapBackedSet { 32 | 33 | private static final long serialVersionUID = 6948202189467167147L; 34 | 35 | public IdentityHashSet() { 36 | super(new IdentityHashMap()); 37 | } 38 | 39 | public IdentityHashSet(int expectedMaxSize) { 40 | super(new IdentityHashMap(expectedMaxSize)); 41 | } 42 | 43 | public IdentityHashSet(Collection c) { 44 | super(new IdentityHashMap(), c); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/util/LazyInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.util; 21 | 22 | /** 23 | * An abstract class which provides semantics for an object which will be only 24 | * fully initialized when requested to. It allows to avoid loosing time when 25 | * early initializing unnecessary objects. 26 | * 27 | * @author Apache MINA Project 28 | * @since MINA 2.0.0-M2 29 | */ 30 | public abstract class LazyInitializer { 31 | 32 | /** 33 | * The value that results on the {@link #init()} call. If null, 34 | * it means that the value has not been initialized yet. 35 | */ 36 | private V value; 37 | 38 | /** 39 | * Initializes the value. 40 | * 41 | * @return the initialized value 42 | */ 43 | public abstract V init(); 44 | 45 | /** 46 | * Returns the value resulting from the initialization. 47 | * @return the initialized value 48 | */ 49 | public V get() { 50 | if (value == null) { 51 | value = init(); 52 | } 53 | 54 | return value; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/util/byteaccess/ByteArrayFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.util.byteaccess; 21 | 22 | /** 23 | * A factory for ByteArrays. 24 | * 25 | * @author Apache MINA Project 26 | */ 27 | public interface ByteArrayFactory { 28 | /** 29 | * Creates an instance of {@link ByteArray} of size specified by the 30 | * size parameter. 31 | * 32 | * @param size 33 | * The size of the ByteArray 34 | * @return 35 | * The ByteArray 36 | */ 37 | ByteArray create(int size); 38 | } -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/util/byteaccess/SimpleByteArrayFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | * 19 | */ 20 | package org.apache.mina.util.byteaccess; 21 | 22 | import org.apache.mina.core.buffer.IoBuffer; 23 | 24 | /** 25 | * Creates ByteArray backed by a heap-allocated 26 | * IoBuffer. The free method on returned 27 | * ByteArrays is a nop. 28 | * 29 | * @author Apache MINA Project 30 | */ 31 | public class SimpleByteArrayFactory implements ByteArrayFactory { 32 | /** 33 | * 34 | * Creates a new instance of SimpleByteArrayFactory. 35 | * 36 | */ 37 | public SimpleByteArrayFactory() { 38 | super(); 39 | } 40 | 41 | /** 42 | * @inheritDoc 43 | */ 44 | public ByteArray create(int size) { 45 | if (size < 0) { 46 | throw new IllegalArgumentException("Buffer size must not be negative:" + size); 47 | } 48 | IoBuffer bb = IoBuffer.allocate(size); 49 | ByteArray ba = new BufferByteArray(bb) { 50 | 51 | @Override 52 | public void free() { 53 | // Nothing to do. 54 | } 55 | 56 | }; 57 | return ba; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /common/src/main/java/org/apache/mina/util/package.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | Miscellaneous utility classes 23 | 24 | 25 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Oct 21 11:34:03 PDT 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip 7 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | //rootProject.name = 'tcp-long-connection-based-on-apache-mina' 2 | include ':android-client' 3 | include ':common' 4 | include ':SumUpCommon' 5 | 6 | include ':Long_TCP_Client' 7 | include ':NetCatClient' 8 | include ':SumUpClient' 9 | include ':TCPClient' 10 | include ':UDPClient' 11 | 12 | include ':Long_TCP_Server' 13 | include ':TimeServer' 14 | include ':Proxyserver' 15 | include ':EchoServer' 16 | include ':HaikuValidationServer' 17 | include ':ReverserServer' 18 | include ':SumUpServer' 19 | include ':TCPServer' 20 | include ':UDPServer' 21 | 22 | include ':TennisBall' 23 | 24 | include ':MemoryMonitor' 25 | include ':MemMonClient' --------------------------------------------------------------------------------