├── .gitignore
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── chao
│ │ │ └── android
│ │ │ └── tools
│ │ │ └── service_pools
│ │ │ ├── A.java
│ │ │ ├── App.java
│ │ │ ├── AppService.java
│ │ │ ├── AppService2.java
│ │ │ ├── BaseActivity.java
│ │ │ ├── CommonPrinter.java
│ │ │ ├── IA.java
│ │ │ ├── LauncherActivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── Printer.java
│ │ │ ├── Printer2.java
│ │ │ ├── SecondActivity.java
│ │ │ ├── SimpleFragment.java
│ │ │ ├── abs
│ │ │ └── Abs.java
│ │ │ ├── cache
│ │ │ ├── IPoolInstance.java
│ │ │ ├── Pool.java
│ │ │ └── PoolInstance.java
│ │ │ ├── event
│ │ │ ├── EventSample.java
│ │ │ ├── HisEvent.java
│ │ │ └── MyEvent.java
│ │ │ ├── fragments
│ │ │ ├── EventFragment.java
│ │ │ └── HisEventFragment.java
│ │ │ ├── inherited
│ │ │ ├── BaseInheritedActivity.java
│ │ │ ├── InheritedInheritedActivity1.java
│ │ │ ├── InheritedInheritedActivity11.java
│ │ │ ├── InheritedInheritedActivity111.java
│ │ │ └── InheritedInheritedActivity2.java
│ │ │ ├── init
│ │ │ ├── InitSampleActivity.java
│ │ │ ├── InitSyncSampleFragment.java
│ │ │ ├── Test.java
│ │ │ ├── TestInitService.java
│ │ │ ├── TestLazyInitServicePriorityMax.java
│ │ │ ├── TestLazyInitServicePriorityMin.java
│ │ │ └── TestLazyInitServicePriorityNormal.java
│ │ │ ├── path
│ │ │ ├── IRepeat.java
│ │ │ ├── PathService.java
│ │ │ ├── PathService2.java
│ │ │ ├── RepeatePathService.java
│ │ │ └── TestPathServices.java
│ │ │ ├── route
│ │ │ ├── AppRouters.java
│ │ │ ├── RouteDefine.java
│ │ │ ├── RouteField.java
│ │ │ ├── TestRouteTargetActivity.java
│ │ │ └── interceptor
│ │ │ │ ├── RouteContinueInterceptor5.java
│ │ │ │ ├── RouteExceptionInterceptor1.java
│ │ │ │ └── RouteInterruptInterceptor4.java
│ │ │ ├── router2
│ │ │ ├── RouteApi.java
│ │ │ └── RouteFragment.java
│ │ │ ├── rpc
│ │ │ ├── RPCSampleFragment.java
│ │ │ ├── TestService.java
│ │ │ └── impl
│ │ │ │ └── LocalFirstServiceImpl.java
│ │ │ ├── sample
│ │ │ └── SimpleBaseActivity.java
│ │ │ ├── serviceinterceptor
│ │ │ ├── MinPriorityServiceInterceptor.java
│ │ │ ├── NormalServiceInterceptor.java
│ │ │ └── ServiceDirectReturnInterceptor.java
│ │ │ ├── test
│ │ │ ├── InitService1.java
│ │ │ ├── InitService2.java
│ │ │ ├── InitService3.java
│ │ │ ├── InitService4.java
│ │ │ └── InitService5.java
│ │ │ └── xxxxx
│ │ │ ├── ASMServiceProxy.java
│ │ │ ├── ASMStaticClass.java
│ │ │ └── ServiceProxyBean.java
│ ├── res
│ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ │ ├── device_info_settings.xml
│ │ │ ├── empty.xml
│ │ │ ├── init_sync_sample.xml
│ │ │ ├── main.xml
│ │ │ ├── rpc_page.xml
│ │ │ └── test_route_activity.xml
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── raw
│ │ │ └── ami_config.xml
│ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ └── resources
│ │ └── META-INF
│ │ └── my-services
│ │ └── test.txt
│ └── test
│ └── java
│ └── chao
│ └── test
│ └── service_pools
│ └── ExampleUnitTest.java
├── assembleDebug.sh
├── autoservice
├── .gitignore
├── build.gradle
├── gradle.properties
└── src
│ └── main
│ ├── groovy
│ └── chao
│ │ └── android
│ │ └── gradle
│ │ └── servicepool
│ │ ├── Logger.java
│ │ ├── compiler
│ │ ├── AutoServiceAnnotation.java
│ │ ├── AutoServiceAnnotationDetect.java
│ │ ├── AutoServiceEventVisitor.groovy
│ │ ├── AutoServiceExtension.java
│ │ ├── AutoServiceField.java
│ │ ├── AutoServiceFieldClassVisitor.java
│ │ ├── AutoServicePlugin.groovy
│ │ ├── AutoServiceTransform.groovy
│ │ ├── AutoServiceVisitor.java
│ │ ├── AutoServiceWeaver.groovy
│ │ ├── ClassUtil.java
│ │ ├── Constant.java
│ │ └── ServiceInfo.java
│ │ └── hunter
│ │ ├── HunterTransform.java
│ │ ├── RunVariant.java
│ │ ├── asm
│ │ ├── BaseWeaver.java
│ │ ├── ClassLoaderHelper.java
│ │ ├── ExtendClassWriter.java
│ │ └── IWeaver.java
│ │ └── package-info.java
│ └── resources
│ └── META-INF
│ └── gradle-plugins
│ └── sp.autoservice.properties
├── build.gradle
├── buildSrc
├── .gitignore
└── build.gradle
├── changelog.md
├── debug.sh
├── empty.gradle
├── empty
├── .gitignore
└── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── maven.gradle
├── modules.gradle
├── release.keystore
├── settings.gradle
├── sp
├── .gitignore
├── build.gradle
├── gradle.properties
└── src
│ ├── main
│ └── java
│ │ └── chao
│ │ └── java
│ │ └── tools
│ │ └── servicepool
│ │ ├── AbsInitServiceManager.java
│ │ ├── BuildInServiceLoader.java
│ │ ├── ClassTypeAdapter.java
│ │ ├── Constant.java
│ │ ├── DefaultInitService.java
│ │ ├── DefaultService.java
│ │ ├── DefaultServiceController.java
│ │ ├── DependencyManager.java
│ │ ├── ExceptionHandler.java
│ │ ├── IInitService.java
│ │ ├── ILogger.java
│ │ ├── IPathService.java
│ │ ├── IService.java
│ │ ├── IServiceFactories.java
│ │ ├── IServiceFactory.java
│ │ ├── IServiceInterceptor.java
│ │ ├── IServiceInterceptorCallback.java
│ │ ├── IServiceLoader.java
│ │ ├── IServices.java
│ │ ├── InitProxy.java
│ │ ├── InitServiceManager.java
│ │ ├── InnerProxy.java
│ │ ├── LazyHolder.java
│ │ ├── Logger.java
│ │ ├── NoOpConstructorArg.java
│ │ ├── NoOpInstance.java
│ │ ├── NoOpInstanceFactory.java
│ │ ├── NoOpInstantiator.java
│ │ ├── PathServices.java
│ │ ├── ReflectUtil.java
│ │ ├── ServiceController.java
│ │ ├── ServiceFactories.java
│ │ ├── ServiceInterceptorStrategy.java
│ │ ├── ServicePool.java
│ │ ├── ServicePoolException.java
│ │ ├── ServiceProxy.java
│ │ ├── ServiceThreadFactory.java
│ │ ├── Sp.java
│ │ ├── annotation
│ │ ├── Event.java
│ │ ├── Init.java
│ │ ├── Service.java
│ │ └── Services.java
│ │ ├── cache
│ │ ├── AbsServiceCacheStrategy.java
│ │ ├── Global.java
│ │ ├── Once.java
│ │ ├── ServiceCacheStrategy.java
│ │ ├── Soft.java
│ │ ├── Specific.java
│ │ ├── Weak.java
│ │ └── custom
│ │ │ ├── Custom.java
│ │ │ ├── CustomCacheStrategy.java
│ │ │ └── CustomCombineStrategy.java
│ │ ├── combine
│ │ ├── CombineCallback.java
│ │ ├── CombineEmptyHandler.java
│ │ ├── CombineManager.java
│ │ ├── CombineService.java
│ │ ├── CombineStrategy.java
│ │ ├── CombineThreadExecutor.java
│ │ ├── CombineThreadFactory.java
│ │ └── DefaultCombineStrategy.java
│ │ ├── debug
│ │ └── Debug.java
│ │ ├── event
│ │ ├── EventManager.java
│ │ ├── EventService.java
│ │ └── WeakList.java
│ │ └── thirdparty
│ │ └── CancelableCountDownLatch.java
│ └── test
│ ├── java
│ └── chao
│ │ └── test
│ │ └── servicepool
│ │ └── test
│ │ └── noop
│ │ ├── NoOpInstanceFactoryForTest.java
│ │ ├── TestNoOpObject.java
│ │ └── test
│ │ ├── DependencyTest.java
│ │ ├── NoOpTest.java
│ │ ├── SampleTest.java
│ │ ├── ServiceTest.java
│ │ ├── TestLazy.java
│ │ ├── TestOpInstanceFactory.java
│ │ ├── noop
│ │ ├── TestNoOpObjectWithArgumentsConstructor.java
│ │ ├── TestNoOpObjectWithDefaultConstructor.java
│ │ ├── TestNoOpObjectWithPrivateConstructor.java
│ │ └── TestNoOpObjectWithProtectedConstructor.java
│ │ └── service
│ │ ├── II.java
│ │ ├── IPrinter.java
│ │ ├── NoOp.java
│ │ ├── NoPublicService.java
│ │ ├── Printer.java
│ │ ├── TestAbsImplService.java
│ │ ├── TestAbsService.java
│ │ ├── TestLazyService.java
│ │ ├── TestLazyService1.java
│ │ ├── TestLazyService2.java
│ │ ├── TestLazyServiceFactory.java
│ │ ├── TestNoOpService.java
│ │ ├── TestService.java
│ │ ├── TestService2.java
│ │ └── TestWeakService.java
│ └── resources
│ └── META-INF
│ └── services
│ ├── chao.java.tools.servicepool.IService
│ ├── chao.java.tools.servicepool.IServiceFactory
│ └── com.aicaigroup.servicepool.DependencyManager
├── spa
├── .gitignore
├── build.gradle
├── gradle.properties
├── proguard-rules.pro
└── src
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── chao
│ │ │ └── android
│ │ │ └── tools
│ │ │ └── servicepool
│ │ │ ├── AndroidLogger.java
│ │ │ ├── Spa.java
│ │ │ └── init
│ │ │ ├── AndroidInitService.java
│ │ │ └── DefaultDependencyManager.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── chao
│ └── test
│ └── servicepool
│ └── android
│ ├── ExampleInstrumentedTest.java
│ └── ExampleUnitTest.java
├── sprouter
├── .gitignore
├── build.gradle
├── gradle.properties
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── chao
│ │ └── android
│ │ └── tools
│ │ └── router
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── chao
│ │ │ └── android
│ │ │ └── tools
│ │ │ └── router
│ │ │ ├── Autowired.java
│ │ │ ├── RouteArgs.java
│ │ │ ├── RouteBuilder.java
│ │ │ ├── RouteCombineStrategyImpl.java
│ │ │ ├── RouteException.java
│ │ │ ├── RouteInterceptor.java
│ │ │ ├── RouteInterceptorCallback.java
│ │ │ ├── RouteManager.java
│ │ │ ├── RouteNavigationCallback.java
│ │ │ ├── RouteParamParse.java
│ │ │ ├── RouterService.java
│ │ │ ├── RouterServiceInterceptor.java
│ │ │ ├── SpRouter.java
│ │ │ └── annotation
│ │ │ ├── Route.java
│ │ │ ├── RouteAction.java
│ │ │ ├── RouteData.java
│ │ │ ├── RouteEnterAnim.java
│ │ │ ├── RouteExitAnim.java
│ │ │ ├── RouteFlags.java
│ │ │ ├── RouteParam.java
│ │ │ ├── RouteRequestCode.java
│ │ │ └── RouteType.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── chao
│ └── android
│ └── tools
│ └── router
│ └── ExampleUnitTest.java
├── sprpc
├── .gitignore
├── build.gradle
├── proguard-rules.pro
├── readme.md
└── src
│ ├── androidTest
│ └── java
│ │ └── chao
│ │ └── android
│ │ └── tools
│ │ └── servicepool
│ │ └── rpc
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── chao
│ │ │ └── android
│ │ │ └── tools
│ │ │ └── rpc
│ │ │ ├── ClassArrayTypeAdapter.java
│ │ │ ├── RemoteCallbackHandler.java
│ │ │ ├── RemoteClient.java
│ │ │ ├── RemoteClientMethod.java
│ │ │ ├── RemoteHandler.java
│ │ │ ├── RemoteMessageService.java
│ │ │ ├── RemoteServer.java
│ │ │ ├── RemoteService.java
│ │ │ ├── RemoteServiceException.java
│ │ │ ├── RemoteServiceInterceptor.java
│ │ │ ├── RemoteUtil.java
│ │ │ ├── SpRPC.java
│ │ │ └── annotation
│ │ │ └── RemoteServiceConfig.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── chao
│ └── android
│ └── tools
│ └── servicepool
│ └── rpc
│ └── ExampleUnitTest.java
├── tests
├── applib1
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── chao
│ │ │ └── test
│ │ │ └── applib1
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── chao
│ │ │ │ └── test
│ │ │ │ └── applib1
│ │ │ │ ├── AService.java
│ │ │ │ ├── GlobalService.java
│ │ │ │ ├── OnceService.java
│ │ │ │ ├── PathService.java
│ │ │ │ ├── PriorityService1.java
│ │ │ │ ├── PriorityService2.java
│ │ │ │ └── TempService.java
│ │ └── res
│ │ │ └── values
│ │ │ └── strings.xml
│ │ └── test
│ │ └── java
│ │ └── chao
│ │ └── test
│ │ └── applib1
│ │ └── ExampleUnitTest.java
├── applib2
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── chao
│ │ │ └── app
│ │ │ └── applib2
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── chao
│ │ │ │ └── app
│ │ │ │ └── applib2
│ │ │ │ └── BService.java
│ │ └── res
│ │ │ └── values
│ │ │ └── strings.xml
│ │ └── test
│ │ └── java
│ │ └── chao
│ │ └── app
│ │ └── applib2
│ │ └── ExampleUnitTest.java
├── appservice
│ ├── .gitignore
│ ├── build.gradle
│ └── src
│ │ └── main
│ │ └── java
│ │ └── chao
│ │ └── test
│ │ └── appservice
│ │ ├── AppServiceFactory.java
│ │ ├── IAppLib.java
│ │ └── IJavaLib.java
├── pool
│ ├── .gitignore
│ ├── build.gradle
│ └── src
│ │ └── main
│ │ └── java
│ │ └── chao
│ │ └── app
│ │ └── pool
│ │ ├── IA.java
│ │ ├── IB.java
│ │ ├── IPathInstanceService.java
│ │ ├── IPriorityService.java
│ │ └── LifecycleService.java
├── remoteexample
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── chao
│ │ │ └── app
│ │ │ └── remoteexample
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── chao
│ │ │ │ └── app
│ │ │ │ └── remoteexample
│ │ │ │ ├── ExampleService.java
│ │ │ │ ├── LaunchActivity.java
│ │ │ │ └── serviceimpl
│ │ │ │ ├── ExampleServiceImpl.java
│ │ │ │ ├── LocalFirstServiceImpl.java
│ │ │ │ └── RPCForceMainServiceImpl.java
│ │ └── res
│ │ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ │ └── values
│ │ │ └── strings.xml
│ │ └── test
│ │ └── java
│ │ └── chao
│ │ └── app
│ │ └── remoteexample
│ │ └── ExampleUnitTest.java
├── testpluginlib
│ ├── .gitignore
│ ├── build.gradle
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── testpluginlib
│ │ │ ├── MyClass.java
│ │ │ ├── TestPluginService.java
│ │ │ ├── TestPluginService2.java
│ │ │ └── TestPluginService3.java
│ │ └── resources
│ │ └── META-INF
│ │ └── services
│ │ └── chao.java.tools.servicepool.IService
└── testremoteapi
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ ├── androidTest
│ └── java
│ │ └── chao
│ │ └── app
│ │ └── remoteapi
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── chao
│ │ │ └── app
│ │ │ └── remoteapi
│ │ │ ├── IExampleService.java
│ │ │ ├── LocalFirstService.java
│ │ │ └── RPCForceMainService.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── chao
│ └── app
│ └── remoteapi
│ └── ExampleUnitTest.java
├── todo-list.md
└── transformJarDir.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | /.idea/caches/build_file_checksums.ser
6 | /.idea/libraries
7 | /.idea/modules.xml
8 | /.idea/workspace.xml
9 | .DS_Store
10 | /build
11 | /captures
12 | .externalNativeBuild
13 |
14 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | /release
3 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 |
2 | -ignorewarnings
3 |
4 | -dontwarn com.google.common.**
5 |
6 | -dontwarn net.bytebuddy.**
7 | -keep class net.bytebuddy.** {*;}
8 |
9 | -keep class chao.android.tools.router.** {*;}
10 | -keep class chao.android.tools.rpc.** {*;}
11 | -keep class chao.android.tools.servicepool.** {*;}
12 |
13 | -keep @chao.java.tools.servicepool.annotation.* class *
14 | -keep class * implements chao.java.tools.servicepool.IService { *; }
15 |
16 | -keep @chao.android.tools.rpc.annotation.* class ** {*;}
17 |
18 | -keep class chao.java.tools.** {*;}
19 |
20 | -keep class com.android.** {*;}
21 |
22 | # 避免混淆泛型
23 | #-keepattributes Signature
24 | # 抛出异常时保留代码行号
25 | -keepattributes SourceFile,LineNumberTable
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/A.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools;
2 |
3 | import chao.java.tools.servicepool.IService;
4 | import chao.java.tools.servicepool.annotation.Service;
5 |
6 | /**
7 | * @author qinchao
8 | * @since 2019/6/25
9 | */
10 | @Service
11 | public class A implements IA, IService {
12 |
13 | private int a;
14 |
15 | {
16 | a = 10;
17 | }
18 |
19 | public A() {
20 | a = 100;
21 | }
22 |
23 | public int getInt() {
24 | return 10086;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/App.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 |
6 | import com.google.common.base.Stopwatch;
7 |
8 | import java.util.concurrent.TimeUnit;
9 |
10 | import chao.android.tools.servicepool.Spa;
11 | import chao.app.ami.Ami;
12 |
13 | /**
14 | *
15 | *
16 | * @author qinchao
17 | * @since 2019/4/30
18 | */
19 | public class App extends Application {
20 |
21 | public static Context sContext;
22 |
23 | private static Application sApp;
24 |
25 | public App() {
26 | }
27 |
28 | public static Context getContext() {
29 | return sContext;
30 | }
31 |
32 | public static Application application() {
33 | return sApp;
34 | }
35 |
36 | @Override
37 | public void onCreate() {
38 | super.onCreate();
39 |
40 | sApp = this;
41 |
42 | sContext = getApplicationContext();
43 |
44 | Stopwatch stopwatch = Stopwatch.createStarted();
45 |
46 |
47 | // new SimpleFragment().onClick(null);
48 |
49 | Spa.init(this);
50 | Spa.setExceptionHandler((e, message) -> {
51 | // logger.log(message);
52 | e.printStackTrace();
53 | System.out.println("get service err: " + e);
54 | });
55 |
56 | Ami.log(stopwatch.elapsed(TimeUnit.MILLISECONDS));
57 |
58 | // Ami.init(this);
59 | // Ami.setDrawerId(R.raw.ami_config);
60 | Ami.log(stopwatch.elapsed(TimeUnit.MILLISECONDS));
61 |
62 | // commonService.print();
63 | //
64 | // haha.print();
65 | //
66 | // appService.print();
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/AppService.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools;
2 |
3 | import chao.java.tools.servicepool.IService;
4 | import chao.java.tools.servicepool.annotation.Service;
5 |
6 | /**
7 | * @author qinchao
8 | * @since 2019/4/29
9 | */
10 | @Service(priority = IService.Priority.MAX_PRIORITY, scope = IService.Scope.once)
11 | public class AppService implements Printer {
12 |
13 | @Override
14 | public void print() {
15 | System.out.println("I'm app service");
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/AppService2.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools;
2 |
3 | import chao.java.tools.servicepool.IService;
4 | import chao.java.tools.servicepool.annotation.Service;
5 |
6 | /**
7 | * @author qinchao
8 | * @since 2019/4/29
9 | */
10 | @Service(priority = IService.Priority.MAX_PRIORITY)
11 | public class AppService2 implements Printer2 {
12 |
13 | @Override
14 | public void print() {
15 | System.out.println("I'm app service 2");
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.os.Bundle;
5 | import androidx.annotation.Nullable;
6 |
7 | import chao.app.ami.base.AMIActivity;
8 | import chao.java.tools.servicepool.IService;
9 |
10 | /**
11 | * @author luqin
12 | * @since 2019-10-09
13 | */
14 |
15 | @SuppressLint("Registered")
16 | public class BaseActivity extends AMIActivity implements IService {
17 |
18 |
19 | @Override
20 | public void onCreate(@Nullable Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | }
23 |
24 | @Override
25 | public void onDestroy() {
26 | super.onDestroy();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/CommonPrinter.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools;
2 |
3 | import chao.java.tools.servicepool.annotation.Service;
4 |
5 | /**
6 | * @author luqin
7 | * @date 2019-07-17
8 | */
9 | @Service
10 | public class CommonPrinter implements Printer {
11 |
12 | public void print() {
13 | System.out.println("I'm a common Printer.");
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/IA.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * @author luqin
7 | * @since 2020-07-12
8 | */
9 | public interface IA extends IService {
10 | int getInt();
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/LauncherActivity.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools;
2 |
3 | import android.os.Bundle;
4 |
5 | import chao.android.tools.service_pools.router2.RouteFragment;
6 | import chao.android.tools.service_pools.rpc.RPCSampleFragment;
7 | import chao.app.ami.UI;
8 | import chao.app.ami.base.AMIActivity;
9 |
10 | /**
11 | * @author luqin
12 | * @since 2020-07-02
13 | */
14 | public class LauncherActivity extends AMIActivity {
15 |
16 |
17 | @Override
18 | public void setupView(Bundle savedInstanceState) {
19 | super.setupView(savedInstanceState);
20 |
21 | UI.show(this, MainActivity.class);
22 | finish();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/Printer.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * @author luqin qinchao@mochongsoft.com
7 | * @project: zmjx-sp
8 | * @description:
9 | * @date 2019-07-16
10 | */
11 | public interface Printer extends IService {
12 | void print();
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/Printer2.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools;
2 |
3 | /**
4 | * @author luqin qinchao@mochongsoft.com
5 | * @project: zmjx-sp
6 | * @description:
7 | * @date 2019-07-16
8 | */
9 | public interface Printer2 {
10 | void print();
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/SecondActivity.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools;
2 |
3 | import android.os.Bundle;
4 | import androidx.annotation.Nullable;
5 | import androidx.appcompat.app.AppCompatActivity;
6 |
7 | import chao.android.tools.service_pools.path.PathService;
8 | import chao.java.tools.servicepool.annotation.Service;
9 |
10 |
11 | /**
12 | * @author luqin
13 | * @since 2019-08-26
14 | */
15 | public class SecondActivity extends AppCompatActivity {
16 |
17 | // @Service
18 | // private CommonPrinter commonPrinter;
19 |
20 | @Service(path = "/app/path")
21 | private PathService pathService;
22 |
23 |
24 |
25 | SecondPrinter secondPrinter = new SecondPrinter();
26 |
27 |
28 | @Override
29 | protected void onCreate(@Nullable Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | secondPrinter.print();
32 |
33 | pathService.print();
34 | }
35 |
36 | public class SecondPrinter implements Printer {
37 |
38 | @Override
39 | public void print() {
40 | System.out.println("I'm in second activity.");
41 | // commonPrinter.print();
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/SimpleFragment.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools;
2 |
3 | import android.view.View;
4 |
5 | import java.lang.reflect.Method;
6 | import java.util.HashMap;
7 | import java.util.Map;
8 | import java.util.concurrent.ExecutorService;
9 | import java.util.concurrent.Executors;
10 |
11 | import chao.android.tools.service_pools.xxxxx.ASMServiceProxy;
12 | import chao.android.tools.servicepool.Spa;
13 | import chao.app.ami.base.AmiSimpleFragment;
14 |
15 | /**
16 | * @author luqin
17 | * @since 2020-07-02
18 | */
19 | public class SimpleFragment extends AmiSimpleFragment {
20 |
21 |
22 | @Override
23 | public void onClick(View v) {
24 | ExecutorService executorService = Executors.newFixedThreadPool(300);
25 | for (int i = 0; i < 300; i++) {
26 | executorService.execute(new Runnable() {
27 | @Override
28 | public void run() {
29 | Spa.init(App.sContext);
30 | }
31 | });
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/abs/Abs.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.abs;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * @author luqin
7 | * @since 2019-09-26
8 | */
9 | public abstract class Abs implements IService {
10 | public abstract void method();
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/cache/IPoolInstance.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.cache;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * @author luqin
7 | * @since 2020-08-06
8 | */
9 | public interface IPoolInstance extends IService {
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/cache/Pool.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.cache;
2 |
3 | import chao.java.tools.servicepool.IServiceFactory;
4 | import chao.java.tools.servicepool.annotation.Service;
5 | import chao.java.tools.servicepool.cache.custom.CustomCacheStrategy;
6 |
7 | /**
8 | * @author luqin
9 | * @since 2020-08-06
10 | */
11 | @Service(scope = 10)
12 | public class Pool implements CustomCacheStrategy {
13 |
14 | @Override
15 | public IPoolInstance getService(IServiceFactory factory, Class originClass, Class serviceClass) {
16 | return (IPoolInstance) factory.createInstance(serviceClass);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/cache/PoolInstance.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.cache;
2 |
3 | import chao.java.tools.servicepool.annotation.Service;
4 |
5 | /**
6 | * @author luqin
7 | * @since 2020-08-06
8 | */
9 | @Service(scope = 10)
10 | public class PoolInstance implements IPoolInstance {
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/event/EventSample.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.event;
2 |
3 | import chao.android.tools.service_pools.Printer;
4 | import chao.java.tools.servicepool.ServicePool;
5 | import chao.java.tools.servicepool.annotation.Service;
6 |
7 | /**
8 | * @author luqin
9 | * @since 2019-08-27
10 | */
11 | public class EventSample implements MyEvent {
12 |
13 | private int event;
14 |
15 | @Service
16 | private Printer printer;
17 |
18 | public EventSample() {
19 | this(0);
20 | }
21 |
22 | public EventSample(int event) {
23 | }
24 |
25 | public void handleEvent() {
26 | printer.print();
27 | }
28 |
29 | @Override
30 | public void postEvent() {
31 | System.out.println("this is event sample.");
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/event/HisEvent.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.event;
2 |
3 | import chao.java.tools.servicepool.annotation.Event;
4 |
5 | /**
6 | * @author luqin
7 | * @since 2019-08-29
8 | */
9 | @Event
10 | public interface HisEvent {
11 | void postHisEvent();
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/event/MyEvent.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.event;
2 |
3 | import chao.java.tools.servicepool.annotation.Event;
4 | import chao.java.tools.servicepool.event.EventService;
5 |
6 | /**
7 | * @author luqin
8 | * @since 2019-08-27
9 | */
10 | @Event
11 | public interface MyEvent {
12 | void postEvent();
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/fragments/EventFragment.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.fragments;
2 |
3 | import android.view.View;
4 |
5 | import chao.android.tools.service_pools.R;
6 | import chao.android.tools.service_pools.event.MyEvent;
7 | import chao.app.ami.Ami;
8 | import chao.app.ami.UI;
9 | import chao.app.ami.annotations.LayoutID;
10 | import chao.app.ami.base.AMISupportFragment;
11 | import chao.java.tools.servicepool.ServicePool;
12 | import chao.java.tools.servicepool.annotation.Event;
13 |
14 | /**
15 | * @author luqin
16 | * @since 2019-08-27
17 | */
18 | @LayoutID(R.layout.main)
19 | public class EventFragment extends AMISupportFragment implements MyEvent {
20 |
21 | @Event
22 | private MyEvent myEvent;
23 |
24 |
25 | public EventFragment() {
26 | }
27 |
28 | @Override
29 | public void setupView(View layout) {
30 | myEvent.postEvent();
31 |
32 | layout.findViewById(R.id.btn).setOnClickListener(v->{
33 | UI.show(getActivity(), EventFragment.class);
34 | });
35 | }
36 |
37 | @Override
38 | public void postEvent() {
39 | System.out.println("post event in EventFragment.");
40 | }
41 |
42 |
43 | public class InnerEvent implements MyEvent {
44 |
45 | @Override
46 | public void postEvent() {
47 | System.out.println("post event in EventFragment inner.");
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/fragments/HisEventFragment.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.fragments;
2 |
3 | import android.view.View;
4 |
5 | import chao.android.tools.service_pools.R;
6 | import chao.android.tools.service_pools.event.HisEvent;
7 | import chao.app.ami.annotations.LayoutID;
8 | import chao.app.ami.base.AMISupportFragment;
9 | import chao.java.tools.servicepool.annotation.Event;
10 |
11 | /**
12 | * @author luqin
13 | * @since 2019-08-29
14 | */
15 | @LayoutID(R.layout.main)
16 | public class HisEventFragment extends AMISupportFragment {
17 |
18 |
19 | @Event
20 | private HisEvent hisEvent;
21 |
22 | @Override
23 | public void setupView(View layout) {
24 | hisEvent.postHisEvent();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/inherited/BaseInheritedActivity.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.inherited;
2 |
3 | import chao.app.ami.base.AMIActivity;
4 | import chao.java.tools.servicepool.IService;
5 | import chao.java.tools.servicepool.annotation.Service;
6 |
7 | /**
8 | * @author luqin
9 | * @since 2020-07-13
10 | */
11 | @Service(inherited = true, priority = IService.Priority.MIN_PRIORITY)
12 | public abstract class BaseInheritedActivity extends AMIActivity implements IService {
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/inherited/InheritedInheritedActivity1.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.inherited;
2 |
3 | import android.os.Bundle;
4 | import android.os.PersistableBundle;
5 |
6 | /**
7 | * @author luqin
8 | * @since 2020-07-13
9 | */
10 | public class InheritedInheritedActivity1 extends BaseInheritedActivity {
11 |
12 | @Override
13 | public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
14 | super.onCreate(savedInstanceState, persistentState);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/inherited/InheritedInheritedActivity11.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.inherited;
2 |
3 | import android.os.Bundle;
4 | import android.os.PersistableBundle;
5 |
6 | import chao.java.tools.servicepool.IService;
7 | import chao.java.tools.servicepool.annotation.Service;
8 |
9 | /**
10 | * @author luqin
11 | * @since 2020-07-13
12 | */
13 | @Service(priority = IService.Priority.MAX_PRIORITY)
14 | public class InheritedInheritedActivity11 extends InheritedInheritedActivity1 {
15 |
16 | @Override
17 | public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
18 | super.onCreate(savedInstanceState, persistentState);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/inherited/InheritedInheritedActivity111.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.inherited;
2 |
3 | import android.os.Bundle;
4 | import android.os.PersistableBundle;
5 |
6 | /**
7 | * @author luqin
8 | * @since 2020-07-13
9 | */
10 | public class InheritedInheritedActivity111 extends InheritedInheritedActivity11 {
11 |
12 | @Override
13 | public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
14 | super.onCreate(savedInstanceState, persistentState);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/inherited/InheritedInheritedActivity2.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.inherited;
2 |
3 | import android.app.Activity;
4 |
5 | /**
6 | * @author luqin
7 | * @since 2020-07-13
8 | */
9 | public class InheritedInheritedActivity2 extends Activity {
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/init/InitSampleActivity.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.init;
2 |
3 | import android.os.Bundle;
4 | import androidx.annotation.Nullable;
5 |
6 | import chao.android.tools.service_pools.R;
7 | import chao.android.tools.service_pools.test.InitService5;
8 | import chao.app.ami.annotations.LayoutID;
9 | import chao.app.ami.base.AMIActivity;
10 | import chao.java.tools.servicepool.annotation.Service;
11 |
12 | /**
13 | * @author luqin
14 | * @since 2019-09-30
15 | */
16 | @LayoutID(R.layout.ami_home_layout)
17 | public class InitSampleActivity extends AMIActivity {
18 |
19 | @Service
20 | private InitService5 initService5;
21 |
22 | @Override
23 | public void onCreate(@Nullable Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/init/Test.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.init;
2 |
3 | import chao.java.tools.servicepool.AbsInitServiceManager;
4 |
5 | /**
6 | * @author luqin
7 | * @since 2019-09-17
8 | */
9 | public class Test extends AbsInitServiceManager {
10 |
11 | public Test(){
12 | addInitService(TestInitService.class);
13 | }
14 |
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/init/TestInitService.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.init;
2 |
3 | import chao.java.tools.servicepool.IInitService;
4 | import chao.java.tools.servicepool.annotation.Init;
5 | import chao.java.tools.servicepool.annotation.Service;
6 |
7 | /**
8 | * @author luqin
9 | * @since 2019-09-17
10 | */
11 | @Init(lazy = false)
12 | @Service
13 | public class TestInitService implements IInitService {
14 | @Override
15 | public void onInit() {
16 | System.out.println("lazy service inited.");
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/init/TestLazyInitServicePriorityMax.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.init;
2 |
3 | import chao.java.tools.servicepool.IInitService;
4 | import chao.java.tools.servicepool.Sp;
5 | import chao.java.tools.servicepool.annotation.Init;
6 | import chao.java.tools.servicepool.annotation.Service;
7 |
8 | /**
9 | * @author luqin
10 | * @since 2019-09-17
11 | */
12 | @Init(lazy = false, priority = Sp.MAX_PRIORITY)
13 | @Service
14 | public class TestLazyInitServicePriorityMax implements IInitService {
15 | @Override
16 | public void onInit() {
17 | System.out.println("max priority lazy service inited.");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/init/TestLazyInitServicePriorityMin.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.init;
2 |
3 | import chao.java.tools.servicepool.IInitService;
4 | import chao.java.tools.servicepool.Sp;
5 | import chao.java.tools.servicepool.annotation.Init;
6 | import chao.java.tools.servicepool.annotation.Service;
7 |
8 | /**
9 | * @author luqin
10 | * @since 2019-09-17
11 | */
12 | @Init(lazy = false, priority = Sp.MIN_PRIORITY)
13 | @Service
14 | public class TestLazyInitServicePriorityMin implements IInitService {
15 | @Override
16 | public void onInit() {
17 | System.out.println("min priority lazy service inited.");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/init/TestLazyInitServicePriorityNormal.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.init;
2 |
3 | import chao.java.tools.servicepool.IInitService;
4 | import chao.java.tools.servicepool.Sp;
5 | import chao.java.tools.servicepool.annotation.Init;
6 | import chao.java.tools.servicepool.annotation.Service;
7 |
8 | /**
9 | * @author luqin
10 | * @since 2019-09-17
11 | */
12 | @Init(lazy = false)
13 | @Service
14 | public class TestLazyInitServicePriorityNormal implements IInitService {
15 | @Override
16 | public void onInit() {
17 | System.out.println("normal lazy service inited.");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/path/IRepeat.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.path;
2 |
3 | /**
4 | * @author luqin
5 | * @since 2020-06-16
6 | */
7 | public interface IRepeat {
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/path/PathService.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.path;
2 |
3 | import chao.android.tools.service_pools.Printer;
4 | import chao.java.tools.servicepool.IService;
5 | import chao.java.tools.servicepool.annotation.Service;
6 |
7 | /**
8 | * @author luqin
9 | * @since 2019-09-18
10 | */
11 | @Service(path = "/app/path", scope = IService.Scope.global)
12 | public class PathService implements Printer, IService {
13 |
14 | public void print(){
15 | System.out.println("this is a path service.");
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/path/PathService2.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.path;
2 |
3 | import chao.android.tools.service_pools.Printer;
4 | import chao.java.tools.servicepool.IService;
5 | import chao.java.tools.servicepool.annotation.Service;
6 |
7 | /**
8 | * @author luqin
9 | * @since 2019-09-18
10 | */
11 | @Service(path = "/app/path2")
12 | public class PathService2 implements Printer, IService {
13 |
14 | public void print(){
15 | System.out.println("this is a path service 2.");
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/path/RepeatePathService.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.path;
2 |
3 | import android.util.Log;
4 |
5 | import chao.android.tools.service_pools.Printer;
6 | import chao.java.tools.servicepool.IService;
7 | import chao.java.tools.servicepool.annotation.Service;
8 |
9 | /**
10 | * @author luqin
11 | * @since 2020-06-16
12 | */
13 | @Service(path = "/app/repeat")
14 | @Service(path = "/app/repeatable", scope = IService.Scope.global)
15 | public class RepeatePathService implements Printer,IRepeat {
16 | @Override
17 | public void print() {
18 | System.out.println("this is a repeat path service.");
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/path/TestPathServices.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.path;
2 |
3 | import chao.java.tools.servicepool.PathServices;
4 |
5 | /**
6 | * @author luqin
7 | * @since 2019-09-18
8 | */
9 | public class TestPathServices extends PathServices {
10 |
11 | public TestPathServices() {
12 | put("/app/path", PathService.class);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/route/AppRouters.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.route;
2 |
3 | /**
4 | * @author luqin
5 | * @since 2019-09-03
6 | */
7 | public interface AppRouters {
8 |
9 | void startActivity();
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/route/RouteDefine.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.route;
2 |
3 | import android.os.Bundle;
4 |
5 | /**
6 | *
7 | * 动画animation
8 | * 参数
9 | * path
10 | * Activity
11 | *
12 | * flag
13 | *
14 | *
15 | *
16 | * @author luqin
17 | * @since 2019-09-03
18 | */
19 | public class RouteDefine {
20 |
21 | private int inAnim;
22 |
23 | private int outAnim;
24 |
25 | private String path;
26 |
27 | private int flag;
28 |
29 | private Bundle extras;
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/route/RouteField.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.route;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * @author luqin
10 | * @since 2019-09-03
11 | */
12 | @Target(ElementType.FIELD)
13 | @Retention(RetentionPolicy.CLASS)
14 | public @interface RouteField {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/route/TestRouteTargetActivity.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.route;
2 |
3 | import chao.android.tools.service_pools.R;
4 | import chao.app.ami.annotations.LayoutID;
5 | import chao.app.ami.base.AMIActivity;
6 | import chao.java.tools.servicepool.annotation.Service;
7 |
8 | /**
9 | * @author luqin
10 | * @since 2019-10-09
11 | */
12 | @LayoutID(R.layout.empty)
13 | @Service(path = "/app/routeTarget")
14 | public class TestRouteTargetActivity extends AMIActivity {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/route/interceptor/RouteContinueInterceptor5.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.route.interceptor;
2 |
3 | import chao.android.tools.router.RouteBuilder;
4 | import chao.android.tools.router.RouteInterceptor;
5 | import chao.android.tools.router.RouteInterceptorCallback;
6 | import chao.app.ami.Ami;
7 | import chao.java.tools.servicepool.IService;
8 | import chao.java.tools.servicepool.annotation.Service;
9 |
10 | /**
11 | * @author luqin
12 | * @since 2019-10-09
13 | */
14 | @Service(priority = 5, scope = IService.Scope.global)
15 | public class RouteContinueInterceptor5 implements RouteInterceptor {
16 | @Override
17 | public void intercept(RouteBuilder route, RouteInterceptorCallback callback) {
18 | Ami.log(route);
19 | callback.onContinue(route);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/route/interceptor/RouteExceptionInterceptor1.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.route.interceptor;
2 |
3 | import chao.android.tools.router.RouteBuilder;
4 | import chao.android.tools.router.RouteInterceptor;
5 | import chao.android.tools.router.RouteInterceptorCallback;
6 | import chao.app.ami.Ami;
7 | import chao.java.tools.servicepool.IService;
8 | import chao.java.tools.servicepool.annotation.Service;
9 |
10 | /**
11 | * @author luqin
12 | * @since 2019-10-09
13 | */
14 | @Service(priority = 1,scope = IService.Scope.global)
15 | public class RouteExceptionInterceptor1 implements RouteInterceptor {
16 | @Override
17 | public void intercept(RouteBuilder route, RouteInterceptorCallback callback) {
18 | Ami.log(route);
19 | if (route.extras.getInt("interceptor") == 2) {
20 | throw new RuntimeException("route interceptor err test.");
21 | } else {
22 | callback.onContinue(route);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/route/interceptor/RouteInterruptInterceptor4.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.route.interceptor;
2 |
3 | import chao.android.tools.router.RouteBuilder;
4 | import chao.android.tools.router.RouteInterceptor;
5 | import chao.android.tools.router.RouteInterceptorCallback;
6 | import chao.app.ami.Ami;
7 | import chao.java.tools.servicepool.IService;
8 | import chao.java.tools.servicepool.annotation.Service;
9 |
10 | /**
11 | * @author luqin
12 | * @since 2019-10-09
13 | */
14 | @Service(priority = 4, scope = IService.Scope.global)
15 | public class RouteInterruptInterceptor4 implements RouteInterceptor {
16 | @Override
17 | public void intercept(RouteBuilder route, RouteInterceptorCallback callback) {
18 | Ami.log(route);
19 | if (route.extras.getInt("interceptor") == 1) {
20 | callback.onInterrupt(null);
21 | } else {
22 | callback.onContinue(route);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/router2/RouteApi.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.router2;
2 |
3 | import android.content.Intent;
4 |
5 | import java.io.Serializable;
6 | import java.util.ArrayList;
7 |
8 | import chao.android.tools.router.annotation.Route;
9 | import chao.android.tools.router.annotation.RouteParam;
10 | import chao.android.tools.service_pools.SimpleFragment;
11 | import chao.java.tools.servicepool.IService;
12 |
13 | /**
14 | * @author luqin
15 | * @since 2020-07-28
16 | */
17 | public interface RouteApi extends IService {
18 |
19 | @Route(path = "/app/testRoute",
20 | flags = Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK,
21 | requestCode = 1
22 | )
23 | void startTestRouterActivity(
24 | @RouteParam("int") int iv,
25 | @RouteParam("int[]") int[] liv,
26 | @RouteParam("boolean") boolean bv,
27 | @RouteParam("float") float fValue,
28 | @RouteParam("double") double dValue,
29 | @RouteParam("Integer") Integer Iv,
30 | @RouteParam("string") String sValue,
31 | @RouteParam("serializable") Serializable s,
32 | @RouteParam("slist")ArrayList slist,
33 | @RouteParam("simple") ArrayList containers
34 | );
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/rpc/TestService.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.rpc;
2 |
3 | import chao.android.tools.rpc.RemoteCallbackHandler;
4 | import chao.android.tools.service_pools.router2.RouteFragment;
5 | import chao.java.tools.servicepool.IService;
6 |
7 | /**
8 | * @author luqin
9 | * @since 2020-08-03
10 | */
11 | public interface TestService extends IService {
12 | void test(RemoteCallbackHandler callbackHandler);
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/rpc/impl/LocalFirstServiceImpl.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.rpc.impl;
2 |
3 | import chao.app.remoteapi.LocalFirstService;
4 | import chao.java.tools.servicepool.annotation.Service;
5 |
6 | /**
7 | * @author luqin
8 | * @since 2020-07-27
9 | */
10 | @Service
11 | public class LocalFirstServiceImpl implements LocalFirstService {
12 | @Override
13 | public int getInt() {
14 | return 55;
15 | }
16 |
17 | @Override
18 | public String getString() {
19 | return "local first";
20 | }
21 |
22 | @Override
23 | public void function() {
24 | System.out.println("local first called!");
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/sample/SimpleBaseActivity.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.sample;
2 |
3 | import android.os.Bundle;
4 | import androidx.annotation.Nullable;
5 | import androidx.appcompat.app.AppCompatActivity;
6 |
7 | /**
8 | * @author luqin
9 | * @since 2020-01-09
10 | */
11 | public class SimpleBaseActivity extends AppCompatActivity {
12 |
13 | @Override
14 | protected void onCreate(@Nullable Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/serviceinterceptor/MinPriorityServiceInterceptor.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.serviceinterceptor;
2 |
3 | import java.lang.reflect.Method;
4 |
5 | import chao.java.tools.servicepool.IService;
6 | import chao.java.tools.servicepool.IServiceInterceptor;
7 | import chao.java.tools.servicepool.IServiceInterceptorCallback;
8 | import chao.java.tools.servicepool.annotation.Service;
9 |
10 | import static chao.java.tools.servicepool.ServicePool.logger;
11 |
12 | /**
13 | * @author luqin
14 | * @since 2020-07-12
15 | */
16 | @Service(priority = IService.Priority.MIN_PRIORITY)
17 | public class MinPriorityServiceInterceptor implements IServiceInterceptor {
18 | @Override
19 | public void intercept(Class extends IService> originClass, IService source, Method method, Object[] args, IServiceInterceptorCallback callback) {
20 | logger.log(source.toString() + ": " + method.getName());
21 | if (method.getReturnType() == int.class) {
22 | callback.onInterrupt(10010);
23 | } else {
24 | callback.onContinue(method, args);
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/serviceinterceptor/NormalServiceInterceptor.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.serviceinterceptor;
2 |
3 | import java.lang.reflect.Method;
4 |
5 | import chao.java.tools.servicepool.IService;
6 | import chao.java.tools.servicepool.IServiceInterceptor;
7 | import chao.java.tools.servicepool.IServiceInterceptorCallback;
8 | import chao.java.tools.servicepool.annotation.Service;
9 |
10 | import static chao.java.tools.servicepool.ServicePool.logger;
11 |
12 | /**
13 | * @author luqin
14 | * @since 2020-07-12
15 | */
16 | @Service
17 | public class NormalServiceInterceptor implements IServiceInterceptor {
18 |
19 | @Override
20 | public void intercept(Class extends IService> originClass, IService source, Method method, Object[] args, IServiceInterceptorCallback callback) {
21 | logger.log(method);
22 | callback.onContinue(method, args);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/serviceinterceptor/ServiceDirectReturnInterceptor.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.serviceinterceptor;
2 |
3 | import java.lang.reflect.Method;
4 |
5 | import chao.java.tools.servicepool.IService;
6 | import chao.java.tools.servicepool.IServiceInterceptor;
7 | import chao.java.tools.servicepool.IServiceInterceptorCallback;
8 | import chao.java.tools.servicepool.annotation.Service;
9 |
10 | /**
11 | * @author luqin
12 | * @since 2020-08-12
13 | */
14 | @Service
15 | public class ServiceDirectReturnInterceptor implements IServiceInterceptor {
16 | @Override
17 | public void intercept(Class extends IService> originClass, IService source, Method method, Object[] args, IServiceInterceptorCallback callback) {
18 | return;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/test/InitService1.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.test;
2 |
3 | import android.os.SystemClock;
4 |
5 | import chao.app.ami.Ami;
6 | import chao.java.tools.servicepool.IInitService;
7 | import chao.java.tools.servicepool.annotation.Service;
8 |
9 | /**
10 | * @author luqin
11 | * @since 2019-08-06
12 | */
13 | @Service
14 | public class InitService1 implements IInitService {
15 | @Override
16 | public void onInit() {
17 | Ami.log(Thread.currentThread().getName() + " , " + Integer.toHexString(this.hashCode()) + ": init start.");
18 | SystemClock.sleep(1000);
19 | Ami.log(Thread.currentThread().getName() + " , " + Integer.toHexString(this.hashCode()) + ": init done.");
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/test/InitService2.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.test;
2 |
3 | import android.os.SystemClock;
4 |
5 | import chao.app.ami.Ami;
6 | import chao.java.tools.servicepool.IInitService;
7 | import chao.java.tools.servicepool.Sp;
8 | import chao.java.tools.servicepool.annotation.Init;
9 | import chao.java.tools.servicepool.annotation.Service;
10 |
11 | /**
12 | * @author luqin
13 | * @since 2019-08-06
14 | */
15 | @Init(dependencies = InitService1.class, priority = Sp.MAX_PRIORITY)
16 | @Service
17 | public class InitService2 implements IInitService {
18 | @Override
19 | public void onInit() {
20 | Ami.log("start");
21 |
22 | SystemClock.sleep(1000);
23 | Ami.log("done");
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/test/InitService3.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.test;
2 |
3 | import android.os.SystemClock;
4 |
5 | import chao.app.ami.Ami;
6 | import chao.java.tools.servicepool.IInitService;
7 | import chao.java.tools.servicepool.annotation.Init;
8 | import chao.java.tools.servicepool.annotation.Service;
9 |
10 | /**
11 | * @author luqin
12 | * @since 2019-08-06
13 | */
14 | @Init(dependencies = {InitService1.class, InitService2.class})
15 | @Service
16 | public class InitService3 implements IInitService {
17 | @Override
18 | public void onInit() {
19 | Ami.log("start");
20 | SystemClock.sleep(1000);
21 | Ami.log("done");
22 |
23 | }
24 | }
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/test/InitService4.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.test;
2 |
3 | import android.os.SystemClock;
4 |
5 | import chao.app.ami.Ami;
6 | import chao.java.tools.servicepool.IInitService;
7 | import chao.java.tools.servicepool.annotation.Init;
8 | import chao.java.tools.servicepool.annotation.Service;
9 |
10 | /**
11 | * @author luqin
12 | * @since 2019-08-06
13 | */
14 | @Init(dependencies = {InitService1.class, InitService2.class})
15 | @Service
16 | public class InitService4 implements IInitService {
17 | @Override
18 | public void onInit() {
19 | Ami.log("start");
20 | SystemClock.sleep(1000);
21 | Ami.log("done");
22 |
23 | }
24 | }
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/test/InitService5.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.test;
2 |
3 | import android.os.SystemClock;
4 |
5 | import chao.app.ami.Ami;
6 | import chao.java.tools.servicepool.IInitService;
7 | import chao.java.tools.servicepool.annotation.Init;
8 | import chao.java.tools.servicepool.annotation.Service;
9 |
10 | /**
11 | * @author luqin
12 | * @since 2019-08-06
13 | */
14 | @Init(dependencies = {InitService4.class, InitService3.class})
15 | @Service
16 | public class InitService5 implements IInitService {
17 | @Override
18 | public void onInit() {
19 | Ami.log("start");
20 | SystemClock.sleep(1000);
21 | Ami.log("done");
22 | }
23 | }
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/xxxxx/ASMServiceProxy.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.xxxxx;
2 |
3 | import java.util.ArrayList;
4 |
5 | import chao.android.tools.service_pools.test.InitService1;
6 | import chao.android.tools.service_pools.test.InitService2;
7 | import chao.android.tools.service_pools.test.InitService3;
8 | import chao.java.tools.servicepool.IInitService;
9 | import chao.java.tools.servicepool.ServiceProxy;
10 |
11 | /**
12 | * @author luqin
13 | * @since 2019-08-28
14 | */
15 | public class ASMServiceProxy {
16 |
17 | static {
18 | System.out.println("this is a clinit method.");
19 | }
20 |
21 | private void newServiceProxy() {
22 | ArrayList> services = new ArrayList<>();
23 | services.add(InitService1.class);
24 | services.add(InitService2.class);
25 |
26 | ServiceProxy proxy = new ServiceProxy<>(InitService3.class, null, 100, 200, false, true, services);
27 |
28 | ASMStaticClass clzz = new ASMStaticClass();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/xxxxx/ASMStaticClass.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.xxxxx;
2 |
3 | import chao.android.tools.service_pools.Printer;
4 | import chao.android.tools.service_pools.event.EventSample;
5 | import chao.java.tools.servicepool.annotation.Service;
6 |
7 | /**
8 | * @author luqin
9 | * @since 2019-08-28
10 | */
11 | public class ASMStaticClass {
12 |
13 | @Service
14 | private Printer sssssssprinter;
15 |
16 | // private static EventSample eventSample = new EventSample();
17 |
18 | public ASMStaticClass() {
19 |
20 | }
21 |
22 | public ASMStaticClass(int i) {
23 |
24 | }
25 |
26 |
27 | public void printer() {
28 | // sssssssprinter.print();
29 | }
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/java/chao/android/tools/service_pools/xxxxx/ServiceProxyBean.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.service_pools.xxxxx;
2 |
3 | import java.util.List;
4 |
5 | import chao.java.tools.servicepool.IInitService;
6 |
7 | /**
8 | * @author luqin
9 | * @since 2019-08-28
10 | */
11 | public class ServiceProxyBean {
12 |
13 | public List> services;
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/device_info_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/empty.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/init_sync_sample.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
14 |
15 |
22 |
23 |
30 |
31 |
38 |
39 |
46 |
47 |
54 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/rpc_page.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
17 |
25 |
26 |
34 |
35 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/test_route_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
21 |
22 |
28 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luqinx/sp/8cc0a51d878381d6530ffd89d410e70d282aade3/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luqinx/sp/8cc0a51d878381d6530ffd89d410e70d282aade3/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luqinx/sp/8cc0a51d878381d6530ffd89d410e70d282aade3/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luqinx/sp/8cc0a51d878381d6530ffd89d410e70d282aade3/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luqinx/sp/8cc0a51d878381d6530ffd89d410e70d282aade3/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luqinx/sp/8cc0a51d878381d6530ffd89d410e70d282aade3/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luqinx/sp/8cc0a51d878381d6530ffd89d410e70d282aade3/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luqinx/sp/8cc0a51d878381d6530ffd89d410e70d282aade3/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luqinx/sp/8cc0a51d878381d6530ffd89d410e70d282aade3/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luqinx/sp/8cc0a51d878381d6530ffd89d410e70d282aade3/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/raw/ami_config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | service-pools
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/resources/META-INF/my-services/test.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luqinx/sp/8cc0a51d878381d6530ffd89d410e70d282aade3/app/src/main/resources/META-INF/my-services/test.txt
--------------------------------------------------------------------------------
/assembleDebug.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | #/bin/sh
3 | ./gradlew :app:assembleDebug -xlint -xtest --stacktrace
--------------------------------------------------------------------------------
/autoservice/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/autoservice/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'groovy'
2 | apply plugin: 'maven'
3 |
4 | apply from: '../maven.gradle'
5 |
6 | dependencies {
7 | implementation gradleApi()
8 | implementation localGroovy()
9 | implementation 'com.android.tools.build:gradle:3.6.4'
10 | implementation 'com.android.tools.build:gradle-api:3.6.4'
11 | implementation 'org.ow2.asm:asm:7.0'
12 | implementation 'org.ow2.asm:asm-util:7.0'
13 | implementation 'org.ow2.asm:asm-commons:7.0'
14 | }
15 |
16 | repositories {
17 | maven { url 'http://maven.aliyun.com/nexus/content/groups/public/'}
18 | maven { url "https://maven.aliyun.com/repository/central"}
19 | mavenCentral()
20 | google()
21 | }
22 |
23 | sourceCompatibility = '1.8'
24 | targetCompatibility = '1.8'
25 |
--------------------------------------------------------------------------------
/autoservice/gradle.properties:
--------------------------------------------------------------------------------
1 | GROUP_ID=io.github.luqinx
2 | # POM文件中指向你网站的地址
3 | POM_URL=https://github.com/luqinx
4 | POM_DESCRIPTION="advance SPI for java"
5 | # SCM是指版本管理工具,一下说他的相关信息
6 | POM_SCM_URL=https://github.com/
7 | POM_SCM_CONNECTION=https://github.com/luqinx
8 | POM_SCM_DEV_CONNECTION=https://github.com/luqinx
9 | # 你的开放协议相关信息
10 | POM_LICENCE_NAME= Apache License Version 2.0
11 | POM_LICENCE_URL= https://github.com/luqinx/abkit/blob/master/LICENSE
12 | POM_LICENCE_DIST=Apache License Version 2.0
13 | # 开发者的相关信息
14 | POM_DEVELOPER_ID=luqinx
15 | POM_DEVELOPER_NAME=luqinx
16 | POM_DEVELOPER_EMAIL=qch5240@163.com
17 |
18 | POM_PACKAGING=jar
19 | VERSION_NAME=1.9.0
20 | ARTIFACT_ID=autoservice
21 |
--------------------------------------------------------------------------------
/autoservice/src/main/groovy/chao/android/gradle/servicepool/Logger.java:
--------------------------------------------------------------------------------
1 | package chao.android.gradle.servicepool;
2 |
3 | /**
4 | * @author luqin
5 | * @since 2019-07-09
6 | */
7 | public class Logger {
8 |
9 | public static void log(String tag, Object... args) {
10 | StringBuilder sbuilder = new StringBuilder();
11 | sbuilder.append(tag).append(": ");
12 | for (Object arg: args) {
13 | sbuilder.append(arg).append(",");
14 | }
15 | System.out.println(sbuilder.toString());
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/autoservice/src/main/groovy/chao/android/gradle/servicepool/compiler/AutoServiceAnnotation.java:
--------------------------------------------------------------------------------
1 | package chao.android.gradle.servicepool.compiler;
2 |
3 | /**
4 | * @author luqin 2019-07-15
5 | */
6 | public class AutoServiceAnnotation {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/autoservice/src/main/groovy/chao/android/gradle/servicepool/compiler/AutoServiceEventVisitor.groovy:
--------------------------------------------------------------------------------
1 | package chao.android.gradle.servicepool.compiler
2 |
3 |
4 | import org.objectweb.asm.ClassVisitor
5 | import org.objectweb.asm.Opcodes
6 |
7 | /**
8 | *
9 | * @author luqin* @since 2019-08-29
10 | */
11 | class AutoServiceEventVisitor extends ClassVisitor {
12 |
13 |
14 | AutoServiceEventVisitor(ClassVisitor cv) {
15 | super(Opcodes.ASM7, cv)
16 | }
17 |
18 | @Override
19 | void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
20 |
21 | for (String intf: interfaces) {
22 | if (Constant.EVENT_ASM_NAME == intf) {
23 | super.visit(version, access, name, signature, superName, interfaces)
24 | return
25 | }
26 | }
27 | String[] addInterfaces = new String[interfaces.length + 1]
28 | System.arraycopy(interfaces, 0, addInterfaces, 0, interfaces.length)
29 | addInterfaces[addInterfaces.length - 1] = Constant.EVENT_ASM_NAME
30 | super.visit(version, access, name, signature, superName, addInterfaces)
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/autoservice/src/main/groovy/chao/android/gradle/servicepool/compiler/AutoServiceExtension.java:
--------------------------------------------------------------------------------
1 | package chao.android.gradle.servicepool.compiler;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * @author luqin 2019-07-15
8 | */
9 | public class AutoServiceExtension {
10 |
11 | private boolean debuggable;
12 |
13 | private List excludes;
14 |
15 | private boolean inheritedOn;
16 |
17 | public AutoServiceExtension() {
18 | excludes = new ArrayList<>();
19 | //排除掉android framework包, android support, androidx
20 | excludes.add("com.android.");
21 | excludes.add("android.");
22 | excludes.add("androidx.");
23 | excludes.add("com.google.");
24 | //排除掉一些常用的三方组件
25 | excludes.add("com.jakewharton.");
26 | excludes.add("com.squareup."); //排除掉retrofit等square库
27 | excludes.add("com.facebook.");
28 |
29 | excludes.add("io.reactivex.");
30 | excludes.add("org.apache.");
31 |
32 | inheritedOn = false; //默认打开
33 | }
34 |
35 | public List excludes() {
36 | return excludes;
37 | }
38 |
39 | public void exclude(String name) {
40 | excludes.add(name);
41 | }
42 |
43 | public void debuggable(boolean debuggable) {
44 | this.debuggable = debuggable;
45 | }
46 |
47 | public boolean isDebuggable() {
48 | return debuggable;
49 | }
50 |
51 | public boolean isInheritedOn() {
52 | return inheritedOn;
53 | }
54 |
55 | public void setInheritedOn(boolean inheritedOn) {
56 | this.inheritedOn = inheritedOn;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/autoservice/src/main/groovy/chao/android/gradle/servicepool/compiler/AutoServiceField.java:
--------------------------------------------------------------------------------
1 | package chao.android.gradle.servicepool.compiler;
2 |
3 | /**
4 | * @author luqin
5 | * @since 2019-07-15
6 | */
7 | public class AutoServiceField {
8 | public String name;
9 | public String desc;
10 | public String signature;
11 | public Object value;
12 | public String asmFullName;
13 | public String annotationValue;
14 | public String annotationPath;
15 | public boolean isStatic;
16 |
17 | @Override
18 | public String toString() {
19 | return "AutoServiceField{" +
20 | "name='" + name + '\'' +
21 | ", desc='" + desc + '\'' +
22 | ", signature='" + signature + '\'' +
23 | ", value=" + value +
24 | '}';
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/autoservice/src/main/groovy/chao/android/gradle/servicepool/compiler/AutoServicePlugin.groovy:
--------------------------------------------------------------------------------
1 | package chao.android.gradle.servicepool.compiler
2 |
3 | import com.android.build.gradle.AppExtension
4 | import org.gradle.api.Plugin
5 | import org.gradle.api.Project
6 |
7 | /**
8 | * @author qinchao
9 | * @since 2019/6/25
10 | */
11 | class AutoServicePlugin implements Plugin {
12 |
13 | @Override
14 | void apply(Project project) {
15 | AppExtension android = project.extensions.getByName("android")
16 | android.registerTransform(new AutoServiceTransform(project))
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/autoservice/src/main/groovy/chao/android/gradle/servicepool/compiler/AutoServiceTransform.groovy:
--------------------------------------------------------------------------------
1 | package chao.android.gradle.servicepool.compiler
2 |
3 | import chao.android.gradle.servicepool.hunter.HunterTransform
4 | import com.android.build.api.transform.Context
5 | import com.android.build.api.transform.TransformException
6 | import com.android.build.api.transform.TransformInput
7 | import com.android.build.api.transform.TransformOutputProvider
8 | import org.apache.commons.io.IOUtils
9 | import org.gradle.api.Project
10 |
11 | /**
12 | * @author qinchao
13 | * @since 2019/6/25
14 | */
15 | class AutoServiceTransform extends HunterTransform {
16 |
17 | private AutoServiceWeaver autoServiceWeaver
18 |
19 |
20 | AutoServiceTransform(Project project) {
21 | super(project)
22 | autoServiceWeaver = new AutoServiceWeaver()
23 | this.bytecodeWeaver = autoServiceWeaver
24 | AutoServiceExtension extension = project.extensions.create(Constant.EXTENSION_NAME, AutoServiceExtension)
25 | autoServiceWeaver.setExtension(extension)
26 | }
27 |
28 |
29 | @Override
30 | protected void transformFinished(File destJar) {
31 | System.out.println("add autoservice generate jar: " + destJar.path)
32 | autoServiceWeaver.transformFinished(destJar)
33 | System.out.println("transformFinished ")
34 |
35 | // IOUtils.copy(new FileInputStream(destJar), new )
36 | }
37 |
38 | @Override
39 | boolean isIncremental() {
40 | return false
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/autoservice/src/main/groovy/chao/android/gradle/servicepool/compiler/AutoServiceVisitor.java:
--------------------------------------------------------------------------------
1 | package chao.android.gradle.servicepool.compiler;
2 |
3 | import org.objectweb.asm.ClassVisitor;
4 | import org.objectweb.asm.Opcodes;
5 |
6 | /**
7 | *
8 | *
9 | *
10 | * @author luqin
11 | * @since 2019-07-09
12 | */
13 | class AutoServiceVisitor extends ClassVisitor implements Constant{
14 |
15 |
16 | AutoServiceVisitor(ClassVisitor cv) {
17 | super(Opcodes.ASM7, cv);
18 | }
19 |
20 | @Override
21 | public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
22 |
23 | for (String intf: interfaces) {
24 | if (SERVICE_ASM_NAME.equals(intf)) {
25 | super.visit(version, access, name, signature, superName, interfaces);
26 | return;
27 | }
28 | }
29 | String[] addInterfaces = new String[interfaces.length + 1];
30 | System.arraycopy(interfaces, 0, addInterfaces, 0, interfaces.length);
31 | addInterfaces[addInterfaces.length - 1] = SERVICE_FULL_NAME.replaceAll("\\.", "/");
32 | super.visit(version, access, name, signature, superName, addInterfaces);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/autoservice/src/main/groovy/chao/android/gradle/servicepool/compiler/ClassUtil.java:
--------------------------------------------------------------------------------
1 | package chao.android.gradle.servicepool.compiler;
2 |
3 | /**
4 | * @author luqin
5 | * @since 2019-07-17
6 | */
7 | public class ClassUtil {
8 |
9 | public static String class2Desc(Class> clazz) {
10 | return "L" + clazz.getName().replaceAll("\\.", "/") + ";";
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/autoservice/src/main/groovy/chao/android/gradle/servicepool/hunter/RunVariant.java:
--------------------------------------------------------------------------------
1 | package chao.android.gradle.servicepool.hunter;
2 |
3 | /**
4 | * Created by Quinn on 10/05/2018
5 | */
6 | public enum RunVariant {
7 | DEBUG, RELEASE, ALWAYS, NEVER
8 | }
9 |
--------------------------------------------------------------------------------
/autoservice/src/main/groovy/chao/android/gradle/servicepool/hunter/asm/IWeaver.java:
--------------------------------------------------------------------------------
1 | package chao.android.gradle.servicepool.hunter.asm;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 |
6 | /**
7 | * Created by quinn on 06/09/2018
8 | */
9 | public interface IWeaver {
10 |
11 | int NO_JAR_ID = -1;
12 |
13 | /**
14 | * Check a certain file is weavable
15 | */
16 | boolean isWeavableClass(String filePath) throws IOException;
17 |
18 | /**
19 | * Weave single class to byte array
20 | */
21 | byte[] weaveSingleClassToByteArray(int jarId, InputStream inputStream) throws IOException;
22 |
23 |
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/autoservice/src/main/groovy/chao/android/gradle/servicepool/hunter/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * copy form git@github.com:Leaking/Hunter.git
4 | *
5 | */
6 |
7 | package chao.android.gradle.servicepool.hunter;
8 |
--------------------------------------------------------------------------------
/autoservice/src/main/resources/META-INF/gradle-plugins/sp.autoservice.properties:
--------------------------------------------------------------------------------
1 | implementation-class=chao.android.gradle.servicepool.compiler.AutoServicePlugin
2 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | apply plugin: "abkit"
4 |
5 | abkit {
6 | abVersion { // 统一管理Android的版本号
7 | compileSdkVersion 29
8 | buildToolsVersion "29.0.3"
9 | minSdkVersion 21
10 | targetSdkVersion 29
11 | force = true // force为true表示强制所有模块使用这里的版本号,false会以各个模块定义版本号为准,没有定义才会取这里的版本号
12 | }
13 | }
14 |
15 | buildscript {
16 |
17 | repositories {
18 | maven { url 'http://maven.aliyun.com/nexus/content/groups/public/'}
19 | maven { url "https://maven.aliyun.com/repository/central"}
20 | mavenCentral()
21 | google()
22 | mavenLocal()
23 | }
24 | dependencies {
25 | classpath 'com.android.tools.build:gradle:3.5.4'
26 | classpath "io.github.luqinx:abkit:0.0.1"
27 | classpath 'io.github.luqinx:autoservice:1.8.0-LOCAL'
28 | // classpath project(':autoservice')
29 | classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0'
30 | // NOTE: Do not place your application dependencies here; they belong
31 | // in the individual module build.gradle files
32 | }
33 | }
34 |
35 | allprojects {
36 | repositories {
37 | mavenCentral()
38 | // maven { url 'http://maven.aliyun.com/nexus/content/groups/public/'}
39 | maven { url "https://maven.aliyun.com/repository/central"}
40 | google()
41 | mavenLocal()
42 | }
43 | }
44 |
45 | task clean(type: Delete) {
46 | delete rootProject.buildDir
47 | }
48 |
--------------------------------------------------------------------------------
/buildSrc/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/buildSrc/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'groovy'
2 |
3 | dependencies {
4 | implementation gradleApi()
5 | implementation localGroovy()
6 | implementation 'com.android.tools.build:gradle:3.6.4'
7 | implementation 'com.android.tools.build:gradle-api:3.6.4'
8 | implementation 'org.ow2.asm:asm:7.0'
9 | implementation 'org.ow2.asm:asm-util:7.0'
10 | implementation 'org.ow2.asm:asm-commons:7.0'
11 | }
12 |
13 |
14 |
15 | repositories {
16 | maven { url 'http://maven.aliyun.com/nexus/content/groups/public/'}
17 | maven { url "https://maven.aliyun.com/repository/central"}
18 | mavenCentral()
19 | google()
20 | }
21 |
22 | sourceCompatibility = '1.8'
23 | targetCompatibility = '1.8'
24 |
--------------------------------------------------------------------------------
/changelog.md:
--------------------------------------------------------------------------------
1 | #changelog
2 |
3 | 1.5.5
4 | 1. 优化sp初始化机制,提升初始化效率
5 | 2. 严格区分getService, getFixedService
6 | 3. autoservice兼容gradle6.0
7 | 4. Android组件初始化增加按优先级顺序初始化
8 | 5. 修复一些bug
9 |
10 | 1.5.0
11 | 1. scope增加Soft, 对应Weak
12 | 2. 命名规范, SP -> Sp, SPA -> Spa
13 | 3. 增加混淆配置
14 | 4. 其他优化
15 |
16 | 1.4.0
17 | 1. 版本规范化、名称规范化
18 | 2. scope增加custom类型, 支持开发者自定义scope
19 | 3. 增加disableIntercept属性, 支持禁用service方法调用拦截
20 | 4. 扩大scope, priority取值范围
21 |
22 | 1.3.6
23 | 1. 新增sprouter模块, 扩展路由能力
24 | 2. 新增sprpc模块, 增加rpc能力
25 | 3. 修复已知问题
26 |
27 | 1.2.1
28 | 1. service方法调用过程增加同步拦截
29 | 2. 新增getFixedService方法,通过class获取该class的实例,而不会是class的子类实例
30 | 3. @Service支持inherited属性, inherited属性为true时,
31 | 他的所有子类都会被当做一个Service
32 | 4. 修复@Service注解处理Field字段生成注入对象时机不准确问题
33 | 5. 修复@Service会对Field进行重复多次注入问题
34 | 6. 其他一些优化
35 |
--------------------------------------------------------------------------------
/debug.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #./gradlew buildDebug -xlint -xtest --stacktrace -Dorg.gradle.debug=true
4 | ./gradlew clean && ./gradlew :app:assembleDebug -xlint -xtest --stacktrace -Dorg.gradle.daemon=false -Dorg.gradle.debug=true
5 | #./gradlew clean && ./gradlew :app:assembleDebug -Dorg.gradle.debug=true
6 |
--------------------------------------------------------------------------------
/empty.gradle:
--------------------------------------------------------------------------------
1 |
2 |
3 | //module("app").project(":app").include()
--------------------------------------------------------------------------------
/empty/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/empty/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 |
3 | dependencies {
4 | implementation fileTree(dir: 'libs', include: ['*.jar'])
5 | }
6 |
7 | sourceCompatibility = "7"
8 | targetCompatibility = "7"
9 |
10 |
11 | abkit {
12 | maven {
13 | groupId "chao.java.tools"
14 | artifactId "empty"
15 | versionName "1.0.0"
16 | }
17 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | android.enableJetifier=true
10 | android.useAndroidX=true
11 | org.gradle.jvmargs=-Xmx1536m
12 | # When configured, Gradle will run in incubating parallel mode.
13 | # This option should only be used with decoupled projects. More details, visit
14 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
15 | # org.gradle.parallel=true
16 |
17 |
18 | #org.gradle.debug=true
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luqinx/sp/8cc0a51d878381d6530ffd89d410e70d282aade3/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Jul 10 15:27:33 CST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/modules.gradle:
--------------------------------------------------------------------------------
1 | /** modules.gradle是ABKit插件提供的能力, 如果您喜欢这种组件管理方式,可以到https://github.com/luqinx/abkit了解他 **/
2 | /** ABKit管理模块的方式和Gradle本身的模块管理方式完全兼容, 接入的话不用担心改造成本 **/
3 |
4 | include ':app'
5 | include ':tests:remoteexample', //module.gradle兼容settings.gradle的api
6 | ':tests:testremoteapi'
7 | include ':autoservice'
8 |
9 | module("sp") //首先定义名称,每个模块直接依赖这个名称即可 --> implementation servicepool
10 | .remote("io.github.luqinx:sp:1.9.0") // 定义远程aar, 即使其他组件或aar包依赖了其他的版本的sp, sp最终的版本号一定会是这里指定的版本号
11 | .project(':sp') //定义project
12 | // .include() //include表示使用project, 不调用include表示使用remote远程仓库对应的aar
13 | // .disabled() //禁用这个模块, 在这里禁用,引用servicepool的模块不需要在dependencies里将"implementation servicepool"删除
14 | // .enabledByProperty("p1") // 通过gradle.properties, local.properties等属性文件中的属性是否为true|1来启用一个组件
15 | // .disabledByProperty("p2") // 通过gradle.properties, local.properties等属性文件中的属性是否为true|1来禁用一个组件
16 |
17 | module("spa")
18 | .remote("io.github.luqinx:spa:1.9.0")
19 | .project(':spa')
20 | // .include()
21 |
22 | module("sprouter")
23 | .remote("io.github.luqinx:sprouter:1.7.0")
24 | .project(":sprouter")
25 | .include()
26 |
27 | // Deprecated
28 | module("sprpc")
29 | .remote("io.github.luqinx:sprpc:1.0.0")
30 | .project(":sprpc")
31 | .include()
32 |
33 |
34 |
35 | module("A").project(":tests:applib1").include()
36 | module("B").project(":tests:applib2").include()
37 | module("pool").project(":tests:pool").include()
38 | module("appservice").project(":tests:appservice").include()
39 | module("testpluginlib").project(":tests:testpluginlib").include()
40 | module("pool").project(":tests:pool").include()
41 |
42 |
43 |
44 | module("ami").remote("io.github.luqinx:ami:0.0.1")
45 | module("interceptor").remote("io.github.luqinx:interceptor:0.0.3")
46 | module("guava").remote("com.google.guava:guava:19.0")
47 | module("gson").remote("com.google.code.gson:gson:2.8.5")
48 |
--------------------------------------------------------------------------------
/release.keystore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luqinx/sp/8cc0a51d878381d6530ffd89d410e70d282aade3/release.keystore
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenLocal()
4 | mavenCentral()
5 | google()
6 | maven { url 'http://maven.aliyun.com/nexus/content/groups/public/'}
7 | }
8 |
9 | dependencies {
10 | classpath 'io.github.luqinx:abkit:0.0.1'
11 | }
12 | }
13 |
14 | /** 使用ABKit将依赖管理转移到modules.gradle **/
15 | /** ABKit可以将模块管理统一聚合到modules.gradle中 **/
16 | import chao.android.gradle.plugin.api.ABKit
17 | ABKit.inject(getSettings(), getGradle())
--------------------------------------------------------------------------------
/sp/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sp/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 | apply plugin: 'maven'
3 | apply plugin: 'jacoco'
4 |
5 | apply from: '../maven.gradle'
6 |
7 |
8 | dependencies {
9 | implementation fileTree(dir: 'libs', include: ['*.jar'])
10 | testImplementation "junit:junit:4.12"
11 | // testImplementation "chao.android.tools:testsuit:0.0.1.dev1"
12 | implementation interceptor
13 | // implementation "net.bytebuddy:byte-buddy:1.10.14"
14 |
15 | implementation gson
16 | }
17 |
18 | //abkit {
19 | // maven {
20 | // artifactId 'sp'
21 | // groupId 'chao.java.tools'
22 | // versionName '1.5.5'
23 | // publish2Local false
24 | // }
25 | //}
26 |
27 |
28 | sourceCompatibility = "7"
29 | targetCompatibility = "7"
30 |
31 | jacocoTestReport {
32 | reports {
33 | xml.enabled false
34 | html.enabled true
35 | }
36 | }
37 |
38 | check.dependsOn jacocoTestReport
--------------------------------------------------------------------------------
/sp/gradle.properties:
--------------------------------------------------------------------------------
1 | GROUP_ID=io.github.luqinx
2 | # POM文件中指向你网站的地址
3 | POM_URL=https://github.com/luqinx
4 | POM_DESCRIPTION="advance SPI for java"
5 | # SCM是指版本管理工具,一下说他的相关信息
6 | POM_SCM_URL=https://github.com/
7 | POM_SCM_CONNECTION=https://github.com/luqinx
8 | POM_SCM_DEV_CONNECTION=https://github.com/luqinx
9 | # 你的开放协议相关信息
10 | POM_LICENCE_NAME= Apache License Version 2.0
11 | POM_LICENCE_URL= https://github.com/luqinx/abkit/blob/master/LICENSE
12 | POM_LICENCE_DIST=Apache License Version 2.0
13 | # 开发者的相关信息
14 | POM_DEVELOPER_ID=luqinx
15 | POM_DEVELOPER_NAME=luqinx
16 | POM_DEVELOPER_EMAIL=qch5240@163.com
17 |
18 | POM_PACKAGING=jar
19 | VERSION_NAME=1.9.0
20 | ARTIFACT_ID=sp
21 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/AbsInitServiceManager.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * @author luqin
8 | * @since 2019-09-17
9 | */
10 | public abstract class AbsInitServiceManager extends DefaultService implements InitServiceManager {
11 |
12 | private List> initServices;
13 |
14 | public AbsInitServiceManager() {
15 | initServices = new ArrayList<>();
16 | }
17 |
18 | @Override
19 | public void addInitService(Class extends IInitService> initService) {
20 | initServices.add(initService);
21 | }
22 |
23 | @Override
24 | public void initService() {
25 | for (Class extends IInitService> clazz: initServices) {
26 | //getService会唤起Service的init
27 | ServicePool.getFixedServiceOrNull(clazz);
28 | }
29 | }
30 |
31 | @Override
32 | public int scope() {
33 | return Scope.once;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/BuildInServiceLoader.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | *
8 | * chao.java.tools.servicepool.gen.ServiceFactoriesInstance
9 | * chao.java.tools.servicepool.gen.InitServiceManagerInstance
10 | * chao.java.tools.servicepool.gen.PathServicesInstance
11 | * chao.android.tools.servicepool.AndroidNoOpInstantiator
12 | *
13 | * @author luqin
14 | * @since 2020/9/6
15 | */
16 | public class BuildInServiceLoader implements IServiceLoader {
17 |
18 | private List> services;
19 |
20 | public BuildInServiceLoader() {
21 | services = new ArrayList<>();
22 |
23 | try {
24 | services.add(Class.forName("chao.java.tools.servicepool.gen.PathServicesInstance").asSubclass(IService.class));
25 | services.add(Class.forName("chao.java.tools.servicepool.gen.ServiceFactoriesInstance").asSubclass(IService.class));
26 | services.add(Class.forName("chao.java.tools.servicepool.gen.InitServiceManagerInstance").asSubclass(IService.class));
27 | } catch (ClassNotFoundException e) {
28 | throw new ServicePoolException("build in services not found.", e);
29 | }
30 | }
31 |
32 | @Override
33 | public Iterable> getServices() {
34 | return services;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/ClassTypeAdapter.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | import com.google.gson.TypeAdapter;
4 | import com.google.gson.stream.JsonReader;
5 | import com.google.gson.stream.JsonWriter;
6 |
7 | import java.io.IOException;
8 |
9 | /**
10 | * @author luqin
11 | * @since 2020-07-24
12 | */
13 | public class ClassTypeAdapter extends TypeAdapter {
14 | @Override
15 | public void write(JsonWriter out, Class value) throws IOException {
16 | out.value(value.getName());
17 | }
18 |
19 | @Override
20 | public Class read(JsonReader in) throws IOException {
21 | Class clazz = Object.class;
22 | if (in.hasNext()) {
23 | String nextName = in.nextString();
24 | switch (nextName) {
25 | case "int":
26 | clazz = int.class;
27 | break;
28 | case "boolean":
29 | clazz = boolean.class;
30 | break;
31 | case "short":
32 | clazz = short.class;
33 | break;
34 | case "byte":
35 | clazz = byte.class;
36 | break;
37 | case "long":
38 | clazz = long.class;
39 | break;
40 | case "float":
41 | clazz = float.class;
42 | break;
43 | case "double":
44 | clazz = double.class;
45 | break;
46 | default:
47 | try {
48 | clazz = Class.forName(nextName);
49 | } catch (ClassNotFoundException e) {
50 | e.printStackTrace();
51 | }
52 | break;
53 | }
54 | }
55 | return clazz;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/Constant.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | /**
4 | * @author qinchao
5 | * @since 2019/4/30
6 | */
7 | public interface Constant {
8 |
9 | interface initState {
10 | int UNINIT = 0;
11 | int TRYING = 1;
12 | int INITING = 2;
13 | int INITED = 3;
14 | int FAILED = 4;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/DefaultInitService.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | /**
4 | * @author qinchao
5 | * @since 2019/4/30
6 | */
7 | public class DefaultInitService extends DefaultService implements IInitService {
8 |
9 | @Override
10 | public void onInit() {
11 |
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/DefaultService.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 |
4 | /**
5 | * @author qinchao
6 | * @since 2019/5/1
7 | */
8 | public class DefaultService implements IService {
9 | public String path() {
10 | return getClass().getName();
11 | }
12 |
13 | public int priority() {
14 | return IService.Priority.NORMAL_PRIORITY;
15 | }
16 |
17 | public int scope() {
18 | return Scope.once;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/DependencyManager.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * @author qinchao
7 | * @since 2019/4/30
8 | */
9 | public interface DependencyManager extends IService {
10 | // void addService(IInitService service);
11 | //
12 | // void servicesInit();
13 |
14 | void tryInitService(IInitService service, List> dependencies, boolean async);
15 | }
16 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/ExceptionHandler.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | /**
4 | * @author luqin
5 | * @since 2019-08-20
6 | */
7 | public interface ExceptionHandler {
8 | void onException(Throwable e, String message);
9 | }
10 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/IInitService.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | /**
4 | * InitService默认scope为global
5 | */
6 | public interface IInitService extends IService {
7 | void onInit();
8 | }
9 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/ILogger.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | /**
4 | * @author luqin
5 | * @since 2019-08-06
6 | */
7 | public interface ILogger extends IService {
8 | void e(String tag, String message);
9 | void w(String tag, String message);
10 | void d(String tag, String message);
11 | void i(String tag, String message);
12 | void v(String tag, String message);
13 | void log(Object... messages);
14 | void method();
15 | }
16 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/IPathService.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | /**
4 | * 实现类由插件AutoService生成
5 | *
6 | * chao/java/tools/servicepool/gen/PathServicesInstance
7 | *
8 | *
9 | * @author luqin
10 | * @since 2019-09-26
11 | */
12 | public interface IPathService extends IService {
13 |
14 | void put(String path, Class extends IService> service);
15 |
16 | Class extends IService> get(String path);
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/IService.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | /**
4 | * @author qinchao
5 | * @since 2019/5/1
6 | */
7 | public interface IService {
8 |
9 | // String path();
10 | //
11 | // int priority();
12 | //
13 | // int scope();
14 |
15 |
16 | /**
17 | * 优先级范围 0-5
18 | * 服务优先级,优先级数值越大优先级越高, 优先级最低是0
19 | */
20 | @Deprecated
21 | interface Priority {
22 | /**
23 | * 低优先级
24 | *
25 | * @deprecated by {@link ServicePool#MIN_PRIORITY}
26 | */
27 | @Deprecated
28 | int MIN_PRIORITY = 0;
29 |
30 | /**
31 | * 普通优先级, 默认
32 | *
33 | * @deprecated by {@link ServicePool#NORMAL_PRIORITY}
34 | */
35 | @Deprecated
36 | int NORMAL_PRIORITY = 3;
37 |
38 | /**
39 | * 高优先级
40 | *
41 | * @deprecated by {@link ServicePool#MAX_PRIORITY}
42 | */
43 | @Deprecated
44 | int MAX_PRIORITY = 5;
45 | }
46 |
47 | /**
48 | * 服务缓存周期
49 | */
50 | @Deprecated
51 | interface Scope {
52 | /**
53 | * 全局缓存, 创建后不会被回收,直到进程结束
54 | *
55 | * @deprecated by {@link ServicePool#SCOPE_GLOBAL}
56 | */
57 | @Deprecated
58 | int global = Sp.SCOPE_GLOBAL;
59 |
60 | /**
61 | * 临时缓存, 只要不被gc回收,服务对象一直存在
62 | * 如果被gc回收, 则重新创建
63 | * @deprecated by {@link ServicePool#SCOPE_WEAK}
64 | */
65 | @Deprecated
66 | int temp = Sp.SCOPE_WEAK;
67 |
68 | /**
69 | * 不会缓存, 每次获取都会重新创建
70 | *
71 | * 默认Scope
72 | * @deprecated by {@link ServicePool#SCOPE_ONCE}
73 | */
74 | @Deprecated
75 | int once = Sp.SCOPE_ONCE;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/IServiceFactories.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | /**
4 | * 实现类由插件AutoService生成:
5 | *
6 | * chao/java/tools/servicepool/gen/ServiceFactoriesInstance
7 | *
8 | * @author luqin
9 | * @since 2019-07-13
10 | */
11 | public interface IServiceFactories extends IService {
12 | void addFactory(String pkgName, IServiceFactory serviceFactory);
13 |
14 | IServiceFactory getServiceFactory(String packageName);
15 | }
16 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/IServiceFactory.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | import java.util.HashSet;
4 |
5 | /**
6 | * @author qinchao
7 | * @since 2019/5/4
8 | *
9 | */
10 | public interface IServiceFactory {
11 |
12 | HashSet createServiceProxies(Class> clazz);
13 |
14 | ServiceProxy extends IService> createFixedServiceProxy(Class> clazz);
15 |
16 | ServiceProxy extends IService> createServiceProxy(Class> clazz);
17 |
18 | IService createInstance(Class> clazz);
19 | }
20 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/IServiceInterceptor.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | import java.lang.reflect.Method;
4 |
5 | /**
6 | *
7 | * 拦截器
8 | *
9 | * @author luqin
10 | * @since 2020-07-12
11 | */
12 | public interface IServiceInterceptor extends IService {
13 | void intercept(Class extends IService> originClass, IService source, Method method, Object[] args, IServiceInterceptorCallback callback);
14 | }
15 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/IServiceInterceptorCallback.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | import java.lang.reflect.Method;
4 |
5 | /**
6 | *
7 | * 拦截器
8 | *
9 | * @author luqin
10 | * @since 2020-07-12
11 | */
12 | public interface IServiceInterceptorCallback {
13 |
14 | /**
15 | * @param method next method
16 | * 继续执行下一个拦截策略, 如果没有下一个拦截,执行源对象方法
17 | * @param args args
18 | */
19 | void onContinue(Method method, Object... args);
20 |
21 | /**
22 | * 拦截,并返回指定result
23 | *
24 | * @param result 拦截返回值
25 | */
26 | void onInterrupt(Object result);
27 | }
28 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/IServiceLoader.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | /**
4 | * @author luqin
5 | * @since 2020/9/6
6 | */
7 | public interface IServiceLoader extends IService {
8 |
9 | Iterable> getServices();
10 | }
11 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/IServices.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | /**
4 | * @author luqin
5 | * @since 2020-07-26
6 | */
7 | public interface IServices extends IService, Iterable {
8 | }
9 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/InitServiceManager.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | /**
4 | *
5 | * 实现类由插件AutoService生成
6 | *
7 | * chao/java/tools/servicepool/gen/InitServiceManagerInstance
8 | *
9 | *
10 | * InitService默认使用懒加载,但有的场景需要启动时直接加载
11 | *
12 | * 这里加载的是非懒加载的InitService (lazy=false)
13 | *
14 | * @author luqin
15 | * @since 2019-09-26
16 | */
17 | public interface InitServiceManager extends IService {
18 |
19 | void initService();
20 |
21 | void addInitService(Class extends IInitService> initService);
22 | }
23 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/InnerProxy.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | import chao.java.tools.servicepool.cache.Specific;
4 |
5 | /**
6 | * @author luqin
7 | * @since 2019-09-03
8 | */
9 | public class InnerProxy extends ServiceProxy {
10 |
11 | private T service;
12 |
13 | private Specific cacheStrategy;
14 |
15 | public InnerProxy(T service) {
16 | super((Class) service.getClass());
17 | this.service = service;
18 | cacheStrategy = new Specific<>(this.service);
19 | setOriginClass(service.getClass());
20 | }
21 |
22 | @Override
23 | public T getService() {
24 | return cacheStrategy.getService(getOriginClass(), getOriginClass());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/LazyHolder.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | /**
4 | * @author qinchao
5 | * @since 2023/2/5
6 | */
7 | class LazyHolder {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/NoOpConstructorArg.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | /**
4 | * @author qinchao
5 | * @since 2019/5/3
6 | */
7 | public class NoOpConstructorArg {
8 | }
9 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/NoOpInstance.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | /**
4 | * @author qinchao
5 | * @since 2019/5/1
6 | */
7 | public interface NoOpInstance {
8 | }
9 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/NoOpInstantiator.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | import java.lang.reflect.Constructor;
4 | import java.util.concurrent.atomic.AtomicInteger;
5 |
6 | /**
7 | * @author qinchao
8 | * @since 2019/6/19
9 | */
10 | public interface NoOpInstantiator extends IService{
11 | Class> make(Class clazz, Constructor> constructor, Object[] params, AtomicInteger noOpCount);
12 | }
13 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/PathServices.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | import java.util.Map;
4 | import java.util.concurrent.ConcurrentHashMap;
5 |
6 | /**
7 | * @author luqin
8 | * @since 2019-09-18
9 | */
10 | public abstract class PathServices extends DefaultService implements IPathService {
11 |
12 | private Map> pathServices;
13 |
14 | public PathServices() {
15 | pathServices = new ConcurrentHashMap<>();
16 | }
17 |
18 | @Override
19 | public void put(String path, Class extends IService> service) {
20 | pathServices.put(path, service);
21 | }
22 |
23 | @Override
24 | public Class extends IService> get(String path) {
25 | return pathServices.get(path);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/ReflectUtil.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | import java.lang.reflect.Constructor;
4 |
5 | /**
6 | * @author qinchao
7 | * @since 2019/5/5
8 | */
9 | public class ReflectUtil {
10 |
11 | public static T newInstance(Class serviceClass) {
12 | try {
13 | Constructor> constructor = serviceClass.getDeclaredConstructor();
14 | constructor.setAccessible(true);
15 | return serviceClass.cast(constructor.newInstance());
16 | } catch (Throwable e) {
17 | e.printStackTrace();
18 | }
19 | return null;
20 | }
21 |
22 | public static Object getDefaultValue(Class> type) {
23 | if (Number.class.isAssignableFrom(type)) {
24 | if (Float.class.isAssignableFrom(type)) {
25 | return 0.0f;
26 | } else if (Long.class.isAssignableFrom(type)) {
27 | return 0L;
28 | } else if (Short.class.isAssignableFrom(type)) {
29 | return (short) 0;
30 | } else if (Double.class.isAssignableFrom(type)) {
31 | return 0.0;
32 | }
33 | return 0;
34 | } else if (boolean.class.isAssignableFrom(type)) {
35 | return false;
36 | } else if (Object.class.isAssignableFrom(type)) {
37 | return null;
38 | }
39 | return 0;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/ServiceController.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | /**
4 | * @author qinchao
5 | * @since 2019/4/29
6 | */
7 | public interface ServiceController {
8 |
9 |
10 | T getFixedServiceByClass(Class t);
11 |
12 | T getServiceByClass(Class t);
13 |
14 | void loadFinished();
15 |
16 | ServiceProxy extends IService> getProxy(Class extends IService> clazz);
17 |
18 | void recycleService(Class> clazz);
19 | }
20 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/ServiceFactories.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | /**
7 | * @author luqin
8 | * @since 2019-07-13
9 | */
10 | public abstract class ServiceFactories implements IServiceFactories {
11 |
12 | private Map factories = new HashMap<>();
13 |
14 |
15 | @Override
16 | public void addFactory(String pkgName, IServiceFactory serviceFactory) {
17 | factories.put(pkgName, serviceFactory);
18 | }
19 |
20 | /**
21 | * service类的包名
22 | *
23 | * @param packageName 类的包名
24 | * @return IServiceFactory
25 | */
26 | @Override
27 | public IServiceFactory getServiceFactory(String packageName) {
28 | return factories.get(packageName);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/ServicePoolException.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | /**
4 | * @author qinchao
5 | * @since 2019/5/3
6 | */
7 | public class ServicePoolException extends RuntimeException {
8 |
9 | public ServicePoolException(String message) {
10 | super(message);
11 | }
12 |
13 | public ServicePoolException(String message, Throwable t) {
14 | super(message, t);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/ServiceThreadFactory.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | import java.util.concurrent.ThreadFactory;
4 | import java.util.concurrent.atomic.AtomicInteger;
5 |
6 | /**
7 | * @author qinchao
8 | * @since 2019/4/30
9 | */
10 | public class ServiceThreadFactory implements ThreadFactory {
11 |
12 | private final AtomicInteger mCount = new AtomicInteger(1);
13 |
14 | @Override
15 | public Thread newThread(Runnable runnable) {
16 | return new Thread(runnable, "servicepool-" + mCount.getAndIncrement());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/Sp.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool;
2 |
3 | /**
4 | *
5 | * Service Pool 别名
6 | *
7 | * @author luqin
8 | * @since 2020-08-06
9 | */
10 | public final class Sp extends ServicePool {
11 | }
12 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/annotation/Event.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * @author luqin
10 | * @since 2019-08-27
11 | */
12 | @Target({ElementType.TYPE, ElementType.FIELD})
13 | @Retention(RetentionPolicy.RUNTIME)
14 | public @interface Event {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/annotation/Init.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | import chao.java.tools.servicepool.IInitService;
9 | import chao.java.tools.servicepool.ServicePool;
10 | import chao.java.tools.servicepool.Sp;
11 |
12 | /**
13 | * @author luqin
14 | * @since 2019-08-05
15 | */
16 | @Target({ElementType.TYPE})
17 | @Retention(RetentionPolicy.RUNTIME)
18 | public @interface Init {
19 | /**
20 | * @return 是否异步初始化
21 | */
22 | boolean async() default false;
23 |
24 | /**
25 | * @return 是否懒加载模式, 默认懒加载
26 | *
27 | * 懒加载模式会在组件第一次被调用的时候初始化,否则
28 | * 在ServicePool.init()函数中执行初始化。
29 | *
30 | * {@link ServicePool#loadInitService()}
31 | *
32 | */
33 | boolean lazy() default true;
34 |
35 |
36 | int priority() default Sp.NORMAL_PRIORITY;
37 |
38 | /**
39 | * @return 依赖组件
40 | *
41 | * 如果有依赖组件,依赖组件先初始化后,本组件才开始初始化
42 | */
43 | Class extends IInitService>[] dependencies() default {};
44 | }
45 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/annotation/Service.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Repeatable;
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.lang.annotation.Target;
8 |
9 | import chao.java.tools.servicepool.ServicePool;
10 |
11 | /**
12 | * 标记一个类是一个服务类Service
13 | *
14 | * 通过 {@link chao.java.tools.servicepool.IServiceLoader} 加载,
15 | * 并通过 {@link chao.java.tools.servicepool.ServiceController} 缓存。
16 | *
17 | * RetentionPolicy.RUNTIME 说明:
18 | * 在和AutoService配合使用时,Service使用RetentionPolicy.Class就够了
19 | * 在不适用AutoService时,需要使用RetentionPolicy.RUNTIME来获取priority, scope, tag等信息
20 | *
21 | *
22 | * @author qinchao
23 | * @since 2019/6/21
24 | */
25 | @Target({ElementType.TYPE, ElementType.FIELD})
26 | @Retention(RetentionPolicy.RUNTIME)
27 | @Repeatable(Services.class)
28 | public @interface Service {
29 |
30 | /**
31 | * 服务优先级
32 | *
33 | * 当一个服务接口存在多个实现时, 可以通过优先级来指定使用哪个接口
34 | *
35 | *
36 | * @return priority
37 | */
38 | int priority() default ServicePool.NORMAL_PRIORITY;
39 |
40 | /**
41 | * 服务对象的缓存策略
42 | *
43 | *
44 | * @return scope
45 | */
46 | int scope() default ServicePool.SCOPE_ONCE;
47 |
48 | String path() default "";
49 |
50 | Class> value() default Void.class;
51 |
52 | /**
53 | * @return 当inherited为true时, 被Service标记的类的子类也会被当做一个Service
54 | */
55 | boolean inherited() default false;
56 |
57 | boolean disableIntercept() default false;
58 | }
59 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/annotation/Services.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Inherited;
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.lang.annotation.Target;
8 |
9 | /**
10 | *
11 | *
12 | * @author luqin
13 | * @since 2020-06-15
14 | */
15 | @Target(ElementType.TYPE)
16 | @Retention(RetentionPolicy.RUNTIME)
17 | public @interface Services {
18 | Service[] value();
19 | }
20 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/cache/Global.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.cache;
2 |
3 | import chao.java.tools.servicepool.IService;
4 | import chao.java.tools.servicepool.IServiceFactory;
5 | import chao.java.tools.servicepool.ReflectUtil;
6 |
7 | /**
8 | * 全局策略, 类似一个单例
9 | */
10 | public final class Global extends AbsServiceCacheStrategy {
11 |
12 | private T service;
13 |
14 | private IServiceFactory factory;
15 |
16 | public Global(IServiceFactory factory) {
17 | this.factory = factory;
18 | }
19 |
20 | @Override
21 | public T getService(Class serviceClass, Class originClass) {
22 | if (service == null) {
23 | synchronized (this) {
24 | if (service == null) {
25 | if (factory != null) {
26 | service = serviceClass.cast(factory.createInstance(serviceClass));
27 | } else {
28 | service = ReflectUtil.newInstance(serviceClass);
29 | }
30 | service = getProxyService(originClass, service);
31 | }
32 | }
33 | }
34 | return service;
35 | }
36 | }
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/cache/Once.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.cache;
2 |
3 | import chao.java.tools.servicepool.IService;
4 | import chao.java.tools.servicepool.IServiceFactory;
5 | import chao.java.tools.servicepool.ReflectUtil;
6 |
7 | /**
8 | * 每次获取时创建一个新的对象
9 | */
10 | public final class Once extends AbsServiceCacheStrategy {
11 |
12 | private IServiceFactory factory;
13 |
14 | public Once(IServiceFactory factory) {
15 | this.factory = factory;
16 | }
17 |
18 | @Override
19 | public T getService(Class serviceClass, Class originClass) {
20 | IService instance;
21 | if (factory != null) {
22 | instance = factory.createInstance(serviceClass);
23 | } else {
24 | instance = ReflectUtil.newInstance(serviceClass);
25 | }
26 | if (instance != null) {
27 | return getProxyService(originClass, serviceClass.cast(instance));
28 | }
29 | return null;
30 | }
31 | }
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/cache/ServiceCacheStrategy.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.cache;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * Service缓存策略
7 | *
8 | * @author qinchao
9 | * @since 2019/6/25
10 | */
11 | public interface ServiceCacheStrategy {
12 | T getService(Class serviceClass, Class originClass);
13 | }
14 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/cache/Soft.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.cache;
2 |
3 | import java.lang.ref.SoftReference;
4 | import java.lang.ref.WeakReference;
5 |
6 | import chao.java.tools.servicepool.IService;
7 | import chao.java.tools.servicepool.IServiceFactory;
8 | import chao.java.tools.servicepool.ReflectUtil;
9 |
10 | /**
11 | * 使用软引用
12 | *
13 | * 如果不被gc回收,则不会重新创建
14 | */
15 | public final class Soft extends AbsServiceCacheStrategy {
16 |
17 | private IServiceFactory factory;
18 |
19 | private SoftReference weakService;
20 |
21 | public Soft(IServiceFactory factory) {
22 | this.factory = factory;
23 | }
24 |
25 | @Override
26 | public T getService(Class serviceClass, Class originClass) {
27 | if (weakService == null || weakService.get() == null) {
28 | synchronized (this) {
29 | if (weakService == null || weakService.get() == null) {
30 |
31 | if (factory != null) {
32 | weakService = new SoftReference<>(serviceClass.cast(factory.createInstance(serviceClass)));
33 | } else {
34 | weakService = new SoftReference<>(ReflectUtil.newInstance(serviceClass));
35 | }
36 | }
37 | }
38 | }
39 | return getProxyService(originClass, weakService.get());
40 | }
41 | }
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/cache/Specific.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.cache;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * @author luqin
7 | * @since 2020-07-23
8 | */
9 | public final class Specific extends AbsServiceCacheStrategy {
10 |
11 | private T service;
12 |
13 | public Specific(T service) {
14 | this.service = service;
15 | }
16 |
17 | @Override
18 | public T getService(Class serviceClass, Class originClass) {
19 | return getProxyService(originClass, service);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/cache/Weak.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.cache;
2 |
3 | import java.lang.ref.WeakReference;
4 |
5 | import chao.java.tools.servicepool.IService;
6 | import chao.java.tools.servicepool.IServiceFactory;
7 | import chao.java.tools.servicepool.ReflectUtil;
8 |
9 | /**
10 | * 使用弱引用
11 | *
12 | * 如果不被gc回收,则不会重新创建
13 | */
14 | public final class Weak extends AbsServiceCacheStrategy {
15 |
16 | private IServiceFactory factory;
17 |
18 | private WeakReference weakService;
19 |
20 | public Weak(IServiceFactory factory) {
21 | this.factory = factory;
22 | }
23 |
24 | @Override
25 | public T getService(Class serviceClass, Class originClass) {
26 | if (weakService == null || weakService.get() == null) {
27 | synchronized (this) {
28 | if (weakService == null || weakService.get() == null) {
29 |
30 | if (factory != null) {
31 | weakService = new WeakReference<>(serviceClass.cast(factory.createInstance(serviceClass)));
32 | } else {
33 | weakService = new WeakReference<>(ReflectUtil.newInstance(serviceClass));
34 | }
35 | }
36 | }
37 | }
38 | return getProxyService(originClass, weakService.get());
39 | }
40 | }
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/cache/custom/Custom.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.cache.custom;
2 |
3 | import chao.java.tools.servicepool.IService;
4 | import chao.java.tools.servicepool.IServiceFactory;
5 | import chao.java.tools.servicepool.Sp;
6 | import chao.java.tools.servicepool.cache.AbsServiceCacheStrategy;
7 |
8 | /**
9 | * @author luqin
10 | * @since 2020-08-06
11 | */
12 | public final class Custom extends AbsServiceCacheStrategy {
13 |
14 | private final int customScope;
15 |
16 | private IServiceFactory factory;
17 |
18 | public Custom(int customScope, IServiceFactory factory) {
19 | this.factory = factory;
20 | this.customScope = customScope;
21 | }
22 |
23 | /**
24 | *
25 | * @param serviceClass 经过 {@link chao.java.tools.servicepool.ServicePool} 查找后的class
26 | *
27 | * @param originClass 对应 {@link chao.java.tools.servicepool.ServicePool#getService(Class)}方法的参数class
28 | *
29 | */
30 | @SuppressWarnings("unchecked")
31 | @Override
32 | public T getService(Class serviceClass, Class originClass) {
33 | CustomCacheStrategy customCache = Sp.getCombineService(CustomCacheStrategy.class, new CustomCombineStrategy(customScope));
34 | return getProxyService(originClass, customCache.getService(factory, originClass, serviceClass));
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/cache/custom/CustomCacheStrategy.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.cache.custom;
2 |
3 | import chao.java.tools.servicepool.IService;
4 | import chao.java.tools.servicepool.IServiceFactory;
5 |
6 | /**
7 | *
8 | *
9 | *
10 | *
11 | * @author luqin
12 | * @since 2020-08-06
13 | */
14 | public interface CustomCacheStrategy extends IService {
15 | T getService(IServiceFactory factory, Class originClass, Class serviceClass);
16 | }
17 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/cache/custom/CustomCombineStrategy.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.cache.custom;
2 |
3 | import java.lang.reflect.Method;
4 | import java.util.List;
5 |
6 | import chao.java.tools.servicepool.ServicePoolException;
7 | import chao.java.tools.servicepool.ServiceProxy;
8 | import chao.java.tools.servicepool.combine.CombineStrategy;
9 |
10 | /**
11 | * @author luqin
12 | * @since 2020-08-06
13 | */
14 | public class CustomCombineStrategy implements CombineStrategy {
15 |
16 | private int customScope;
17 |
18 | public CustomCombineStrategy(int customScope) {
19 | this.customScope = customScope;
20 | }
21 |
22 | @Override
23 | public boolean filter(Class serviceClass, Method method, Object[] args) {
24 | return CustomCacheStrategy.class.isAssignableFrom(serviceClass);
25 | }
26 |
27 | @Override
28 | public Object invoke(List proxies, Class serviceClass, Method method, Object[] args) {
29 |
30 | if (proxies.size() == 0) {
31 | return null;
32 | }
33 | //最多能有一个
34 | int count = 0;
35 | for (ServiceProxy proxy: proxies) {
36 | if (proxy.realScope() != customScope) {
37 | continue;
38 | }
39 | count++;
40 | if (count > 1) {
41 | throw new ServicePoolException("more than one custom cache strategy has the same customScope: " + customScope);
42 | }
43 | try {
44 | return method.invoke(proxy.getService(), args);
45 | } catch (Throwable e) {
46 | e.printStackTrace();
47 | }
48 | }
49 | return null;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/combine/CombineCallback.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.combine;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * @author luqin
7 | * @since 2019-09-30
8 | */
9 | public interface CombineCallback {
10 | void onContinue(T t);
11 | void onUserInterrupt(T t, IService service);
12 | void onInterrupt(T t, Throwable e);
13 | }
14 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/combine/CombineEmptyHandler.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.combine;
2 |
3 | import java.lang.reflect.Method;
4 |
5 | /**
6 | * @author luqin
7 | * @since 2020-07-31
8 | */
9 | public interface CombineEmptyHandler {
10 | void onHandleEmpty(T source, Method method, Object[] args);
11 | }
12 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/combine/CombineService.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.combine;
2 |
3 |
4 | /**
5 | * @author luqin
6 | * @since 2019-09-30
7 | */
8 | public interface CombineService extends Iterable {
9 | int size();
10 |
11 | T get(int index);
12 |
13 | T setEmptyHandler(CombineEmptyHandler handler);
14 | }
15 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/combine/CombineStrategy.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.combine;
2 |
3 | import java.lang.reflect.Method;
4 | import java.util.List;
5 |
6 | import chao.java.tools.servicepool.IService;
7 | import chao.java.tools.servicepool.ServiceProxy;
8 |
9 | /**
10 | * @author luqin
11 | * @since 2019-10-08
12 | */
13 | public interface CombineStrategy extends IService {
14 | /**
15 | *
16 | * @param serviceClass class
17 | * @param method method
18 | * @param args args
19 | * @return 过滤器
20 | *
21 | * 可以通过过滤器过滤当前策略对哪些service生效
22 | *
23 | */
24 | boolean filter(Class serviceClass, Method method, Object[] args);
25 |
26 | /**
27 | * CombineService 服务组执行方式的策略
28 | *
29 | * @param proxies service组的代理, 已经根据优先级排序
30 | * @param serviceClass service类
31 | * @param method 将执行的方法
32 | * @param args 执行方法的参数
33 | *
34 | * @return 处理完成返回true, 否则返回false
35 | */
36 | Object invoke(List proxies, Class serviceClass, Method method, Object[] args);
37 | }
38 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/combine/CombineThreadExecutor.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.combine;
2 |
3 | import java.util.concurrent.ArrayBlockingQueue;
4 | import java.util.concurrent.ThreadPoolExecutor;
5 | import java.util.concurrent.TimeUnit;
6 |
7 | /**
8 | * @author luqin
9 | * @since 2019-10-08
10 | */
11 | public class CombineThreadExecutor extends ThreadPoolExecutor {
12 |
13 | private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
14 | private static final int INIT_THREAD_COUNT = CPU_COUNT + 1;
15 | private static final int MAX_THREAD_COUNT = INIT_THREAD_COUNT;
16 | private static final long SURPLUS_THREAD_LIFE = 30L;
17 |
18 | public CombineThreadExecutor() {
19 | super(INIT_THREAD_COUNT, MAX_THREAD_COUNT, SURPLUS_THREAD_LIFE, TimeUnit.SECONDS, new ArrayBlockingQueue(64), new CombineThreadFactory());
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/combine/CombineThreadFactory.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.combine;
2 |
3 | import java.util.concurrent.ThreadFactory;
4 | import java.util.concurrent.atomic.AtomicInteger;
5 |
6 | import chao.java.tools.servicepool.ILogger;
7 | import chao.java.tools.servicepool.Logger;
8 |
9 | /**
10 | * @author luqin
11 | * @since 2019-10-08
12 | */
13 | public class CombineThreadFactory implements ThreadFactory {
14 |
15 | private static final AtomicInteger poolNumber = new AtomicInteger(1);
16 |
17 | private final AtomicInteger threadNumber = new AtomicInteger(1);
18 |
19 | private final String namePrefix;
20 |
21 | private final ThreadGroup group;
22 |
23 | private ILogger logger = new Logger();
24 |
25 | public CombineThreadFactory() {
26 | SecurityManager s = System.getSecurityManager();
27 | group = (s != null) ? s.getThreadGroup() :
28 | Thread.currentThread().getThreadGroup();
29 | namePrefix = "Combine task pool No." + poolNumber.getAndIncrement() + ", thread No.";
30 | }
31 |
32 | @Override
33 | public Thread newThread(Runnable runnable) {
34 | String threadName = namePrefix + threadNumber.getAndIncrement();
35 | Thread thread = new Thread(group, runnable, threadName, 0);
36 | if (thread.isDaemon()) { //设为非后台线程
37 | thread.setDaemon(false);
38 | }
39 | if (thread.getPriority() != Thread.NORM_PRIORITY) { //优先级为normal
40 | thread.setPriority(Thread.NORM_PRIORITY);
41 | }
42 |
43 | // 捕获多线程处理中的异常
44 | thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
45 | @Override
46 | public void uncaughtException(Thread thread, Throwable ex) {
47 | logger.log( "Combine Running task appeared exception! Thread [" + thread.getName() + "], because [" + ex.getMessage() + "]");
48 | }
49 | });
50 | return thread;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/combine/DefaultCombineStrategy.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.combine;
2 |
3 | import java.lang.reflect.Method;
4 | import java.util.List;
5 |
6 | import chao.java.tools.servicepool.ServicePoolException;
7 | import chao.java.tools.servicepool.ServiceProxy;
8 |
9 | /**
10 | * @author luqin
11 | * @since 2020-07-26
12 | */
13 | public class DefaultCombineStrategy implements CombineStrategy {
14 | @Override
15 | public boolean filter(Class serviceClass, Method method, Object[] args) {
16 | return true;
17 | }
18 |
19 | @Override
20 | public Object invoke(List proxies, Class serviceClass, Method method, Object[] args) {
21 | Object result = null;
22 | for (ServiceProxy proxy: proxies) {
23 | try {
24 | result = method.invoke(proxy.getService(), args);
25 | } catch (Throwable e) {
26 | throw new ServicePoolException(e.getMessage(), e);
27 | }
28 | }
29 | return result;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/debug/Debug.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.debug;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * @author luqin
8 | * @since 2019-08-26
9 | */
10 | public class Debug {
11 |
12 | private static List errors = new ArrayList<>();
13 |
14 | private static List throwables = new ArrayList<>();
15 |
16 | public static void addError(String err) {
17 | if (err != null && err.length() != 0) {
18 | errors.add(err);
19 | }
20 | }
21 |
22 | public static void addThrowable(Throwable e) {
23 | if (e != null) {
24 | throwables.add(e);
25 | }
26 | }
27 |
28 | public static List throwables() {
29 | return throwables;
30 | }
31 |
32 | public static List errors() {
33 | return errors;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/event/EventService.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.event;
2 |
3 | /**
4 | * @author luqin
5 | * @since 2019-08-27
6 | */
7 | public interface EventService {
8 | }
9 |
--------------------------------------------------------------------------------
/sp/src/main/java/chao/java/tools/servicepool/thirdparty/CancelableCountDownLatch.java:
--------------------------------------------------------------------------------
1 | package chao.java.tools.servicepool.thirdparty;
2 |
3 | import java.util.concurrent.CountDownLatch;
4 |
5 | /**
6 | * As its name.
7 | *
8 | * @author Alex Contact me.
9 | * @version 1.0
10 | * @since 16/8/29 15:48
11 | */
12 | public class CancelableCountDownLatch extends CountDownLatch {
13 | /**
14 | * Constructs a {@code CountDownLatch} initialized with the given count.
15 | *
16 | * @param count the number of times {@link #countDown} must be invoked
17 | * before threads can pass through {@link #await}
18 | * @throws IllegalArgumentException if {@code count} is negative
19 | */
20 | public CancelableCountDownLatch(int count) {
21 | super(count);
22 | }
23 |
24 | public void cancel() {
25 | while (getCount() > 0) {
26 | countDown();
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/NoOpInstanceFactoryForTest.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop;
2 |
3 |
4 | import chao.java.tools.servicepool.NoOpInstanceFactory;
5 |
6 | /**
7 | * @author qinchao
8 | * @since 2019/5/5
9 | */
10 | public class NoOpInstanceFactoryForTest extends NoOpInstanceFactory {
11 |
12 | @Override
13 | public T newInstance(Class clazz) {
14 | return super.newInstance(clazz);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/TestNoOpObject.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop;
2 |
3 | /**
4 | * @author qinchao
5 | * @since 2019/5/5
6 | */
7 | public class TestNoOpObject {
8 | }
9 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/DependencyTest.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test;
2 |
3 | import chao.java.tools.servicepool.ServicePool;
4 | import org.junit.Before;
5 | import org.junit.Test;
6 |
7 | /**
8 | * @author qinchao
9 | * @since 2019/4/30
10 | */
11 | public class DependencyTest {
12 |
13 | @Before
14 | public void init() {
15 | ServicePool.loadServices();
16 | }
17 |
18 | @Test
19 | public void testDependency() {
20 |
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/NoOpTest.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test;
2 |
3 | import chao.java.tools.servicepool.NoOpInstance;
4 | import chao.java.tools.servicepool.ServicePool;
5 | import chao.test.servicepool.test.noop.test.service.NoOp;
6 | import chao.test.servicepool.test.noop.test.service.TestNoOpService;
7 | import com.android.tools.testsuit.internal.SampleCase;
8 | import org.junit.Before;
9 | import org.junit.Test;
10 |
11 | /**
12 | * @author qinchao
13 | * @since 2019/5/1
14 | */
15 | public class NoOpTest extends SampleCase {
16 |
17 | @Before
18 | public void init() {
19 | }
20 |
21 | @Test
22 | public void testNoOpClass() {
23 | assertInstanceOf(ServicePool.getService(TestNoOpService.class), NoOpInstance.class);
24 | System.out.println(ServicePool.getService(TestNoOpService.class));
25 |
26 | assertEquals(ServicePool.getService(TestNoOpService.class).hashCode(), 0);
27 | assertEquals(ServicePool.getService(TestNoOpService.class).getInteger(), new Integer(0));
28 | assertFalse(ServicePool.getService(TestNoOpService.class).equals(ServicePool.getService(TestNoOpService.class)));
29 | }
30 |
31 | @Test
32 | public void testNoOpInterface() {
33 |
34 | assertEquals(ServicePool.getService(TestNoOpService.class).hashCode(), 0);
35 | assertEquals(ServicePool.getService(TestNoOpService.class).getInteger(), new Integer(0));
36 | assertFalse(ServicePool.getService(TestNoOpService.class).equals(ServicePool.getService(TestNoOpService.class)));
37 |
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/SampleTest.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test;
2 |
3 | import chao.java.tools.servicepool.IService;
4 | import chao.java.tools.servicepool.IInitService;
5 | import java.util.Arrays;
6 | import org.junit.Test;
7 |
8 | /**
9 |
10 | * @author qinchao
11 | * @since 2019/5/1
12 | */
13 | public class SampleTest {
14 |
15 | @Test
16 | public void test() {
17 | System.out.println(Arrays.toString(IInitService.class.getInterfaces()));
18 |
19 | System.out.println(Arrays.toString(IService.class.getInterfaces()));
20 |
21 | System.out.println(Arrays.toString(IInitService.class.getGenericInterfaces()));
22 |
23 | System.out.println(Arrays.toString(IService.class.getGenericInterfaces()));
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/TestLazy.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test;
2 |
3 | import chao.java.tools.servicepool.NoOpInstance;
4 | import chao.java.tools.servicepool.ServicePool;
5 | import chao.test.servicepool.test.noop.test.service.TestLazyService;
6 | import chao.test.servicepool.test.noop.test.service.TestLazyService1;
7 | import chao.test.servicepool.test.noop.test.service.TestLazyService2;
8 | import com.android.tools.testsuit.internal.SampleCase;
9 | import org.junit.Before;
10 | import org.junit.Test;
11 |
12 | /**
13 | * @author qinchao
14 | * @since 2019/5/4
15 | */
16 | public class TestLazy extends SampleCase {
17 |
18 | @Before
19 | public void init() {
20 | ServicePool.loadServices();
21 | }
22 |
23 | @Test
24 | public void testGetLazyService() {
25 | assertNotInstanceOf(ServicePool.getService(TestLazyService.class), NoOpInstance.class);
26 |
27 | assertNotInstanceOf(ServicePool.getService(TestLazyService1.class), NoOpInstance.class);
28 |
29 | assertNotInstanceOf(ServicePool.getService(TestLazyService2.class), NoOpInstance.class);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/TestOpInstanceFactory.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test;
2 |
3 | import chao.java.tools.servicepool.NoOpInstance;
4 | import chao.test.servicepool.test.noop.NoOpInstanceFactoryForTest;
5 | import chao.test.servicepool.test.noop.TestNoOpObject;
6 | import chao.test.servicepool.test.noop.test.noop.TestNoOpObjectWithArgumentsConstructor;
7 | import chao.test.servicepool.test.noop.test.noop.TestNoOpObjectWithDefaultConstructor;
8 | import chao.test.servicepool.test.noop.test.noop.TestNoOpObjectWithProtectedConstructor;
9 | import com.android.tools.testsuit.internal.SampleCase;
10 | import org.junit.Before;
11 | import org.junit.Test;
12 |
13 | /**
14 | * @author qinchao
15 | * @since 2019/5/5
16 | */
17 | public class TestOpInstanceFactory extends SampleCase {
18 |
19 | private NoOpInstanceFactoryForTest factory;
20 |
21 | @Before
22 | public void init() {
23 | factory = new NoOpInstanceFactoryForTest();
24 | }
25 |
26 | @Test
27 | public void testNewInstance() {
28 | assertInstanceOf(factory.newInstance(TestNoOpObject.class), NoOpInstance.class);
29 |
30 | assertInstanceOf(factory.newInstance(TestNoOpObjectWithDefaultConstructor.class), NoOpInstance.class);
31 |
32 | assertInstanceOf(factory.newInstance(TestNoOpObjectWithProtectedConstructor.class), NoOpInstance.class);
33 |
34 | assertInstanceOf(factory.newInstance(TestNoOpObjectWithArgumentsConstructor.class), NoOpInstance.class);
35 |
36 | // assertInstanceOf(factory.newInstance(TestNoOpObjectWithPrivateConstructor.class), NoOpInstance.class);
37 |
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/noop/TestNoOpObjectWithArgumentsConstructor.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test.noop;
2 |
3 | /**
4 | * @author qinchao
5 | * @since 2019/5/5
6 | */
7 | public class TestNoOpObjectWithArgumentsConstructor {
8 |
9 | private final Double db;
10 | private final Short s;
11 | private long l;
12 | private float f;
13 |
14 | public TestNoOpObjectWithArgumentsConstructor(int a, String b, boolean c, Object d, Long l, Float f, Short s, Double db) {
15 | this.f = f;
16 | this.l = l;
17 | this.s = s;
18 | this.db = db;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/noop/TestNoOpObjectWithDefaultConstructor.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test.noop;
2 |
3 | /**
4 | * @author qinchao
5 | * @since 2019/5/5
6 | */
7 | public class TestNoOpObjectWithDefaultConstructor {
8 |
9 | public TestNoOpObjectWithDefaultConstructor() {
10 |
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/noop/TestNoOpObjectWithPrivateConstructor.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test.noop;
2 |
3 | /**
4 | * @author qinchao
5 | * @since 2019/5/5
6 | */
7 | public class TestNoOpObjectWithPrivateConstructor {
8 |
9 | private TestNoOpObjectWithPrivateConstructor() {
10 |
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/noop/TestNoOpObjectWithProtectedConstructor.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test.noop;
2 |
3 | /**
4 | * @author qinchao
5 | * @since 2019/5/5
6 | */
7 | public class TestNoOpObjectWithProtectedConstructor {
8 |
9 | TestNoOpObjectWithProtectedConstructor() {
10 |
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/service/II.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test.service;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * @author qinchao
7 | * @since 2019/5/5
8 | */
9 | public interface II extends IService {
10 | }
11 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/service/IPrinter.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test.service;
2 |
3 | import chao.java.tools.servicepool.IInitService;
4 |
5 | /**
6 | * @author qinchao
7 | * @since 2019/4/30
8 | */
9 | public interface IPrinter extends IInitService {
10 |
11 | void setName(String name);
12 |
13 | void printName();
14 | }
15 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/service/NoOp.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test.service;
2 |
3 | /**
4 | * @author qinchao
5 | * @since 2019/5/5
6 | */
7 | public interface NoOp {
8 | }
9 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/service/NoPublicService.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test.service;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * @author qinchao
7 | * @since 2019/5/5
8 | */
9 | class NoPublicService implements IService {
10 |
11 | // public NoPublicService() {}
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/service/Printer.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test.service;
2 |
3 | /**
4 | * @author qinchao
5 | * @since 2019/4/30
6 | */
7 | public class Printer implements IPrinter {
8 |
9 | private String mName;
10 |
11 | @Override
12 | public void setName(String name) {
13 | mName = name;
14 | }
15 |
16 | @Override
17 | public void printName() {
18 | System.out.println("I'm " + mName);
19 | }
20 |
21 | @Override
22 | public void onInit() {
23 | try {
24 | Thread.sleep((long) (Math.random() * 3000));
25 | } catch (InterruptedException e) {
26 | e.printStackTrace();
27 | }
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/service/TestAbsImplService.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test.service;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * @author qinchao
7 | * @since 2019/5/5
8 | */
9 | public class TestAbsImplService extends TestAbsService implements IService, II {
10 | public String tag() {
11 | return null;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/service/TestAbsService.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test.service;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * @author qinchao
7 | * @since 2019/5/5
8 | */
9 | public abstract class TestAbsService implements IService {
10 | }
11 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/service/TestLazyService.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test.service;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * @author qinchao
7 | * @since 2019/5/4
8 | */
9 | public class TestLazyService implements IService {
10 | }
11 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/service/TestLazyService1.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test.service;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * @author qinchao
7 | * @since 2019/5/4
8 | */
9 | public class TestLazyService1 implements IService{
10 | }
11 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/service/TestLazyService2.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test.service;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * @author qinchao
7 | * @since 2019/5/4
8 | */
9 | public class TestLazyService2 implements IService {
10 | }
11 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/service/TestLazyServiceFactory.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test.service;
2 |
3 | import chao.java.tools.servicepool.IService;
4 | import chao.java.tools.servicepool.IServiceFactory;
5 | import chao.java.tools.servicepool.ServiceProxy;
6 |
7 | import java.util.HashSet;
8 |
9 | /**
10 | * @author qinchao
11 | * @since 2019/5/4
12 | */
13 | public class TestLazyServiceFactory implements IServiceFactory {
14 |
15 | @Override
16 | public HashSet createServiceProxies(Class> clazz) {
17 | return null;
18 | }
19 |
20 | @Override
21 | public ServiceProxy extends IService> createFixedServiceProxy(Class> clazz) {
22 | return null;
23 | }
24 |
25 | @Override
26 | public ServiceProxy extends IService> createServiceProxy(Class> clazz) {
27 | return null;
28 | }
29 |
30 | @Override
31 | public IService createInstance(Class> clazz) {
32 | return null;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/service/TestNoOpService.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test.service;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * @author qinchao
7 | * @since 2019/5/5
8 | */
9 | public class TestNoOpService implements NoOp, IService {
10 |
11 | public Integer getInteger() {
12 | return 10086;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/service/TestService.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test.service;
2 |
3 | import chao.java.tools.servicepool.DefaultInitService;
4 |
5 | /**
6 | * @author qinchao
7 | * @since 2019/4/29
8 | */
9 | public class TestService extends DefaultInitService {
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/service/TestService2.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test.service;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * @author qinchao
7 | * @since 2019/5/3
8 | */
9 | public class TestService2 implements IService {
10 | }
11 |
--------------------------------------------------------------------------------
/sp/src/test/java/chao/test/servicepool/test/noop/test/service/TestWeakService.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.test.noop.test.service;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * @author qinchao
7 | * @since 2019/5/5
8 | */
9 | public class TestWeakService implements IService {
10 | }
11 |
--------------------------------------------------------------------------------
/sp/src/test/resources/META-INF/services/chao.java.tools.servicepool.IService:
--------------------------------------------------------------------------------
1 | chao.test.servicepool.test.noop.test.service.TestService
2 | chao.test.servicepool.test.noop.test.service.TestService2
3 | chao.test.servicepool.test.noop.test.service.TestLazyService
4 | chao.test.servicepool.test.noop.test.service.NoPublicService
5 | chao.test.servicepool.test.noop.test.service.TestAbsImplService
6 |
7 |
--------------------------------------------------------------------------------
/sp/src/test/resources/META-INF/services/chao.java.tools.servicepool.IServiceFactory:
--------------------------------------------------------------------------------
1 | chao.test.servicepool.test.noop.test.service.TestLazyServiceFactory
--------------------------------------------------------------------------------
/sp/src/test/resources/META-INF/services/com.aicaigroup.servicepool.DependencyManager:
--------------------------------------------------------------------------------
1 | chao.test.servicepool.test.service.TestDependencyManager
--------------------------------------------------------------------------------
/spa/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/spa/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'maven'
3 |
4 | apply from: '../maven.gradle'
5 |
6 |
7 | android {
8 | compileSdkVersion 28
9 | defaultConfig {
10 | minSdkVersion 19
11 | targetSdkVersion 28
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
16 |
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(dir: 'libs', include: ['*.jar'])
30 |
31 | testImplementation 'junit:junit:4.12'
32 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
33 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
34 | api sp
35 | api interceptor
36 | // implementation ("net.bytebuddy:byte-buddy-android:1.10.14")
37 | // implementation "net.bytebuddy:byte-buddy-android:1.9.6"
38 | implementation gson
39 | }
40 |
--------------------------------------------------------------------------------
/spa/gradle.properties:
--------------------------------------------------------------------------------
1 | GROUP_ID=io.github.luqinx
2 | # POM文件中指向你网站的地址
3 | POM_URL=https://github.com/luqinx
4 | POM_DESCRIPTION="advance SPI for java"
5 | # SCM是指版本管理工具,一下说他的相关信息
6 | POM_SCM_URL=https://github.com/
7 | POM_SCM_CONNECTION=https://github.com/luqinx
8 | POM_SCM_DEV_CONNECTION=https://github.com/luqinx
9 | # 你的开放协议相关信息
10 | POM_LICENCE_NAME= Apache License Version 2.0
11 | POM_LICENCE_URL= https://github.com/luqinx/abkit/blob/master/LICENSE
12 | POM_LICENCE_DIST=Apache License Version 2.0
13 | # 开发者的相关信息
14 | POM_DEVELOPER_ID=luqinx
15 | POM_DEVELOPER_NAME=luqinx
16 | POM_DEVELOPER_EMAIL=qch5240@163.com
17 |
18 | POM_PACKAGING=aar
19 | VERSION_NAME=1.9.0
20 | ARTIFACT_ID=spa
21 |
--------------------------------------------------------------------------------
/spa/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
23 | -ignorewarnings
--------------------------------------------------------------------------------
/spa/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/spa/src/main/java/chao/android/tools/servicepool/Spa.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.servicepool;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.os.Handler;
6 | import android.os.Looper;
7 |
8 | import chao.java.tools.servicepool.ServicePool;
9 |
10 | /**
11 | *
12 | * service pool for android
13 | *
14 | * @author qinchao
15 | * @since 2019/6/19
16 | */
17 | public class Spa extends ServicePool {
18 |
19 | @SuppressLint("StaticFieldLeak")
20 | private static Context sContext;
21 |
22 | private static final Object initLock = new Object();
23 |
24 | private static volatile boolean sInited = false;
25 |
26 |
27 | public static Context getContext() {
28 | return sContext;
29 | }
30 |
31 | public static void init(Context context) {
32 | if (sInited) {
33 | return;
34 | }
35 | synchronized (initLock) {
36 | if (sInited) {
37 | return;
38 | }
39 | sContext = context.getApplicationContext();
40 | if (Looper.myLooper() != Looper.getMainLooper()) {
41 | Handler handler = new Handler(Looper.getMainLooper());
42 | handler.post(new Runnable() {
43 | @Override
44 | public void run() {
45 | loadInitService();
46 | }
47 | });
48 | } else {
49 | loadInitService();
50 | }
51 | checkLoader();
52 | sInited = true;
53 | }
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/spa/src/main/java/chao/android/tools/servicepool/init/AndroidInitService.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.servicepool.init;
2 |
3 | import android.content.Context;
4 |
5 | import chao.android.tools.servicepool.Spa;
6 | import chao.java.tools.servicepool.IInitService;
7 |
8 | /**
9 | * @author luqin
10 | * @since 2020/8/21
11 | */
12 | public abstract class AndroidInitService implements IInitService {
13 |
14 | @Override
15 | public void onInit() {
16 | onInit(Spa.getContext());
17 | }
18 |
19 | protected abstract void onInit(Context applicationContext);
20 | }
21 |
--------------------------------------------------------------------------------
/spa/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | servicepool_android
3 |
4 |
--------------------------------------------------------------------------------
/spa/src/test/java/chao/test/servicepool/android/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.android;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 |
6 | import android.content.Context;
7 | import androidx.test.platform.app.InstrumentationRegistry;
8 | import androidx.test.ext.junit.runners.AndroidJUnit4;
9 | import org.junit.Test;
10 | import org.junit.runner.RunWith;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("chao.test.servicepool.android.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spa/src/test/java/chao/test/servicepool/android/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package chao.test.servicepool.android;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 |
6 | import org.junit.Test;
7 |
8 | /**
9 | * Example local unit test, which will execute on the development machine (host).
10 | *
11 | * @see Testing documentation
12 | */
13 | public class ExampleUnitTest {
14 | @Test
15 | public void addition_isCorrect() {
16 | assertEquals(4, 2 + 2);
17 | }
18 | }
--------------------------------------------------------------------------------
/sprouter/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sprouter/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'maven'
3 |
4 | apply from: '../maven.gradle'
5 |
6 | android {
7 |
8 |
9 | defaultConfig {
10 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
11 | }
12 |
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 |
20 | }
21 |
22 | dependencies {
23 | implementation fileTree(dir: 'libs', include: ['*.jar'])
24 |
25 | implementation 'androidx.appcompat:appcompat:1.0.0'
26 | testImplementation 'junit:junit:4.12'
27 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
28 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
29 |
30 | api spa
31 | implementation gson
32 | implementation interceptor
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/sprouter/gradle.properties:
--------------------------------------------------------------------------------
1 | GROUP_ID=io.github.luqinx
2 | # POM文件中指向你网站的地址
3 | POM_URL=https://github.com/luqinx
4 | POM_DESCRIPTION="advance SPI for java"
5 | # SCM是指版本管理工具,一下说他的相关信息
6 | POM_SCM_URL=https://github.com/
7 | POM_SCM_CONNECTION=https://github.com/luqinx
8 | POM_SCM_DEV_CONNECTION=https://github.com/luqinx
9 | # 你的开放协议相关信息
10 | POM_LICENCE_NAME= Apache License Version 2.0
11 | POM_LICENCE_URL= https://github.com/luqinx/abkit/blob/master/LICENSE
12 | POM_LICENCE_DIST=Apache License Version 2.0
13 | # 开发者的相关信息
14 | POM_DEVELOPER_ID=luqinx
15 | POM_DEVELOPER_NAME=luqinx
16 | POM_DEVELOPER_EMAIL=qch5240@163.com
17 |
18 | POM_PACKAGING=aar
19 | VERSION_NAME=1.9.0
20 | ARTIFACT_ID=sprouter
21 |
--------------------------------------------------------------------------------
/sprouter/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/sprouter/src/androidTest/java/chao/android/tools/router/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.router;
2 |
3 | import android.content.Context;
4 | import androidx.test.platform.app.InstrumentationRegistry;
5 | import androidx.test.ext.junit.runners.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("chao.android.tools.router.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/sprouter/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/sprouter/src/main/java/chao/android/tools/router/Autowired.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.router;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | *
10 | * todo impl
11 | *
12 | * @author luqin
13 | * @since 2019-10-17
14 | */
15 | @Retention(RetentionPolicy.CLASS)
16 | @Target(ElementType.FIELD)
17 | public @interface Autowired {
18 | String value();
19 | }
20 |
--------------------------------------------------------------------------------
/sprouter/src/main/java/chao/android/tools/router/RouteArgs.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.router;
2 |
3 | /**
4 | * @author luqin
5 | * @since 2019-10-09
6 | */
7 | public class RouteArgs {
8 |
9 | static final int INTERCEPTOR_CODE_USER = -2;
10 |
11 | static final int INTERCEPTOR_CODE_ERR = -1;
12 |
13 | static final int INTERCEPTOR_CODE_TIMEOUT = -3;
14 |
15 | static final int INTERCEPTOR_CODE_OK = 0;
16 |
17 |
18 | RouteBuilder route;
19 |
20 | Throwable e;
21 |
22 | String message;
23 |
24 | RouteInterceptorCallback callback;
25 |
26 | int code = INTERCEPTOR_CODE_OK;
27 |
28 | public RouteArgs(RouteBuilder route) {
29 | this.route = route;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/sprouter/src/main/java/chao/android/tools/router/RouteException.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.router;
2 |
3 | /**
4 | * @author luqin
5 | * @since 2020-07-28
6 | */
7 | public class RouteException extends RuntimeException {
8 | public RouteException(String m) {
9 | super(m);
10 | }
11 |
12 | public RouteException(String m, Throwable e) {
13 | super(m, e);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/sprouter/src/main/java/chao/android/tools/router/RouteInterceptor.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.router;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * @author luqin
7 | * @since 2019-10-08
8 | */
9 | public interface RouteInterceptor extends IService {
10 | void intercept(RouteBuilder route, RouteInterceptorCallback callback);
11 | }
12 |
--------------------------------------------------------------------------------
/sprouter/src/main/java/chao/android/tools/router/RouteInterceptorCallback.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.router;
2 |
3 | /**
4 | * @author luqin
5 | * @since 2019-09-30
6 | */
7 | public interface RouteInterceptorCallback {
8 | void onContinue(RouteBuilder route);
9 |
10 | void onInterrupt(Throwable e);
11 | }
12 |
--------------------------------------------------------------------------------
/sprouter/src/main/java/chao/android/tools/router/RouteNavigationCallback.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.router;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * @author luqin
7 | * @since 2019-09-30
8 | */
9 | public interface RouteNavigationCallback {
10 | void onLost(RouteBuilder route);
11 |
12 | void onFound(Class extends IService> service, RouteBuilder builder);
13 |
14 | void onInterrupt(RouteBuilder route, Throwable e);
15 |
16 | void onArrival(RouteBuilder route);
17 | }
18 |
--------------------------------------------------------------------------------
/sprouter/src/main/java/chao/android/tools/router/RouteParamParse.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.router;
2 |
3 | import java.lang.annotation.Annotation;
4 |
5 | /**
6 | * @author luqin
7 | * @since 2020-07-28
8 | */
9 | class RouteParamParse {
10 |
11 | public static T parse(Annotation annotation, T value, Object... except) {
12 | return null;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/sprouter/src/main/java/chao/android/tools/router/RouterService.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.router;
2 |
3 | /**
4 | * @author luqin
5 | * @since 2020-07-28
6 | */
7 | public interface RouterService {
8 | }
9 |
--------------------------------------------------------------------------------
/sprouter/src/main/java/chao/android/tools/router/annotation/Route.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.router.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | import chao.java.tools.servicepool.IService;
9 |
10 | /**
11 | *
12 | *
13 | * @author luqin
14 | * @since 2020-07-28
15 | */
16 | @Target(ElementType.METHOD)
17 | @Retention(RetentionPolicy.RUNTIME)
18 | public @interface Route {
19 | /** 路由参数 **/
20 | String path();
21 | int flags() default 0;
22 | String action() default "";
23 | String dataUri() default "";
24 | String type() default "";
25 | int requestCode() default -1;
26 |
27 | /** 自定义参数 **/
28 | int customFlags() default 0; //可以用来做业务层flag定制,比如是否需要登录
29 | }
30 |
--------------------------------------------------------------------------------
/sprouter/src/main/java/chao/android/tools/router/annotation/RouteAction.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.router.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * @author luqin
10 | * @since 2020-07-28
11 | */
12 | @Target(ElementType.PARAMETER)
13 | @Retention(RetentionPolicy.RUNTIME)
14 | public @interface RouteAction {
15 | }
16 |
--------------------------------------------------------------------------------
/sprouter/src/main/java/chao/android/tools/router/annotation/RouteData.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.router.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * @author luqin
10 | * @since 2020-07-28
11 | */
12 | @Target(ElementType.PARAMETER)
13 | @Retention(RetentionPolicy.RUNTIME)
14 | public @interface RouteData {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/sprouter/src/main/java/chao/android/tools/router/annotation/RouteEnterAnim.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.router.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * @author luqin
10 | * @since 2020-07-28
11 | */
12 | @Target(ElementType.PARAMETER)
13 | @Retention(RetentionPolicy.RUNTIME)
14 | public @interface RouteEnterAnim {
15 | }
16 |
--------------------------------------------------------------------------------
/sprouter/src/main/java/chao/android/tools/router/annotation/RouteExitAnim.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.router.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * @author luqin
10 | * @since 2020-07-28
11 | */
12 | @Target(ElementType.PARAMETER)
13 | @Retention(RetentionPolicy.RUNTIME)
14 | public @interface RouteExitAnim {
15 | }
16 |
--------------------------------------------------------------------------------
/sprouter/src/main/java/chao/android/tools/router/annotation/RouteFlags.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.router.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * @author luqin
10 | * @since 2020-07-28
11 | */
12 | @Target(ElementType.PARAMETER)
13 | @Retention(RetentionPolicy.RUNTIME)
14 | public @interface RouteFlags {
15 | }
16 |
--------------------------------------------------------------------------------
/sprouter/src/main/java/chao/android/tools/router/annotation/RouteParam.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.router.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * @author luqin
10 | * @since 2020-07-28
11 | */
12 | @Target(ElementType.PARAMETER)
13 | @Retention(RetentionPolicy.RUNTIME)
14 | public @interface RouteParam {
15 | String value();
16 | }
17 |
--------------------------------------------------------------------------------
/sprouter/src/main/java/chao/android/tools/router/annotation/RouteRequestCode.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.router.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * @author luqin
10 | * @since 2020-07-28
11 | */
12 | @Target(ElementType.PARAMETER)
13 | @Retention(RetentionPolicy.RUNTIME)
14 | public @interface RouteRequestCode {
15 | }
16 |
--------------------------------------------------------------------------------
/sprouter/src/main/java/chao/android/tools/router/annotation/RouteType.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.router.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * @author luqin
10 | * @since 2020-07-28
11 | */
12 | @Target(ElementType.PARAMETER)
13 | @Retention(RetentionPolicy.RUNTIME)
14 | public @interface RouteType {
15 | }
16 |
--------------------------------------------------------------------------------
/sprouter/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SpRouter
3 |
4 |
--------------------------------------------------------------------------------
/sprouter/src/test/java/chao/android/tools/router/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.router;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/sprpc/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sprpc/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 |
5 | defaultConfig {
6 | minSdkVersion 19
7 | targetSdkVersion 28
8 | versionCode 1
9 | versionName "1.0"
10 |
11 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
12 |
13 | }
14 |
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 |
22 | }
23 |
24 |
25 | //abkit {
26 | // maven {
27 | // artifactId 'sprpc'
28 | // groupId 'chao.android.tools'
29 | // versionName '1.5.5'
30 | // publish2Local false
31 | // }
32 | //}
33 |
34 | dependencies {
35 | implementation fileTree(dir: 'libs', include: ['*.jar'])
36 |
37 | implementation 'androidx.appcompat:appcompat:1.0.0'
38 | testImplementation 'junit:junit:4.12'
39 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
40 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
41 |
42 | api sp
43 | api spa
44 | implementation interceptor
45 | implementation gson
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/sprpc/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/sprpc/readme.md:
--------------------------------------------------------------------------------
1 | #后续将推出XBinder, 一个轻量、高效、功能完善的替代aidl的跨进程框架
2 | 这个组件只是一个跨进程的尝试,不再更新
--------------------------------------------------------------------------------
/sprpc/src/androidTest/java/chao/android/tools/servicepool/rpc/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.servicepool.rpc;
2 |
3 | import android.content.Context;
4 | import androidx.test.platform.app.InstrumentationRegistry;
5 | import androidx.test.ext.junit.runners.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("chao.android.tools.servicepool.rpc.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/sprpc/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/sprpc/src/main/java/chao/android/tools/rpc/RemoteCallbackHandler.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.rpc;
2 |
3 | /**
4 | * @author luqin
5 | * @since 2020-08-03
6 | */
7 | public interface RemoteCallbackHandler {
8 | void resolve(T result);
9 | }
10 |
--------------------------------------------------------------------------------
/sprpc/src/main/java/chao/android/tools/rpc/RemoteHandler.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.rpc;
2 |
3 | import android.os.Handler;
4 | import android.os.HandlerThread;
5 |
6 | /**
7 | * @author luqin
8 | * @since 2020-07-26
9 | */
10 | public class RemoteHandler extends Handler {
11 |
12 | private static HandlerThread handlerThread = new HandlerThread("Remote-Client-Handler-Thread");
13 |
14 | static {
15 | handlerThread.start();
16 | }
17 |
18 | public RemoteHandler() {
19 | super(handlerThread.getLooper());
20 | }
21 |
22 | public RemoteHandler(Callback callback) {
23 | super(handlerThread.getLooper(), callback);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/sprpc/src/main/java/chao/android/tools/rpc/RemoteMessageService.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.rpc;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.os.IBinder;
6 |
7 | /**
8 | * @author luqin
9 | * @since 2020-07-22
10 | */
11 | public class RemoteMessageService extends Service implements RemoteServer.OnServerListener {
12 |
13 | private RemoteServer remoteServer;
14 |
15 | @Override
16 | public IBinder onBind(Intent intent) {
17 | if (remoteServer == null) {
18 | remoteServer = new RemoteServer();
19 | remoteServer.setOnServerListener(this);
20 | }
21 |
22 | return remoteServer.getReceiveMessage().getBinder();
23 | }
24 |
25 | @Override
26 | public int onStartCommand(Intent intent, int flags, int startId) {
27 | return super.onStartCommand(intent, flags, startId);
28 | }
29 |
30 | @Override
31 | public void onServerDisconnected() {
32 | stopSelf();
33 | }
34 |
35 | @Override
36 | public void onHandleException(Throwable e) {
37 | e.printStackTrace();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/sprpc/src/main/java/chao/android/tools/rpc/RemoteService.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.rpc;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * @author luqin
7 | * @since 2020-07-27
8 | */
9 | public interface RemoteService extends IService {
10 | boolean remoteExist();
11 | }
12 |
--------------------------------------------------------------------------------
/sprpc/src/main/java/chao/android/tools/rpc/RemoteServiceException.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.rpc;
2 |
3 | /**
4 | * @author luqin
5 | * @since 2020-07-23
6 | */
7 | public class RemoteServiceException extends RuntimeException {
8 | public RemoteServiceException() {
9 | super();
10 | }
11 |
12 | public RemoteServiceException(String message) {
13 | super(message);
14 | }
15 |
16 | public RemoteServiceException(String message, Throwable e) {
17 | super(message, e);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/sprpc/src/main/java/chao/android/tools/rpc/annotation/RemoteServiceConfig.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.rpc.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * @author luqin
10 | * @since 2020-07-27
11 | */
12 | @Target(ElementType.TYPE)
13 | @Retention(RetentionPolicy.RUNTIME)
14 | public @interface RemoteServiceConfig {
15 | boolean forceMainThread() default false;
16 |
17 | /**
18 | * 远程Service组件packageName
19 | */
20 | String remotePackageName();
21 |
22 | /**
23 | * 远程Service组件componentName
24 | */
25 | String remoteComponentName();
26 |
27 | /**
28 | * 数据传输超时
29 | */
30 | int timeout() default 3000;
31 | }
32 |
--------------------------------------------------------------------------------
/sprpc/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | spRpc
3 |
4 |
--------------------------------------------------------------------------------
/sprpc/src/test/java/chao/android/tools/servicepool/rpc/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package chao.android.tools.servicepool.rpc;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/tests/applib1/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/tests/applib1/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 14
10 | targetSdkVersion 28
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
15 |
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 |
30 | implementation 'androidx.appcompat:appcompat:1.0.0'
31 | testImplementation 'junit:junit:4.12'
32 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
33 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
34 |
35 | api project(":tests:appservice")
36 | implementation pool
37 | }
38 |
--------------------------------------------------------------------------------
/tests/applib1/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/tests/applib1/src/androidTest/java/chao/test/applib1/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package chao.test.applib1;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 |
6 | import android.content.Context;
7 | import androidx.test.platform.app.InstrumentationRegistry;
8 | import androidx.test.ext.junit.runners.AndroidJUnit4;
9 | import org.junit.Test;
10 | import org.junit.runner.RunWith;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("chao.test.applib1.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tests/applib1/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/tests/applib1/src/main/java/chao/test/applib1/AService.java:
--------------------------------------------------------------------------------
1 | package chao.test.applib1;
2 |
3 | import chao.app.pool.IA;
4 | import chao.java.tools.servicepool.annotation.Service;
5 |
6 | /**
7 | * @author luqin
8 | * @since 2020-01-09
9 | */
10 | @Service
11 | public class AService implements IA {
12 |
13 | @Override
14 | public String aName() {
15 | return "A Service";
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/tests/applib1/src/main/java/chao/test/applib1/GlobalService.java:
--------------------------------------------------------------------------------
1 | package chao.test.applib1;
2 |
3 | import chao.app.pool.LifecycleService;
4 | import chao.java.tools.servicepool.IService;
5 | import chao.java.tools.servicepool.annotation.Service;
6 |
7 | /**
8 | *
9 | * GlobalService.java
10 | */
11 | @Service(scope = IService.Scope.global)
12 | public class GlobalService implements LifecycleService {
13 | }
14 |
--------------------------------------------------------------------------------
/tests/applib1/src/main/java/chao/test/applib1/OnceService.java:
--------------------------------------------------------------------------------
1 | package chao.test.applib1;
2 |
3 | import chao.app.pool.LifecycleService;
4 | import chao.java.tools.servicepool.IService;
5 | import chao.java.tools.servicepool.annotation.Service;
6 |
7 | /**
8 | *
9 | * OnceService.java
10 | */
11 | @Service(scope = IService.Scope.once)
12 | public class OnceService implements LifecycleService {
13 | }
14 |
--------------------------------------------------------------------------------
/tests/applib1/src/main/java/chao/test/applib1/PathService.java:
--------------------------------------------------------------------------------
1 | package chao.test.applib1;
2 |
3 | import chao.app.pool.IPathInstanceService;
4 | import chao.java.tools.servicepool.annotation.Service;
5 |
6 | /**
7 | * 组件A中
8 | *
9 | * PathService
10 | */
11 | @Service(path = "pathService")
12 | public class PathService implements IPathInstanceService {
13 | @Override
14 | public String pathServiceName() {
15 | return "Path Service";
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/tests/applib1/src/main/java/chao/test/applib1/PriorityService1.java:
--------------------------------------------------------------------------------
1 | package chao.test.applib1;
2 |
3 | import chao.app.pool.IPriorityService;
4 | import chao.java.tools.servicepool.annotation.Service;
5 |
6 | /**
7 | *
8 | * PriorityService1.java
9 | */
10 | @Service(priority = 1)
11 | public class PriorityService1 implements IPriorityService {
12 | @Override
13 | public int getPriority() {
14 | return 1;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/tests/applib1/src/main/java/chao/test/applib1/PriorityService2.java:
--------------------------------------------------------------------------------
1 | package chao.test.applib1;
2 |
3 | import chao.app.pool.IPriorityService;
4 | import chao.java.tools.servicepool.annotation.Service;
5 |
6 | /**
7 | * @author luqin
8 | * @since 2020-01-09
9 | */
10 | @Service(priority = 1)
11 | public class PriorityService2 implements IPriorityService {
12 | @Override
13 | public int getPriority() {
14 | return 2;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/tests/applib1/src/main/java/chao/test/applib1/TempService.java:
--------------------------------------------------------------------------------
1 | package chao.test.applib1;
2 |
3 | import chao.app.pool.LifecycleService;
4 | import chao.java.tools.servicepool.IService;
5 | import chao.java.tools.servicepool.annotation.Service;
6 |
7 | /**
8 | *
9 | * TempService.java
10 | */
11 | @Service(scope = IService.Scope.temp)
12 | public class TempService implements LifecycleService {
13 | }
14 |
--------------------------------------------------------------------------------
/tests/applib1/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | applib1
3 |
4 |
--------------------------------------------------------------------------------
/tests/applib1/src/test/java/chao/test/applib1/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package chao.test.applib1;
2 |
3 | import static org.junit.Assert.assertEquals;
4 |
5 |
6 | import org.junit.Test;
7 |
8 | /**
9 | * Example local unit test, which will execute on the development machine (host).
10 | *
11 | * @see Testing documentation
12 | */
13 | public class ExampleUnitTest {
14 | @Test
15 | public void addition_isCorrect() {
16 | assertEquals(4, 2 + 2);
17 | }
18 | }
--------------------------------------------------------------------------------
/tests/applib2/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/tests/applib2/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 | buildToolsVersion "28.0.3"
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 14
10 | targetSdkVersion 29
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
15 |
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 |
30 | implementation 'androidx.appcompat:appcompat:1.0.0'
31 | testImplementation 'junit:junit:4.12'
32 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
33 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
34 | implementation pool
35 | }
36 |
--------------------------------------------------------------------------------
/tests/applib2/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/tests/applib2/src/androidTest/java/chao/app/applib2/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package chao.app.applib2;
2 |
3 | import android.content.Context;
4 | import androidx.test.platform.app.InstrumentationRegistry;
5 | import androidx.test.ext.junit.runners.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("chao.app.applib2.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tests/applib2/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/tests/applib2/src/main/java/chao/app/applib2/BService.java:
--------------------------------------------------------------------------------
1 | package chao.app.applib2;
2 |
3 | import chao.app.pool.IB;
4 | import chao.java.tools.servicepool.annotation.Service;
5 |
6 | /**
7 | * @author luqin
8 | * @since 2020-01-09
9 | */
10 | @Service
11 | public class BService implements IB {
12 |
13 | @Override
14 | public String bName() {
15 | return "B Service";
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/tests/applib2/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | applib2
3 |
4 |
--------------------------------------------------------------------------------
/tests/applib2/src/test/java/chao/app/applib2/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package chao.app.applib2;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/tests/appservice/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/tests/appservice/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 |
3 | dependencies {
4 | implementation fileTree(dir: 'libs', include: ['*.jar'])
5 | api sp
6 | }
7 |
8 | sourceCompatibility = "7"
9 | targetCompatibility = "7"
10 |
--------------------------------------------------------------------------------
/tests/appservice/src/main/java/chao/test/appservice/AppServiceFactory.java:
--------------------------------------------------------------------------------
1 | package chao.test.appservice;
2 |
3 | public class AppServiceFactory {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/tests/appservice/src/main/java/chao/test/appservice/IAppLib.java:
--------------------------------------------------------------------------------
1 | package chao.test.appservice;
2 |
3 | import chao.java.tools.servicepool.IInitService;
4 |
5 | /**
6 | * @author qinchao
7 | * @since 2019/4/30
8 | */
9 | public interface IAppLib extends IInitService {
10 | void appPrint();
11 | }
12 |
--------------------------------------------------------------------------------
/tests/appservice/src/main/java/chao/test/appservice/IJavaLib.java:
--------------------------------------------------------------------------------
1 | package chao.test.appservice;
2 |
3 | import chao.java.tools.servicepool.IInitService;
4 |
5 | /**
6 | * @author qinchao
7 | * @since 2019/4/30
8 | */
9 | public interface IJavaLib extends IInitService {
10 | void javaPrint();
11 | }
12 |
--------------------------------------------------------------------------------
/tests/pool/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/tests/pool/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 |
3 | dependencies {
4 | implementation fileTree(dir: 'libs', include: ['*.jar'])
5 | api sp
6 | }
7 |
8 | sourceCompatibility = "7"
9 | targetCompatibility = "7"
10 |
--------------------------------------------------------------------------------
/tests/pool/src/main/java/chao/app/pool/IA.java:
--------------------------------------------------------------------------------
1 | package chao.app.pool;
2 |
3 | /**
4 | * IA.java
5 | */
6 | public interface IA {
7 | String aName();
8 | }
9 |
--------------------------------------------------------------------------------
/tests/pool/src/main/java/chao/app/pool/IB.java:
--------------------------------------------------------------------------------
1 | package chao.app.pool;
2 |
3 | /**
4 | * IB.java
5 | */
6 | public interface IB {
7 | String bName();
8 | }
9 |
--------------------------------------------------------------------------------
/tests/pool/src/main/java/chao/app/pool/IPathInstanceService.java:
--------------------------------------------------------------------------------
1 | package chao.app.pool;
2 |
3 | import chao.java.tools.servicepool.IService;
4 |
5 | /**
6 | * IPathInstanceService.java
7 | */
8 | public interface IPathInstanceService extends IService {
9 | String pathServiceName();
10 | }
11 |
--------------------------------------------------------------------------------
/tests/pool/src/main/java/chao/app/pool/IPriorityService.java:
--------------------------------------------------------------------------------
1 | package chao.app.pool;
2 |
3 | /**
4 | *
5 | * IPriorityService.java
6 | */
7 | public interface IPriorityService {
8 | int getPriority();
9 | }
10 |
--------------------------------------------------------------------------------
/tests/pool/src/main/java/chao/app/pool/LifecycleService.java:
--------------------------------------------------------------------------------
1 | package chao.app.pool;
2 |
3 | /**
4 | * @author luqin
5 | * @since 2020-01-09
6 | */
7 | public interface LifecycleService {
8 | }
9 |
--------------------------------------------------------------------------------
/tests/remoteexample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/tests/remoteexample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'sp.autoservice'
3 |
4 | android {
5 | compileSdkVersion 28
6 | buildToolsVersion "28.0.3"
7 |
8 |
9 | defaultConfig {
10 | minSdkVersion 19
11 | targetSdkVersion 28
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
16 |
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | }
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 |
30 | implementation 'androidx.appcompat:appcompat:1.0.0'
31 | testImplementation 'junit:junit:4.12'
32 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
33 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
34 |
35 | implementation sp
36 | implementation spa
37 | implementation gson
38 | implementation sprpc
39 |
40 | implementation project(":tests:testremoteapi")
41 |
42 | }
43 |
44 |
--------------------------------------------------------------------------------
/tests/remoteexample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/tests/remoteexample/src/androidTest/java/chao/app/remoteexample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package chao.app.remoteexample;
2 |
3 | import android.content.Context;
4 | import androidx.test.platform.app.InstrumentationRegistry;
5 | import androidx.test.ext.junit.runners.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("chao.app.remoteexample.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tests/remoteexample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/tests/remoteexample/src/main/java/chao/app/remoteexample/ExampleService.java:
--------------------------------------------------------------------------------
1 | package chao.app.remoteexample;
2 |
3 |
4 | import chao.android.tools.rpc.RemoteMessageService;
5 |
6 | /**
7 | * @author luqin
8 | * @since 2020-07-23
9 | */
10 | public class ExampleService extends RemoteMessageService {
11 | }
12 |
--------------------------------------------------------------------------------
/tests/remoteexample/src/main/java/chao/app/remoteexample/LaunchActivity.java:
--------------------------------------------------------------------------------
1 | package chao.app.remoteexample;
2 |
3 | import android.os.Bundle;
4 | import androidx.annotation.Nullable;
5 | import androidx.appcompat.app.AppCompatActivity;
6 |
7 | import com.google.gson.Gson;
8 | import com.google.gson.GsonBuilder;
9 | import com.google.gson.JsonArray;
10 |
11 | import java.lang.reflect.Method;
12 | import java.util.Arrays;
13 |
14 | import chao.android.tools.servicepool.Spa;
15 | import chao.java.tools.servicepool.ClassTypeAdapter;
16 | import chao.app.remoteapi.IExampleService;
17 |
18 | /**
19 | * @author luqin
20 | * @since 2020-07-23
21 | */
22 | public class LaunchActivity extends AppCompatActivity {
23 |
24 |
25 | @Override
26 | protected void onCreate(@Nullable Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | Spa.init(this);
29 |
30 | Gson gson = new GsonBuilder()
31 | .registerTypeAdapter(Class.class, new ClassTypeAdapter())
32 | // .registerTypeAdapter(Class[].class, new ClassArrayTypeAdapter())
33 | .create();
34 |
35 | try {
36 | Method m = IExampleService.class.getMethod("withII", int.class, int.class);
37 |
38 | // TypeToken typeToken = new TypeToken<>();
39 |
40 | JsonArray je = gson.toJsonTree(m.getParameterTypes()).getAsJsonArray();
41 | System.out.println(je);
42 |
43 | Class[] c = gson.fromJson(je, Class[].class);
44 |
45 | System.out.println(Arrays.toString(c));
46 |
47 |
48 | System.out.println(Class.forName("java.util.List"));
49 | } catch (NoSuchMethodException e) {
50 | e.printStackTrace();
51 | } catch (ClassNotFoundException e) {
52 | e.printStackTrace();
53 | }
54 |
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/tests/remoteexample/src/main/java/chao/app/remoteexample/serviceimpl/ExampleServiceImpl.java:
--------------------------------------------------------------------------------
1 | package chao.app.remoteexample.serviceimpl;
2 |
3 | import java.util.List;
4 |
5 | import chao.android.tools.rpc.RemoteCallbackHandler;
6 | import chao.app.remoteapi.IExampleService;
7 | import chao.java.tools.servicepool.annotation.Service;
8 |
9 | /**
10 | * @author luqin
11 | * @since 2020-07-23
12 | */
13 | @Service
14 | public class ExampleServiceImpl implements IExampleService {
15 | @Override
16 | public int getInt() {
17 | return 50;
18 | }
19 |
20 | @Override
21 | public String getString() {
22 | return "hi, luqin";
23 | }
24 |
25 | @Override
26 | public void function() {
27 | System.out.println("function called");
28 | }
29 |
30 | @Override
31 | public int withInt(int i) {
32 | return i;
33 | }
34 |
35 | @Override
36 | public int withII(int i1, int i2) {
37 | return i1 + i2;
38 | }
39 |
40 | @Override
41 | public void withList(int i, String s, List sl) {
42 | }
43 |
44 | @Override
45 | public void withCallback(int i, RemoteCallbackHandler handler) {
46 | handler.resolve("with callback method: " + i);
47 | }
48 |
49 | @Override
50 | public void withString(String s) {
51 |
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/tests/remoteexample/src/main/java/chao/app/remoteexample/serviceimpl/LocalFirstServiceImpl.java:
--------------------------------------------------------------------------------
1 | package chao.app.remoteexample.serviceimpl;
2 |
3 | import chao.app.remoteapi.LocalFirstService;
4 | import chao.java.tools.servicepool.annotation.Service;
5 |
6 | /**
7 | * @author luqin
8 | * @since 2020-07-27
9 | */
10 | @Service
11 | public class LocalFirstServiceImpl implements LocalFirstService {
12 | @Override
13 | public int getInt() {
14 | return 111;
15 | }
16 |
17 | @Override
18 | public String getString() {
19 | return "remote first";
20 | }
21 |
22 | @Override
23 | public void function() {
24 | System.out.println("remote local first called!");
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tests/remoteexample/src/main/java/chao/app/remoteexample/serviceimpl/RPCForceMainServiceImpl.java:
--------------------------------------------------------------------------------
1 | package chao.app.remoteexample.serviceimpl;
2 |
3 | import java.util.List;
4 |
5 | import chao.android.tools.rpc.RemoteCallbackHandler;
6 | import chao.app.remoteapi.RPCForceMainService;
7 | import chao.java.tools.servicepool.annotation.Service;
8 |
9 | /**
10 | * @author luqin
11 | * @since 2020-07-27
12 | */
13 | @Service
14 | public class RPCForceMainServiceImpl implements RPCForceMainService {
15 | @Override
16 | public int getInt() {
17 | return 60;
18 | }
19 |
20 | @Override
21 | public String getString() {
22 | return "rpc remote force main thread";
23 | }
24 |
25 | @Override
26 | public void function() {
27 |
28 | }
29 |
30 | @Override
31 | public int withInt(int i) {
32 | return 10;
33 | }
34 |
35 | @Override
36 | public int withII(int i1, int i2) {
37 | return 10;
38 | }
39 |
40 | @Override
41 | public void withList(int i, String s, List sl){
42 | }
43 |
44 | @Override
45 | public void withCallback(int i, RemoteCallbackHandler handler) {
46 | handler.resolve("(force main) with callback method: " + i);
47 | }
48 |
49 | @Override
50 | public void withString(String s) {
51 |
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/tests/remoteexample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RemoteExample
3 |
4 |
--------------------------------------------------------------------------------
/tests/remoteexample/src/test/java/chao/app/remoteexample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package chao.app.remoteexample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/tests/testpluginlib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/tests/testpluginlib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 |
3 | dependencies {
4 | implementation fileTree(dir: 'libs', include: ['*.jar'])
5 | implementation sp
6 | }
7 |
8 | sourceCompatibility = "7"
9 | targetCompatibility = "7"
10 |
--------------------------------------------------------------------------------
/tests/testpluginlib/src/main/java/com/example/testpluginlib/MyClass.java:
--------------------------------------------------------------------------------
1 | package com.example.testpluginlib;
2 |
3 | public class MyClass {
4 | }
5 |
--------------------------------------------------------------------------------
/tests/testpluginlib/src/main/java/com/example/testpluginlib/TestPluginService.java:
--------------------------------------------------------------------------------
1 | package com.example.testpluginlib;
2 |
3 | import chao.java.tools.servicepool.annotation.Service;
4 |
5 | /**
6 | * @author luqin
7 | * @since 2019-07-09
8 | */
9 | @Service
10 | public class TestPluginService {
11 | public void print() {
12 | System.out.println("I'm a test service.");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/tests/testpluginlib/src/main/java/com/example/testpluginlib/TestPluginService2.java:
--------------------------------------------------------------------------------
1 | package com.example.testpluginlib;
2 |
3 | /**
4 | * @author luqin
5 | * @date 2019-07-09
6 | */
7 | public class TestPluginService2 {
8 | }
9 |
--------------------------------------------------------------------------------
/tests/testpluginlib/src/main/java/com/example/testpluginlib/TestPluginService3.java:
--------------------------------------------------------------------------------
1 | package com.example.testpluginlib;
2 |
3 | import chao.java.tools.servicepool.DefaultService;
4 | import chao.java.tools.servicepool.IService;
5 |
6 | /**
7 | * @author luqin
8 | * @since 2019-07-09
9 | */
10 | public class TestPluginService3 extends DefaultService implements IService {
11 |
12 | @Override
13 | public String path() {
14 | return "path";
15 | }
16 |
17 | @Override
18 | public int priority() {
19 | return Integer.valueOf(100);
20 | }
21 |
22 | @Override
23 | public int scope() {
24 | return Scope.once;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tests/testpluginlib/src/main/resources/META-INF/services/chao.java.tools.servicepool.IService:
--------------------------------------------------------------------------------
1 | com.example.testpluginlib.TestPluginService3
--------------------------------------------------------------------------------
/tests/testremoteapi/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/tests/testremoteapi/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 |
5 |
6 | defaultConfig {
7 | versionCode 1
8 | versionName "1.0"
9 |
10 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
11 |
12 | }
13 |
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 |
21 | }
22 |
23 | dependencies {
24 | implementation fileTree(dir: 'libs', include: ['*.jar'])
25 |
26 | implementation 'androidx.appcompat:appcompat:1.0.0'
27 | testImplementation 'junit:junit:4.12'
28 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
29 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
30 |
31 | implementation sprpc
32 | implementation sp
33 | }
34 |
--------------------------------------------------------------------------------
/tests/testremoteapi/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/tests/testremoteapi/src/androidTest/java/chao/app/remoteapi/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package chao.app.remoteapi;
2 |
3 | import android.content.Context;
4 | import androidx.test.platform.app.InstrumentationRegistry;
5 | import androidx.test.ext.junit.runners.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("chao.app.remoteapi.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tests/testremoteapi/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/tests/testremoteapi/src/main/java/chao/app/remoteapi/IExampleService.java:
--------------------------------------------------------------------------------
1 | package chao.app.remoteapi;
2 |
3 | import java.util.List;
4 |
5 | import chao.android.tools.rpc.RemoteCallbackHandler;
6 | import chao.android.tools.rpc.annotation.RemoteServiceConfig;
7 | import chao.java.tools.servicepool.IService;
8 |
9 | /**
10 | * @author luqin
11 | * @since 2020-07-23
12 | */
13 | @RemoteServiceConfig(remotePackageName = "chao.app.remoteexample",
14 | remoteComponentName = "chao.app.remoteexample.ExampleService",
15 | timeout = 50000000
16 | )
17 | public interface IExampleService extends IService {
18 | int getInt();
19 |
20 | String getString();
21 |
22 | void function();
23 |
24 | int withInt(int i);
25 |
26 | int withII(int i1, int i2);
27 |
28 | void withString(String s);
29 |
30 | void withList(int i, String s, List sl);
31 |
32 | void withCallback(int i, RemoteCallbackHandler handler);
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/tests/testremoteapi/src/main/java/chao/app/remoteapi/LocalFirstService.java:
--------------------------------------------------------------------------------
1 | package chao.app.remoteapi;
2 |
3 | import chao.android.tools.rpc.annotation.RemoteServiceConfig;
4 | import chao.java.tools.servicepool.IService;
5 |
6 | /**
7 | * @author luqin
8 | * @since 2020-07-27
9 | */
10 | @RemoteServiceConfig(remotePackageName = "chao.app.remoteexample", remoteComponentName = "chao.app.remoteexample.ExampleService")
11 | public interface LocalFirstService extends IService {
12 | int getInt();
13 |
14 | String getString();
15 |
16 | void function();
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/tests/testremoteapi/src/main/java/chao/app/remoteapi/RPCForceMainService.java:
--------------------------------------------------------------------------------
1 | package chao.app.remoteapi;
2 |
3 | import chao.android.tools.rpc.annotation.RemoteServiceConfig;
4 |
5 | /**
6 | * @author luqin
7 | * @since 2020-07-23
8 | */
9 | @RemoteServiceConfig(remotePackageName = "chao.app.remoteexample",
10 | remoteComponentName = "chao.app.remoteexample.ExampleService",
11 | forceMainThread = true,
12 | timeout = 3001
13 | )
14 | public interface RPCForceMainService extends IExampleService {
15 | }
16 |
--------------------------------------------------------------------------------
/tests/testremoteapi/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RemoteApi
3 |
4 |
--------------------------------------------------------------------------------
/tests/testremoteapi/src/test/java/chao/app/remoteapi/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package chao.app.remoteapi;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/transformJarDir.sh:
--------------------------------------------------------------------------------
1 | #!/bin/zsh
2 |
3 | open /Users/chao/codes/mycode/sp/app/build/intermediates/transforms/AutoServiceTransform/debug
--------------------------------------------------------------------------------