├── .gitignore ├── Changelog.md ├── LICENSE ├── README.md ├── bin ├── env-mp.cmd ├── env-mp.sh ├── mp.cmd ├── mp.sh ├── rsa.sh └── set-env.sh ├── conf ├── conf-dev.properties ├── conf-pub.properties └── reference.conf ├── mpush-api ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── mpush │ └── api │ ├── Constants.java │ ├── MPushContext.java │ ├── common │ ├── Condition.java │ ├── Monitor.java │ └── ServerEventListener.java │ ├── connection │ ├── Cipher.java │ ├── Connection.java │ ├── ConnectionManager.java │ └── SessionContext.java │ ├── event │ ├── ConnectionCloseEvent.java │ ├── ConnectionConnectEvent.java │ ├── Event.java │ ├── HandshakeEvent.java │ ├── KickUserEvent.java │ ├── RouterChangeEvent.java │ ├── ServerShutdownEvent.java │ ├── ServerStartupEvent.java │ ├── Topics.java │ ├── UserOfflineEvent.java │ └── UserOnlineEvent.java │ ├── message │ ├── Message.java │ ├── MessageHandler.java │ └── PacketReceiver.java │ ├── protocol │ ├── Command.java │ ├── JsonPacket.java │ ├── Packet.java │ └── UDPPacket.java │ ├── push │ ├── AckModel.java │ ├── BroadcastController.java │ ├── MsgType.java │ ├── PushCallback.java │ ├── PushContext.java │ ├── PushException.java │ ├── PushMsg.java │ ├── PushResult.java │ └── PushSender.java │ ├── router │ ├── ClientClassifier.java │ ├── ClientLocation.java │ ├── Router.java │ └── RouterManager.java │ ├── service │ ├── BaseService.java │ ├── Client.java │ ├── FutureListener.java │ ├── Listener.java │ ├── Server.java │ ├── Service.java │ └── ServiceException.java │ ├── spi │ ├── Factory.java │ ├── Plugin.java │ ├── Spi.java │ ├── SpiLoader.java │ ├── client │ │ └── PusherFactory.java │ ├── common │ │ ├── CacheManager.java │ │ ├── CacheManagerFactory.java │ │ ├── ExecutorFactory.java │ │ ├── Json.java │ │ ├── JsonFactory.java │ │ ├── MQClient.java │ │ ├── MQClientFactory.java │ │ ├── MQMessageReceiver.java │ │ ├── ServiceDiscoveryFactory.java │ │ └── ServiceRegistryFactory.java │ ├── core │ │ ├── RsaCipherFactory.java │ │ └── ServerEventListenerFactory.java │ ├── handler │ │ ├── BindValidator.java │ │ ├── BindValidatorFactory.java │ │ └── PushHandlerFactory.java │ ├── net │ │ ├── DnsMapping.java │ │ └── DnsMappingManager.java │ ├── push │ │ ├── IPushMessage.java │ │ ├── MessagePusher.java │ │ ├── MessagePusherFactory.java │ │ ├── PushListener.java │ │ └── PushListenerFactory.java │ └── router │ │ └── ClientClassifierFactory.java │ └── srd │ ├── CommonServiceNode.java │ ├── ServiceDiscovery.java │ ├── ServiceEvent.java │ ├── ServiceListener.java │ ├── ServiceNames.java │ ├── ServiceNode.java │ └── ServiceRegistry.java ├── mpush-boot ├── assembly.xml ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── mpush │ │ └── bootstrap │ │ ├── BootException.java │ │ ├── Main.java │ │ ├── ServerLauncher.java │ │ └── job │ │ ├── BootChain.java │ │ ├── BootJob.java │ │ ├── CacheManagerBoot.java │ │ ├── HttpProxyBoot.java │ │ ├── MonitorBoot.java │ │ ├── PushCenterBoot.java │ │ ├── RouterCenterBoot.java │ │ ├── ServerBoot.java │ │ ├── ServiceDiscoveryBoot.java │ │ └── ServiceRegistryBoot.java │ └── resources │ ├── logback.xml │ └── mpush.conf ├── mpush-cache ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── mpush │ │ └── cache │ │ └── redis │ │ ├── RedisException.java │ │ ├── RedisServer.java │ │ ├── connection │ │ └── RedisConnectionFactory.java │ │ ├── manager │ │ ├── RedisCacheManagerFactory.java │ │ ├── RedisClusterManager.java │ │ └── RedisManager.java │ │ └── mq │ │ ├── ListenerDispatcher.java │ │ ├── RedisMQClientFactory.java │ │ └── Subscriber.java │ └── resources │ └── META-INF │ └── services │ ├── com.mpush.api.spi.common.CacheManagerFactory │ └── com.mpush.api.spi.common.MQClientFactory ├── mpush-client ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── mpush │ │ └── client │ │ ├── ClientExecutorFactory.java │ │ ├── MPushClient.java │ │ ├── connect │ │ ├── ClientConfig.java │ │ ├── ConnClientChannelHandler.java │ │ ├── ConnectClient.java │ │ └── TestStatistics.java │ │ ├── gateway │ │ ├── GatewayClient.java │ │ ├── GatewayUDPConnector.java │ │ ├── connection │ │ │ ├── GatewayConnectionFactory.java │ │ │ ├── GatewayTCPConnectionFactory.java │ │ │ └── GatewayUDPConnectionFactory.java │ │ └── handler │ │ │ ├── GatewayClientChannelHandler.java │ │ │ ├── GatewayErrorHandler.java │ │ │ └── GatewayOKHandler.java │ │ ├── push │ │ ├── PushClient.java │ │ ├── PushClientFactory.java │ │ ├── PushRequest.java │ │ └── PushRequestBus.java │ │ └── user │ │ └── UserStatusChangeListener.java │ └── resources │ └── META-INF │ └── services │ ├── com.mpush.api.spi.client.PusherFactory │ └── com.mpush.api.spi.common.ExecutorFactory ├── mpush-common ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── mpush │ │ └── common │ │ ├── CacheKeys.java │ │ ├── CommonExecutorFactory.java │ │ ├── ErrorCode.java │ │ ├── MessageDispatcher.java │ │ ├── ServerNodes.java │ │ ├── condition │ │ ├── AwaysPassCondition.java │ │ ├── ScriptCondition.java │ │ └── TagsCondition.java │ │ ├── handler │ │ ├── BaseMessageHandler.java │ │ ├── ErrorMessageHandler.java │ │ └── OkMessageHandler.java │ │ ├── memory │ │ └── PacketFactory.java │ │ ├── message │ │ ├── AckMessage.java │ │ ├── BaseMessage.java │ │ ├── BindUserMessage.java │ │ ├── ByteBufMessage.java │ │ ├── ErrorMessage.java │ │ ├── FastConnectMessage.java │ │ ├── FastConnectOkMessage.java │ │ ├── HandshakeMessage.java │ │ ├── HandshakeOkMessage.java │ │ ├── HttpRequestMessage.java │ │ ├── HttpResponseMessage.java │ │ ├── KickUserMessage.java │ │ ├── OkMessage.java │ │ ├── PushMessage.java │ │ └── gateway │ │ │ ├── GatewayKickUserMessage.java │ │ │ └── GatewayPushMessage.java │ │ ├── net │ │ └── HttpProxyDnsMappingManager.java │ │ ├── push │ │ ├── GatewayPushResult.java │ │ └── RedisBroadcastController.java │ │ ├── qps │ │ ├── ExactFlowControl.java │ │ ├── FastFlowControl.java │ │ ├── FlowControl.java │ │ ├── GlobalFlowControl.java │ │ ├── OverFlowException.java │ │ └── RedisFlowControl.java │ │ ├── router │ │ ├── CachedRemoteRouterManager.java │ │ ├── ClientType.java │ │ ├── DefaultClientClassifier.java │ │ ├── KickRemoteMsg.java │ │ ├── MQKickRemoteMsg.java │ │ ├── RemoteRouter.java │ │ └── RemoteRouterManager.java │ │ ├── security │ │ ├── AesCipher.java │ │ ├── CipherBox.java │ │ ├── DefaultRsaCipherFactory.java │ │ └── RsaCipher.java │ │ └── user │ │ └── UserManager.java │ └── resources │ └── META-INF │ └── services │ ├── com.mpush.api.spi.core.RsaCipherFactory │ ├── com.mpush.api.spi.net.DnsMappingManager │ └── com.mpush.api.spi.router.ClientClassifierFactory ├── mpush-core ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── mpush │ │ │ └── core │ │ │ ├── MPushServer.java │ │ │ ├── ServerExecutorFactory.java │ │ │ ├── ack │ │ │ ├── AckCallback.java │ │ │ ├── AckTask.java │ │ │ └── AckTaskQueue.java │ │ │ ├── handler │ │ │ ├── AckHandler.java │ │ │ ├── AdminHandler.java │ │ │ ├── BindUserHandler.java │ │ │ ├── ClientPushHandler.java │ │ │ ├── FastConnectHandler.java │ │ │ ├── GatewayKickUserHandler.java │ │ │ ├── GatewayPushHandler.java │ │ │ ├── HandshakeHandler.java │ │ │ ├── HeartBeatHandler.java │ │ │ └── HttpProxyHandler.java │ │ │ ├── mq │ │ │ ├── MQClient.java │ │ │ ├── MQMessageReceiver.java │ │ │ ├── MQPushListener.java │ │ │ └── MQPushMessage.java │ │ │ ├── push │ │ │ ├── BroadcastPushTask.java │ │ │ ├── GatewayPushListener.java │ │ │ ├── PushAckCallback.java │ │ │ ├── PushCenter.java │ │ │ ├── PushTask.java │ │ │ └── SingleUserPushTask.java │ │ │ ├── router │ │ │ ├── LocalRouter.java │ │ │ ├── LocalRouterManager.java │ │ │ ├── RouterCenter.java │ │ │ ├── RouterChangeListener.java │ │ │ └── UserEventConsumer.java │ │ │ ├── server │ │ │ ├── AdminServer.java │ │ │ ├── ConnectionServer.java │ │ │ ├── DefaultServerEventListener.java │ │ │ ├── GatewayServer.java │ │ │ ├── GatewayUDPConnector.java │ │ │ ├── ServerChannelHandler.java │ │ │ ├── ServerConnectionManager.java │ │ │ ├── WebSocketChannelHandler.java │ │ │ ├── WebSocketIndexPageHandler.java │ │ │ └── WebsocketServer.java │ │ │ └── session │ │ │ ├── ReusableSession.java │ │ │ └── ReusableSessionManager.java │ └── resources │ │ ├── META-INF │ │ └── services │ │ │ ├── com.mpush.api.spi.common.ExecutorFactory │ │ │ ├── com.mpush.api.spi.core.ServerEventListenerFactory │ │ │ ├── com.mpush.api.spi.handler.BindValidatorFactory │ │ │ ├── com.mpush.api.spi.handler.PushHandlerFactory │ │ │ └── com.mpush.api.spi.push.PushListenerFactory │ │ └── index.html │ └── test │ └── java │ └── com │ └── mpush │ └── core │ └── security │ └── CipherBoxTest.java ├── mpush-monitor ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── mpush │ │ └── monitor │ │ ├── data │ │ ├── MonitorResult.java │ │ └── ResultCollector.java │ │ ├── jmx │ │ ├── MBeanInfo.java │ │ ├── MBeanRegistry.java │ │ ├── MException.java │ │ ├── mxbean │ │ │ ├── PushCenterBean.java │ │ │ ├── PushCenterMXBean.java │ │ │ └── ServerMXBean.java │ │ └── stats │ │ │ ├── ServerStats.java │ │ │ └── Stats.java │ │ ├── quota │ │ ├── GCMQuota.java │ │ ├── InfoQuota.java │ │ ├── MemoryQuota.java │ │ ├── MonitorQuota.java │ │ ├── ThreadPoolQuota.java │ │ ├── ThreadQuota.java │ │ └── impl │ │ │ ├── JVMGC.java │ │ │ ├── JVMInfo.java │ │ │ ├── JVMMemory.java │ │ │ ├── JVMThread.java │ │ │ └── JVMThreadPool.java │ │ └── service │ │ ├── MonitorService.java │ │ └── ThreadPoolManager.java │ └── test │ └── java │ └── com │ └── mpush │ └── AppTest.java ├── mpush-netty ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── mpush │ └── netty │ ├── client │ └── NettyTCPClient.java │ ├── codec │ ├── DecodeException.java │ ├── PacketDecoder.java │ └── PacketEncoder.java │ ├── connection │ ├── NettyConnection.java │ └── NettyConnectionManager.java │ ├── http │ ├── HttpCallback.java │ ├── HttpClient.java │ ├── HttpClientHandler.java │ ├── HttpConnectionPool.java │ ├── NettyHttpClient.java │ └── RequestContext.java │ ├── server │ └── NettyTCPServer.java │ └── udp │ ├── NettyUDPConnector.java │ └── UDPChannelHandler.java ├── mpush-test ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── mpush │ │ └── test │ │ ├── client │ │ ├── ConnClientBoot.java │ │ └── ConnClientTestMain.java │ │ ├── configcenter │ │ └── ConfigCenterTest.java │ │ ├── connection │ │ └── body │ │ │ └── BodyTest.java │ │ ├── crypto │ │ └── RsaTest.java │ │ ├── gson │ │ ├── DnsMappingTest.java │ │ └── GsonTest.java │ │ ├── push │ │ ├── PushClientTestMain.java │ │ └── PushClientTestMain2.java │ │ ├── redis │ │ ├── PubSubTest.java │ │ ├── RedisClusterTest.java │ │ ├── RedisUtilTest.java │ │ └── User.java │ │ ├── sever │ │ └── ServerTestMain.java │ │ ├── spi │ │ ├── FileCacheManger.java │ │ ├── FileSrd.java │ │ ├── SimpleCacheMangerFactory.java │ │ ├── SimpleDiscoveryFactory.java │ │ ├── SimpleMQClientFactory.java │ │ └── SimpleRegistryFactory.java │ │ ├── udp │ │ ├── MulticastTest.java │ │ └── MulticastTest2.java │ │ ├── util │ │ ├── IPTest.java │ │ └── TelnetTest.java │ │ └── zk │ │ └── ZKClientTest.java │ └── resources │ ├── META-INF │ └── services │ │ ├── com.mpush.api.spi.common.CacheManagerFactory │ │ ├── com.mpush.api.spi.common.MQClientFactory │ │ ├── com.mpush.api.spi.common.ServiceDiscoveryFactory │ │ └── com.mpush.api.spi.common.ServiceRegistryFactory │ ├── application.conf │ └── logback.xml ├── mpush-tools ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── mpush │ │ │ └── tools │ │ │ ├── Jsons.java │ │ │ ├── Utils.java │ │ │ ├── common │ │ │ ├── DefaultJsonFactory.java │ │ │ ├── Holder.java │ │ │ ├── IOUtils.java │ │ │ ├── JVMUtil.java │ │ │ ├── Pair.java │ │ │ ├── Profiler.java │ │ │ ├── Reflects.java │ │ │ ├── RollingNumber.java │ │ │ ├── Strings.java │ │ │ ├── TimeLine.java │ │ │ └── URI.java │ │ │ ├── config │ │ │ ├── CC.java │ │ │ ├── ConfigBeanImpl.java │ │ │ ├── ConfigTools.java │ │ │ └── data │ │ │ │ ├── RedisGroup.java │ │ │ │ └── RedisNode.java │ │ │ ├── crypto │ │ │ ├── AESUtils.java │ │ │ ├── Base64Utils.java │ │ │ ├── CryptoException.java │ │ │ ├── MD5Utils.java │ │ │ └── RSAUtils.java │ │ │ ├── event │ │ │ ├── EventBus.java │ │ │ └── EventConsumer.java │ │ │ ├── log │ │ │ └── Logs.java │ │ │ └── thread │ │ │ ├── NamedPoolThreadFactory.java │ │ │ ├── NamedThreadFactory.java │ │ │ ├── ThreadNames.java │ │ │ └── pool │ │ │ ├── DefaultExecutor.java │ │ │ ├── DumpThreadRejectedHandler.java │ │ │ └── ThreadPoolConfig.java │ └── resources │ │ └── META-INF │ │ └── services │ │ └── com.mpush.api.spi.common.JsonFactory │ └── test │ └── java │ └── com │ └── mpush │ └── tools │ ├── IOUtilsTest.java │ └── crypto │ ├── AESUtilsTest.java │ └── RSAUtilsTest.java ├── mpush-zk ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── mpush │ │ └── zk │ │ ├── ZKCacheListener.java │ │ ├── ZKClient.java │ │ ├── ZKConfig.java │ │ ├── ZKDiscoveryFactory.java │ │ ├── ZKException.java │ │ ├── ZKPath.java │ │ ├── ZKRegistryFactory.java │ │ ├── ZKServiceRegistryAndDiscovery.java │ │ └── ZKSyncMap.java │ └── resources │ └── META-INF │ └── services │ ├── com.mpush.api.spi.common.ServiceDiscoveryFactory │ └── com.mpush.api.spi.common.ServiceRegistryFactory └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.classpath 3 | *.project 4 | */.settings/ 5 | */target/ 6 | */bin/ 7 | */WebContent/ 8 | */.DS_Store 9 | 10 | .idea/ 11 | 12 | target/ 13 | 14 | # Mobile Tools for Java (J2ME) 15 | .mtj.tmp/ 16 | 17 | # Package Files # 18 | *.jar 19 | *.war 20 | *.ear 21 | *.iml 22 | .DS_Store 23 | 24 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 25 | hs_err_pid* 26 | mpush-test/src/test/resources/application.conf 27 | -------------------------------------------------------------------------------- /bin/env-mp.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | REM Licensed to the Apache Software Foundation (ASF) under one or more 3 | REM contributor license agreements. See the NOTICE file distributed with 4 | REM this work for additional information regarding copyright ownership. 5 | REM The ASF licenses this file to You under the Apache License, Version 2.0 6 | REM (the "License"); you may not use this file except in compliance with 7 | REM the License. You may obtain a copy of the License at 8 | REM 9 | REM http://www.apache.org/licenses/LICENSE-2.0 10 | REM 11 | REM Unless required by applicable law or agreed to in writing, software 12 | REM distributed under the License is distributed on an "AS IS" BASIS, 13 | REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | REM See the License for the specific language governing permissions and 15 | REM limitations under the License. 16 | 17 | set MPCFGDIR=%~dp0%..\conf 18 | set MP_LOG_DIR=%~dp0%..\logs 19 | set MP_LOG4J_PROP=INFO,CONSOLE 20 | 21 | REM for sanity sake assume Java 1.6 22 | REM see: http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html 23 | 24 | REM add the mpcfg dir to classpath 25 | set CLASSPATH=%MPCFGDIR% 26 | 27 | REM make it work in the release 28 | SET CLASSPATH=%~dp0..\*;%~dp0..\lib\*;%CLASSPATH% 29 | 30 | REM make it work for developers 31 | SET CLASSPATH=%~dp0..\build\classes;%~dp0..\build\lib\*;%CLASSPATH% 32 | 33 | set MPCFG=%MPCFGDIR%\mpush.conf 34 | 35 | @REM setup java environment variables 36 | 37 | if not defined JAVA_HOME ( 38 | echo Error: JAVA_HOME is not set. 39 | goto :eof 40 | ) 41 | 42 | set JAVA_HOME=%JAVA_HOME:"=% 43 | 44 | if not exist "%JAVA_HOME%"\bin\java.exe ( 45 | echo Error: JAVA_HOME is incorrectly set. 46 | goto :eof 47 | ) 48 | 49 | set JAVA="%JAVA_HOME%"\bin\java 50 | -------------------------------------------------------------------------------- /bin/mp.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | REM Licensed to the Apache Software Foundation (ASF) under one or more 3 | REM contributor license agreements. See the NOTICE file distributed with 4 | REM this work for additional information regarding copyright ownership. 5 | REM The ASF licenses this file to You under the Apache License, Version 2.0 6 | REM (the "License"); you may not use this file except in compliance with 7 | REM the License. You may obtain a copy of the License at 8 | REM 9 | REM http://www.apache.org/licenses/LICENSE-2.0 10 | REM 11 | REM Unless required by applicable law or agreed to in writing, software 12 | REM distributed under the License is distributed on an "AS IS" BASIS, 13 | REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | REM See the License for the specific language governing permissions and 15 | REM limitations under the License. 16 | REM java -Dmp.conf=../conf/mpush.conf -Dmp.home=. -jar bootstrap.jar 17 | REM setlocal 18 | 19 | REM call "%~dp0env-mp.cmd" 20 | 21 | REM set MPMAIN=-jar %~dp0bootstrap.jar 22 | 23 | REM call %JAVA% "-Dmp.conf=%MPCFG%" "-Dmp.home=%~dp0%.." -cp "%CLASSPATH%" %MPMAIN% %* 24 | 25 | REM endlocal 26 | 27 | 28 | java -Dmp.conf=../conf/mpush.conf -Dmp.home=.. -jar bootstrap.jar 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /bin/rsa.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Licensed to the Apache Software Foundation (ASF) under one or more 4 | # contributor license agreements. See the NOTICE file distributed with 5 | # this work for additional information regarding copyright ownership. 6 | # The ASF licenses this file to You under the Apache License, Version 2.0 7 | # (the "License"); you may not use this file except in compliance with 8 | # 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, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | # use POSTIX interface, symlink is followed automatically 19 | MP_BIN="${BASH_SOURCE-$0}" 20 | MP_BIN="$(dirname "${MP_BIN}")" 21 | MP_BIN_DIR="$(cd "${MP_BIN}"; pwd)" 22 | 23 | if [ -e "$MP_BIN/../libexec/env-mp.sh" ]; then 24 | . "$MP_BIN_DIR/../libexec/env-mp.sh" 25 | else 26 | . "$MP_BIN_DIR/env-mp.sh" 27 | fi 28 | 29 | if [ $1 -gt 1024 ] ;then 30 | echo "use rsa key size $1" 31 | keySize = $1 32 | else 33 | echo "use rsa key size 1024" 34 | keySize = 1024 35 | fi 36 | 37 | "$JAVA" -cp "$CLASSPATH" com.mpush.tools.crypto.RSAUtils $keySize -------------------------------------------------------------------------------- /bin/set-env.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #1. Netty 相关关设置项 3 | 4 | #-Dio.netty.leakDetection.level 5 | #netty的内存泄露检测分为四级: 6 | #DISABLED: 不进行内存泄露的检测; 7 | #SIMPLE: 抽样检测,且只对部分方法调用进行记录,消耗较小,有泄漏时可能会延迟报告,默认级别; 8 | #ADVANCED: 抽样检测,记录对象最近几次的调用记录,有泄漏时可能会延迟报告; 9 | #PARANOID: 每次创建一个对象时都进行泄露检测,且会记录对象最近的详细调用记录。是比较激进的内存泄露检测级别,消耗最大,建议只在测试时使用。 10 | 11 | #-Dio.netty.selectorAutoRebuildThreshold=512 默认512 12 | #在NIO中通过Selector的轮询当前是否有IO事件,根据JDK NIO api描述,Selector的select方法会一直阻塞,直到IO事件达到或超时,但是在Linux平台上这里有时会出现问题,在某些场景下select方法会直接返回,即使没有超时并且也没有IO事件到达,这就是著名的epoll bug,这是一个比较严重的bug,它会导致线程陷入死循环,会让CPU飙到100%,极大地影响系统的可靠性,到目前为止,JDK都没有完全解决这个问题。 13 | #但是Netty有效的规避了这个问题,经过实践证明,epoll bug已Netty框架解决,Netty的处理方式是这样的: 14 | #记录select空转的次数,定义一个阀值,这个阀值默认是512,可以在应用层通过设置系统属性io.netty.selectorAutoRebuildThreshold传入,当空转的次数超过了这个阀值,重新构建新Selector,将老Selector上注册的Channel转移到新建的Selector上,关闭老Selector,用新的Selector代替老Selector,详细实现可以查看NioEventLoop中的selector和rebuildSelector方法: 15 | 16 | #-Dio.netty.noKeySetOptimization 17 | #是否禁用nio Selector.selectedKeys优化, 通过反射实现, 默认false 18 | 19 | JVM_FLAGS="-Dio.netty.leakDetection.level=advanced" 20 | 21 | #JMX 22 | 23 | JMXDISABLE=true 24 | #JMXPORT=1099 25 | 26 | #3. 开启远程调试 27 | 28 | #JVM_FLAGS="$JVM_FLAGS -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8008" 29 | 30 | #4. GC配置 31 | 32 | #运行模式 整个堆内存大小 GC算法 33 | #JVM_FLAGS="$JVM_FLAGS -server -Xmx1024m -Xms1024m -XX:+UseG1GC -XX:MaxGCPauseMillis=200" 34 | #GC日志 发生OOM时创建堆内存转储文件 35 | #JVM_FLAGS="$JVM_FLAGS -Xloggc:$MP_LOG_DIR/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps" 36 | #发生OOM后的操作 37 | #JVM_FLAGS="-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$MP_LOG_DIR -XX:OnOutOfMemoryError=$MP_BIN_DIR/restart.sh" -------------------------------------------------------------------------------- /conf/conf-dev.properties: -------------------------------------------------------------------------------- 1 | log.level=debug 2 | min.hb=10s 3 | rsa.privateKey=MIIBNgIBADANBgkqhkiG9w0BAQEFAASCASAwggEcAgEAAoGBAKCE8JYKhsbydMPbiO7BJVq1pbuJWJHFxOR7L8Hv3ZVkSG4eNC8DdwAmDHYu/wadfw0ihKFm2gKDcLHp5yz5UQ8PZ8FyDYvgkrvGV0ak4nc40QDJWws621dm01e/INlGKOIStAAsxOityCLv0zm5Vf3+My/YaBvZcB5mGUsPbx8fAgEAAoGAAy0+WanRqwRHXUzt89OsupPXuNNqBlCEqgTqGAt4Nimq6Ur9u2R1KXKXUotxjp71Ubw6JbuUWvJg+5Rmd9RjT0HOUEQF3rvzEepKtaraPhV5ejEIrB+nJWNfGye4yzLdfEXJBGUQzrG+wNe13izfRNXI4dN/6Q5npzqaqv0E1CkCAQACAQACAQACAQACAQA= 4 | rsa.publicKey=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCghPCWCobG8nTD24juwSVataW7iViRxcTkey/B792VZEhuHjQvA3cAJgx2Lv8GnX8NIoShZtoCg3Cx6ecs+VEPD2fBcg2L4JK7xldGpOJ3ONEAyVsLOttXZtNXvyDZRijiErQALMTorcgi79M5uVX9/jMv2Ggb2XAeZhlLD28fHwIDAQAB 5 | -------------------------------------------------------------------------------- /conf/conf-pub.properties: -------------------------------------------------------------------------------- 1 | log.level=warn 2 | min.hb=3m 3 | rsa.privateKey=MIIBNgIBADANBgkqhkiG9w0BAQEFAASCASAwggEcAgEAAoGBAKCE8JYKhsbydMPbiO7BJVq1pbuJWJHFxOR7L8Hv3ZVkSG4eNC8DdwAmDHYu/wadfw0ihKFm2gKDcLHp5yz5UQ8PZ8FyDYvgkrvGV0ak4nc40QDJWws621dm01e/INlGKOIStAAsxOityCLv0zm5Vf3+My/YaBvZcB5mGUsPbx8fAgEAAoGAAy0+WanRqwRHXUzt89OsupPXuNNqBlCEqgTqGAt4Nimq6Ur9u2R1KXKXUotxjp71Ubw6JbuUWvJg+5Rmd9RjT0HOUEQF3rvzEepKtaraPhV5ejEIrB+nJWNfGye4yzLdfEXJBGUQzrG+wNe13izfRNXI4dN/6Q5npzqaqv0E1CkCAQACAQACAQACAQACAQA= 4 | rsa.publicKey=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCghPCWCobG8nTD24juwSVataW7iViRxcTkey/B792VZEhuHjQvA3cAJgx2Lv8GnX8NIoShZtoCg3Cx6ecs+VEPD2fBcg2L4JK7xldGpOJ3ONEAyVsLOttXZtNXvyDZRijiErQALMTorcgi79M5uVX9/jMv2Ggb2XAeZhlLD28fHwIDAQAB 5 | -------------------------------------------------------------------------------- /mpush-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | 9 | mpush 10 | com.github.mpusher 11 | 0.8.1 12 | ../pom.xml 13 | 14 | 15 | mpush-api 16 | jar 17 | mpush-api 18 | MPUSH消息推送系统Api模块 19 | https://github.com/mpusher/mpush 20 | 21 | 22 | 23 | io.netty 24 | netty-transport 25 | compile 26 | 27 | 28 | io.netty 29 | netty-codec-http 30 | compile 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api; 21 | 22 | import java.nio.charset.Charset; 23 | import java.nio.charset.StandardCharsets; 24 | 25 | /** 26 | * Created by ohun on 2015/12/23. 27 | * 28 | * @author ohun@live.cn 29 | */ 30 | public interface Constants { 31 | Charset UTF_8 = StandardCharsets.UTF_8; 32 | byte[] EMPTY_BYTES = new byte[0]; 33 | String HTTP_HEAD_READ_TIMEOUT = "readTimeout"; 34 | String EMPTY_STRING = ""; 35 | String ANY_HOST = "0.0.0.0"; 36 | String KICK_CHANNEL_PREFIX = "/mpush/kick/"; 37 | 38 | static String getKickChannel(String hostAndPort) { 39 | return KICK_CHANNEL_PREFIX + hostAndPort; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/MPushContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api; 21 | 22 | import com.mpush.api.common.Monitor; 23 | import com.mpush.api.spi.common.CacheManager; 24 | import com.mpush.api.spi.common.MQClient; 25 | import com.mpush.api.srd.ServiceDiscovery; 26 | import com.mpush.api.srd.ServiceRegistry; 27 | 28 | /** 29 | * Created by ohun on 2017/6/21. 30 | * 31 | * @author ohun@live.cn (夜色) 32 | */ 33 | public interface MPushContext { 34 | 35 | Monitor getMonitor(); 36 | 37 | ServiceDiscovery getDiscovery(); 38 | 39 | ServiceRegistry getRegistry(); 40 | 41 | CacheManager getCacheManager(); 42 | 43 | MQClient getMQClient(); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/common/Condition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.common; 21 | 22 | import java.util.Map; 23 | import java.util.function.Predicate; 24 | 25 | /** 26 | * Created by ohun on 16/10/24. 27 | * 28 | * @author ohun@live.cn (夜色) 29 | */ 30 | public interface Condition extends Predicate> { 31 | } 32 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/common/Monitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.common; 21 | 22 | import java.util.concurrent.Executor; 23 | 24 | /** 25 | * Created by ohun on 2017/7/15. 26 | * 27 | * @author ohun@live.cn (夜色) 28 | */ 29 | public interface Monitor { 30 | 31 | void monitor(String name, Thread thread); 32 | 33 | void monitor(String name, Executor executor); 34 | } 35 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/connection/Cipher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.connection; 21 | 22 | /** 23 | * Created by ohun on 2015/12/28. 24 | * 25 | * @author ohun@live.cn 26 | */ 27 | public interface Cipher { 28 | 29 | byte[] decrypt(byte[] data); 30 | 31 | byte[] encrypt(byte[] data); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/connection/Connection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.connection; 21 | 22 | import com.mpush.api.protocol.Packet; 23 | import io.netty.channel.Channel; 24 | import io.netty.channel.ChannelFuture; 25 | import io.netty.channel.ChannelFutureListener; 26 | 27 | /** 28 | * Created by ohun on 2015/12/22. 29 | * 30 | * @author ohun@live.cn (夜色) 31 | */ 32 | public interface Connection { 33 | byte STATUS_NEW = 0; 34 | byte STATUS_CONNECTED = 1; 35 | byte STATUS_DISCONNECTED = 2; 36 | 37 | void init(Channel channel, boolean security); 38 | 39 | SessionContext getSessionContext(); 40 | 41 | void setSessionContext(SessionContext context); 42 | 43 | ChannelFuture send(Packet packet); 44 | 45 | ChannelFuture send(Packet packet, ChannelFutureListener listener); 46 | 47 | String getId(); 48 | 49 | ChannelFuture close(); 50 | 51 | boolean isConnected(); 52 | 53 | boolean isReadTimeout(); 54 | 55 | boolean isWriteTimeout(); 56 | 57 | void updateLastReadTime(); 58 | 59 | void updateLastWriteTime(); 60 | 61 | Channel getChannel(); 62 | 63 | } 64 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/connection/ConnectionManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.connection; 21 | 22 | import io.netty.channel.Channel; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * Created by ohun on 2015/12/30. 28 | * 29 | * @author ohun@live.cn (夜色) 30 | */ 31 | public interface ConnectionManager { 32 | 33 | Connection get(Channel channel); 34 | 35 | Connection removeAndClose(Channel channel); 36 | 37 | void add(Connection connection); 38 | 39 | int getConnNum(); 40 | 41 | void init(); 42 | 43 | void destroy(); 44 | } 45 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/event/ConnectionCloseEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.event; 21 | 22 | import com.mpush.api.connection.Connection; 23 | 24 | /** 25 | * Created by ohun on 2016/1/10. 26 | * 27 | * @author ohun@live.cn (夜色) 28 | */ 29 | public final class ConnectionCloseEvent implements Event { 30 | public final Connection connection; 31 | 32 | 33 | public ConnectionCloseEvent(Connection connection) { 34 | this.connection = connection; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/event/ConnectionConnectEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.event; 21 | 22 | import com.mpush.api.connection.Connection; 23 | 24 | /** 25 | * Created by ohun on 2016/12/27. 26 | * 27 | * @author ohun@live.cn (夜色) 28 | */ 29 | public final class ConnectionConnectEvent implements Event { 30 | public final Connection connection; 31 | 32 | public ConnectionConnectEvent(Connection connection) { 33 | this.connection = connection; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/event/Event.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.event; 21 | 22 | /** 23 | * Created by ohun on 2015/12/29. 24 | * 25 | * @author ohun@live.cn 26 | */ 27 | public interface Event { 28 | } 29 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/event/HandshakeEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.event; 21 | 22 | import com.mpush.api.connection.Connection; 23 | 24 | /** 25 | * Created by ohun on 2015/12/29. 26 | * 27 | * @author ohun@live.cn 28 | */ 29 | public final class HandshakeEvent implements Event { 30 | public final Connection connection; 31 | public final int heartbeat; 32 | 33 | public HandshakeEvent(Connection connection, int heartbeat) { 34 | this.connection = connection; 35 | this.heartbeat = heartbeat; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/event/KickUserEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.event; 21 | 22 | /** 23 | * Created by ohun on 2015/12/29. 24 | * 25 | * @author ohun@live.cn 26 | */ 27 | public final class KickUserEvent implements Event { 28 | public final String userId; 29 | public final String deviceId; 30 | public final String fromServer; 31 | 32 | public KickUserEvent(String userId, String deviceId, String fromServer) { 33 | this.userId = userId; 34 | this.deviceId = deviceId; 35 | this.fromServer = fromServer; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/event/RouterChangeEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.event; 21 | 22 | import com.mpush.api.router.Router; 23 | 24 | /** 25 | * Created by ohun on 2016/1/4. 26 | * 27 | * @author ohun@live.cn 28 | */ 29 | public final class RouterChangeEvent implements Event { 30 | public final String userId; 31 | public final Router router; 32 | 33 | public RouterChangeEvent(String userId, Router router) { 34 | this.userId = userId; 35 | this.router = router; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/event/ServerShutdownEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.event; 21 | 22 | /** 23 | * Created by ohun on 16/10/19. 24 | * 25 | * @author ohun@live.cn (夜色) 26 | */ 27 | public final class ServerShutdownEvent implements Event { 28 | } 29 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/event/ServerStartupEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.event; 21 | 22 | /** 23 | * Created by ohun on 16/10/19. 24 | * 25 | * @author ohun@live.cn (夜色) 26 | */ 27 | public final class ServerStartupEvent implements Event { 28 | } 29 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/event/Topics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.event; 21 | 22 | /** 23 | * Created by ohun on 16/9/19. 24 | * 25 | * @author ohun@live.cn (夜色) 26 | */ 27 | public interface Topics { 28 | String ONLINE_CHANNEL = "/mpush/online/"; 29 | 30 | String OFFLINE_CHANNEL = "/mpush/offline/"; 31 | } 32 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/event/UserOfflineEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.event; 21 | 22 | import com.mpush.api.connection.Connection; 23 | 24 | /** 25 | * 链接超时,用户解绑的时候,用户主动关闭链接,才会触发该事件 26 | */ 27 | public final class UserOfflineEvent implements Event { 28 | 29 | private final Connection connection; 30 | private final String userId; 31 | 32 | public UserOfflineEvent(Connection connection, String userId) { 33 | this.connection = connection; 34 | this.userId = userId; 35 | } 36 | 37 | public Connection getConnection() { 38 | return connection; 39 | } 40 | 41 | public String getUserId() { 42 | return userId; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/event/UserOnlineEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.event; 21 | 22 | import com.mpush.api.connection.Connection; 23 | 24 | /** 25 | * 绑定用户的时候才会触发该事件 26 | */ 27 | public final class UserOnlineEvent implements Event { 28 | 29 | private final Connection connection; 30 | private final String userId; 31 | 32 | public UserOnlineEvent(Connection connection, String userId) { 33 | this.connection = connection; 34 | this.userId = userId; 35 | } 36 | 37 | public Connection getConnection() { 38 | return connection; 39 | } 40 | 41 | public String getUserId() { 42 | return userId; 43 | } 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/message/Message.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.message; 21 | 22 | import com.mpush.api.connection.Connection; 23 | import com.mpush.api.protocol.Packet; 24 | import io.netty.channel.ChannelFutureListener; 25 | 26 | /** 27 | * Created by ohun on 2015/12/22. 28 | * 29 | * @author ohun@live.cn 30 | */ 31 | public interface Message { 32 | 33 | Connection getConnection(); 34 | 35 | void decodeBody(); 36 | 37 | void encodeBody(); 38 | 39 | /** 40 | * 发送当前message, 并根据情况最body进行数据压缩、加密 41 | * 42 | * @param listener 发送成功后的回调 43 | */ 44 | void send(ChannelFutureListener listener); 45 | 46 | /** 47 | * 发送当前message, 不会对body进行数据压缩、加密, 原样发送 48 | * 49 | * @param listener 发送成功后的回调 50 | */ 51 | void sendRaw(ChannelFutureListener listener); 52 | 53 | Packet getPacket(); 54 | } 55 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/message/MessageHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.message; 21 | 22 | import com.mpush.api.connection.Connection; 23 | import com.mpush.api.protocol.Packet; 24 | 25 | /** 26 | * Created by ohun on 2015/12/22. 27 | * 28 | * @author ohun@live.cn 29 | */ 30 | public interface MessageHandler { 31 | void handle(Packet packet, Connection connection); 32 | } 33 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/message/PacketReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.message; 21 | 22 | import com.mpush.api.connection.Connection; 23 | import com.mpush.api.protocol.Packet; 24 | 25 | /** 26 | * Created by ohun on 2015/12/22. 27 | * 28 | * @author ohun@live.cn 29 | */ 30 | public interface PacketReceiver { 31 | void onReceive(Packet packet, Connection connection); 32 | } 33 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/protocol/Command.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.protocol; 21 | 22 | /** 23 | * Created by ohun on 2015/12/22. 24 | * 25 | * @author ohun@live.cn 26 | */ 27 | public enum Command { 28 | HEARTBEAT(1), 29 | HANDSHAKE(2), 30 | LOGIN(3), 31 | LOGOUT(4), 32 | BIND(5), 33 | UNBIND(6), 34 | FAST_CONNECT(7), 35 | PAUSE(8), 36 | RESUME(9), 37 | ERROR(10), 38 | OK(11), 39 | HTTP_PROXY(12), 40 | KICK(13), 41 | GATEWAY_KICK(14), 42 | PUSH(15), 43 | GATEWAY_PUSH(16), 44 | NOTIFICATION(17), 45 | GATEWAY_NOTIFICATION(18), 46 | CHAT(19), 47 | GATEWAY_CHAT(20), 48 | GROUP(21), 49 | GATEWAY_GROUP(22), 50 | ACK(23), 51 | NACK(24), 52 | UNKNOWN(-1); 53 | 54 | Command(int cmd) { 55 | this.cmd = (byte) cmd; 56 | } 57 | 58 | public final byte cmd; 59 | 60 | public static Command toCMD(byte b) { 61 | Command[] values = values(); 62 | if (b > 0 && b < values.length) return values[b - 1]; 63 | return UNKNOWN; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/push/AckModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.push; 21 | 22 | import com.mpush.api.protocol.Packet; 23 | 24 | /** 25 | * Created by ohun on 16/9/6. 26 | * 27 | * @author ohun@live.cn (夜色) 28 | */ 29 | public enum AckModel { 30 | NO_ACK((byte) 0),//不需要ACK 31 | AUTO_ACK(Packet.FLAG_AUTO_ACK),//客户端收到消息后自动确认消息 32 | BIZ_ACK(Packet.FLAG_BIZ_ACK);//由客户端业务自己确认消息是否到达 33 | public final byte flag; 34 | 35 | AckModel(byte flag) { 36 | this.flag = flag; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/push/BroadcastController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.push; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * Created by ohun on 16/10/25. 26 | * 27 | * @author ohun@live.cn (夜色) 28 | */ 29 | public interface BroadcastController { 30 | 31 | String taskId(); 32 | 33 | int qps(); 34 | 35 | void updateQps(int qps); 36 | 37 | boolean isDone(); 38 | 39 | int sendCount(); 40 | 41 | void cancel(); 42 | 43 | boolean isCancelled(); 44 | 45 | int incSendCount(int count); 46 | 47 | void success(String... userIds); 48 | 49 | List successUserIds(); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/push/MsgType.java: -------------------------------------------------------------------------------- 1 | package com.mpush.api.push; 2 | 3 | public enum MsgType { 4 | NOTIFICATION("提醒", 1),//会在通知栏显示 5 | MESSAGE("消息", 2),//不会在通知栏显示,业务自定义消息 6 | NOTIFICATION_AND_MESSAGE("提醒+消息", 3);//1+2 7 | 8 | MsgType(String desc, int value) { 9 | this.desc = desc; 10 | this.value = value; 11 | } 12 | 13 | private final String desc; 14 | private final int value; 15 | 16 | public String getDesc() { 17 | return desc; 18 | } 19 | 20 | public int getValue() { 21 | return value; 22 | } 23 | } -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/push/PushCallback.java: -------------------------------------------------------------------------------- 1 | package com.mpush.api.push; 2 | 3 | import com.mpush.api.router.ClientLocation; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Created by ohun on 2015/12/30. 9 | * 10 | * @author ohun@live.cn 11 | */ 12 | public interface PushCallback { 13 | 14 | default void onResult(PushResult result) { 15 | switch (result.resultCode) { 16 | case PushResult.CODE_SUCCESS: 17 | onSuccess(result.userId, result.location); 18 | break; 19 | case PushResult.CODE_FAILURE: 20 | onFailure(result.userId, result.location); 21 | break; 22 | case PushResult.CODE_OFFLINE: 23 | onOffline(result.userId, result.location); 24 | break; 25 | case PushResult.CODE_TIMEOUT: 26 | onTimeout(result.userId, result.location); 27 | break; 28 | } 29 | } 30 | 31 | /** 32 | * 推送成功, 指定用户推送时重写此方法 33 | * 34 | * @param userId 成功的用户, 如果是广播, 值为空 35 | * @param location 用户所在机器, 如果是广播, 值为空 36 | */ 37 | default void onSuccess(String userId, ClientLocation location) { 38 | } 39 | 40 | /** 41 | * 推送失败 42 | * 43 | * @param userId 推送用户 44 | * @param location 用户所在机器 45 | */ 46 | default void onFailure(String userId, ClientLocation location) { 47 | } 48 | 49 | /** 50 | * 推送用户不在线 51 | * 52 | * @param userId 推送用户 53 | * @param location 用户所在机器 54 | */ 55 | default void onOffline(String userId, ClientLocation location) { 56 | } 57 | 58 | /** 59 | * 推送超时 60 | * 61 | * @param userId 推送用户 62 | * @param location 用户所在机器 63 | */ 64 | default void onTimeout(String userId, ClientLocation location) { 65 | } 66 | } -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/push/PushException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | package com.mpush.api.push; 20 | 21 | /** 22 | * Created by yxx on 2016/5/28. 23 | * 24 | * @author ohun@live.cn (夜色) 25 | */ 26 | public class PushException extends RuntimeException { 27 | 28 | public PushException(Throwable cause) { 29 | super(cause); 30 | } 31 | 32 | public PushException(String message) { 33 | super(message); 34 | } 35 | 36 | public PushException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/router/ClientClassifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.router; 21 | 22 | import com.mpush.api.spi.router.ClientClassifierFactory; 23 | 24 | /** 25 | * Created by ohun on 16/10/26. 26 | * 27 | * @author ohun@live.cn (夜色) 28 | */ 29 | public interface ClientClassifier { 30 | ClientClassifier I = ClientClassifierFactory.create(); 31 | 32 | int getClientType(String osName); 33 | } 34 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/router/Router.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.router; 21 | 22 | /** 23 | * Created by ohun on 2015/12/23. 24 | * 25 | * @author ohun@live.cn 26 | */ 27 | public interface Router { 28 | 29 | T getRouteValue(); 30 | 31 | RouterType getRouteType(); 32 | 33 | enum RouterType { 34 | LOCAL, REMOTE 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/router/RouterManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.router; 21 | 22 | import java.util.Set; 23 | 24 | /** 25 | * Created by ohun on 2015/12/23. 26 | * 27 | * @author ohun@live.cn 28 | */ 29 | public interface RouterManager { 30 | 31 | /** 32 | * 注册路由 33 | * 34 | * @param userId 用户ID 35 | * @param router 新路由 36 | * @return 如果有旧的的路由信息则返回之,否则返回空。 37 | */ 38 | R register(String userId, R router); 39 | 40 | /** 41 | * 删除路由 42 | * 43 | * @param userId 用户ID 44 | * @param clientType 客户端类型 45 | * @return true:成功,false:失败 46 | */ 47 | boolean unRegister(String userId, int clientType); 48 | 49 | /** 50 | * 查询路由 51 | * 52 | * @param userId 用户ID 53 | * @return userId对应的所有的路由信息 54 | */ 55 | Set lookupAll(String userId); 56 | 57 | /** 58 | * 查询指定设备类型的用户路由信息 59 | * 60 | * @param userId 用户ID 61 | * @param clientType 客户端类型 62 | * @return 指定类型的路由信息 63 | */ 64 | R lookup(String userId, int clientType); 65 | } 66 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/service/Client.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.service; 21 | 22 | public interface Client extends Service { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/service/Listener.java: -------------------------------------------------------------------------------- 1 | package com.mpush.api.service; 2 | 3 | public interface Listener { 4 | void onSuccess(Object... args); 5 | 6 | void onFailure(Throwable cause); 7 | } -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/service/Server.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.service; 21 | 22 | /** 23 | * Created by ohun on 2015/12/24. 24 | * 25 | * @author ohun@live.cn 26 | */ 27 | public interface Server extends Service { 28 | 29 | } 30 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/service/Service.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.service; 21 | 22 | import java.util.concurrent.CompletableFuture; 23 | 24 | /** 25 | * Created by yxx on 2016/5/17. 26 | * 27 | * @author ohun@live.cn 28 | */ 29 | public interface Service { 30 | 31 | void start(Listener listener); 32 | 33 | void stop(Listener listener); 34 | 35 | CompletableFuture start(); 36 | 37 | CompletableFuture stop(); 38 | 39 | boolean syncStart(); 40 | 41 | boolean syncStop(); 42 | 43 | void init(); 44 | 45 | boolean isRunning(); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/service/ServiceException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | package com.mpush.api.service; 20 | 21 | /** 22 | * Created by yxx on 2016/5/27. 23 | * 24 | * @author ohun@live.cn (夜色) 25 | */ 26 | public class ServiceException extends RuntimeException { 27 | 28 | public ServiceException(String message) { 29 | super(message); 30 | } 31 | 32 | public ServiceException(Throwable cause) { 33 | super(cause); 34 | } 35 | 36 | public ServiceException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/Factory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi; 21 | 22 | import java.util.function.Supplier; 23 | 24 | /** 25 | * Created by yxx on 2016/5/18. 26 | * 27 | * @author ohun@live.cn 28 | */ 29 | @FunctionalInterface 30 | public interface Factory extends Supplier { 31 | } 32 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/Plugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi; 21 | 22 | import com.mpush.api.MPushContext; 23 | 24 | /** 25 | * Created by ohun on 2017/6/21. 26 | * 27 | * @author ohun@live.cn (夜色) 28 | */ 29 | public interface Plugin { 30 | 31 | default void init(MPushContext context) { 32 | 33 | } 34 | 35 | default void destroy() { 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/Spi.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi; 21 | 22 | import java.lang.annotation.*; 23 | 24 | /** 25 | * Created by ohun on 16/10/14. 26 | * 27 | * @author ohun@live.cn (夜色) 28 | */ 29 | @Documented 30 | @Retention(RetentionPolicy.RUNTIME) 31 | @Target(ElementType.TYPE) 32 | public @interface Spi { 33 | 34 | /** 35 | * SPI name 36 | * 37 | * @return name 38 | */ 39 | String value() default ""; 40 | 41 | /** 42 | * 排序顺序 43 | * 44 | * @return sortNo 45 | */ 46 | int order() default 0; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/client/PusherFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.client; 21 | 22 | import com.mpush.api.push.PushSender; 23 | import com.mpush.api.spi.Factory; 24 | import com.mpush.api.spi.SpiLoader; 25 | 26 | /** 27 | * Created by yxx on 2016/5/18. 28 | * 29 | * @author ohun@live.cn 30 | */ 31 | public interface PusherFactory extends Factory { 32 | static PushSender create() { 33 | return SpiLoader.load(PusherFactory.class).get(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/common/CacheManagerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.common; 21 | 22 | import com.mpush.api.spi.Factory; 23 | import com.mpush.api.spi.SpiLoader; 24 | 25 | /** 26 | * Created by ohun on 2016/12/27. 27 | * 28 | * @author ohun@live.cn (夜色) 29 | */ 30 | public interface CacheManagerFactory extends Factory { 31 | static CacheManager create() { 32 | return SpiLoader.load(CacheManagerFactory.class).get(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/common/ExecutorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.common; 21 | 22 | import com.mpush.api.spi.SpiLoader; 23 | 24 | import java.util.concurrent.Executor; 25 | 26 | /** 27 | * Created by yxx on 2016/5/20. 28 | * 29 | * @author ohun@live.cn 30 | */ 31 | public interface ExecutorFactory { 32 | String PUSH_CLIENT = "push-client"; 33 | String PUSH_TASK = "push-task"; 34 | String ACK_TIMER = "ack-timer"; 35 | String EVENT_BUS = "event-bus"; 36 | String MQ = "mq"; 37 | 38 | Executor get(String name); 39 | 40 | static ExecutorFactory create() { 41 | return SpiLoader.load(ExecutorFactory.class); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/common/Json.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.common; 21 | 22 | /** 23 | * Created by ohun on 2016/12/17. 24 | * 25 | * @author ohun@live.cn (夜色) 26 | */ 27 | public interface Json { 28 | Json JSON = JsonFactory.create(); 29 | 30 | T fromJson(String json, Class clazz); 31 | 32 | String toJson(Object json); 33 | } 34 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/common/JsonFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.common; 21 | 22 | import com.mpush.api.spi.Factory; 23 | import com.mpush.api.spi.SpiLoader; 24 | 25 | /** 26 | * Created by ohun on 2016/12/17. 27 | * 28 | * @author ohun@live.cn (夜色) 29 | */ 30 | public interface JsonFactory extends Factory { 31 | 32 | static Json create() { 33 | return SpiLoader.load(JsonFactory.class).get(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/common/MQClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.common; 21 | 22 | import com.mpush.api.spi.Plugin; 23 | 24 | /** 25 | * Created by ohun on 2016/12/27. 26 | * 27 | * @author ohun@live.cn (夜色) 28 | */ 29 | public interface MQClient extends Plugin { 30 | 31 | void subscribe(String topic, MQMessageReceiver receiver); 32 | 33 | void publish(String topic, Object message); 34 | } 35 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/common/MQClientFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.common; 21 | 22 | import com.mpush.api.spi.Factory; 23 | import com.mpush.api.spi.SpiLoader; 24 | 25 | /** 26 | * Created by ohun on 2016/12/27. 27 | * 28 | * @author ohun@live.cn (夜色) 29 | */ 30 | public interface MQClientFactory extends Factory { 31 | 32 | static MQClient create() { 33 | return SpiLoader.load(MQClientFactory.class).get(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/common/MQMessageReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.common; 21 | 22 | /** 23 | * Created by ohun on 2016/12/27. 24 | * 25 | * @author ohun@live.cn (夜色) 26 | */ 27 | public interface MQMessageReceiver { 28 | void receive(String topic, Object message); 29 | } 30 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/common/ServiceDiscoveryFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.common; 21 | 22 | import com.mpush.api.spi.Factory; 23 | import com.mpush.api.spi.SpiLoader; 24 | import com.mpush.api.srd.ServiceDiscovery; 25 | import com.mpush.api.srd.ServiceRegistry; 26 | 27 | /** 28 | * Created by ohun on 2016/12/27. 29 | * 30 | * @author ohun@live.cn (夜色) 31 | */ 32 | public interface ServiceDiscoveryFactory extends Factory { 33 | static ServiceDiscovery create() { 34 | return SpiLoader.load(ServiceDiscoveryFactory.class).get(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/common/ServiceRegistryFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.common; 21 | 22 | import com.mpush.api.spi.Factory; 23 | import com.mpush.api.spi.SpiLoader; 24 | import com.mpush.api.srd.ServiceRegistry; 25 | 26 | /** 27 | * Created by ohun on 2016/12/27. 28 | * 29 | * @author ohun@live.cn (夜色) 30 | */ 31 | public interface ServiceRegistryFactory extends Factory { 32 | static ServiceRegistry create() { 33 | return SpiLoader.load(ServiceRegistryFactory.class).get(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/core/RsaCipherFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.core; 21 | 22 | import com.mpush.api.connection.Cipher; 23 | import com.mpush.api.spi.Factory; 24 | import com.mpush.api.spi.SpiLoader; 25 | 26 | /** 27 | * Created by yxx on 2016/5/19. 28 | * 29 | * @author ohun@live.cn 30 | */ 31 | public interface RsaCipherFactory extends Factory { 32 | static Cipher create() { 33 | return SpiLoader.load(RsaCipherFactory.class).get(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/core/ServerEventListenerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.core; 21 | 22 | import com.mpush.api.common.ServerEventListener; 23 | import com.mpush.api.spi.Factory; 24 | import com.mpush.api.spi.SpiLoader; 25 | 26 | /** 27 | * Created by ohun on 16/10/19. 28 | * 29 | * @author ohun@live.cn (夜色) 30 | */ 31 | public interface ServerEventListenerFactory extends Factory { 32 | static ServerEventListener create() { 33 | return SpiLoader.load(ServerEventListenerFactory.class).get(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/handler/BindValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.handler; 21 | 22 | import com.mpush.api.spi.Plugin; 23 | 24 | /** 25 | * Created by ohun on 16/10/19. 26 | * 27 | * @author ohun@live.cn (夜色) 28 | */ 29 | public interface BindValidator extends Plugin { 30 | boolean validate(String userId, String data); 31 | } 32 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/handler/BindValidatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.handler; 21 | 22 | import com.mpush.api.spi.Factory; 23 | import com.mpush.api.spi.SpiLoader; 24 | 25 | /** 26 | * Created by ohun on 16/10/19. 27 | * 28 | * @author ohun@live.cn (夜色) 29 | */ 30 | public interface BindValidatorFactory extends Factory { 31 | static BindValidator create() { 32 | return SpiLoader.load(BindValidatorFactory.class).get(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/handler/PushHandlerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.handler; 21 | 22 | import com.mpush.api.message.MessageHandler; 23 | import com.mpush.api.spi.Factory; 24 | import com.mpush.api.spi.SpiLoader; 25 | 26 | /** 27 | * Created by ohun on 16/10/14. 28 | * 29 | * @author ohun@live.cn (夜色) 30 | */ 31 | public interface PushHandlerFactory extends Factory { 32 | static MessageHandler create() { 33 | return SpiLoader.load(PushHandlerFactory.class).get(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/net/DnsMappingManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.net; 21 | 22 | import com.mpush.api.service.Service; 23 | import com.mpush.api.spi.SpiLoader; 24 | 25 | /** 26 | * Created by yxx on 2016/5/23. 27 | * 28 | * @author ohun@live.cn (夜色) 29 | */ 30 | public interface DnsMappingManager extends Service { 31 | 32 | static DnsMappingManager create() { 33 | return SpiLoader.load(DnsMappingManager.class); 34 | } 35 | 36 | DnsMapping lookup(String origin); 37 | } 38 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/push/IPushMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.push; 21 | 22 | import com.mpush.api.common.Condition; 23 | 24 | /** 25 | * Created by ohun on 2016/12/24. 26 | * 27 | * @author ohun@live.cn (夜色) 28 | */ 29 | public interface IPushMessage { 30 | 31 | boolean isBroadcast(); 32 | 33 | String getUserId(); 34 | 35 | int getClientType(); 36 | 37 | byte[] getContent(); 38 | 39 | boolean isNeedAck(); 40 | 41 | byte getFlags(); 42 | 43 | int getTimeoutMills(); 44 | 45 | default String getTaskId() { 46 | return null; 47 | } 48 | 49 | default Condition getCondition() { 50 | return null; 51 | } 52 | 53 | default void finalized() { 54 | 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/push/MessagePusher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.push; 21 | 22 | /** 23 | * Created by ohun on 2016/12/24. 24 | * 25 | * @author ohun@live.cn (夜色) 26 | */ 27 | public interface MessagePusher { 28 | void push(IPushMessage message); 29 | } 30 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/push/MessagePusherFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.push; 21 | 22 | import com.mpush.api.spi.Factory; 23 | import com.mpush.api.spi.SpiLoader; 24 | 25 | /** 26 | * Created by ohun on 2016/12/24. 27 | * 28 | * @author ohun@live.cn (夜色) 29 | */ 30 | public interface MessagePusherFactory extends Factory { 31 | 32 | static MessagePusher create() { 33 | return SpiLoader.load(MessagePusherFactory.class).get(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/push/PushListener.java: -------------------------------------------------------------------------------- 1 | package com.mpush.api.spi.push; 2 | 3 | import com.mpush.api.spi.Plugin; 4 | 5 | public interface PushListener extends Plugin { 6 | 7 | /** 8 | * 消息下发成功后回调 9 | * 如果消息需要ACK则该方法不会被调用 10 | * 11 | * @param message 要下发的消息 12 | * @param timePoints 消息流转时间节点 13 | */ 14 | void onSuccess(T message, Object[] timePoints); 15 | 16 | /** 17 | * 收到客户端ACK后回调 18 | * 19 | * @param message 要下发的消息 20 | * @param timePoints 消息流转时间节点 21 | */ 22 | void onAckSuccess(T message, Object[] timePoints); 23 | 24 | /** 25 | * 广播消息推送全部结束后回调 26 | * 27 | * @param message 要下发的消息 28 | * @param timePoints 消息流转时间节点 29 | */ 30 | void onBroadcastComplete(T message, Object[] timePoints); 31 | 32 | /** 33 | * 消息下发失败后回调 34 | * 35 | * @param message 要下发的消息 36 | * @param timePoints 消息流转时间节点 37 | */ 38 | void onFailure(T message, Object[] timePoints); 39 | 40 | /** 41 | * 推送消息发现用户不在线时回调 42 | * 43 | * @param message 要下发的消息 44 | * @param timePoints 消息流转时间节点 45 | */ 46 | void onOffline(T message, Object[] timePoints); 47 | 48 | /** 49 | * 推送消息发现用户不在当前机器时回调 50 | * 51 | * @param message 要下发的消息 52 | * @param timePoints 消息流转时间节点 53 | */ 54 | void onRedirect(T message, Object[] timePoints); 55 | 56 | /** 57 | * 发送消息超时或等待客户端ACK超时时回调 58 | * 59 | * @param message 要下发的消息 60 | * @param timePoints 消息流转时间节点 61 | */ 62 | void onTimeout(T message, Object[] timePoints); 63 | } -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/push/PushListenerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.push; 21 | 22 | import com.mpush.api.spi.Factory; 23 | import com.mpush.api.spi.SpiLoader; 24 | 25 | /** 26 | * Created by ohun on 2016/12/24. 27 | * 28 | * @author ohun@live.cn (夜色) 29 | */ 30 | public interface PushListenerFactory extends Factory> { 31 | 32 | @SuppressWarnings("unchecked") 33 | static PushListener create() { 34 | return (PushListener) SpiLoader.load(PushListenerFactory.class).get(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/spi/router/ClientClassifierFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.spi.router; 21 | 22 | import com.mpush.api.router.ClientClassifier; 23 | import com.mpush.api.spi.Factory; 24 | import com.mpush.api.spi.SpiLoader; 25 | 26 | /** 27 | * Created by ohun on 16/10/26. 28 | * 29 | * @author ohun@live.cn (夜色) 30 | */ 31 | public interface ClientClassifierFactory extends Factory { 32 | 33 | static ClientClassifier create() { 34 | return SpiLoader.load(ClientClassifierFactory.class).get(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/srd/ServiceDiscovery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.srd; 21 | 22 | import com.mpush.api.service.Service; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * Created by ohun on 2016/12/19. 28 | * 29 | * @author ohun@live.cn (夜色) 30 | */ 31 | public interface ServiceDiscovery extends Service { 32 | 33 | List lookup(String path); 34 | 35 | void subscribe(String path, ServiceListener listener); 36 | 37 | void unsubscribe(String path, ServiceListener listener); 38 | } 39 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/srd/ServiceEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.srd; 21 | 22 | import com.mpush.api.event.Event; 23 | 24 | /** 25 | * Created by ohun on 2016/12/20. 26 | * 27 | * @author ohun@live.cn (夜色) 28 | */ 29 | public interface ServiceEvent extends Event { 30 | } 31 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/srd/ServiceListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.srd; 21 | 22 | /** 23 | * Created by ohun on 2016/12/19. 24 | * 25 | * @author ohun@live.cn (夜色) 26 | */ 27 | public interface ServiceListener { 28 | 29 | void onServiceAdded(String path, ServiceNode node); 30 | 31 | void onServiceUpdated(String path, ServiceNode node); 32 | 33 | void onServiceRemoved(String path, ServiceNode node); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/srd/ServiceNames.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.srd; 21 | 22 | /** 23 | * Created by ohun on 2016/12/27. 24 | * 25 | * @author ohun@live.cn (夜色) 26 | */ 27 | public interface ServiceNames { 28 | String CONN_SERVER = "/cluster/cs"; 29 | String WS_SERVER = "/cluster/ws"; 30 | String GATEWAY_SERVER = "/cluster/gs"; 31 | String DNS_MAPPING = "/dns/mapping"; 32 | 33 | String ATTR_PUBLIC_IP = "public_ip"; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/srd/ServiceNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.srd; 21 | 22 | /** 23 | * Created by ohun on 2016/12/19. 24 | * 25 | * @author ohun@live.cn (夜色) 26 | */ 27 | public interface ServiceNode { 28 | 29 | String serviceName(); 30 | 31 | String nodeId(); 32 | 33 | String getHost(); 34 | 35 | int getPort(); 36 | 37 | default T getAttr(String name) { 38 | return null; 39 | } 40 | 41 | default boolean isPersistent() { 42 | return false; 43 | } 44 | 45 | default String hostAndPort() { 46 | return getHost() + ":" + getPort(); 47 | } 48 | 49 | default String nodePath() { 50 | return serviceName() + '/' + nodeId(); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /mpush-api/src/main/java/com/mpush/api/srd/ServiceRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.api.srd; 21 | 22 | import com.mpush.api.service.Service; 23 | 24 | /** 25 | * Created by ohun on 2016/12/19. 26 | * 27 | * @author ohun@live.cn (夜色) 28 | */ 29 | public interface ServiceRegistry extends Service { 30 | 31 | void register(ServiceNode node); 32 | 33 | void deregister(ServiceNode node); 34 | } 35 | -------------------------------------------------------------------------------- /mpush-boot/src/main/java/com/mpush/bootstrap/BootException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.bootstrap; 21 | 22 | /** 23 | * Created by yxx on 2016/5/19. 24 | * 25 | * @author ohun@live.cn 26 | */ 27 | public class BootException extends RuntimeException { 28 | public BootException(String s) { 29 | super(s); 30 | } 31 | 32 | public BootException(String message, Throwable cause) { 33 | super(message, cause); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mpush-boot/src/main/java/com/mpush/bootstrap/job/CacheManagerBoot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.bootstrap.job; 21 | 22 | import com.mpush.api.spi.common.CacheManagerFactory; 23 | import com.mpush.common.user.UserManager; 24 | import com.mpush.core.MPushServer; 25 | 26 | /** 27 | * Created by yxx on 2016/5/14. 28 | * 29 | * @author ohun@live.cn 30 | */ 31 | public final class CacheManagerBoot extends BootJob { 32 | 33 | @Override 34 | protected void start() { 35 | CacheManagerFactory.create().init(); 36 | startNext(); 37 | } 38 | 39 | @Override 40 | protected void stop() { 41 | stopNext(); 42 | CacheManagerFactory.create().destroy(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mpush-boot/src/main/java/com/mpush/bootstrap/job/HttpProxyBoot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.bootstrap.job; 21 | 22 | import com.mpush.api.spi.net.DnsMappingManager; 23 | import com.mpush.core.MPushServer; 24 | 25 | /** 26 | * Created by yxx on 2016/5/15. 27 | * 28 | * @author ohun@live.cn 29 | */ 30 | public final class HttpProxyBoot extends BootJob { 31 | 32 | private final MPushServer mPushServer; 33 | 34 | public HttpProxyBoot(MPushServer mPushServer) { 35 | this.mPushServer = mPushServer; 36 | } 37 | 38 | @Override 39 | protected void start() { 40 | mPushServer.getHttpClient().syncStart(); 41 | DnsMappingManager.create().start(); 42 | 43 | startNext(); 44 | } 45 | 46 | @Override 47 | protected void stop() { 48 | stopNext(); 49 | mPushServer.getHttpClient().syncStop(); 50 | DnsMappingManager.create().stop(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /mpush-boot/src/main/java/com/mpush/bootstrap/job/MonitorBoot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.bootstrap.job; 21 | 22 | import com.mpush.core.MPushServer; 23 | 24 | /** 25 | * Created by yxx on 2016/5/15. 26 | * 27 | * @author ohun@live.cn 28 | */ 29 | public final class MonitorBoot extends BootJob { 30 | 31 | private final MPushServer mPushServer; 32 | 33 | public MonitorBoot(MPushServer mPushServer) { 34 | this.mPushServer = mPushServer; 35 | } 36 | 37 | @Override 38 | protected void start() { 39 | mPushServer.getMonitor().start(); 40 | startNext(); 41 | } 42 | 43 | @Override 44 | protected void stop() { 45 | stopNext(); 46 | mPushServer.getMonitor().stop(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /mpush-boot/src/main/java/com/mpush/bootstrap/job/PushCenterBoot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.bootstrap.job; 21 | 22 | import com.mpush.core.MPushServer; 23 | 24 | /** 25 | * Created by ohun on 16/10/25. 26 | * 27 | * @author ohun@live.cn (夜色) 28 | */ 29 | public final class PushCenterBoot extends BootJob { 30 | private final MPushServer mPushServer; 31 | 32 | public PushCenterBoot(MPushServer mPushServer) { 33 | this.mPushServer = mPushServer; 34 | } 35 | 36 | @Override 37 | protected void start() { 38 | mPushServer.getPushCenter().start(); 39 | startNext(); 40 | } 41 | 42 | @Override 43 | protected void stop() { 44 | stopNext(); 45 | mPushServer.getPushCenter().stop(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /mpush-boot/src/main/java/com/mpush/bootstrap/job/RouterCenterBoot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.bootstrap.job; 21 | 22 | import com.mpush.core.MPushServer; 23 | 24 | /** 25 | * Created by ohun on 16/10/25. 26 | * 27 | * @author ohun@live.cn (夜色) 28 | */ 29 | public final class RouterCenterBoot extends BootJob { 30 | private final MPushServer mPushServer; 31 | 32 | public RouterCenterBoot(MPushServer mPushServer) { 33 | this.mPushServer = mPushServer; 34 | } 35 | 36 | @Override 37 | protected void start() { 38 | mPushServer.getRouterCenter().start(); 39 | startNext(); 40 | } 41 | 42 | @Override 43 | protected void stop() { 44 | stopNext(); 45 | mPushServer.getRouterCenter().stop(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /mpush-boot/src/main/java/com/mpush/bootstrap/job/ServiceDiscoveryBoot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.bootstrap.job; 21 | 22 | import com.mpush.api.spi.common.ServiceDiscoveryFactory; 23 | import com.mpush.api.spi.common.ServiceRegistryFactory; 24 | import com.mpush.api.srd.ServiceDiscovery; 25 | import com.mpush.tools.log.Logs; 26 | 27 | /** 28 | * Created by yxx on 2016/5/14. 29 | * 30 | * @author ohun@live.cn 31 | */ 32 | public final class ServiceDiscoveryBoot extends BootJob { 33 | 34 | @Override 35 | protected void start() { 36 | Logs.Console.info("init service discovery waiting for connected..."); 37 | ServiceDiscoveryFactory.create().syncStart(); 38 | startNext(); 39 | } 40 | 41 | @Override 42 | protected void stop() { 43 | stopNext(); 44 | ServiceDiscoveryFactory.create().syncStop(); 45 | Logs.Console.info("service discovery closed..."); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /mpush-boot/src/main/java/com/mpush/bootstrap/job/ServiceRegistryBoot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.bootstrap.job; 21 | 22 | import com.mpush.api.spi.common.ServiceRegistryFactory; 23 | import com.mpush.tools.log.Logs; 24 | 25 | /** 26 | * Created by yxx on 2016/5/14. 27 | * 28 | * @author ohun@live.cn 29 | */ 30 | public final class ServiceRegistryBoot extends BootJob { 31 | 32 | @Override 33 | protected void start() { 34 | Logs.Console.info("init service registry waiting for connected..."); 35 | ServiceRegistryFactory.create().syncStart(); 36 | startNext(); 37 | } 38 | 39 | @Override 40 | protected void stop() { 41 | stopNext(); 42 | ServiceRegistryFactory.create().syncStop(); 43 | Logs.Console.info("service registry closed..."); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /mpush-boot/src/main/resources/mpush.conf: -------------------------------------------------------------------------------- 1 | mp.log-level=${log.level} 2 | mp.core.min-heartbeat=${min.hb} 3 | mp.security.private-key="${rsa.privateKey}" 4 | mp.security.public-key="${rsa.publicKey}" 5 | mp.zk.server-address="127.0.0.1:2181" //多台机器使用","分隔如:"10.0.10.44:2181,10.0.10.49:2181" 6 | mp.redis { //redis 集群配置 7 | nodes:["127.0.0.1:6379"] //格式是ip:port 8 | cluster-model:single //single, cluster 9 | } 10 | mp.net.local-ip="" //本地ip, 默认取第一个网卡的本地IP 11 | mp.net.public-ip="" //外网ip, 默认取第一个网卡的外网IP 12 | mp.net.ws-server-port=0 //websocket对外端口, 0表示禁用websocket 13 | mp.net.gateway-server-net=tcp // 网关服务使用的网络 udp/tcp 14 | mp.net.connect-server-port=3000 //接入服务的端口号 15 | mp.http.proxy-enabled=true //启用Http代理功能 16 | -------------------------------------------------------------------------------- /mpush-cache/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | mpush 9 | com.github.mpusher 10 | 0.8.1 11 | ../pom.xml 12 | 13 | 14 | mpush-cache 15 | jar 16 | mpush-cache 17 | MPUSH消息推送系统缓存模块 18 | https://github.com/mpusher/mpush 19 | 20 | 21 | 22 | ${project.groupId} 23 | mpush-monitor 24 | 25 | 26 | redis.clients 27 | jedis 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /mpush-cache/src/main/java/com/mpush/cache/redis/RedisException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | package com.mpush.cache.redis; 20 | 21 | /** 22 | * Created by yxx on 2016/5/27. 23 | * 24 | * @author ohun@live.cn (夜色) 25 | */ 26 | public class RedisException extends RuntimeException { 27 | 28 | public RedisException() { 29 | } 30 | 31 | public RedisException(Throwable cause) { 32 | super(cause); 33 | } 34 | 35 | public RedisException(String message) { 36 | super(message); 37 | } 38 | 39 | public RedisException(String message, Throwable cause) { 40 | super(message, cause); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /mpush-cache/src/main/java/com/mpush/cache/redis/RedisServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.cache.redis; 21 | 22 | import com.mpush.tools.config.data.RedisNode; 23 | import redis.clients.jedis.HostAndPort; 24 | 25 | /** 26 | * redis 相关的配置信息 27 | */ 28 | public class RedisServer extends RedisNode { 29 | 30 | public RedisServer(String ip, int port) { 31 | super(ip, port); 32 | } 33 | 34 | public HostAndPort convert() { 35 | return new HostAndPort(host, port); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /mpush-cache/src/main/java/com/mpush/cache/redis/manager/RedisCacheManagerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.cache.redis.manager; 21 | 22 | import com.mpush.api.spi.Spi; 23 | import com.mpush.api.spi.common.CacheManager; 24 | import com.mpush.api.spi.common.CacheManagerFactory; 25 | 26 | /** 27 | * Created by ohun on 2016/12/27. 28 | * 29 | * @author ohun@live.cn (夜色) 30 | */ 31 | @Spi(order = 1) 32 | public final class RedisCacheManagerFactory implements CacheManagerFactory { 33 | @Override 34 | public CacheManager get() { 35 | return RedisManager.I; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /mpush-cache/src/main/java/com/mpush/cache/redis/manager/RedisClusterManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.cache.redis.manager; 21 | 22 | import com.mpush.cache.redis.RedisServer; 23 | 24 | import java.util.List; 25 | 26 | public interface RedisClusterManager { 27 | 28 | void init(); 29 | 30 | List getServers(); 31 | } 32 | -------------------------------------------------------------------------------- /mpush-cache/src/main/java/com/mpush/cache/redis/mq/RedisMQClientFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.cache.redis.mq; 21 | 22 | import com.mpush.api.spi.Spi; 23 | import com.mpush.api.spi.common.MQClient; 24 | import com.mpush.api.spi.common.MQClientFactory; 25 | 26 | /** 27 | * Created by ohun on 2016/12/27. 28 | * 29 | * @author ohun@live.cn (夜色) 30 | */ 31 | @Spi(order = 1) 32 | public final class RedisMQClientFactory implements MQClientFactory { 33 | private ListenerDispatcher listenerDispatcher = new ListenerDispatcher(); 34 | 35 | @Override 36 | public MQClient get() { 37 | return listenerDispatcher; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /mpush-cache/src/main/resources/META-INF/services/com.mpush.api.spi.common.CacheManagerFactory: -------------------------------------------------------------------------------- 1 | com.mpush.cache.redis.manager.RedisCacheManagerFactory -------------------------------------------------------------------------------- /mpush-cache/src/main/resources/META-INF/services/com.mpush.api.spi.common.MQClientFactory: -------------------------------------------------------------------------------- 1 | com.mpush.cache.redis.mq.RedisMQClientFactory -------------------------------------------------------------------------------- /mpush-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | 9 | mpush 10 | com.github.mpusher 11 | 0.8.1 12 | ../pom.xml 13 | 14 | 15 | mpush-client 16 | jar 17 | mpush-client 18 | MPUSH消息推送系统服务端SDK 19 | https://github.com/mpusher/mpush 20 | 21 | 22 | 23 | ${project.groupId} 24 | mpush-netty 25 | 26 | 27 | ${project.groupId} 28 | mpush-common 29 | 30 | 31 | ${project.groupId} 32 | mpush-cache 33 | 34 | 35 | ${project.groupId} 36 | mpush-zk 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /mpush-client/src/main/java/com/mpush/client/connect/ConnectClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.client.connect; 21 | 22 | import com.google.common.eventbus.Subscribe; 23 | import com.mpush.api.event.ConnectionCloseEvent; 24 | import com.mpush.netty.client.NettyTCPClient; 25 | import com.mpush.tools.event.EventBus; 26 | import io.netty.channel.ChannelHandler; 27 | 28 | public class ConnectClient extends NettyTCPClient { 29 | private final ConnClientChannelHandler handler; 30 | 31 | public ConnectClient(String host, int port, ClientConfig config) { 32 | handler = new ConnClientChannelHandler(config); 33 | EventBus.register(this); 34 | } 35 | 36 | @Override 37 | public ChannelHandler getChannelHandler() { 38 | return handler; 39 | } 40 | 41 | @Subscribe 42 | void on(ConnectionCloseEvent event) { 43 | this.stop(); 44 | } 45 | 46 | @Override 47 | protected int getWorkThreadNum() { 48 | return 1; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /mpush-client/src/main/java/com/mpush/client/connect/TestStatistics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.client.connect; 21 | 22 | import java.util.concurrent.atomic.AtomicInteger; 23 | 24 | /** 25 | * Created by ohun on 2016/12/8. 26 | * 27 | * @author ohun@live.cn (夜色) 28 | */ 29 | public final class TestStatistics { 30 | public AtomicInteger clientNum = new AtomicInteger(); 31 | public AtomicInteger connectedNum = new AtomicInteger(); 32 | public AtomicInteger bindUserNum = new AtomicInteger(); 33 | public AtomicInteger receivePushNum = new AtomicInteger(); 34 | 35 | @Override 36 | public String toString() { 37 | return "TestStatistics{" + 38 | "clientNum=" + clientNum + 39 | ", connectedNum=" + connectedNum + 40 | ", bindUserNum=" + bindUserNum + 41 | ", receivePushNum=" + receivePushNum + 42 | '}'; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mpush-client/src/main/java/com/mpush/client/push/PushClientFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.client.push; 21 | 22 | import com.mpush.api.push.PushSender; 23 | import com.mpush.api.spi.Spi; 24 | import com.mpush.api.spi.client.PusherFactory; 25 | import com.mpush.client.MPushClient; 26 | 27 | /** 28 | * Created by yxx on 2016/5/18. 29 | * 30 | * @author ohun@live.cn 31 | */ 32 | @Spi 33 | public class PushClientFactory implements PusherFactory { 34 | private volatile PushClient client; 35 | 36 | @Override 37 | public PushSender get() { 38 | if (client == null) { 39 | synchronized (PushClientFactory.class) { 40 | if (client == null) { 41 | client = new PushClient(); 42 | } 43 | } 44 | } 45 | return client; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /mpush-client/src/main/java/com/mpush/client/user/UserStatusChangeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.client.user; 21 | 22 | import com.mpush.api.spi.common.MQClientFactory; 23 | import com.mpush.api.spi.common.MQMessageReceiver; 24 | import com.mpush.tools.Utils; 25 | import com.mpush.tools.config.ConfigTools; 26 | import org.slf4j.Logger; 27 | import org.slf4j.LoggerFactory; 28 | 29 | import static com.mpush.api.event.Topics.OFFLINE_CHANNEL; 30 | import static com.mpush.api.event.Topics.ONLINE_CHANNEL; 31 | 32 | /** 33 | * Created by ohun on 2016/1/4. 34 | * 35 | * @author ohun@live.cn 36 | */ 37 | public class UserStatusChangeListener implements MQMessageReceiver { 38 | 39 | private static final Logger LOGGER = LoggerFactory.getLogger(UserStatusChangeListener.class); 40 | 41 | //只需要一台机器注册online、offline 消息通道 42 | public UserStatusChangeListener() { 43 | MQClientFactory.create().subscribe(ONLINE_CHANNEL, this); 44 | MQClientFactory.create().subscribe(OFFLINE_CHANNEL, this); 45 | } 46 | 47 | @Override 48 | public void receive(String channel, Object message) { 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /mpush-client/src/main/resources/META-INF/services/com.mpush.api.spi.client.PusherFactory: -------------------------------------------------------------------------------- 1 | com.mpush.client.push.PushClientFactory 2 | -------------------------------------------------------------------------------- /mpush-client/src/main/resources/META-INF/services/com.mpush.api.spi.common.ExecutorFactory: -------------------------------------------------------------------------------- 1 | com.mpush.client.ClientExecutorFactory -------------------------------------------------------------------------------- /mpush-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | mpush 7 | com.github.mpusher 8 | 0.8.1 9 | ../pom.xml 10 | 11 | 4.0.0 12 | 13 | mpush-common 14 | jar 15 | mpush-common 16 | MPUSH消息推送系统基础模块 17 | https://github.com/mpusher/mpush 18 | 19 | 20 | 21 | ${project.groupId} 22 | mpush-tools 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /mpush-common/src/main/java/com/mpush/common/condition/AwaysPassCondition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.common.condition; 21 | 22 | import com.mpush.api.common.Condition; 23 | 24 | import java.util.Map; 25 | 26 | /** 27 | * Created by ohun on 16/10/24. 28 | * 29 | * @author ohun@live.cn (夜色) 30 | */ 31 | public final class AwaysPassCondition implements Condition { 32 | public static final Condition I = new AwaysPassCondition(); 33 | 34 | @Override 35 | public boolean test(Map env) { 36 | return true; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /mpush-common/src/main/java/com/mpush/common/condition/ScriptCondition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.common.condition; 21 | 22 | import com.mpush.api.common.Condition; 23 | 24 | import javax.script.*; 25 | import java.util.Map; 26 | 27 | /** 28 | * Created by ohun on 16/10/24. 29 | * 30 | * @author ohun@live.cn (夜色) 31 | */ 32 | public final class ScriptCondition implements Condition { 33 | private static final ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); 34 | private static final ScriptEngine jsEngine = scriptEngineManager.getEngineByName("js"); 35 | 36 | private final String script; 37 | 38 | public ScriptCondition(String script) { 39 | this.script = script; 40 | } 41 | 42 | @Override 43 | public boolean test(Map env) { 44 | try { 45 | return (Boolean) jsEngine.eval(script, new SimpleBindings(env)); 46 | } catch (Exception e) { 47 | return false; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /mpush-common/src/main/java/com/mpush/common/condition/TagsCondition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.common.condition; 21 | 22 | import com.mpush.api.common.Condition; 23 | 24 | import java.util.Map; 25 | import java.util.Set; 26 | 27 | /** 28 | * Created by ohun on 16/10/24. 29 | * 30 | * @author ohun@live.cn (夜色) 31 | */ 32 | public final class TagsCondition implements Condition { 33 | private final Set tagList; 34 | 35 | public TagsCondition(Set tags) { 36 | this.tagList = tags; 37 | } 38 | 39 | @Override 40 | public boolean test(Map env) { 41 | //2.按标签过滤,目前只有include, 后续会增加exclude 42 | String tags = (String) env.get("tags"); 43 | return tags != null && tagList.stream().anyMatch(tags::contains); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /mpush-common/src/main/java/com/mpush/common/handler/ErrorMessageHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.common.handler; 21 | 22 | import com.mpush.api.connection.Connection; 23 | import com.mpush.api.protocol.Packet; 24 | import com.mpush.common.message.ErrorMessage; 25 | 26 | /** 27 | * Created by ohun on 2015/12/30. 28 | * 29 | * @author ohun@live.cn 30 | */ 31 | public class ErrorMessageHandler extends BaseMessageHandler { 32 | @Override 33 | public ErrorMessage decode(Packet packet, Connection connection) { 34 | return new ErrorMessage(packet, connection); 35 | } 36 | 37 | @Override 38 | public void handle(ErrorMessage message) { 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /mpush-common/src/main/java/com/mpush/common/handler/OkMessageHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.common.handler; 21 | 22 | import com.mpush.api.connection.Connection; 23 | import com.mpush.api.protocol.Packet; 24 | import com.mpush.common.message.OkMessage; 25 | 26 | /** 27 | * Created by ohun on 2015/12/30. 28 | * 29 | * @author ohun@live.cn 30 | */ 31 | public class OkMessageHandler extends BaseMessageHandler { 32 | @Override 33 | public OkMessage decode(Packet packet, Connection connection) { 34 | return new OkMessage(packet, connection); 35 | } 36 | 37 | @Override 38 | public void handle(OkMessage message) { 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /mpush-common/src/main/java/com/mpush/common/memory/PacketFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.common.memory; 21 | 22 | import com.mpush.api.protocol.Command; 23 | import com.mpush.api.protocol.Packet; 24 | import com.mpush.api.protocol.UDPPacket; 25 | import com.mpush.tools.config.CC; 26 | 27 | /** 28 | * Created by ohun on 16/10/22. 29 | * 30 | * @author ohun@live.cn (夜色) 31 | */ 32 | public interface PacketFactory { 33 | PacketFactory FACTORY = CC.mp.net.udpGateway() ? UDPPacket::new : Packet::new; 34 | 35 | static Packet get(Command command) { 36 | return FACTORY.create(command); 37 | } 38 | 39 | Packet create(Command command); 40 | } -------------------------------------------------------------------------------- /mpush-common/src/main/java/com/mpush/common/message/AckMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.common.message; 21 | 22 | import com.mpush.api.connection.Connection; 23 | import com.mpush.api.protocol.Command; 24 | import com.mpush.api.protocol.Packet; 25 | import io.netty.buffer.ByteBuf; 26 | 27 | /** 28 | * Created by ohun on 16/9/5. 29 | * 30 | * @author ohun@live.cn (夜色) 31 | */ 32 | public final class AckMessage extends BaseMessage { 33 | 34 | 35 | public AckMessage(Packet packet, Connection connection) { 36 | super(packet, connection); 37 | } 38 | 39 | @Override 40 | public void decode(byte[] body) { 41 | 42 | } 43 | 44 | @Override 45 | public byte[] encode() { 46 | return null; 47 | } 48 | 49 | 50 | public static AckMessage from(BaseMessage src) { 51 | return new AckMessage(new Packet(Command.ACK, src.getSessionId()), src.connection); 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "AckMessage{" + 57 | "packet=" + packet + 58 | '}'; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /mpush-common/src/main/java/com/mpush/common/push/GatewayPushResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.common.push; 21 | 22 | import com.mpush.common.message.gateway.GatewayPushMessage; 23 | import com.mpush.tools.Jsons; 24 | 25 | /** 26 | * Created by ohun on 2016/12/29. 27 | * 28 | * @author ohun@live.cn (夜色) 29 | */ 30 | public final class GatewayPushResult { 31 | public String userId; 32 | public Integer clientType; 33 | public Object[] timePoints; 34 | 35 | public GatewayPushResult() { 36 | } 37 | 38 | public GatewayPushResult(String userId, Integer clientType, Object[] timePoints) { 39 | this.userId = userId; 40 | this.timePoints = timePoints; 41 | if (clientType > 0) this.clientType = clientType; 42 | } 43 | 44 | public static String toJson(GatewayPushMessage message, Object[] timePoints) { 45 | return Jsons.toJson(new GatewayPushResult(message.userId, message.clientType, timePoints)); 46 | } 47 | 48 | public static GatewayPushResult fromJson(String json) { 49 | if (json == null) return null; 50 | return Jsons.fromJson(json, GatewayPushResult.class); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /mpush-common/src/main/java/com/mpush/common/qps/FlowControl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.common.qps; 21 | 22 | /** 23 | * Created by ohun on 16/10/24. 24 | * 25 | * @author ohun@live.cn (夜色) 26 | */ 27 | public interface FlowControl { 28 | 29 | void reset(); 30 | 31 | int total(); 32 | 33 | /** 34 | * 判断瞬时qps是否超出设定的流量 35 | * 36 | * @return true/false 37 | * @throws OverFlowException 超出最大限制,会直接抛出异常 38 | */ 39 | boolean checkQps() throws OverFlowException; 40 | 41 | default void end(Object results) { 42 | } 43 | 44 | /** 45 | * 超出流控的任务,应该延迟执行的时间(ns) 46 | * 47 | * @return 单位纳秒 48 | */ 49 | long getDelay(); 50 | 51 | /** 52 | * 任务从开始到现在的平均qps 53 | * 54 | * @return 平均qps 55 | */ 56 | int qps(); 57 | 58 | String report(); 59 | 60 | } 61 | -------------------------------------------------------------------------------- /mpush-common/src/main/java/com/mpush/common/qps/OverFlowException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.common.qps; 21 | 22 | /** 23 | * Created by ohun on 16/10/24. 24 | * 25 | * @author ohun@live.cn (夜色) 26 | */ 27 | public final class OverFlowException extends RuntimeException { 28 | 29 | private boolean overMaxLimit = false; 30 | 31 | public OverFlowException() { 32 | super(null, null, false, false); 33 | } 34 | 35 | public OverFlowException(boolean overMaxLimit) { 36 | super(null, null, false, false); 37 | this.overMaxLimit = overMaxLimit; 38 | } 39 | 40 | public OverFlowException(String message) { 41 | super(message, null, false, false); 42 | } 43 | 44 | public boolean isOverMaxLimit() { 45 | return overMaxLimit; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /mpush-common/src/main/java/com/mpush/common/router/DefaultClientClassifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.common.router; 21 | 22 | import com.mpush.api.router.ClientClassifier; 23 | import com.mpush.api.spi.Spi; 24 | import com.mpush.api.spi.router.ClientClassifierFactory; 25 | 26 | /** 27 | * Created by ohun on 16/10/26. 28 | * 29 | * @author ohun@live.cn (夜色) 30 | */ 31 | @Spi(order = 1) 32 | public final class DefaultClientClassifier implements ClientClassifier, ClientClassifierFactory { 33 | 34 | @Override 35 | public int getClientType(String osName) { 36 | return ClientType.find(osName).type; 37 | } 38 | 39 | @Override 40 | public ClientClassifier get() { 41 | return this; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mpush-common/src/main/java/com/mpush/common/router/KickRemoteMsg.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.common.router; 21 | 22 | import com.mpush.common.ServerNodes; 23 | import com.mpush.tools.config.ConfigTools; 24 | 25 | 26 | /** 27 | * Created by ohun on 16/10/23. 28 | * 29 | * @author ohun@live.cn (夜色) 30 | */ 31 | public interface KickRemoteMsg { 32 | String getUserId(); 33 | 34 | String getDeviceId(); 35 | 36 | String getConnId(); 37 | 38 | int getClientType(); 39 | 40 | String getTargetServer(); 41 | 42 | int getTargetPort(); 43 | 44 | default boolean isTargetMachine(String host, int port) { 45 | return this.getTargetPort() == port 46 | && this.getTargetServer().equals(host); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /mpush-common/src/main/java/com/mpush/common/router/RemoteRouter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.common.router; 21 | 22 | import com.mpush.api.router.ClientLocation; 23 | import com.mpush.api.router.Router; 24 | 25 | /** 26 | * Created by ohun on 2015/12/23. 27 | * 28 | * @author ohun@live.cn 29 | */ 30 | public final class RemoteRouter implements Router { 31 | private final ClientLocation clientLocation; 32 | 33 | public RemoteRouter(ClientLocation clientLocation) { 34 | this.clientLocation = clientLocation; 35 | } 36 | 37 | public boolean isOnline(){ 38 | return clientLocation.isOnline(); 39 | } 40 | 41 | public boolean isOffline(){ 42 | return clientLocation.isOffline(); 43 | } 44 | 45 | @Override 46 | public ClientLocation getRouteValue() { 47 | return clientLocation; 48 | } 49 | 50 | @Override 51 | public RouterType getRouteType() { 52 | return RouterType.REMOTE; 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "RemoteRouter{" + clientLocation + '}'; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /mpush-common/src/main/java/com/mpush/common/security/DefaultRsaCipherFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.common.security; 21 | 22 | import com.mpush.api.connection.Cipher; 23 | import com.mpush.api.spi.Spi; 24 | import com.mpush.api.spi.core.RsaCipherFactory; 25 | 26 | /** 27 | * Created by yxx on 2016/5/19. 28 | * 29 | * @author ohun@live.cn 30 | */ 31 | @Spi 32 | public class DefaultRsaCipherFactory implements RsaCipherFactory { 33 | private static final RsaCipher RSA_CIPHER = RsaCipher.create(); 34 | 35 | @Override 36 | public Cipher get() { 37 | return RSA_CIPHER; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /mpush-common/src/main/resources/META-INF/services/com.mpush.api.spi.core.RsaCipherFactory: -------------------------------------------------------------------------------- 1 | com.mpush.common.security.DefaultRsaCipherFactory 2 | -------------------------------------------------------------------------------- /mpush-common/src/main/resources/META-INF/services/com.mpush.api.spi.net.DnsMappingManager: -------------------------------------------------------------------------------- 1 | com.mpush.common.net.HttpProxyDnsMappingManager -------------------------------------------------------------------------------- /mpush-common/src/main/resources/META-INF/services/com.mpush.api.spi.router.ClientClassifierFactory: -------------------------------------------------------------------------------- 1 | com.mpush.common.router.DefaultClientClassifier -------------------------------------------------------------------------------- /mpush-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | 9 | mpush 10 | com.github.mpusher 11 | 0.8.1 12 | ../pom.xml 13 | 14 | 15 | mpush-core 16 | jar 17 | mpush-core 18 | MPUSH消息推送系统核心模块 19 | https://github.com/mpusher/mpush 20 | 21 | 22 | 23 | ${project.groupId} 24 | mpush-netty 25 | 26 | 27 | ${project.groupId} 28 | mpush-common 29 | 30 | 31 | ${project.groupId} 32 | mpush-monitor 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /mpush-core/src/main/java/com/mpush/core/ack/AckCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.core.ack; 21 | 22 | /** 23 | * Created by ohun on 16/9/6. 24 | * 25 | * @author ohun@live.cn (夜色) 26 | */ 27 | public interface AckCallback { 28 | void onSuccess(AckTask context); 29 | 30 | void onTimeout(AckTask context); 31 | } 32 | -------------------------------------------------------------------------------- /mpush-core/src/main/java/com/mpush/core/handler/GatewayPushHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.core.handler; 21 | 22 | import com.mpush.api.connection.Connection; 23 | import com.mpush.api.protocol.Packet; 24 | import com.mpush.common.handler.BaseMessageHandler; 25 | import com.mpush.common.message.gateway.GatewayPushMessage; 26 | import com.mpush.core.push.PushCenter; 27 | 28 | /** 29 | * Created by ohun on 2015/12/30. 30 | * 31 | * @author ohun@live.cn 32 | */ 33 | public final class GatewayPushHandler extends BaseMessageHandler { 34 | 35 | private final PushCenter pushCenter; 36 | 37 | public GatewayPushHandler(PushCenter pushCenter) { 38 | this.pushCenter = pushCenter; 39 | } 40 | 41 | @Override 42 | public GatewayPushMessage decode(Packet packet, Connection connection) { 43 | return new GatewayPushMessage(packet, connection); 44 | } 45 | 46 | @Override 47 | public void handle(GatewayPushMessage message) { 48 | pushCenter.push(message); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /mpush-core/src/main/java/com/mpush/core/handler/HeartBeatHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.core.handler; 21 | 22 | import com.mpush.api.message.MessageHandler; 23 | import com.mpush.api.connection.Connection; 24 | import com.mpush.api.protocol.Packet; 25 | import com.mpush.tools.log.Logs; 26 | 27 | /** 28 | * Created by ohun on 2015/12/22. 29 | * 30 | * @author ohun@live.cn 31 | */ 32 | public final class HeartBeatHandler implements MessageHandler { 33 | 34 | @Override 35 | public void handle(Packet packet, Connection connection) { 36 | connection.send(packet);//ping -> pong 37 | Logs.HB.info("ping -> pong, {}", connection); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /mpush-core/src/main/java/com/mpush/core/mq/MQClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.core.mq; 21 | 22 | import java.util.Collection; 23 | import java.util.Collections; 24 | 25 | /** 26 | * Created by ohun on 2016/12/26. 27 | * 28 | * @author ohun@live.cn (夜色) 29 | */ 30 | public final class MQClient { 31 | 32 | public void init() { 33 | 34 | } 35 | 36 | public void subscribe(String topic, MQMessageReceiver listener) { 37 | 38 | } 39 | 40 | public void publish(String topic, MQPushMessage message) { 41 | 42 | } 43 | 44 | public Collection take(String topic) { 45 | return Collections.emptyList(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /mpush-core/src/main/java/com/mpush/core/push/PushAckCallback.java: -------------------------------------------------------------------------------- 1 | package com.mpush.core.push; 2 | 3 | import com.mpush.api.spi.push.IPushMessage; 4 | import com.mpush.core.ack.AckCallback; 5 | import com.mpush.core.ack.AckTask; 6 | import com.mpush.tools.common.TimeLine; 7 | import com.mpush.tools.log.Logs; 8 | 9 | public final class PushAckCallback implements AckCallback { 10 | private final IPushMessage message; 11 | private final TimeLine timeLine; 12 | private final PushCenter pushCenter; 13 | 14 | public PushAckCallback(IPushMessage message, TimeLine timeLine, PushCenter pushCenter) { 15 | this.message = message; 16 | this.timeLine = timeLine; 17 | this.pushCenter = pushCenter; 18 | } 19 | 20 | @Override 21 | public void onSuccess(AckTask task) { 22 | pushCenter.getPushListener().onAckSuccess(message, timeLine.successEnd().getTimePoints()); 23 | Logs.PUSH.info("[SingleUserPush] client ack success, timeLine={}, task={}", timeLine, task); 24 | } 25 | 26 | @Override 27 | public void onTimeout(AckTask task) { 28 | pushCenter.getPushListener().onTimeout(message, timeLine.timeoutEnd().getTimePoints()); 29 | Logs.PUSH.warn("[SingleUserPush] client ack timeout, timeLine={}, task={}", timeLine, task); 30 | } 31 | } -------------------------------------------------------------------------------- /mpush-core/src/main/java/com/mpush/core/push/PushTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.core.push; 21 | 22 | import java.util.concurrent.ScheduledExecutorService; 23 | 24 | /** 25 | * Created by ohun on 16/10/24. 26 | * 27 | * @author ohun@live.cn (夜色) 28 | */ 29 | public interface PushTask extends Runnable { 30 | ScheduledExecutorService getExecutor(); 31 | } 32 | -------------------------------------------------------------------------------- /mpush-core/src/main/java/com/mpush/core/server/DefaultServerEventListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.core.server; 21 | 22 | import com.mpush.api.common.ServerEventListener; 23 | import com.mpush.api.spi.Spi; 24 | import com.mpush.api.spi.core.ServerEventListenerFactory; 25 | 26 | /** 27 | * Created by ohun on 16/10/19. 28 | * 29 | * @author ohun@live.cn (夜色) 30 | */ 31 | @Spi(order = 1) 32 | public final class DefaultServerEventListener implements ServerEventListener, ServerEventListenerFactory { 33 | 34 | @Override 35 | public ServerEventListener get() { 36 | return this; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /mpush-core/src/main/resources/META-INF/services/com.mpush.api.spi.common.ExecutorFactory: -------------------------------------------------------------------------------- 1 | com.mpush.core.ServerExecutorFactory -------------------------------------------------------------------------------- /mpush-core/src/main/resources/META-INF/services/com.mpush.api.spi.core.ServerEventListenerFactory: -------------------------------------------------------------------------------- 1 | com.mpush.core.server.DefaultServerEventListener -------------------------------------------------------------------------------- /mpush-core/src/main/resources/META-INF/services/com.mpush.api.spi.handler.BindValidatorFactory: -------------------------------------------------------------------------------- 1 | com.mpush.core.handler.BindUserHandler$DefaultBindValidatorFactory -------------------------------------------------------------------------------- /mpush-core/src/main/resources/META-INF/services/com.mpush.api.spi.handler.PushHandlerFactory: -------------------------------------------------------------------------------- 1 | com.mpush.core.handler.ClientPushHandler -------------------------------------------------------------------------------- /mpush-core/src/main/resources/META-INF/services/com.mpush.api.spi.push.PushListenerFactory: -------------------------------------------------------------------------------- 1 | com.mpush.core.push.GatewayPushListener -------------------------------------------------------------------------------- /mpush-core/src/test/java/com/mpush/core/security/CipherBoxTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.core.security; 21 | 22 | import com.mpush.common.security.CipherBox; 23 | import org.junit.Test; 24 | 25 | import java.util.Arrays; 26 | 27 | /** 28 | * Created by ohun on 2015/12/25. 29 | */ 30 | public class CipherBoxTest { 31 | 32 | @Test 33 | public void testGetPrivateKey() throws Exception { 34 | } 35 | 36 | @Test 37 | public void testGetPublicKey() throws Exception { 38 | for (int i = 0; i < 1000; i++) { 39 | byte[] clientKey = CipherBox.I.randomAESKey(); 40 | byte[] serverKey = CipherBox.I.randomAESKey(); 41 | byte[] sessionKey = CipherBox.I.mixKey(clientKey, serverKey); 42 | //System.out.println("clientKey:" + Arrays.toString(clientKey)); 43 | //System.out.println("serverKey:" + Arrays.toString(serverKey)); 44 | System.out.println("sessionKey:" + Arrays.toString(sessionKey)); 45 | 46 | } 47 | 48 | } 49 | } -------------------------------------------------------------------------------- /mpush-monitor/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | mpush 5 | com.github.mpusher 6 | 0.8.1 7 | ../pom.xml 8 | 9 | 4.0.0 10 | 11 | mpush-monitor 12 | jar 13 | mpush-monitor 14 | MPUSH消息推送系统监控模块 15 | https://github.com/mpusher/mpush 16 | 17 | 18 | 19 | ${project.groupId} 20 | mpush-tools 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /mpush-monitor/src/main/java/com/mpush/monitor/jmx/MBeanInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.monitor.jmx; 21 | 22 | /** 23 | * Created by ohun on 16/10/23. 24 | * 25 | * @author ohun@live.cn (夜色) 26 | */ 27 | public interface MBeanInfo { 28 | String getName(); 29 | } 30 | -------------------------------------------------------------------------------- /mpush-monitor/src/main/java/com/mpush/monitor/jmx/MException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.monitor.jmx; 21 | 22 | /** 23 | * Created by ohun on 16/10/23. 24 | * 25 | * @author ohun@live.cn (夜色) 26 | */ 27 | public final class MException extends RuntimeException { 28 | public MException(String message) { 29 | super(message); 30 | } 31 | 32 | public MException(String message, Throwable cause) { 33 | super(message, cause); 34 | } 35 | 36 | public MException(Throwable cause) { 37 | super(cause); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /mpush-monitor/src/main/java/com/mpush/monitor/jmx/mxbean/PushCenterBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.monitor.jmx.mxbean; 21 | 22 | import com.mpush.monitor.jmx.MBeanInfo; 23 | 24 | import java.util.concurrent.atomic.AtomicInteger; 25 | import java.util.concurrent.atomic.AtomicLong; 26 | 27 | /** 28 | * Created by ohun on 2016/12/23. 29 | * 30 | * @author ohun@live.cn (夜色) 31 | */ 32 | public final class PushCenterBean implements PushCenterMXBean, MBeanInfo { 33 | private final AtomicLong taskNum; 34 | 35 | public PushCenterBean(AtomicLong taskNum) { 36 | this.taskNum = taskNum; 37 | } 38 | 39 | @Override 40 | public String getName() { 41 | return "PushCenter"; 42 | } 43 | 44 | @Override 45 | public long getTaskNum() { 46 | return taskNum.get(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /mpush-monitor/src/main/java/com/mpush/monitor/jmx/mxbean/PushCenterMXBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.monitor.jmx.mxbean; 21 | 22 | /** 23 | * Created by ohun on 2016/12/23. 24 | * 25 | * @author ohun@live.cn (夜色) 26 | */ 27 | public interface PushCenterMXBean { 28 | long getTaskNum(); 29 | } 30 | -------------------------------------------------------------------------------- /mpush-monitor/src/main/java/com/mpush/monitor/quota/GCMQuota.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.monitor.quota; 21 | 22 | public interface GCMQuota extends MonitorQuota { 23 | 24 | long yongGcCollectionCount(); 25 | 26 | long yongGcCollectionTime(); 27 | 28 | long fullGcCollectionCount(); 29 | 30 | long fullGcCollectionTime(); 31 | 32 | long spanYongGcCollectionCount(); 33 | 34 | long spanYongGcCollectionTime(); 35 | 36 | long spanFullGcCollectionCount(); 37 | 38 | long spanFullGcCollectionTime(); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /mpush-monitor/src/main/java/com/mpush/monitor/quota/InfoQuota.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.monitor.quota; 21 | 22 | public interface InfoQuota extends MonitorQuota { 23 | 24 | String pid(); 25 | 26 | double load(); 27 | } 28 | -------------------------------------------------------------------------------- /mpush-monitor/src/main/java/com/mpush/monitor/quota/MonitorQuota.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.monitor.quota; 21 | 22 | public interface MonitorQuota { 23 | 24 | Object monitor(Object... args); 25 | } 26 | -------------------------------------------------------------------------------- /mpush-monitor/src/main/java/com/mpush/monitor/quota/ThreadPoolQuota.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.monitor.quota; 21 | 22 | public interface ThreadPoolQuota extends MonitorQuota { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /mpush-monitor/src/main/java/com/mpush/monitor/quota/ThreadQuota.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.monitor.quota; 21 | 22 | 23 | public interface ThreadQuota extends MonitorQuota { 24 | 25 | int daemonThreadCount(); 26 | 27 | int threadCount(); 28 | 29 | long totalStartedThreadCount(); 30 | 31 | int deadLockedThreadCount(); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /mpush-monitor/src/test/java/com/mpush/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.mpush; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase { 12 | /** 13 | * Create the test case 14 | * 15 | * @param testName name of the test case 16 | */ 17 | public AppTest(String testName) { 18 | super(testName); 19 | } 20 | 21 | /** 22 | * @return the suite of tests being tested 23 | */ 24 | public static Test suite() { 25 | return new TestSuite(AppTest.class); 26 | } 27 | 28 | /** 29 | * Rigourous Test :-) 30 | */ 31 | public void testApp() { 32 | assertTrue(true); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /mpush-netty/src/main/java/com/mpush/netty/codec/DecodeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.netty.codec; 21 | 22 | /** 23 | * Created by ohun on 2015/12/23. 24 | * 25 | * @author ohun@live.cn 26 | */ 27 | public class DecodeException extends RuntimeException { 28 | public DecodeException(String message) { 29 | super(message); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /mpush-netty/src/main/java/com/mpush/netty/codec/PacketEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.netty.codec; 21 | 22 | import com.mpush.api.protocol.Command; 23 | import com.mpush.api.protocol.Packet; 24 | import io.netty.buffer.ByteBuf; 25 | import io.netty.channel.Channel; 26 | import io.netty.channel.ChannelHandler; 27 | import io.netty.channel.ChannelHandlerContext; 28 | import io.netty.handler.codec.MessageToByteEncoder; 29 | 30 | import static com.mpush.api.protocol.Packet.encodePacket; 31 | 32 | /** 33 | * Created by ohun on 2015/12/19. 34 | * length(4)+cmd(1)+cc(2)+flags(1)+sessionId(4)+lrc(1)+body(n) 35 | * 36 | * @author ohun@live.cn 37 | */ 38 | @ChannelHandler.Sharable 39 | public final class PacketEncoder extends MessageToByteEncoder { 40 | public static final PacketEncoder INSTANCE = new PacketEncoder(); 41 | 42 | @Override 43 | protected void encode(ChannelHandlerContext ctx, Packet packet, ByteBuf out) throws Exception { 44 | encodePacket(packet, out); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /mpush-netty/src/main/java/com/mpush/netty/http/HttpCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.netty.http; 21 | 22 | 23 | import io.netty.handler.codec.http.HttpResponse; 24 | 25 | /** 26 | * Created by ohun on 2016/2/15. 27 | * 28 | * @author ohun@live.cn 29 | */ 30 | public interface HttpCallback { 31 | 32 | void onResponse(HttpResponse response); 33 | 34 | void onFailure(int statusCode, String reasonPhrase); 35 | 36 | void onException(Throwable throwable); 37 | 38 | void onTimeout(); 39 | 40 | boolean onRedirect(HttpResponse response); 41 | } 42 | -------------------------------------------------------------------------------- /mpush-netty/src/main/java/com/mpush/netty/http/HttpClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.netty.http; 21 | 22 | import com.mpush.api.service.Service; 23 | 24 | /** 25 | * Created by ohun on 2016/2/15. 26 | * 27 | * @author ohun@live.cn 28 | */ 29 | public interface HttpClient extends Service { 30 | void request(RequestContext context) throws Exception; 31 | } 32 | -------------------------------------------------------------------------------- /mpush-test/src/main/java/com/mpush/test/gson/DnsMappingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.test.gson; 21 | 22 | import com.mpush.api.spi.net.DnsMapping; 23 | import org.junit.Test; 24 | 25 | import java.net.MalformedURLException; 26 | import java.net.URL; 27 | 28 | public class DnsMappingTest { 29 | 30 | @Test 31 | public void test() throws MalformedURLException { 32 | String url = "http://baidu.com:9001/xxx/xxx?s=nc=1"; 33 | DnsMapping mapping = new DnsMapping("127.0.0.1", 8080); 34 | String s = mapping.translate(new URL(url)); 35 | System.out.println(url); 36 | System.out.println(s); 37 | 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /mpush-test/src/main/java/com/mpush/test/redis/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.test.redis; 21 | 22 | import java.io.Serializable; 23 | import java.util.Date; 24 | 25 | public class User implements Serializable { 26 | 27 | private static final long serialVersionUID = -6269129553435313118L; 28 | 29 | private String name; 30 | private int age; 31 | private Date date; 32 | 33 | public User(String name, int age, Date date) { 34 | this.name = name; 35 | this.age = age; 36 | this.date = date; 37 | } 38 | 39 | public String getName() { 40 | return name; 41 | } 42 | 43 | public void setName(String name) { 44 | this.name = name; 45 | } 46 | 47 | public int getAge() { 48 | return age; 49 | } 50 | 51 | public void setAge(int age) { 52 | this.age = age; 53 | } 54 | 55 | public Date getDate() { 56 | return date; 57 | } 58 | 59 | public void setDate(Date date) { 60 | this.date = date; 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /mpush-test/src/main/java/com/mpush/test/sever/ServerTestMain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.test.sever; 21 | 22 | import com.mpush.bootstrap.Main; 23 | import org.junit.Test; 24 | 25 | import java.util.concurrent.locks.LockSupport; 26 | 27 | /** 28 | * Created by yxx on 2016/5/16. 29 | * 30 | * @author ohun@live.cn 31 | */ 32 | public class ServerTestMain { 33 | 34 | public static void main(String[] args) { 35 | start(); 36 | } 37 | 38 | @Test 39 | public void testServer() { 40 | start(); 41 | LockSupport.park(); 42 | } 43 | 44 | public static void start() { 45 | System.setProperty("io.netty.leakDetection.level", "PARANOID"); 46 | System.setProperty("io.netty.noKeySetOptimization", "false"); 47 | Main.main(null); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /mpush-test/src/main/java/com/mpush/test/spi/SimpleCacheMangerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.test.spi; 21 | 22 | import com.mpush.api.spi.Spi; 23 | import com.mpush.api.spi.common.CacheManager; 24 | import com.mpush.api.spi.common.CacheManagerFactory; 25 | 26 | /** 27 | * Created by ohun on 2016/12/28. 28 | * 29 | * @author ohun@live.cn (夜色) 30 | */ 31 | @Spi(order = 2) 32 | public final class SimpleCacheMangerFactory implements CacheManagerFactory { 33 | @Override 34 | public CacheManager get() { 35 | return FileCacheManger.I; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /mpush-test/src/main/java/com/mpush/test/spi/SimpleDiscoveryFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.test.spi; 21 | 22 | import com.mpush.api.spi.Spi; 23 | import com.mpush.api.spi.common.ServiceDiscoveryFactory; 24 | import com.mpush.api.srd.ServiceDiscovery; 25 | 26 | /** 27 | * Created by ohun on 2016/12/28. 28 | * 29 | * @author ohun@live.cn (夜色) 30 | */ 31 | @Spi(order = 2) 32 | public final class SimpleDiscoveryFactory implements ServiceDiscoveryFactory { 33 | @Override 34 | public ServiceDiscovery get() { 35 | return FileSrd.I; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /mpush-test/src/main/java/com/mpush/test/spi/SimpleMQClientFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.test.spi; 21 | 22 | import com.mpush.api.spi.Spi; 23 | import com.mpush.api.spi.common.MQClient; 24 | import com.mpush.api.spi.common.MQMessageReceiver; 25 | 26 | /** 27 | * Created by ohun on 2016/12/28. 28 | * 29 | * @author ohun@live.cn (夜色) 30 | */ 31 | @Spi(order = 2) 32 | public final class SimpleMQClientFactory implements com.mpush.api.spi.common.MQClientFactory { 33 | private MQClient mqClient = new MQClient() { 34 | @Override 35 | public void subscribe(String topic, MQMessageReceiver receiver) { 36 | System.err.println("subscribe " + topic); 37 | } 38 | 39 | @Override 40 | public void publish(String topic, Object message) { 41 | System.err.println("publish " + topic + " " + message); 42 | } 43 | }; 44 | 45 | @Override 46 | public MQClient get() { 47 | return mqClient; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /mpush-test/src/main/java/com/mpush/test/spi/SimpleRegistryFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.test.spi; 21 | 22 | import com.mpush.api.spi.Spi; 23 | import com.mpush.api.spi.common.ServiceRegistryFactory; 24 | import com.mpush.api.srd.ServiceRegistry; 25 | 26 | /** 27 | * Created by ohun on 2016/12/28. 28 | * 29 | * @author ohun@live.cn (夜色) 30 | */ 31 | @Spi(order = 2) 32 | public final class SimpleRegistryFactory implements ServiceRegistryFactory { 33 | @Override 34 | public ServiceRegistry get() { 35 | return FileSrd.I; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /mpush-test/src/main/java/com/mpush/test/util/IPTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.test.util; 21 | 22 | import com.mpush.tools.Utils; 23 | import org.junit.Test; 24 | 25 | /** 26 | * Created by ohun on 16/9/8. 27 | * 28 | * @author ohun@live.cn (夜色) 29 | */ 30 | public class IPTest { 31 | @Test 32 | public void getLocalIP() throws Exception { 33 | System.out.println(Utils.lookupLocalIp()); 34 | System.out.println(Utils.lookupExtranetIp()); 35 | 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /mpush-test/src/main/java/com/mpush/test/util/TelnetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.test.util; 21 | 22 | import com.mpush.tools.Utils; 23 | import org.junit.Test; 24 | 25 | import java.net.URI; 26 | import java.net.URISyntaxException; 27 | 28 | public class TelnetTest { 29 | 30 | @Test 31 | public void test() { 32 | boolean ret = Utils.checkHealth("120.27.196.68", 82); 33 | System.out.println(ret); 34 | } 35 | 36 | @Test 37 | public void test2() { 38 | boolean ret = Utils.checkHealth("120.27.196.68", 80); 39 | System.out.println(ret); 40 | } 41 | 42 | @Test 43 | public void uriTest() throws URISyntaxException { 44 | String url = "http://127.0.0.1"; 45 | URI uri = new URI(url); 46 | System.out.println(uri.getPort()); 47 | } 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /mpush-test/src/main/resources/META-INF/services/com.mpush.api.spi.common.CacheManagerFactory: -------------------------------------------------------------------------------- 1 | com.mpush.test.spi.SimpleCacheMangerFactory -------------------------------------------------------------------------------- /mpush-test/src/main/resources/META-INF/services/com.mpush.api.spi.common.MQClientFactory: -------------------------------------------------------------------------------- 1 | com.mpush.test.spi.SimpleMQClientFactory -------------------------------------------------------------------------------- /mpush-test/src/main/resources/META-INF/services/com.mpush.api.spi.common.ServiceDiscoveryFactory: -------------------------------------------------------------------------------- 1 | com.mpush.test.spi.SimpleDiscoveryFactory -------------------------------------------------------------------------------- /mpush-test/src/main/resources/META-INF/services/com.mpush.api.spi.common.ServiceRegistryFactory: -------------------------------------------------------------------------------- 1 | com.mpush.test.spi.SimpleRegistryFactory -------------------------------------------------------------------------------- /mpush-test/src/main/resources/application.conf: -------------------------------------------------------------------------------- 1 | mp.home=${user.dir}/target 2 | mp.log-level=debug 3 | mp.log-conf-path=logback.xml 4 | mp.core.min-heartbeat=30s 5 | mp.core.max-heartbeat=30s 6 | mp.core.compress-threshold=10k 7 | mp.zk.server-address="127.0.0.1:2181" //多台机器使用","分隔如:"10.0.10.44:2181,10.0.10.49:2181" 8 | mp.redis {// redis 集群配置 9 | nodes:["127.0.0.1:6379"]//格式是ip:port,密码可以没有ip:port 10 | } 11 | mp.http.proxy-enabled=true 12 | 13 | mp.net { 14 | gateway-server-net=tcp //网关服务使用的网络类型tcp/udp 15 | connect-server-port=3000 //长链接服务对外端口, 公网端口 16 | gateway-server-port=3001 //网关服务端口, 内部端口 17 | gateway-client-port=4000 //UDP客户端端口, 内部端口 18 | admin-server-port=3002 //控制台服务端口, 内部端口 19 | ws-server-port=8008 //websocket对外端口, 0表示禁用websocket 20 | } 21 | -------------------------------------------------------------------------------- /mpush-tools/src/main/java/com/mpush/tools/common/DefaultJsonFactory.java: -------------------------------------------------------------------------------- 1 | package com.mpush.tools.common; 2 | 3 | import com.mpush.api.spi.Spi; 4 | import com.mpush.api.spi.common.Json; 5 | import com.mpush.api.spi.common.JsonFactory; 6 | import com.mpush.tools.Jsons; 7 | 8 | @Spi 9 | public final class DefaultJsonFactory implements JsonFactory, Json { 10 | @Override 11 | public T fromJson(String json, Class clazz) { 12 | return Jsons.fromJson(json, clazz); 13 | } 14 | 15 | @Override 16 | public String toJson(Object json) { 17 | return Jsons.toJson(json); 18 | } 19 | 20 | @Override 21 | public Json get() { 22 | return this; 23 | } 24 | } -------------------------------------------------------------------------------- /mpush-tools/src/main/java/com/mpush/tools/common/Holder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.tools.common; 21 | 22 | /** 23 | * Created by ohun on 16/10/22. 24 | * 25 | * @author ohun@live.cn (夜色) 26 | */ 27 | public final class Holder { 28 | private T t; 29 | 30 | public Holder() { 31 | } 32 | 33 | public Holder(T t) { 34 | this.t = t; 35 | } 36 | 37 | public static Holder of(T t) { 38 | return new Holder<>(t); 39 | } 40 | 41 | public T get() { 42 | return t; 43 | } 44 | 45 | public void set(T t) { 46 | this.t = t; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /mpush-tools/src/main/java/com/mpush/tools/common/Pair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.tools.common; 21 | 22 | /** 23 | * Created by ohun on 2015/12/24. 24 | * 25 | * @author ohun@live.cn 26 | */ 27 | public final class Pair { 28 | public final K key; 29 | public final V value; 30 | 31 | public Pair(K key, V value) { 32 | this.key = key; 33 | this.value = value; 34 | } 35 | 36 | public K first() { 37 | return key; 38 | } 39 | 40 | public V second() { 41 | return value; 42 | } 43 | 44 | public static Pair of(K k, V v) { 45 | return new Pair<>(k, v); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /mpush-tools/src/main/java/com/mpush/tools/common/Reflects.java: -------------------------------------------------------------------------------- 1 | package com.mpush.tools.common; 2 | 3 | import java.lang.reflect.Field; 4 | import java.lang.reflect.Method; 5 | import java.lang.reflect.ParameterizedType; 6 | import java.lang.reflect.Type; 7 | import java.util.ArrayList; 8 | import java.util.Collections; 9 | import java.util.List; 10 | 11 | public class Reflects { 12 | 13 | public static Class getSuperClassGenericType(final Class clazz, int index) { 14 | return getGenericType(clazz.getGenericSuperclass(), index); 15 | } 16 | 17 | public static Class getFieldGenericType(final Field field, final int index) { 18 | return getGenericType(field.getGenericType(), index); 19 | } 20 | 21 | public static List getMethodGenericTypes(final Method method, final int paramIndex) { 22 | return getGenericTypes(method.getGenericParameterTypes()[paramIndex]); 23 | } 24 | 25 | 26 | public static Class getGenericType(Type genType, int index) { 27 | List params = getGenericTypes(genType); 28 | if (index >= params.size() || index < 0) return null; 29 | return params.get(index); 30 | } 31 | 32 | public static List getGenericTypes(Type genType) { 33 | if (!(genType instanceof ParameterizedType)) return Collections.emptyList(); 34 | Type[] types = ((ParameterizedType) genType).getActualTypeArguments(); 35 | List list = new ArrayList(types.length); 36 | for (Type type : types) { 37 | if (type instanceof Class) list.add((Class) type); 38 | else if (type instanceof ParameterizedType) { 39 | Type type1 = ((ParameterizedType) type).getRawType(); 40 | if (type1 instanceof Class) list.add((Class) type1); 41 | } 42 | } 43 | return list; 44 | } 45 | } -------------------------------------------------------------------------------- /mpush-tools/src/main/java/com/mpush/tools/common/Strings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.tools.common; 21 | 22 | /** 23 | * Created by ohun on 2015/12/23. 24 | * 25 | * @author ohun@live.cn 26 | */ 27 | public final class Strings { 28 | public static final String EMPTY = ""; 29 | 30 | public static boolean isBlank(CharSequence text) { 31 | if (text == null || text.length() == 0) return true; 32 | for (int i = 0, L = text.length(); i < L; i++) { 33 | if (!Character.isWhitespace(text.charAt(i))) return false; 34 | } 35 | return true; 36 | } 37 | 38 | public static String trimAll(CharSequence s) { 39 | if (s == null || s.length() == 0) return Strings.EMPTY; 40 | StringBuilder sb = new StringBuilder(s.length()); 41 | for (int i = 0, L = s.length(); i < L; i++) { 42 | char c = s.charAt(i); 43 | if (c != ' ') sb.append(c); 44 | } 45 | return sb.toString(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /mpush-tools/src/main/java/com/mpush/tools/config/data/RedisGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.tools.config.data; 21 | 22 | import java.util.Collections; 23 | import java.util.List; 24 | 25 | 26 | /** 27 | * redis 组 28 | */ 29 | public class RedisGroup { 30 | public List redisNodeList = Collections.emptyList(); 31 | 32 | public RedisGroup() { 33 | } 34 | 35 | public RedisGroup(List redisNodeList) { 36 | this.redisNodeList = redisNodeList; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "RedisGroup{" + 42 | "redisNodeList=" + redisNodeList + 43 | '}'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /mpush-tools/src/main/java/com/mpush/tools/crypto/Base64Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.tools.crypto; 21 | 22 | 23 | import com.mpush.api.Constants; 24 | 25 | import java.util.Base64; 26 | 27 | public class Base64Utils { 28 | 29 | /** 30 | *

31 | * BASE64字符串解码为二进制数据 32 | *

33 | * 34 | * @param base64 base64 35 | * @return 源二进制数据 36 | */ 37 | public static byte[] decode(String base64) { 38 | return Base64.getDecoder().decode(base64.getBytes(Constants.UTF_8)); 39 | } 40 | 41 | /** 42 | *

43 | * 二进制数据编码为BASE64字符串 44 | *

45 | * 46 | * @param bytes base64 47 | * @return BASE64后的二进制数据 48 | */ 49 | public static String encode(byte[] bytes) { 50 | return new String(Base64.getEncoder().encode(bytes), Constants.UTF_8); 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /mpush-tools/src/main/java/com/mpush/tools/crypto/CryptoException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.tools.crypto; 21 | 22 | /** 23 | * Created by ohun on 2015/12/23. 24 | * 25 | * @author ohun@live.cn 26 | */ 27 | public class CryptoException extends RuntimeException { 28 | 29 | private static final long serialVersionUID = 368277451733324220L; 30 | 31 | public CryptoException(String message) { 32 | super(message); 33 | } 34 | 35 | public CryptoException(String message, Throwable cause) { 36 | super(message, cause); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /mpush-tools/src/main/java/com/mpush/tools/event/EventBus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.tools.event; 21 | 22 | import com.google.common.eventbus.AsyncEventBus; 23 | import com.mpush.api.event.Event; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | 27 | import java.util.concurrent.Executor; 28 | 29 | /** 30 | * Created by ohun on 2015/12/29. 31 | * 32 | * @author ohun@live.cn 33 | */ 34 | public class EventBus { 35 | private static final Logger LOGGER = LoggerFactory.getLogger(EventBus.class); 36 | private static com.google.common.eventbus.EventBus eventBus; 37 | 38 | public static void create(Executor executor) { 39 | eventBus = new AsyncEventBus(executor, (exception, context) 40 | -> LOGGER.error("event bus subscriber ex", exception)); 41 | } 42 | 43 | public static void post(Event event) { 44 | eventBus.post(event); 45 | } 46 | 47 | public static void register(Object bean) { 48 | eventBus.register(bean); 49 | } 50 | 51 | public static void unregister(Object bean) { 52 | eventBus.unregister(bean); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /mpush-tools/src/main/java/com/mpush/tools/event/EventConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.tools.event; 21 | 22 | public abstract class EventConsumer { 23 | 24 | public EventConsumer() { 25 | EventBus.register(this); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /mpush-tools/src/main/java/com/mpush/tools/thread/pool/DefaultExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | package com.mpush.tools.thread.pool; 20 | 21 | import java.util.concurrent.*; 22 | 23 | /** 24 | * Created by yxx on 2016/5/29. 25 | * 26 | * @author ohun@live.cn (夜色) 27 | */ 28 | public final class DefaultExecutor extends ThreadPoolExecutor { 29 | 30 | public DefaultExecutor(int corePoolSize, int maximumPoolSize, 31 | long keepAliveTime, TimeUnit unit, 32 | BlockingQueue workQueue, 33 | ThreadFactory threadFactory, 34 | RejectedExecutionHandler handler) { 35 | super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /mpush-tools/src/main/resources/META-INF/services/com.mpush.api.spi.common.JsonFactory: -------------------------------------------------------------------------------- 1 | com.mpush.tools.common.DefaultJsonFactory -------------------------------------------------------------------------------- /mpush-tools/src/test/java/com/mpush/tools/crypto/AESUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.tools.crypto; 21 | 22 | import com.mpush.api.Constants; 23 | import org.junit.Test; 24 | 25 | import java.util.Random; 26 | 27 | /** 28 | * Created by ohun on 2015/12/25. 29 | */ 30 | public class AESUtilsTest { 31 | 32 | @Test 33 | public void testEncryptDES() throws Exception { 34 | String data = "似的士大夫士大夫士大夫首发式发生士大夫"; 35 | System.out.println("原文:\n" + data); 36 | byte[] key = new byte[16]; 37 | new Random().nextBytes(key); 38 | byte[] d1 = AESUtils.encrypt(data.getBytes(Constants.UTF_8), key,key); 39 | System.out.println("加密后:\n" + new String(d1)); 40 | byte[] d2 = AESUtils.decrypt(d1, key,key); 41 | System.out.println("解密后:\n" + new String(d2, Constants.UTF_8)); 42 | } 43 | 44 | @Test 45 | public void testDecryptDES() throws Exception { 46 | 47 | } 48 | } -------------------------------------------------------------------------------- /mpush-zk/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | 9 | mpush 10 | com.github.mpusher 11 | 0.8.1 12 | ../pom.xml 13 | 14 | 15 | mpush-zk 16 | jar 17 | mpush-zookeeper 18 | MPUSH消息推送系统zookeeper集群控制模块 19 | https://github.com/mpusher/mpush 20 | 21 | 22 | 23 | ${project.groupId} 24 | mpush-monitor 25 | 26 | 27 | org.apache.curator 28 | curator-recipes 29 | 30 | 31 | org.apache.curator 32 | curator-x-discovery 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /mpush-zk/src/main/java/com/mpush/zk/ZKDiscoveryFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.zk; 21 | 22 | import com.mpush.api.spi.Spi; 23 | import com.mpush.api.spi.common.ServiceDiscoveryFactory; 24 | import com.mpush.api.srd.ServiceDiscovery; 25 | 26 | /** 27 | * Created by ohun on 2016/12/27. 28 | * 29 | * @author ohun@live.cn (夜色) 30 | */ 31 | @Spi(order = 1) 32 | public final class ZKDiscoveryFactory implements ServiceDiscoveryFactory { 33 | @Override 34 | public ServiceDiscovery get() { 35 | return ZKServiceRegistryAndDiscovery.I; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /mpush-zk/src/main/java/com/mpush/zk/ZKException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.zk; 21 | 22 | /** 23 | * Created by yxx on 2016/5/14. 24 | * 25 | * @author ohun@live.cn 26 | */ 27 | public class ZKException extends RuntimeException { 28 | 29 | public ZKException() { 30 | } 31 | 32 | public ZKException(String message) { 33 | super(message); 34 | } 35 | 36 | public ZKException(String message, Throwable cause) { 37 | super(message, cause); 38 | } 39 | 40 | public ZKException(Throwable cause) { 41 | super(cause); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mpush-zk/src/main/java/com/mpush/zk/ZKRegistryFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2015-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Contributors: 17 | * ohun@live.cn (夜色) 18 | */ 19 | 20 | package com.mpush.zk; 21 | 22 | import com.mpush.api.spi.Spi; 23 | import com.mpush.api.spi.common.ServiceRegistryFactory; 24 | import com.mpush.api.srd.ServiceRegistry; 25 | 26 | /** 27 | * Created by ohun on 2016/12/27. 28 | * 29 | * @author ohun@live.cn (夜色) 30 | */ 31 | @Spi(order = 1) 32 | public final class ZKRegistryFactory implements ServiceRegistryFactory { 33 | @Override 34 | public ServiceRegistry get() { 35 | return ZKServiceRegistryAndDiscovery.I; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /mpush-zk/src/main/resources/META-INF/services/com.mpush.api.spi.common.ServiceDiscoveryFactory: -------------------------------------------------------------------------------- 1 | com.mpush.zk.ZKDiscoveryFactory -------------------------------------------------------------------------------- /mpush-zk/src/main/resources/META-INF/services/com.mpush.api.spi.common.ServiceRegistryFactory: -------------------------------------------------------------------------------- 1 | com.mpush.zk.ZKRegistryFactory --------------------------------------------------------------------------------