├── .gitignore ├── 01jvm ├── AnalysisForList.java ├── GCLogAnalysis.java ├── HelloByteCode.java ├── HelloNum.java ├── JvmClassLoaderPrintPath.java ├── README.md ├── TestAddUrl.java ├── XlassLoader.java ├── jvm │ ├── HelloClassLoader.java │ └── TestMem.java ├── lib │ ├── Hello.java │ ├── Hello.xlass │ └── HelloKimmking.java ├── out │ └── production │ │ └── 01jvm │ │ ├── README.md │ │ └── 环境准备.txt ├── subinterface │ ├── Mapper.java │ ├── User.java │ ├── UserDAO.java │ ├── UserMain.java │ └── UserMapper.java └── 环境准备.txt ├── 02nio ├── GCLogAnalysis.java ├── README.md ├── nio01 │ ├── dependency-reduced-pom.xml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ ├── Main.java │ │ └── java0 │ │ └── nio01 │ │ ├── HttpClientDemo.java │ │ ├── HttpServer01.java │ │ ├── HttpServer02.java │ │ ├── HttpServer03.java │ │ ├── OKHttpClientDemo.java │ │ └── netty │ │ ├── HttpHandler.java │ │ ├── HttpInitializer.java │ │ └── NettyHttpServer.java └── nio02 │ ├── README.md │ ├── pom.xml │ └── src │ └── main │ └── java │ └── io │ └── github │ └── kimmking │ └── gateway │ ├── NettyServerApplication.java │ ├── filter │ ├── HeaderHttpRequestFilter.java │ ├── HeaderHttpResponseFilter.java │ ├── HttpRequestFilter.java │ └── HttpResponseFilter.java │ ├── inbound │ ├── HttpInboundHandler.java │ ├── HttpInboundInitializer.java │ ├── HttpInboundServer.java │ └── NettyInfoHandler.java │ ├── outbound │ ├── httpclient4 │ │ ├── HttpOutboundHandler.java │ │ └── NamedThreadFactory.java │ ├── netty4 │ │ ├── NettyHttpClient.java │ │ └── NettyHttpClientOutboundHandler.java │ └── okhttp │ │ └── OkhttpOutboundHandler.java │ └── router │ ├── HttpEndpointRouter.java │ └── RandomHttpEndpointRouter.java ├── 03concurrency ├── 0301 │ ├── j.txt │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── java0 │ │ ├── conc0301 │ │ ├── DaemonThread.java │ │ ├── Runner1.java │ │ ├── Runner2.java │ │ ├── RunnerMain.java │ │ ├── ThreadA.java │ │ ├── ThreadB.java │ │ ├── ThreadC.java │ │ ├── ThreadCount.java │ │ ├── ThreadMain.java │ │ ├── ThreadMain2.java │ │ ├── op │ │ │ ├── Join.java │ │ │ └── WaitAndNotify.java │ │ └── sync │ │ │ ├── Counter.java │ │ │ ├── Cref.java │ │ │ ├── TestSetGet.java │ │ │ ├── Thread1.java │ │ │ ├── Thread2.java │ │ │ └── Thread3.java │ │ ├── conc0302 │ │ ├── atomic │ │ │ ├── AtomicCount.java │ │ │ ├── AtomicMain.java │ │ │ ├── Count.java │ │ │ ├── LongDemo.java │ │ │ └── SyncCount.java │ │ ├── lock │ │ │ ├── ConditionDemo.java │ │ │ ├── Count.java │ │ │ ├── Count2.java │ │ │ ├── Count3.java │ │ │ ├── LockMain.java │ │ │ ├── LockSupportDemo.java │ │ │ ├── ObjectCache.java │ │ │ ├── ReentrantLockDemo.java │ │ │ ├── ReentrantReadWriteLockDemo.java │ │ │ ├── ReentrantReadWriteLockDemo2.java │ │ │ ├── TestFair.java │ │ │ ├── ThreadA.java │ │ │ └── ThreadB.java │ │ └── threadpool │ │ │ ├── ExceptionDemo.java │ │ │ ├── ExecutorServiceDemo.java │ │ │ ├── NewCachedThreadPoolDemo.java │ │ │ ├── NewFixedThreadPoolDemo.java │ │ │ ├── NewScheduledThreadExecutorDemo.java │ │ │ └── NewSingleThreadExecutorDemo.java │ │ └── conc0303 │ │ ├── Homework03.java │ │ ├── collection │ │ ├── ConcurrentHashMapDemo.java │ │ ├── CopyOnWriteArrayListDemo.java │ │ ├── CopyOnWriteArrayListDemo1.java │ │ ├── CopyOnWriteArrayListDemo2.java │ │ ├── LinkedHashMapDemo.java │ │ ├── SyncListDemo.java │ │ └── TreeMapDemo.java │ │ ├── future │ │ ├── CompletableFutureDemo.java │ │ ├── FutureDemo1.java │ │ └── FutureTask1.java │ │ ├── stream │ │ └── StreamParallelDemo.java │ │ ├── threadlocal │ │ └── ThreadLocalDemo.java │ │ └── tool │ │ ├── CountDownLatchDemo.java │ │ ├── CountDownLatchDemo2.java │ │ ├── CyclicBarrierDemo.java │ │ ├── CyclicBarrierDemo2.java │ │ ├── SemaphoreDemo.java │ │ ├── SemaphoreDemo2.java │ │ └── SemaphoreDemo3.java └── README.md ├── 04fx ├── Java8inAction │ ├── .gitignore │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ ├── lambdasinaction │ │ │ ├── appa │ │ │ │ ├── Author.java │ │ │ │ ├── Authors.java │ │ │ │ └── Book.java │ │ │ ├── appc │ │ │ │ ├── StreamForker.java │ │ │ │ └── StreamForkerExample.java │ │ │ ├── appd │ │ │ │ ├── InnerClass.java │ │ │ │ └── Lambda.java │ │ │ ├── chap1 │ │ │ │ └── FilteringApples.java │ │ │ ├── chap10 │ │ │ │ ├── Car.java │ │ │ │ ├── Insurance.java │ │ │ │ ├── OperationsWithOptional.java │ │ │ │ ├── OptionalMain.java │ │ │ │ ├── Person.java │ │ │ │ └── ReadPositiveIntParam.java │ │ │ ├── chap11 │ │ │ │ ├── AsyncShop.java │ │ │ │ ├── AsyncShopClient.java │ │ │ │ ├── BestPriceFinder.java │ │ │ │ ├── BestPriceFinderMain.java │ │ │ │ ├── Discount.java │ │ │ │ ├── ExchangeService.java │ │ │ │ ├── Quote.java │ │ │ │ ├── Shop.java │ │ │ │ ├── Util.java │ │ │ │ └── v1 │ │ │ │ │ ├── BestPriceFinder.java │ │ │ │ │ ├── BestPriceFinderMain.java │ │ │ │ │ ├── Shop.java │ │ │ │ │ └── ShopMain.java │ │ │ ├── chap12 │ │ │ │ └── DateTimeExamples.java │ │ │ ├── chap13 │ │ │ │ ├── Recursion.java │ │ │ │ └── SubsetsMain.java │ │ │ ├── chap14 │ │ │ │ ├── Combinators.java │ │ │ │ ├── Currying.java │ │ │ │ ├── LazyLists.java │ │ │ │ ├── PatternMatching.java │ │ │ │ ├── PersistentTrainJourney.java │ │ │ │ └── PersistentTree.java │ │ │ ├── chap2 │ │ │ │ ├── FilteringApples.java │ │ │ │ └── MeaningOfThis.java │ │ │ ├── chap3 │ │ │ │ ├── ExecuteAround.java │ │ │ │ ├── Lambdas.java │ │ │ │ └── Sorting.java │ │ │ ├── chap4 │ │ │ │ ├── Dish.java │ │ │ │ ├── StreamBasic.java │ │ │ │ └── StreamVsCollection.java │ │ │ ├── chap5 │ │ │ │ ├── BuildingStreams.java │ │ │ │ ├── Filtering.java │ │ │ │ ├── Finding.java │ │ │ │ ├── Laziness.java │ │ │ │ ├── Mapping.java │ │ │ │ ├── NumericStreams.java │ │ │ │ ├── PuttingIntoPractice.java │ │ │ │ ├── Reducing.java │ │ │ │ ├── Trader.java │ │ │ │ └── Transaction.java │ │ │ ├── chap6 │ │ │ │ ├── CollectorHarness.java │ │ │ │ ├── Dish.java │ │ │ │ ├── Grouping.java │ │ │ │ ├── GroupingTransactions.java │ │ │ │ ├── PartitionPrimeNumbers.java │ │ │ │ ├── Partitioning.java │ │ │ │ ├── Reducing.java │ │ │ │ ├── Summarizing.java │ │ │ │ └── ToListCollector.java │ │ │ ├── chap7 │ │ │ │ ├── ForkJoinSumCalculator.java │ │ │ │ ├── ParallelStreamBenchmark.java │ │ │ │ ├── ParallelStreams.java │ │ │ │ ├── ParallelStreamsHarness.java │ │ │ │ └── WordCount.java │ │ │ ├── chap8 │ │ │ │ ├── ChainOfResponsibilityMain.java │ │ │ │ ├── Debugging.java │ │ │ │ ├── FactoryMain.java │ │ │ │ ├── ObserverMain.java │ │ │ │ ├── OnlineBanking.java │ │ │ │ ├── OnlineBankingLambda.java │ │ │ │ ├── Peek.java │ │ │ │ └── StrategyMain.java │ │ │ ├── chap9 │ │ │ │ ├── Ambiguous.java │ │ │ │ ├── Diamond.java │ │ │ │ ├── Drawable.java │ │ │ │ ├── Ellipse.java │ │ │ │ ├── Game.java │ │ │ │ ├── Intro.java │ │ │ │ ├── Letter.java │ │ │ │ ├── MostSpecific.java │ │ │ │ ├── README │ │ │ │ ├── Resizable.java │ │ │ │ ├── Square.java │ │ │ │ ├── Triangle.java │ │ │ │ └── Utils.java │ │ │ └── dsl │ │ │ │ ├── Grouping.java │ │ │ │ ├── LambdaOrderBuilder.java │ │ │ │ ├── Main.java │ │ │ │ ├── MethodChainingOrderBuilder.java │ │ │ │ ├── Mixed.java │ │ │ │ ├── MixedBuilder.java │ │ │ │ ├── NestedFunctionOrderBuilder.java │ │ │ │ ├── TaxCalculator.java │ │ │ │ └── model │ │ │ │ ├── Order.java │ │ │ │ ├── Stock.java │ │ │ │ ├── Tax.java │ │ │ │ └── Trade.java │ │ └── winterbe │ │ │ └── java8 │ │ │ └── samples │ │ │ ├── concurrent │ │ │ ├── Atomic1.java │ │ │ ├── CompletableFuture1.java │ │ │ ├── ConcurrentHashMap1.java │ │ │ ├── ConcurrentUtils.java │ │ │ ├── Executors1.java │ │ │ ├── Executors2.java │ │ │ ├── Executors3.java │ │ │ ├── Lock1.java │ │ │ ├── Lock2.java │ │ │ ├── Lock3.java │ │ │ ├── Lock4.java │ │ │ ├── Lock5.java │ │ │ ├── Lock6.java │ │ │ ├── LongAccumulator1.java │ │ │ ├── LongAdder1.java │ │ │ ├── Semaphore1.java │ │ │ ├── Semaphore2.java │ │ │ ├── Synchronized1.java │ │ │ ├── Synchronized2.java │ │ │ └── Threads1.java │ │ │ ├── lambda │ │ │ ├── Interface1.java │ │ │ ├── Lambda1.java │ │ │ ├── Lambda2.java │ │ │ ├── Lambda3.java │ │ │ ├── Lambda4.java │ │ │ ├── Lambda5.java │ │ │ └── Person.java │ │ │ ├── misc │ │ │ ├── Annotations1.java │ │ │ ├── CheckedFunctions.java │ │ │ ├── Concurrency1.java │ │ │ ├── Files1.java │ │ │ ├── Maps1.java │ │ │ ├── Math1.java │ │ │ └── String1.java │ │ │ ├── nashorn │ │ │ ├── Nashorn1.java │ │ │ ├── Nashorn10.java │ │ │ ├── Nashorn11.java │ │ │ ├── Nashorn2.java │ │ │ ├── Nashorn3.java │ │ │ ├── Nashorn4.java │ │ │ ├── Nashorn5.java │ │ │ ├── Nashorn6.java │ │ │ ├── Nashorn7.java │ │ │ ├── Nashorn8.java │ │ │ ├── Nashorn9.java │ │ │ ├── Product.java │ │ │ └── SuperRunner.java │ │ │ ├── stream │ │ │ ├── Optional1.java │ │ │ ├── Optional2.java │ │ │ ├── Streams1.java │ │ │ ├── Streams10.java │ │ │ ├── Streams11.java │ │ │ ├── Streams12.java │ │ │ ├── Streams13.java │ │ │ ├── Streams2.java │ │ │ ├── Streams3.java │ │ │ ├── Streams4.java │ │ │ ├── Streams5.java │ │ │ ├── Streams6.java │ │ │ ├── Streams7.java │ │ │ ├── Streams8.java │ │ │ └── Streams9.java │ │ │ └── time │ │ │ ├── LocalDate1.java │ │ │ ├── LocalDateTime1.java │ │ │ └── LocalTime1.java │ │ └── resources │ │ └── lambdasinaction │ │ ├── chap3 │ │ └── data.txt │ │ └── chap5 │ │ └── data.txt ├── demo │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── MavenWrapperDownloader.java │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ ├── A.java │ │ │ └── io │ │ │ │ └── kimmking │ │ │ │ └── javacourse │ │ │ │ └── demo │ │ │ │ ├── ConsConfig.java │ │ │ │ ├── ConsConfigAutoConfiguration.java │ │ │ │ ├── ConsConfigs.java │ │ │ │ ├── DemoApplication.java │ │ │ │ ├── DemoConfig.java │ │ │ │ ├── DemoConfigBindingsRegistrar.java │ │ │ │ ├── EnableDemoConfigBindings.java │ │ │ │ └── PropertySourcesUtils.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── io │ │ └── kimmking │ │ └── javacourse │ │ └── demo │ │ └── DemoApplicationTests.java ├── dtx01 │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── io │ │ │ │ └── kimmking │ │ │ │ └── dtx01 │ │ │ │ ├── Dtx01Application.java │ │ │ │ ├── controller │ │ │ │ └── UserController.java │ │ │ │ ├── entity │ │ │ │ └── User.java │ │ │ │ ├── mapper │ │ │ │ └── UserMapper.java │ │ │ │ └── service │ │ │ │ ├── UserService.java │ │ │ │ └── UserServiceImpl.java │ │ └── resources │ │ │ ├── application.yml │ │ │ └── mapper │ │ │ └── UserMapper.xml │ │ └── test │ │ └── java │ │ └── io │ │ └── kimmking │ │ └── dtx01 │ │ └── Dtx01ApplicationTests.java ├── java8 │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── io │ │ │ │ └── kimmking │ │ │ │ └── java8 │ │ │ │ ├── A.java │ │ │ │ ├── CollectionDemo.java │ │ │ │ ├── ForeachDemo.java │ │ │ │ ├── GenericDemo.java │ │ │ │ ├── GuavaDemo.java │ │ │ │ ├── LambdaDemo.java │ │ │ │ ├── LombokDemo.java │ │ │ │ ├── ParallelDemo.java │ │ │ │ ├── ResourceLoader.java │ │ │ │ ├── StreamDemo.java │ │ │ │ ├── StreamDemo2.java │ │ │ │ ├── Student.java │ │ │ │ └── TestMem.java │ │ └── resources │ │ │ ├── conf │ │ │ └── a.properties │ │ │ └── log4j.xml │ │ └── test │ │ └── java │ │ └── io │ │ └── kimmking │ │ └── java8 │ │ └── StudentTest.java ├── spring01 │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── io │ │ │ │ └── kimmking │ │ │ │ ├── DemoMethodIncepter.java │ │ │ │ ├── anno │ │ │ │ ├── AnnoDemo.java │ │ │ │ ├── IA1.java │ │ │ │ ├── IA2.java │ │ │ │ ├── IAnno2.java │ │ │ │ └── IAnnotation.java │ │ │ │ ├── aop │ │ │ │ └── ISchool.java │ │ │ │ ├── spring01 │ │ │ │ ├── A.java │ │ │ │ ├── CollectionDemo.java │ │ │ │ ├── GuavaDemo.java │ │ │ │ ├── LombokDemo.java │ │ │ │ ├── StreamDemo.java │ │ │ │ ├── Student.java │ │ │ │ └── http │ │ │ │ │ ├── HttpServer01.java │ │ │ │ │ ├── HttpServer02.java │ │ │ │ │ └── HttpServer03.java │ │ │ │ ├── spring02 │ │ │ │ ├── Aop1.java │ │ │ │ ├── Aop2.java │ │ │ │ ├── HelloBeanDefinitionRegistryPostProcessor.java │ │ │ │ ├── HelloBeanPostProcessor.java │ │ │ │ ├── Klass.java │ │ │ │ ├── School.java │ │ │ │ ├── SpringDemo01.java │ │ │ │ └── SpringDemo11.java │ │ │ │ ├── spring03 │ │ │ │ ├── Spring03Main.java │ │ │ │ ├── TestService1.java │ │ │ │ └── TestService2.java │ │ │ │ ├── spring04 │ │ │ │ ├── ABCPlugin.java │ │ │ │ ├── ABCStartup.java │ │ │ │ ├── ABCStartupListener.java │ │ │ │ ├── MockABCPlugin1.java │ │ │ │ ├── MockABCPlugin2.java │ │ │ │ └── Spring04Main.java │ │ │ │ └── springjms │ │ │ │ ├── JmsListener.java │ │ │ │ ├── JmsReceiver.java │ │ │ │ ├── JmsSender.java │ │ │ │ └── SendService.java │ │ └── resources │ │ │ ├── applicationContext.xml │ │ │ ├── log4j.xml │ │ │ ├── springjms-receiver.xml │ │ │ └── springjms-sender.xml │ │ └── test │ │ └── java │ │ ├── Spring02Test.java │ │ └── Sprint01Test.java └── springboot01 │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── kimmking │ │ │ └── springboot01 │ │ │ ├── Springboot01Application.java │ │ │ ├── jms │ │ │ ├── BeanConfig.java │ │ │ ├── ProducerController.java │ │ │ ├── QueueConsumerListener.java │ │ │ └── TopicConsumerListener.java │ │ │ └── mongo │ │ │ ├── MongoController.java │ │ │ └── User.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── io │ └── kimmking │ └── springboot01 │ └── Springboot01ApplicationTests.java ├── 06db └── shardingsphere │ ├── config-replica-query.yaml │ ├── config-sharding.yaml │ ├── init.sql │ └── server.yaml ├── 07rpc ├── README.md ├── mysql-demo │ ├── .gitignore │ ├── README.md │ ├── docker-compose.yml │ ├── docker_data │ │ └── docker-entrypoint-initdb.d │ │ │ └── 01-mysql_demo-init.ddl.sql │ ├── generateMapper.sh │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── cncounter │ │ │ │ └── mysqldemo │ │ │ │ ├── MysqlDemoApplication.java │ │ │ │ ├── dao │ │ │ │ └── mapper │ │ │ │ │ └── TBizOrderMapper.java │ │ │ │ └── model │ │ │ │ └── TBizOrder.java │ │ └── resources │ │ │ ├── MybatisGeneratorConfig.xml │ │ │ ├── application.yml │ │ │ └── com │ │ │ └── cncounter │ │ │ └── mysqldemo │ │ │ └── dao │ │ │ └── mapper │ │ │ └── TBizOrderMapper.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── cncounter │ │ └── mysqldemo │ │ └── MysqlDemoApplicationTests.java ├── rpc01 │ ├── client-rest.http │ ├── pom.xml │ ├── rpcfx-core │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ └── java │ │ │ │ └── io │ │ │ │ └── kimmking │ │ │ │ └── rpcfx │ │ │ │ ├── annotation │ │ │ │ ├── RpcfxReference.java │ │ │ │ └── RpcfxService.java │ │ │ │ ├── api │ │ │ │ ├── Filter.java │ │ │ │ ├── LoadBalancer.java │ │ │ │ ├── Router.java │ │ │ │ ├── RpcContext.java │ │ │ │ ├── RpcfxRequest.java │ │ │ │ ├── RpcfxResponse.java │ │ │ │ └── ServiceProviderDesc.java │ │ │ │ ├── consumer │ │ │ │ ├── ConsumerBootstrap.java │ │ │ │ ├── RpcfxConsumerInvoker.java │ │ │ │ └── RpcfxInvocationHandler.java │ │ │ │ ├── meta │ │ │ │ ├── InstanceMeta.java │ │ │ │ ├── ProviderMeta.java │ │ │ │ ├── ServerMeta.java │ │ │ │ └── ServiceMeta.java │ │ │ │ ├── provider │ │ │ │ ├── ProviderBootstrap.java │ │ │ │ └── RpcfxProviderInvoker.java │ │ │ │ ├── registry │ │ │ │ ├── ChangedListener.java │ │ │ │ ├── Event.java │ │ │ │ ├── RegistryCenter.java │ │ │ │ ├── RegistryConfiguration.java │ │ │ │ ├── kkregistry │ │ │ │ │ ├── KKHeathChecker.java │ │ │ │ │ └── KKRegistryCenter.java │ │ │ │ └── zookeeper │ │ │ │ │ └── ZookeeperRegistryCenter.java │ │ │ │ ├── stub │ │ │ │ ├── MockHandler.java │ │ │ │ └── StubSkeletonHelper.java │ │ │ │ └── utils │ │ │ │ ├── MethodUtils.java │ │ │ │ ├── MockUtils.java │ │ │ │ └── RoundRobinByWeightLoadBalance.java │ │ │ └── test │ │ │ └── java │ │ │ └── FourSumCount.java │ ├── rpcfx-demo-api │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── io │ │ │ └── kimmking │ │ │ └── rpcfx │ │ │ └── demo │ │ │ └── api │ │ │ ├── Order.java │ │ │ ├── OrderService.java │ │ │ ├── User.java │ │ │ └── UserService.java │ ├── rpcfx-demo-consumer │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── io │ │ │ │ └── kimmking │ │ │ │ └── rpcfx │ │ │ │ └── demo │ │ │ │ └── consumer │ │ │ │ ├── HelloController.java │ │ │ │ └── RpcfxClientApplication.java │ │ │ └── resources │ │ │ └── application.yml │ └── rpcfx-demo-provider │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ ├── java │ │ └── io │ │ │ └── kimmking │ │ │ └── rpcfx │ │ │ └── demo │ │ │ └── provider │ │ │ ├── OrderServiceImpl.java │ │ │ ├── RpcfxServerApplication.java │ │ │ └── UserServiceImpl.java │ │ └── resources │ │ └── application.yml └── rpc02 │ ├── dubbo-demo-api │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── kimmking │ │ └── dubbo │ │ └── demo │ │ └── api │ │ ├── Order.java │ │ ├── OrderService.java │ │ ├── User.java │ │ └── UserService.java │ ├── dubbo-demo-consumer │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── io │ │ │ └── kimmking │ │ │ └── dubbo │ │ │ └── demo │ │ │ └── consumer │ │ │ └── DubboClientApplication.java │ │ └── resources │ │ └── application.yml │ ├── dubbo-demo-provider │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── io │ │ │ └── kimmking │ │ │ └── dubbo │ │ │ └── demo │ │ │ └── provider │ │ │ ├── DubboServerApplication.java │ │ │ ├── OrderServiceImpl.java │ │ │ └── UserServiceImpl.java │ │ └── resources │ │ └── application.yml │ └── pom.xml ├── 08cache ├── README.md ├── cache │ ├── pom.xml │ ├── src │ │ └── main │ │ │ ├── java │ │ │ └── io │ │ │ │ └── kimmking │ │ │ │ └── cache │ │ │ │ ├── CacheApplication.java │ │ │ │ ├── CacheConfig.java │ │ │ │ ├── controller │ │ │ │ └── UserController.java │ │ │ │ ├── entity │ │ │ │ └── User.java │ │ │ │ ├── mapper │ │ │ │ └── UserMapper.java │ │ │ │ └── service │ │ │ │ ├── UserService.java │ │ │ │ └── UserServiceImpl.java │ │ │ └── resources │ │ │ ├── application.yml │ │ │ ├── ehcache.xml │ │ │ └── mapper │ │ │ └── UserMapper.xml │ └── test.sql ├── ha │ └── conf │ │ ├── cluster.txt │ │ ├── redis6379.conf │ │ ├── redis6380.conf │ │ ├── sentinel0.conf │ │ └── sentinel1.conf └── redis │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── io │ │ └── kimmking │ │ └── cache │ │ ├── RedisApplication.java │ │ ├── cluster │ │ └── ClusterJedis.java │ │ ├── controller │ │ └── UserController.java │ │ ├── entity │ │ └── User.java │ │ ├── hazelcast │ │ └── HazelcastDemo.java │ │ ├── redission │ │ ├── RedissionDemo.java │ │ └── RedissionDemo1.java │ │ └── sentinel │ │ └── SentinelJedis.java │ └── resources │ └── application.yml ├── 09mq ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── activemq-demo │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── io │ │ │ │ └── kimmking │ │ │ │ └── javacourse │ │ │ │ └── mq │ │ │ │ └── activemq │ │ │ │ ├── ActiveMQServer.java │ │ │ │ └── ActivemqApplication.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── io │ │ └── kimmking │ │ └── javacourse │ │ └── mq │ │ └── activemq │ │ └── ActivemqApplicationTests.java ├── kafka-demo │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── io │ │ │ └── kimmking │ │ │ └── javacourse │ │ │ └── kafka │ │ │ ├── KafkaConsumerDemo.java │ │ │ ├── KafkaProducerDemo.java │ │ │ ├── Order.java │ │ │ └── kimmking │ │ │ ├── Consumer.java │ │ │ ├── ConsumerImpl.java │ │ │ ├── Producer.java │ │ │ └── ProducerImpl.java │ │ └── resources │ │ └── log4j.xml ├── kmq-core │ ├── .gitignore │ ├── README.md │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── io │ │ │ │ └── kimmking │ │ │ │ └── kmq │ │ │ │ ├── KmqApplication.java │ │ │ │ ├── core │ │ │ │ ├── Kmq.java │ │ │ │ ├── KmqBroker.java │ │ │ │ ├── KmqConsumer.java │ │ │ │ ├── KmqMessage.java │ │ │ │ ├── KmqProducer.java │ │ │ │ └── MessageListener.java │ │ │ │ ├── demo │ │ │ │ ├── KmqDemo.java │ │ │ │ └── Order.java │ │ │ │ └── store │ │ │ │ ├── FileDemo.java │ │ │ │ └── Indexer.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── io │ │ └── kimmking │ │ └── kmq │ │ └── core │ │ └── KmqApplicationTests.java ├── pulsar │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── MavenWrapperDownloader.java │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── io │ │ │ │ └── kimmking │ │ │ │ └── mq │ │ │ │ └── pulsar │ │ │ │ ├── Config.java │ │ │ │ ├── ConsumerDemo.java │ │ │ │ ├── ProducerDemo.java │ │ │ │ └── PulsarApplication.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── io │ │ └── kimmking │ │ └── mq │ │ └── pulsar │ │ └── PulsarApplicationTests.java ├── rabbit │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── MavenWrapperDownloader.java │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── io │ │ │ │ └── kimmking │ │ │ │ └── mq │ │ │ │ ├── camel │ │ │ │ └── README.md │ │ │ │ └── rabbit │ │ │ │ ├── MessageProducer.java │ │ │ │ ├── MessageReceiverA.java │ │ │ │ ├── MessageReceiverB.java │ │ │ │ ├── RabbitApplication.java │ │ │ │ └── RabbitConfig.java │ │ └── resources │ │ │ └── application.yaml │ │ └── test │ │ └── java │ │ └── io │ │ └── kimmking │ │ └── mq │ │ └── rabbit │ │ └── RabbitApplicationTests.java ├── rocket │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── MavenWrapperDownloader.java │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── io │ │ │ │ └── kimmking │ │ │ │ └── mq │ │ │ │ └── rocket │ │ │ │ ├── Order.java │ │ │ │ ├── OrderConsumerDemo.java │ │ │ │ ├── RocketApplication.java │ │ │ │ └── StringConsumerDemo.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── io │ │ └── kimmking │ │ └── mq │ │ └── rocket │ │ └── RocketApplicationTests.java └── spring-kafka-demo │ ├── .gitignore │ ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── kimmking │ │ │ └── javacourse │ │ │ └── kafkademo │ │ │ └── KafkaDemoApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── io │ └── kimmking │ └── javacourse │ └── kafkademo │ └── KafkaDemoApplicationTests.java ├── 11dfs └── dfs │ ├── .gitignore │ ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties │ ├── app │ └── pic │ │ ├── 1.txt │ │ ├── 1644038685842-moon.jpeg │ │ ├── 1644048593861-moon.jpeg │ │ ├── 1644051049289-IMG_0987.JPG │ │ ├── 1644051171701-houyiqibing.jpeg │ │ ├── 1644051228263-houyiqibing.jpeg │ │ ├── 1644051550427-houyiqibing.jpeg │ │ ├── 1646313820045-image1.png │ │ ├── 1646485079290-renshijian.jpeg │ │ ├── 1646485131332-renshijian.jpeg │ │ ├── 1646490487023-renshijian.jpeg │ │ ├── 1646490663637-yushengjiexuan7.jpeg │ │ ├── 1646491143115-yushengjiexuan7.jpeg │ │ └── jiajia.txt │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── kimmking │ │ │ └── javacourse │ │ │ └── dfs │ │ │ ├── DfsApplication.java │ │ │ ├── FastDfsClientConfig.java │ │ │ ├── FileConfig.java │ │ │ ├── JavaConfig.java │ │ │ ├── controller │ │ │ └── FileController.java │ │ │ ├── mapper │ │ │ └── UserMapper.java │ │ │ ├── model │ │ │ └── User.java │ │ │ └── service │ │ │ └── UserService.java │ └── resources │ │ ├── application.yml │ │ ├── mapper │ │ └── userMapper.xml │ │ └── static │ │ ├── index-dfs.html │ │ └── index.html │ └── test │ └── java │ └── io │ └── github │ └── kimmking │ └── javacourse │ └── dfs │ └── DfsApplicationTests.java ├── README.md ├── app ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── app │ │ │ ├── App.java │ │ │ ├── WebAutoConfiguration.java │ │ │ ├── WebConfiguration.java │ │ │ ├── WebInfo.java │ │ │ └── WebProperties.java │ └── resources │ │ ├── META-INF │ │ └── spring.factories │ │ └── application.properties │ └── test │ └── java │ └── com │ └── example │ └── app │ └── AppApplicationTests.java ├── demo ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── demo │ │ │ ├── DemoApplication.java │ │ │ └── controller │ │ │ ├── DemoController.java │ │ │ └── UserController.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── example │ └── demo │ └── DemoApplicationTests.java ├── demoidea ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── kimmking │ │ │ └── demoidea │ │ │ └── DemoideaApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── io │ └── github │ └── kimmking │ └── demoidea │ └── DemoideaApplicationTests.java ├── homework2.0.md ├── java11 ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── klass.png ├── list.png ├── map.png ├── mvnw ├── mvnw.cmd ├── pom.xml ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── demo │ │ │ │ └── DemoApplication.java │ │ └── resources │ │ │ └── application.properties │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── demo │ │ └── DemoApplicationTests.java └── user.png ├── test.txt └── 作业注意事项.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | *.iml 25 | *.idea/ 26 | 27 | out/ 28 | classes/ 29 | target/ 30 | build/ 31 | 32 | .DS_Store 33 | -------------------------------------------------------------------------------- /01jvm/AnalysisForList.java: -------------------------------------------------------------------------------- 1 | public class AnalysisForList { 2 | 3 | private int[] array = new int[] {1,2,3}; 4 | 5 | public void testFor() { 6 | for (int i : array) { 7 | System.out.println(i); 8 | } 9 | } 10 | 11 | public void testForIndex() { 12 | for (int i=0;i { 4 | 5 | void insert(T t); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /01jvm/subinterface/User.java: -------------------------------------------------------------------------------- 1 | package subinterface; 2 | 3 | public class User { 4 | private int id; 5 | 6 | public User(int id) { 7 | this.id = id; 8 | } 9 | 10 | public int getId() { 11 | return id; 12 | } 13 | 14 | public void setId(int id) { 15 | this.id = id; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /01jvm/subinterface/UserDAO.java: -------------------------------------------------------------------------------- 1 | package subinterface; 2 | 3 | public class UserDAO implements UserMapper { 4 | 5 | @Override 6 | public void insert(User user) { 7 | System.out.println("Insert user id: " + user.getId()); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /01jvm/subinterface/UserMain.java: -------------------------------------------------------------------------------- 1 | package subinterface; 2 | 3 | public class UserMain { 4 | 5 | public static void main(String[] args) { 6 | UserDAO dao = new UserDAO(); 7 | dao.insert(new User(123)); 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /01jvm/subinterface/UserMapper.java: -------------------------------------------------------------------------------- 1 | package subinterface; 2 | 3 | public interface UserMapper extends Mapper { 4 | 5 | @Override 6 | void insert(User user); 7 | } 8 | -------------------------------------------------------------------------------- /01jvm/环境准备.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Windows 4 | 5 | 1.管理员身份打开powershell 6 | 7 | 2.运行 8 | Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) 9 | 10 | 3.执行choco install superbenchmarker 11 | 12 | 4.输入 sb 13 | 14 | 执行 sb -u http://localhost:8088/api/hello -c 20 -N 60 15 | 16 | ## Mac 17 | 18 | 1.执行brew install wrk 19 | 如果显式brew update很慢,可以ctrl+C打断更新 20 | 21 | 2.输入 wrk 22 | 23 | 执行 wrk -t8 -c40 -d60s http://localhost:8088/api/hello 24 | 25 | ## 压测程序 26 | 27 | 1.可以从github获取 28 | git clone https://github.com/kimmking/atlantis 29 | cd atlantis\gateway-server 30 | mvn clean package 31 | 然后在target目录可以找到gateway-server-0.0.1-SNAPSHOT.jar 32 | 33 | 2.也可以从此处下载已经编译好的: 34 | 链接:https://pan.baidu.com/s/1NbpYX4M3YKLYM1JJeIzgSQ 35 | 提取码:sp85 36 | 37 | java -jar -Xmx512m -Xms512 gateway-server-0.0.1-SNAPSHOT.jar 38 | 39 | -------------------------------------------------------------------------------- /02nio/nio01/src/main/java/java0/nio01/OKHttpClientDemo.java: -------------------------------------------------------------------------------- 1 | package java0.nio01; 2 | 3 | import okhttp3.OkHttpClient; 4 | import okhttp3.Request; 5 | import okhttp3.Response; 6 | 7 | import java.io.IOException; 8 | 9 | public class OKHttpClientDemo { 10 | 11 | private static OkHttpClient client = new OkHttpClient(); 12 | public static void main(String[] args) throws IOException { 13 | 14 | getBody1(client, "http://localhost:8801"); 15 | client = null; 16 | } 17 | 18 | private static void getBody1(OkHttpClient client, String url){ 19 | 20 | Request request = new Request.Builder() 21 | .get() 22 | .url(url) 23 | .build(); 24 | //String body = "test"; 25 | try { 26 | Response response = client.newCall(request).execute(); 27 | String responseData = response.body().string(); 28 | System.out.println(responseData); 29 | } catch (IOException e) { 30 | e.printStackTrace(); 31 | }finally { 32 | client = null; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /02nio/nio01/src/main/java/java0/nio01/netty/HttpInitializer.java: -------------------------------------------------------------------------------- 1 | package java0.nio01.netty; 2 | 3 | import io.netty.channel.ChannelInitializer; 4 | import io.netty.channel.ChannelPipeline; 5 | import io.netty.channel.socket.SocketChannel; 6 | import io.netty.handler.codec.http.HttpObjectAggregator; 7 | import io.netty.handler.codec.http.HttpServerCodec; 8 | 9 | public class HttpInitializer extends ChannelInitializer { 10 | 11 | @Override 12 | public void initChannel(SocketChannel ch) { 13 | ChannelPipeline p = ch.pipeline(); 14 | p.addLast(new HttpServerCodec()); 15 | //p.addLast(new HttpServerExpectContinueHandler()); 16 | p.addLast(new HttpObjectAggregator(1024 * 1024)); 17 | p.addLast(new HttpHandler()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /02nio/nio02/README.md: -------------------------------------------------------------------------------- 1 | # netty-gateway 2 | 3 | ``` 4 | 5 | 6 | ``` -------------------------------------------------------------------------------- /02nio/nio02/src/main/java/io/github/kimmking/gateway/filter/HeaderHttpRequestFilter.java: -------------------------------------------------------------------------------- 1 | package io.github.kimmking.gateway.filter; 2 | 3 | import io.netty.channel.ChannelHandlerContext; 4 | import io.netty.handler.codec.http.FullHttpRequest; 5 | 6 | public class HeaderHttpRequestFilter implements HttpRequestFilter { 7 | 8 | @Override 9 | public void filter(FullHttpRequest fullRequest, ChannelHandlerContext ctx) { 10 | fullRequest.headers().set("mao", "soul"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /02nio/nio02/src/main/java/io/github/kimmking/gateway/filter/HeaderHttpResponseFilter.java: -------------------------------------------------------------------------------- 1 | package io.github.kimmking.gateway.filter; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | import io.netty.buffer.Unpooled; 5 | import io.netty.handler.codec.http.FullHttpResponse; 6 | import io.netty.handler.codec.http.HttpResponseStatus; 7 | 8 | public class HeaderHttpResponseFilter implements HttpResponseFilter { 9 | @Override 10 | public void filter(FullHttpResponse response) { 11 | response.headers().set("kk", "java-1-nio"); 12 | response.setStatus(HttpResponseStatus.CREATED); 13 | // byte[] array = response.content().array(); 14 | // String content = new String(array); 15 | // System.out.println(content); 16 | // content = content + ",kimmking"; 17 | byte[] bytes = "hello,kimm.".getBytes(); 18 | //response.headers().setInt("Content-Length", bytes.length); 19 | ByteBuf byteBuf = Unpooled.wrappedBuffer(bytes); 20 | ByteBuf content = response.content(); 21 | content.clear(); 22 | content.writeBytes(byteBuf); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /02nio/nio02/src/main/java/io/github/kimmking/gateway/filter/HttpRequestFilter.java: -------------------------------------------------------------------------------- 1 | package io.github.kimmking.gateway.filter; 2 | 3 | import io.netty.channel.ChannelHandlerContext; 4 | import io.netty.handler.codec.http.FullHttpRequest; 5 | 6 | public interface HttpRequestFilter { 7 | 8 | void filter(FullHttpRequest fullRequest, ChannelHandlerContext ctx); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /02nio/nio02/src/main/java/io/github/kimmking/gateway/filter/HttpResponseFilter.java: -------------------------------------------------------------------------------- 1 | package io.github.kimmking.gateway.filter; 2 | 3 | import io.netty.handler.codec.http.FullHttpResponse; 4 | 5 | public interface HttpResponseFilter { 6 | 7 | void filter(FullHttpResponse response); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /02nio/nio02/src/main/java/io/github/kimmking/gateway/outbound/netty4/NettyHttpClientOutboundHandler.java: -------------------------------------------------------------------------------- 1 | package io.github.kimmking.gateway.outbound.netty4; 2 | 3 | import io.netty.channel.ChannelHandlerContext; 4 | import io.netty.channel.ChannelInboundHandlerAdapter; 5 | 6 | public class NettyHttpClientOutboundHandler extends ChannelInboundHandlerAdapter { 7 | 8 | @Override 9 | public void channelActive(ChannelHandlerContext ctx) 10 | throws Exception { 11 | 12 | 13 | } 14 | 15 | @Override 16 | public void channelRead(ChannelHandlerContext ctx, Object msg) 17 | throws Exception { 18 | 19 | 20 | 21 | } 22 | } -------------------------------------------------------------------------------- /02nio/nio02/src/main/java/io/github/kimmking/gateway/outbound/okhttp/OkhttpOutboundHandler.java: -------------------------------------------------------------------------------- 1 | package io.github.kimmking.gateway.outbound.okhttp; 2 | 3 | public class OkhttpOutboundHandler { 4 | } 5 | -------------------------------------------------------------------------------- /02nio/nio02/src/main/java/io/github/kimmking/gateway/router/HttpEndpointRouter.java: -------------------------------------------------------------------------------- 1 | package io.github.kimmking.gateway.router; 2 | 3 | import java.util.List; 4 | 5 | public interface HttpEndpointRouter { 6 | 7 | String route(List endpoints); 8 | 9 | // Load Balance 10 | // Random 11 | // RoundRibbon 12 | // Weight 13 | // - server01,20 14 | // - server02,30 15 | // - server03,50 16 | 17 | } 18 | -------------------------------------------------------------------------------- /02nio/nio02/src/main/java/io/github/kimmking/gateway/router/RandomHttpEndpointRouter.java: -------------------------------------------------------------------------------- 1 | package io.github.kimmking.gateway.router; 2 | 3 | import java.util.List; 4 | import java.util.Random; 5 | 6 | public class RandomHttpEndpointRouter implements HttpEndpointRouter { 7 | @Override 8 | public String route(List urls) { 9 | int size = urls.size(); 10 | Random random = new Random(System.currentTimeMillis()); 11 | return urls.get(random.nextInt(size)); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /03concurrency/0301/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | java0.03concurrency 8 | 0301 9 | 1.0 10 | 11 | 12 | 13 | org.apache.maven.plugins 14 | maven-compiler-plugin 15 | 16 | 8 17 | 8 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0301/DaemonThread.java: -------------------------------------------------------------------------------- 1 | package java0.conc0301; 2 | 3 | public class DaemonThread { 4 | 5 | public static void main(String[] args) throws InterruptedException { 6 | Runnable task = () -> { 7 | try { 8 | Thread.sleep(5000); 9 | } catch (InterruptedException e) { 10 | e.printStackTrace(); 11 | } 12 | Thread t = Thread.currentThread(); 13 | System.out.println("当前线程:" + t.getName()); 14 | }; 15 | Thread thread = new Thread(task); 16 | thread.setName("test-thread-1"); 17 | thread.setDaemon(true); 18 | thread.start(); 19 | 20 | //Thread.sleep(5500); 21 | } 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0301/Runner1.java: -------------------------------------------------------------------------------- 1 | package java0.conc0301; 2 | 3 | public class Runner1 implements Runnable { 4 | 5 | @Override 6 | public void run() { 7 | for (int i = 0; i < 100; i++) { 8 | System.out.println("进入Runner1运行状态——————————" + i); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0301/Runner2.java: -------------------------------------------------------------------------------- 1 | package java0.conc0301; 2 | 3 | public class Runner2 implements Runnable { 4 | 5 | @Override 6 | public void run() { 7 | for (int i = 0; i < 100; i++) { 8 | System.out.println("进入Runner2运行状态——————————" + i); 9 | } 10 | 11 | boolean result = Thread.currentThread().isInterrupted(); 12 | 13 | boolean result1 = Thread.interrupted(); // 重置状态 14 | 15 | boolean result3 = Thread.currentThread().isInterrupted(); 16 | 17 | System.out.println("Runner2.run result ===>" + result); 18 | System.out.println("Runner2.run result1 ===>" + result1); 19 | System.out.println("Runner2.run result3 ===>" + result3); 20 | 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0301/RunnerMain.java: -------------------------------------------------------------------------------- 1 | 2 | package java0.conc0301; 3 | 4 | import java.io.IOException; 5 | 6 | public class RunnerMain { 7 | 8 | public static void main(String[] args) throws IOException { 9 | 10 | Runner1 runner1 = new Runner1(); 11 | Thread thread1 = new Thread(runner1); 12 | 13 | Runner2 runner2 = new Runner2(); 14 | Thread thread2 = new Thread(runner2); 15 | 16 | thread1.start(); 17 | thread2.start(); 18 | 19 | thread2.interrupt(); // i = true 20 | 21 | System.out.println(Thread.activeCount()); 22 | 23 | Thread.currentThread().getThreadGroup().list(); 24 | System.out.println(Thread.currentThread().getThreadGroup().getParent().activeGroupCount()); 25 | Thread.currentThread().getThreadGroup().getParent().list(); 26 | 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0301/ThreadA.java: -------------------------------------------------------------------------------- 1 | package java0.conc0301; 2 | 3 | public class ThreadA extends Thread { 4 | 5 | public void run() { 6 | super.run(); 7 | try { 8 | Thread.sleep(500); 9 | } catch (InterruptedException e) { 10 | e.printStackTrace(); 11 | } 12 | System.out.println("这是线程A"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0301/ThreadC.java: -------------------------------------------------------------------------------- 1 | package java0.conc0301; 2 | 3 | import java.util.concurrent.Callable; 4 | 5 | public class ThreadC implements Callable { 6 | 7 | @Override 8 | public String call() throws Exception { 9 | Thread.sleep(500); 10 | System.out.println("这是线程C"); 11 | return "线程C"; 12 | } 13 | 14 | 15 | 16 | } 17 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0301/ThreadCount.java: -------------------------------------------------------------------------------- 1 | package java0.conc0301; 2 | 3 | public class ThreadCount { 4 | public static void main(String[] args) throws InterruptedException { 5 | //System.out.println("system:"+Thread.currentThread().getThreadGroup().getParent()); 6 | Thread.currentThread().getThreadGroup().getParent().list(); 7 | 8 | // System.out.println("main:"+Thread.currentThread().getThreadGroup()); 9 | // Thread.currentThread().getThreadGroup().list(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0301/ThreadMain.java: -------------------------------------------------------------------------------- 1 | package java0.conc0301; 2 | 3 | import java.util.concurrent.ExecutionException; 4 | import java.util.concurrent.FutureTask; 5 | 6 | public class ThreadMain { 7 | 8 | public static void main(String[] args) { 9 | 10 | ThreadA threadA = new ThreadA(); 11 | threadA.start(); 12 | System.out.println("这是主线程:"); 13 | 14 | ThreadB threadB = new ThreadB(); 15 | new Thread(threadB).start(); 16 | System.out.println("这是主线程:"); 17 | 18 | ThreadC threadC = new ThreadC(); 19 | FutureTask futureTask = new FutureTask<>(threadC); 20 | new Thread(futureTask).start(); 21 | System.out.println("这是主线程:begin!"); 22 | try { 23 | System.out.println("得到的返回结果是:" + futureTask.get()); 24 | } catch (InterruptedException e) { 25 | e.printStackTrace(); 26 | } catch (ExecutionException e) { 27 | e.printStackTrace(); 28 | } 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0301/sync/Cref.java: -------------------------------------------------------------------------------- 1 | package java0.conc0301.sync; 2 | 3 | public class Cref { 4 | public static void main(String[] args) { 5 | int x = 10; 6 | // int y = Counter.B; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0301/sync/Thread1.java: -------------------------------------------------------------------------------- 1 | 2 | package java0.conc0301.sync; 3 | 4 | public class Thread1 implements Runnable { 5 | 6 | @Override 7 | public void run() { 8 | synchronized (this) { 9 | for (int i = 0; i < 10; i++) { 10 | System.out.println(Thread.currentThread().getName() + " synchronized loop " + i); 11 | } 12 | } 13 | } 14 | 15 | public static void main(String[] args) { 16 | Thread1 t1 = new Thread1(); 17 | Thread ta = new Thread(t1, "A"); 18 | Thread tb = new Thread(t1, "B"); 19 | ta.start(); 20 | tb.start(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0302/atomic/AtomicCount.java: -------------------------------------------------------------------------------- 1 | 2 | package java0.conc0302.atomic; 3 | 4 | import java.util.concurrent.atomic.AtomicInteger; 5 | 6 | public class AtomicCount { 7 | 8 | private AtomicInteger num = new AtomicInteger(); 9 | 10 | public int add() { 11 | return num.getAndIncrement(); 12 | } 13 | 14 | public int getNum() { 15 | return num.get(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0302/atomic/AtomicMain.java: -------------------------------------------------------------------------------- 1 | 2 | package java0.conc0302.atomic; 3 | 4 | public class AtomicMain { 5 | 6 | public static void main(String[] args) { 7 | final SyncCount count = new SyncCount(); 8 | for (int i = 0; i < 100; i++) { 9 | new Thread(new Runnable() { 10 | @Override 11 | public void run() { 12 | for (int j = 0; j < 10000; j++) { 13 | count.add(); 14 | } 15 | } 16 | }).start(); 17 | } 18 | 19 | try { 20 | Thread.sleep(5000L); 21 | } catch (InterruptedException e) { 22 | e.printStackTrace(); 23 | } 24 | 25 | System.out.println("num=" + count.getNum()); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0302/atomic/Count.java: -------------------------------------------------------------------------------- 1 | 2 | package java0.conc0302.atomic; 3 | 4 | public class Count { 5 | 6 | private int num = 0; 7 | 8 | public int add() { 9 | return num++; 10 | } 11 | 12 | public int getNum() { 13 | return num; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0302/atomic/SyncCount.java: -------------------------------------------------------------------------------- 1 | 2 | package java0.conc0302.atomic; 3 | 4 | import java.util.concurrent.locks.Lock; 5 | import java.util.concurrent.locks.ReentrantLock; 6 | 7 | public class SyncCount { 8 | 9 | private int num = 0; 10 | 11 | private Lock lock = new ReentrantLock(true); 12 | 13 | public int add() { 14 | try { 15 | lock.lock(); 16 | return num++; 17 | } finally { 18 | lock.unlock(); 19 | } 20 | } 21 | 22 | public int getNum() { 23 | return num; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0302/lock/LockMain.java: -------------------------------------------------------------------------------- 1 | 2 | package java0.conc0302.lock; 3 | 4 | public class LockMain { 5 | 6 | public static void main(String[] args) { 7 | Count3 count3 = new Count3(); 8 | ThreadA threadA = new ThreadA(count3); 9 | threadA.setName("线程A"); 10 | threadA.start(); 11 | 12 | ThreadB threadB = new ThreadB(count3); 13 | threadB.setName("线程B"); 14 | threadB.start(); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0302/lock/ReentrantLockDemo.java: -------------------------------------------------------------------------------- 1 | 2 | package java0.conc0302.lock; 3 | 4 | public class ReentrantLockDemo { 5 | 6 | public static void main(String[] args) { 7 | final Count count = new Count(); 8 | 9 | for (int i = 0; i < 2; i++) { 10 | new Thread() { 11 | public void run() { 12 | count.get(); 13 | } 14 | }.start(); 15 | } 16 | 17 | for (int i = 0; i < 2; i++) { 18 | new Thread() { 19 | public void run() { 20 | count.put(); 21 | } 22 | }.start(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0302/lock/ThreadA.java: -------------------------------------------------------------------------------- 1 | 2 | package java0.conc0302.lock; 3 | 4 | public class ThreadA extends Thread { 5 | private Count3 count3; 6 | 7 | public ThreadA(Count3 count3) { 8 | this.count3 = count3; 9 | } 10 | 11 | public void run() { 12 | count3.add(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0302/lock/ThreadB.java: -------------------------------------------------------------------------------- 1 | 2 | package java0.conc0302.lock; 3 | 4 | public class ThreadB extends Thread { 5 | private Count3 count3; 6 | 7 | public ThreadB(Count3 count3) { 8 | this.count3 = count3; 9 | } 10 | 11 | public void run() { 12 | count3.lockMethod(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0302/threadpool/ExecutorServiceDemo.java: -------------------------------------------------------------------------------- 1 | 2 | package java0.conc0302.threadpool; 3 | 4 | import java.util.concurrent.Callable; 5 | import java.util.concurrent.Executors; 6 | import java.util.concurrent.ScheduledExecutorService; 7 | 8 | public class ExecutorServiceDemo { 9 | 10 | public static void main(String[] args) { 11 | ScheduledExecutorService executorService = Executors.newScheduledThreadPool(16); 12 | try { 13 | String str = executorService.submit(new Callable() { 14 | @Override 15 | public String call() throws Exception { 16 | return "I am a task, which submited by the so called laoda, and run by those anonymous workers"; 17 | } 18 | }).get(); 19 | 20 | System.out.println("str=" + str); 21 | } catch (Exception e) { 22 | e.printStackTrace(); 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0302/threadpool/NewFixedThreadPoolDemo.java: -------------------------------------------------------------------------------- 1 | 2 | package java0.conc0302.threadpool; 3 | 4 | import java.util.concurrent.ExecutorService; 5 | import java.util.concurrent.Executors; 6 | 7 | public class NewFixedThreadPoolDemo { 8 | 9 | public static void main(String[] args) { 10 | ExecutorService executorService = Executors.newFixedThreadPool(16); 11 | for (int i = 0; i < 100; i++) { 12 | final int no = i; 13 | executorService.execute(() -> { 14 | try { 15 | System.out.println("start:" + no); 16 | Thread.sleep(1000L); 17 | System.out.println("end:" + no); 18 | } catch (InterruptedException e) { 19 | e.printStackTrace(); 20 | } 21 | }); 22 | } 23 | executorService.shutdown(); 24 | System.out.println("Main Thread End!"); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0302/threadpool/NewSingleThreadExecutorDemo.java: -------------------------------------------------------------------------------- 1 | 2 | package java0.conc0302.threadpool; 3 | 4 | import java.util.concurrent.ExecutorService; 5 | import java.util.concurrent.Executors; 6 | 7 | public class NewSingleThreadExecutorDemo { 8 | 9 | public static void main(String[] args) { 10 | 11 | ExecutorService executorService = Executors.newSingleThreadExecutor(); 12 | 13 | for (int i = 0; i < 10; i++) { 14 | final int no = i; 15 | executorService.execute(() -> { 16 | System.out.println("start:" + no); 17 | try { 18 | Thread.sleep(1000L); 19 | } catch (InterruptedException e) { 20 | e.printStackTrace(); 21 | } 22 | System.out.println("end:" + no); 23 | }); 24 | } 25 | executorService.shutdown(); 26 | System.out.println("Main Thread End!"); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0303/Homework03.java: -------------------------------------------------------------------------------- 1 | package java0.conc0303; 2 | 3 | import java.util.concurrent.CountDownLatch; 4 | 5 | /** 6 | * 本周作业:(必做)思考有多少种方式,在main函数启动一个新线程或线程池, 7 | * 异步运行一个方法,拿到这个方法的返回值后,退出主线程? 8 | * 写出你的方法,越多越好,提交到github。 9 | * 10 | * 一个简单的代码参考: 11 | */ 12 | public class Homework03 { 13 | 14 | public static void main(String[] args) { 15 | 16 | long start=System.currentTimeMillis(); 17 | 18 | // 在这里创建一个线程或线程池, 19 | // 异步执行 下面方法 20 | 21 | int result = sum(); //这是得到的返回值 22 | 23 | // 确保 拿到result 并输出 24 | System.out.println("异步计算结果为:"+result); 25 | 26 | System.out.println("使用时间:"+ (System.currentTimeMillis()-start) + " ms"); 27 | 28 | // 然后退出main线程 29 | } 30 | 31 | private static int sum() { 32 | return fibo(36); 33 | } 34 | 35 | private static int fibo(int a) { 36 | if ( a < 2) 37 | return 1; 38 | return fibo(a-1) + fibo(a-2); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0303/collection/TreeMapDemo.java: -------------------------------------------------------------------------------- 1 | package java0.conc0303.collection; 2 | 3 | import java.util.Comparator; 4 | import java.util.TreeMap; 5 | 6 | public class TreeMapDemo { 7 | 8 | public static void main(String[] args) { 9 | 10 | // 11 | TreeMap map = new TreeMap<>(Comparator.reverseOrder()); 12 | map.put(3, "val"); 13 | map.put(2, "val"); 14 | map.put(1, "val"); 15 | map.put(5, "val"); 16 | map.put(4, "val"); 17 | // {5=val, 4=val, 3=val, 2=val, 1=val} 18 | System.out.println(map); 19 | 20 | TreeMap map1 = new TreeMap<>(Comparator.naturalOrder()); 21 | map1.putAll(map); 22 | System.out.println(map1); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /03concurrency/0301/src/main/java/java0/conc0303/future/FutureDemo1.java: -------------------------------------------------------------------------------- 1 | package java0.conc0303.future; 2 | 3 | import java.util.Random; 4 | import java.util.concurrent.*; 5 | 6 | public class FutureDemo1 { 7 | public static void main(String[] args) { 8 | ExecutorService executor = Executors.newCachedThreadPool(); 9 | Future result = executor.submit(new Callable() { 10 | public Integer call() throws Exception { 11 | return new Random().nextInt(); 12 | } 13 | }); 14 | executor.shutdown(); 15 | try { 16 | System.out.println("result:" + result.get()); 17 | } catch (InterruptedException e) { 18 | e.printStackTrace(); 19 | } catch (ExecutionException e) { 20 | e.printStackTrace(); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /04fx/Java8inAction/.gitignore: -------------------------------------------------------------------------------- 1 | /ThinkingJava/ThinkingJava.iml 2 | /.idea 3 | *.class 4 | target/ 5 | 6 | # Mobile Tools for Java (J2ME) 7 | .mtj.tmp/ 8 | 9 | # Package Files # 10 | *.jar 11 | *.war 12 | *.ear 13 | 14 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 15 | hs_err_pid* 16 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/appa/Author.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.appa; 2 | 3 | import java.lang.annotation.Repeatable; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | 7 | @Repeatable(Authors.class) 8 | @Retention(RetentionPolicy.RUNTIME) 9 | public @interface Author { 10 | 11 | String name(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/appa/Authors.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.appa; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | 6 | @Retention(RetentionPolicy.RUNTIME) 7 | public @interface Authors { 8 | 9 | Author[] value(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/appa/Book.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.appa; 2 | 3 | import java.util.Arrays; 4 | 5 | @Author(name = "Raoul") 6 | @Author(name = "Mario") 7 | @Author(name = "Alan") 8 | public class Book { 9 | 10 | public static void main(String[] args) { 11 | Author[] authors = Book.class.getAnnotationsByType(Author.class); 12 | Arrays.asList(authors).stream().forEach(a -> { 13 | System.out.println(a.name()); 14 | }); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/appd/InnerClass.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.appd; 2 | 3 | import java.util.function.Function; 4 | 5 | public class InnerClass { 6 | Function f = new Function() { 7 | @Override 8 | public String apply(Object obj) { 9 | return obj.toString(); 10 | } 11 | }; 12 | } 13 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/appd/Lambda.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.appd; 2 | 3 | import java.util.function.Function; 4 | 5 | public class Lambda { 6 | 7 | Function f = obj -> obj.toString(); 8 | } 9 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap10/Car.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap10; 2 | 3 | import java.util.*; 4 | 5 | public class Car { 6 | 7 | private Optional insurance; 8 | 9 | public Optional getInsurance() { 10 | return insurance; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap10/Insurance.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap10; 2 | 3 | public class Insurance { 4 | 5 | private String name; 6 | 7 | public String getName() { 8 | return name; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap10/OperationsWithOptional.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap10; 2 | 3 | import java.util.*; 4 | 5 | import static java.util.Optional.of; 6 | import static java.util.Optional.empty; 7 | 8 | public class OperationsWithOptional { 9 | 10 | public static void main(String... args) { 11 | System.out.println(max(of(3), of(5))); 12 | System.out.println(max(empty(), of(5))); 13 | 14 | Optional opt1 = of(5); 15 | //Optional opt2 = opt1.or(() -> of(4)); 16 | 17 | // System.out.println( 18 | // of(5).or(() -> of(4)) 19 | // ); 20 | } 21 | 22 | public static final Optional max(Optional i, Optional j) { 23 | return i.flatMap(a -> j.map(b -> Math.max(a, b))); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap10/OptionalMain.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap10; 2 | 3 | import java.util.*; 4 | 5 | import static java.util.stream.Collectors.toSet; 6 | 7 | public class OptionalMain { 8 | 9 | public String getCarInsuranceName(Optional person) { 10 | return person.flatMap(Person::getCar) 11 | .flatMap(Car::getInsurance) 12 | .map(Insurance::getName) 13 | .orElse("Unknown"); 14 | } 15 | 16 | public Set getCarInsuranceNames(List persons) { 17 | return persons.stream() 18 | .map(Person::getCar) 19 | .map(optCar -> optCar.flatMap(Car::getInsurance)) 20 | .map(optInsurance -> optInsurance.map(Insurance::getName).get()) 21 | // .flatMap(Optional::stream) 22 | .collect(toSet()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap10/Person.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap10; 2 | 3 | import java.util.*; 4 | 5 | public class Person { 6 | 7 | private Optional car; 8 | 9 | public Optional getCar() { 10 | return car; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap11/AsyncShopClient.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap11; 2 | 3 | import java.util.concurrent.Future; 4 | 5 | public class AsyncShopClient { 6 | 7 | public static void main(String[] args) { 8 | AsyncShop shop = new AsyncShop("BestShop"); 9 | long start = System.nanoTime(); 10 | Future futurePrice = shop.getPrice("myPhone"); 11 | long incocationTime = ((System.nanoTime() - start) / 1_000_000); 12 | System.out.println("Invocation returned after " + incocationTime + " msecs"); 13 | try { 14 | System.out.println("Price is " + futurePrice.get()); 15 | } catch (Exception e) { 16 | throw new RuntimeException(e); 17 | } 18 | long retrivalTime = ((System.nanoTime() - start) / 1_000_000); 19 | System.out.println("Price returned after " + retrivalTime + " msecs"); 20 | } 21 | } -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap11/BestPriceFinderMain.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap11; 2 | 3 | import java.util.List; 4 | import java.util.function.Supplier; 5 | 6 | public class BestPriceFinderMain { 7 | 8 | private static BestPriceFinder bestPriceFinder = new BestPriceFinder(); 9 | 10 | public static void main(String[] args) { 11 | execute("sequential", () -> bestPriceFinder.findPricesSequential("myPhone27S")); 12 | execute("parallel", () -> bestPriceFinder.findPricesParallel("myPhone27S")); 13 | execute("composed CompletableFuture", () -> bestPriceFinder.findPricesFuture("myPhone27S")); 14 | bestPriceFinder.printPricesStream("myPhone27S"); 15 | } 16 | 17 | private static void execute(String msg, Supplier> s) { 18 | long start = System.nanoTime(); 19 | System.out.println(s.get()); 20 | long duration = (System.nanoTime() - start) / 1_000_000; 21 | System.out.println(msg + " done in " + duration + " msecs"); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap11/Discount.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap11; 2 | 3 | import static lambdasinaction.chap11.Util.delay; 4 | import static lambdasinaction.chap11.Util.format; 5 | 6 | public class Discount { 7 | 8 | public enum Code { 9 | NONE(0), SILVER(5), GOLD(10), PLATINUM(15), DIAMOND(20); 10 | 11 | private final int percentage; 12 | 13 | Code(int percentage) { 14 | this.percentage = percentage; 15 | } 16 | } 17 | 18 | public static String applyDiscount(Quote quote) { 19 | return quote.getShopName() + " price is " + Discount.apply(quote.getPrice(), quote.getDiscountCode()); 20 | } 21 | private static double apply(double price, Code code) { 22 | delay(); 23 | return format(price * (100 - code.percentage) / 100); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap11/ExchangeService.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap11; 2 | 3 | import static lambdasinaction.chap11.Util.delay; 4 | 5 | public class ExchangeService { 6 | 7 | public enum Money { 8 | USD(1.0), EUR(1.35387), GBP(1.69715), CAD(.92106), MXN(.07683); 9 | 10 | private final double rate; 11 | 12 | Money(double rate) { 13 | this.rate = rate; 14 | } 15 | } 16 | 17 | public static double getRate(Money source, Money destination) { 18 | return getRateWithDelay(source, destination); 19 | } 20 | 21 | private static double getRateWithDelay(Money source, Money destination) { 22 | delay(); 23 | return destination.rate / source.rate; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap11/Quote.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap11; 2 | 3 | public class Quote { 4 | 5 | private final String shopName; 6 | private final double price; 7 | private final Discount.Code discountCode; 8 | 9 | public Quote(String shopName, double price, Discount.Code discountCode) { 10 | this.shopName = shopName; 11 | this.price = price; 12 | this.discountCode = discountCode; 13 | } 14 | 15 | public static Quote parse(String s) { 16 | String[] split = s.split(":"); 17 | String shopName = split[0]; 18 | double price = Double.parseDouble(split[1]); 19 | Discount.Code discountCode = Discount.Code.valueOf(split[2]); 20 | return new Quote(shopName, price, discountCode); 21 | } 22 | 23 | public String getShopName() { 24 | return shopName; 25 | } 26 | 27 | public double getPrice() { 28 | return price; 29 | } 30 | 31 | public Discount.Code getDiscountCode() { 32 | return discountCode; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap11/Shop.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap11; 2 | 3 | import static lambdasinaction.chap11.Util.delay; 4 | import static lambdasinaction.chap11.Util.format; 5 | 6 | import java.util.Random; 7 | 8 | public class Shop { 9 | 10 | private final String name; 11 | private final Random random; 12 | 13 | public Shop(String name) { 14 | this.name = name; 15 | random = new Random(name.charAt(0) * name.charAt(1) * name.charAt(2)); 16 | } 17 | 18 | public String getPrice(String product) { 19 | double price = calculatePrice(product); 20 | Discount.Code code = Discount.Code.values()[random.nextInt(Discount.Code.values().length)]; 21 | return name + ":" + price + ":" + code; 22 | } 23 | 24 | public double calculatePrice(String product) { 25 | delay(); 26 | return format(random.nextDouble() * product.charAt(0) + product.charAt(1)); 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap14/Combinators.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap14; 2 | 3 | import java.util.function.Function; 4 | 5 | public class Combinators { 6 | 7 | public static void main(String[] args) { 8 | System.out.println(repeat(3, (Integer x) -> 2 * x).apply(10)); 9 | } 10 | 11 | static Function compose(Function g, Function f) { 12 | return x -> g.apply(f.apply(x)); 13 | } 14 | 15 | static Function repeat(int n, Function f) { 16 | return n == 0 ? x -> x : compose(f, repeat(n - 1, f)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap2/MeaningOfThis.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap2; 2 | 3 | public class MeaningOfThis { 4 | 5 | public final int value = 4; 6 | 7 | public void doIt() { 8 | int value = 6; 9 | Runnable r = new Runnable() { 10 | public final int value = 5; 11 | 12 | @Override 13 | public void run() { 14 | int value = 10; 15 | System.out.println(this.value); 16 | } 17 | }; 18 | r.run(); 19 | } 20 | 21 | public static void main(String... args) { 22 | MeaningOfThis m = new MeaningOfThis(); 23 | m.doIt(); // ??? 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap4/StreamVsCollection.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap4; 2 | 3 | import java.util.*; 4 | import java.util.stream.*; 5 | import static java.util.stream.Collectors.toList; 6 | 7 | 8 | public class StreamVsCollection { 9 | 10 | public static void main(String...args){ 11 | List names = Arrays.asList("Java8", "Lambdas", "In", "Action"); 12 | Stream s = names.stream(); 13 | s.forEach(System.out::println); 14 | // uncommenting this line will result in an IllegalStateException 15 | // because streams can be consumed only once 16 | //s.forEach(System.out::println); 17 | } 18 | } -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap5/Laziness.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap5; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | import static java.util.stream.Collectors.toList; 7 | 8 | /** 9 | * Created by raoul-gabrielurma on 14/01/2014. 10 | */ 11 | public class Laziness { 12 | 13 | public static void main(String[] args) { 14 | List numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8); 15 | List twoEvenSquares = 16 | numbers.stream() 17 | .filter(n -> { 18 | System.out.println("filtering " + n); return n % 2 == 0; 19 | }) 20 | .map(n -> { 21 | System.out.println("mapping " + n); 22 | return n * n; 23 | }) 24 | .limit(2) 25 | .collect(toList()); 26 | 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap5/Reducing.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap5; 2 | import lambdasinaction.chap4.*; 3 | 4 | import java.util.stream.*; 5 | import java.util.*; 6 | 7 | import static lambdasinaction.chap4.Dish.menu; 8 | 9 | public class Reducing{ 10 | 11 | public static void main(String...args){ 12 | 13 | List numbers = Arrays.asList(3,4,5,1,2); 14 | int sum = numbers.stream().reduce(0, (a, b) -> a + b); 15 | System.out.println(sum); 16 | 17 | int sum2 = numbers.stream().reduce(0, Integer::sum); 18 | System.out.println(sum2); 19 | 20 | int max = numbers.stream().reduce(0, (a, b) -> Integer.max(a, b)); 21 | System.out.println(max); 22 | 23 | Optional min = numbers.stream().reduce(Integer::min); 24 | min.ifPresent(System.out::println); 25 | 26 | int calories = menu.stream() 27 | .map(Dish::getCalories) 28 | .reduce(0, Integer::sum); 29 | System.out.println("Number of calories:" + calories); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap5/Trader.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap5; 2 | public class Trader{ 3 | 4 | private String name; 5 | private String city; 6 | 7 | public Trader(String n, String c){ 8 | this.name = n; 9 | this.city = c; 10 | } 11 | 12 | public String getName(){ 13 | return this.name; 14 | } 15 | 16 | public String getCity(){ 17 | return this.city; 18 | } 19 | 20 | public void setCity(String newCity){ 21 | this.city = newCity; 22 | } 23 | 24 | public String toString(){ 25 | return "Trader:"+this.name + " in " + this.city; 26 | } 27 | } -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap5/Transaction.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap5; 2 | 3 | public class Transaction{ 4 | 5 | private Trader trader; 6 | private int year; 7 | private int value; 8 | 9 | public Transaction(Trader trader, int year, int value) 10 | { 11 | this.trader = trader; 12 | this.year = year; 13 | this.value = value; 14 | } 15 | 16 | public Trader getTrader(){ 17 | return this.trader; 18 | } 19 | 20 | public int getYear(){ 21 | return this.year; 22 | } 23 | 24 | public int getValue(){ 25 | return this.value; 26 | } 27 | 28 | public String toString(){ 29 | return "{" + this.trader + ", " + 30 | "year: "+this.year+", " + 31 | "value:" + this.value +"}"; 32 | } 33 | } -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap6/CollectorHarness.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap6; 2 | 3 | import java.util.function.*; 4 | 5 | public class CollectorHarness { 6 | 7 | public static void main(String[] args) { 8 | //System.out.println("Partitioning done in: " + execute(PartitionPrimeNumbers::partitionPrimes) + " msecs"); 9 | System.out.println("Partitioning done in: " + execute(PartitionPrimeNumbers::partitionPrimesWithCustomCollector) + " msecs" ); 10 | } 11 | 12 | private static long execute(Consumer primePartitioner) { 13 | long fastest = Long.MAX_VALUE; 14 | for (int i = 0; i < 10; i++) { 15 | long start = System.nanoTime(); 16 | primePartitioner.accept(1_000_000); 17 | long duration = (System.nanoTime() - start) / 1_000_000; 18 | if (duration < fastest) fastest = duration; 19 | System.out.println("done in " + duration); 20 | } 21 | return fastest; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap8/Debugging.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap8; 2 | 3 | 4 | import java.util.*; 5 | 6 | public class Debugging{ 7 | public static void main(String[] args) { 8 | List points = Arrays.asList(new Point(12, 2), null); 9 | points.stream().map(p -> p.getX()).forEach(System.out::println); 10 | } 11 | 12 | 13 | private static class Point{ 14 | private int x; 15 | private int y; 16 | 17 | private Point(int x, int y) { 18 | this.x = x; 19 | this.y = y; 20 | } 21 | 22 | public int getX() { 23 | return x; 24 | } 25 | 26 | public void setX(int x) { 27 | this.x = x; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap8/OnlineBanking.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap8; 2 | 3 | 4 | abstract class OnlineBanking { 5 | public void processCustomer(int id){ 6 | Customer c = Database.getCustomerWithId(id); 7 | makeCustomerHappy(c); 8 | } 9 | abstract void makeCustomerHappy(Customer c); 10 | 11 | 12 | // dummy Customer class 13 | static private class Customer {} 14 | // dummy Datbase class 15 | static private class Database{ 16 | static Customer getCustomerWithId(int id){ return new Customer();} 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap8/OnlineBankingLambda.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap8; 2 | 3 | import java.util.function.Consumer; 4 | 5 | 6 | public class OnlineBankingLambda { 7 | 8 | public static void main(String[] args) { 9 | new OnlineBankingLambda().processCustomer(1337, (Customer c) -> System.out.println("Hello!")); 10 | } 11 | 12 | public void processCustomer(int id, Consumer makeCustomerHappy){ 13 | Customer c = Database.getCustomerWithId(id); 14 | makeCustomerHappy.accept(c); 15 | } 16 | 17 | // dummy Customer class 18 | static private class Customer {} 19 | // dummy Database class 20 | static private class Database{ 21 | static Customer getCustomerWithId(int id){ return new Customer();} 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap8/Peek.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap8; 2 | 3 | import java.util.List; 4 | import java.util.stream.Stream; 5 | 6 | import static java.util.stream.Collectors.toList; 7 | 8 | 9 | public class Peek { 10 | 11 | public static void main(String[] args) { 12 | 13 | List result = Stream.of(2, 3, 4, 5) 14 | .peek(x -> System.out.println("taking from stream: " + x)).map(x -> x + 17) 15 | .peek(x -> System.out.println("after map: " + x)).filter(x -> x % 2 == 0) 16 | .peek(x -> System.out.println("after filter: " + x)).limit(3) 17 | .peek(x -> System.out.println("after limit: " + x)).collect(toList()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap9/Ambiguous.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap9; 2 | 3 | public class Ambiguous{ 4 | 5 | public static void main(String... args) { 6 | new C().hello(); 7 | } 8 | 9 | static interface A{ 10 | public default void hello() { 11 | System.out.println("Hello from A"); 12 | } 13 | } 14 | 15 | static interface B { 16 | public default void hello() { 17 | System.out.println("Hello from B"); 18 | } 19 | } 20 | 21 | static class C implements B, A { 22 | public void hello(){ 23 | A.super.hello(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap9/Diamond.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap9; 2 | 3 | public class Diamond{ 4 | 5 | public static void main(String...args){ 6 | new D().hello(); 7 | } 8 | 9 | static interface A{ 10 | public default void hello(){ 11 | System.out.println("Hello from A"); 12 | } 13 | } 14 | 15 | static interface B extends A { } 16 | 17 | static interface C extends A { 18 | } 19 | 20 | static class D implements B, C { 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap9/Drawable.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap9; 2 | 3 | /** 4 | * Created by raoul-gabrielurma on 15/01/2014. 5 | */ 6 | public interface Drawable{ 7 | public void draw(); 8 | } 9 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap9/Ellipse.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap9; 2 | 3 | /** 4 | * Created by raoul-gabrielurma on 15/01/2014. 5 | */ 6 | public class Ellipse implements Resizable { 7 | @Override 8 | public int getWidth() { 9 | return 0; 10 | } 11 | 12 | @Override 13 | public int getHeight() { 14 | return 0; 15 | } 16 | 17 | @Override 18 | public void setWidth(int width) { 19 | 20 | } 21 | 22 | @Override 23 | public void setHeight(int height) { 24 | 25 | } 26 | 27 | @Override 28 | public void setAbsoluteSize(int width, int height) { 29 | 30 | } 31 | 32 | @Override 33 | public void draw() { 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap9/Game.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap9; 2 | 3 | 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | public class Game { 8 | 9 | public static void main(String...args){ 10 | List resizableShapes = 11 | Arrays.asList(new Square(), 12 | new Triangle(), new Ellipse()); 13 | Utils.paint(resizableShapes); 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap9/Intro.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap9; 2 | 3 | import java.util.Arrays; 4 | import java.util.Comparator; 5 | import java.util.List; 6 | 7 | public class Intro{ 8 | 9 | public static void main(String...args){ 10 | 11 | List numbers = Arrays.asList(3, 5, 1, 2, 6); 12 | // sort is a default method 13 | // naturalOrder is a static method 14 | numbers.sort(Comparator.naturalOrder()); 15 | System.out.println(numbers); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap9/Letter.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap9; 2 | 3 | import java.util.function.Function; 4 | 5 | public class Letter{ 6 | public static String addHeader(String text){ 7 | return "From Raoul, Mario and Alan:" + text; 8 | } 9 | 10 | public static String addFooter(String text){ 11 | return text + "Kind regards"; 12 | } 13 | 14 | public static String checkSpelling(String text){ 15 | return text.replaceAll("C\\+\\+", "**Censored**"); 16 | } 17 | 18 | 19 | public static void main(String...args){ 20 | Function addHeader = Letter::addHeader; 21 | Function transformationPipeline 22 | = addHeader.andThen(Letter::checkSpelling) 23 | .andThen(Letter::addFooter); 24 | 25 | System.out.println(transformationPipeline.apply("C++ stay away from me!")); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap9/MostSpecific.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap9; 2 | 3 | public class MostSpecific{ 4 | 5 | public static void main(String... args) { 6 | new C().hello(); 7 | new E().hello(); 8 | new G().hello(); 9 | } 10 | 11 | static interface A{ 12 | public default void hello() { 13 | System.out.println("Hello from A"); 14 | } 15 | } 16 | 17 | static interface B extends A{ 18 | public default void hello() { 19 | System.out.println("Hello from B"); 20 | } 21 | } 22 | 23 | static class C implements B, A {} 24 | 25 | static class D implements A{} 26 | 27 | static class E extends D implements B, A{} 28 | 29 | static class F implements B, A { 30 | public void hello() { 31 | System.out.println("Hello from F"); 32 | } 33 | } 34 | 35 | static class G extends F implements B, A{} 36 | 37 | } 38 | 39 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap9/Resizable.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap9; 2 | 3 | public interface Resizable extends Drawable{ 4 | public int getWidth(); 5 | public int getHeight(); 6 | public void setWidth(int width); 7 | public void setHeight(int height); 8 | public void setAbsoluteSize(int width, int height); 9 | //TODO: uncomment, read the README for instructions 10 | //public void setRelativeSize(int widthFactor, int heightFactor); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap9/Square.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap9; 2 | 3 | /** 4 | * Created by raoul-gabrielurma on 15/01/2014. 5 | */ 6 | public class Square implements Resizable { 7 | @Override 8 | public int getWidth() { 9 | return 0; 10 | } 11 | 12 | @Override 13 | public int getHeight() { 14 | return 0; 15 | } 16 | 17 | @Override 18 | public void setWidth(int width) { 19 | 20 | } 21 | 22 | @Override 23 | public void setHeight(int height) { 24 | 25 | } 26 | 27 | @Override 28 | public void setAbsoluteSize(int width, int height) { 29 | 30 | } 31 | 32 | @Override 33 | public void draw() { 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap9/Triangle.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap9; 2 | 3 | /** 4 | * Created by raoul-gabrielurma on 15/01/2014. 5 | */ 6 | public class Triangle implements Resizable { 7 | @Override 8 | public int getWidth() { 9 | return 0; 10 | } 11 | 12 | @Override 13 | public int getHeight() { 14 | return 0; 15 | } 16 | 17 | @Override 18 | public void setWidth(int width) { 19 | 20 | } 21 | 22 | @Override 23 | public void setHeight(int height) { 24 | 25 | } 26 | 27 | @Override 28 | public void setAbsoluteSize(int width, int height) { 29 | 30 | } 31 | 32 | @Override 33 | public void draw() { 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/chap9/Utils.java: -------------------------------------------------------------------------------- 1 | package lambdasinaction.chap9; 2 | 3 | import java.util.List; 4 | 5 | public class Utils{ 6 | public static void paint(List l){ 7 | l.forEach(r -> { r.setAbsoluteSize(42, 42); }); 8 | 9 | //TODO: uncomment, read the README for instructions 10 | //l.forEach(r -> { r.setRelativeSize(2, 2); }); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/lambdasinaction/dsl/model/Tax.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005 JBoss Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package lambdasinaction.dsl.model; 18 | 19 | public class Tax { 20 | public static double regional(double value) { 21 | return value * 1.1; 22 | } 23 | 24 | public static double general(double value) { 25 | return value * 1.3; 26 | } 27 | 28 | public static double surcharge(double value) { 29 | return value * 1.05; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/winterbe/java8/samples/concurrent/CompletableFuture1.java: -------------------------------------------------------------------------------- 1 | package winterbe.java8.samples.concurrent; 2 | 3 | import java.util.concurrent.CompletableFuture; 4 | import java.util.concurrent.ExecutionException; 5 | 6 | /** 7 | * @author Benjamin Winterberg 8 | */ 9 | public class CompletableFuture1 { 10 | 11 | public static void main(String[] args) throws ExecutionException, InterruptedException { 12 | CompletableFuture future = new CompletableFuture<>(); 13 | 14 | future.complete("42"); 15 | 16 | future 17 | .thenAccept(System.out::println) 18 | .thenAccept(v -> System.out.println("done")); 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/winterbe/java8/samples/concurrent/ConcurrentUtils.java: -------------------------------------------------------------------------------- 1 | package winterbe.java8.samples.concurrent; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | /** 7 | * @author Benjamin Winterberg 8 | */ 9 | public class ConcurrentUtils { 10 | 11 | public static void stop(ExecutorService executor) { 12 | try { 13 | executor.shutdown(); 14 | executor.awaitTermination(60, TimeUnit.SECONDS); 15 | } 16 | catch (InterruptedException e) { 17 | System.err.println("termination interrupted"); 18 | } 19 | finally { 20 | if (!executor.isTerminated()) { 21 | System.err.println("killing non-finished tasks"); 22 | } 23 | executor.shutdownNow(); 24 | } 25 | } 26 | 27 | public static void sleep(int seconds) { 28 | try { 29 | TimeUnit.SECONDS.sleep(seconds); 30 | } catch (InterruptedException e) { 31 | throw new IllegalStateException(e); 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/winterbe/java8/samples/concurrent/LongAccumulator1.java: -------------------------------------------------------------------------------- 1 | package winterbe.java8.samples.concurrent; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | import java.util.concurrent.atomic.LongAccumulator; 6 | import java.util.function.LongBinaryOperator; 7 | import java.util.stream.IntStream; 8 | 9 | /** 10 | * @author Benjamin Winterberg 11 | */ 12 | public class LongAccumulator1 { 13 | 14 | public static void main(String[] args) { 15 | testAccumulate(); 16 | } 17 | 18 | private static void testAccumulate() { 19 | LongBinaryOperator op = (x, y) -> 2 * x + y; 20 | LongAccumulator accumulator = new LongAccumulator(op, 1L); 21 | 22 | ExecutorService executor = Executors.newFixedThreadPool(2); 23 | 24 | IntStream.range(0, 10) 25 | .forEach(i -> executor.submit(() -> accumulator.accumulate(i))); 26 | 27 | ConcurrentUtils.stop(executor); 28 | 29 | System.out.format("Add: %d\n", accumulator.getThenReset()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/winterbe/java8/samples/concurrent/Synchronized2.java: -------------------------------------------------------------------------------- 1 | package winterbe.java8.samples.concurrent; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | import java.util.stream.IntStream; 6 | 7 | /** 8 | * @author Benjamin Winterberg 9 | */ 10 | public class Synchronized2 { 11 | 12 | private static final int NUM_INCREMENTS = 10000; 13 | 14 | private static int count = 0; 15 | 16 | public static void main(String[] args) { 17 | testSyncIncrement(); 18 | } 19 | 20 | private static void testSyncIncrement() { 21 | count = 0; 22 | 23 | ExecutorService executor = Executors.newFixedThreadPool(2); 24 | 25 | IntStream.range(0, NUM_INCREMENTS) 26 | .forEach(i -> executor.submit(Synchronized2::incrementSync)); 27 | 28 | ConcurrentUtils.stop(executor); 29 | 30 | System.out.println(count); 31 | } 32 | 33 | private static void incrementSync() { 34 | synchronized (Synchronized2.class) { 35 | count = count + 1; 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/winterbe/java8/samples/lambda/Interface1.java: -------------------------------------------------------------------------------- 1 | package winterbe.java8.samples.lambda; 2 | 3 | /** 4 | * @author Benjamin Winterberg 5 | */ 6 | public class Interface1 { 7 | 8 | interface Formula { 9 | double calculate(int a); 10 | 11 | default double sqrt(int a) { 12 | return Math.sqrt(positive(a)); 13 | } 14 | 15 | static int positive(int a) { 16 | return a > 0 ? a : 0; 17 | } 18 | } 19 | 20 | public static void main(String[] args) { 21 | Formula formula1 = new Formula() { 22 | @Override 23 | public double calculate(int a) { 24 | return sqrt(a * 100); 25 | } 26 | }; 27 | 28 | formula1.calculate(100); // 100.0 29 | formula1.sqrt(-23); // 0.0 30 | Formula.positive(-4); // 0.0 31 | 32 | // Formula formula2 = (a) -> sqrt( a * 100); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/winterbe/java8/samples/lambda/Lambda5.java: -------------------------------------------------------------------------------- 1 | package winterbe.java8.samples.lambda; 2 | 3 | import java.util.HashMap; 4 | import java.util.function.BiConsumer; 5 | 6 | /** 7 | * Created by grijesh 8 | */ 9 | public class Lambda5 { 10 | 11 | //Pre-Defined Functional Interfaces 12 | public static void main(String... args) { 13 | 14 | //BiConsumer Example 15 | BiConsumer printKeyAndValue 16 | = (key,value) -> System.out.println(key+"-"+value); 17 | 18 | printKeyAndValue.accept("One",1); 19 | printKeyAndValue.accept("Two",2); 20 | 21 | System.out.println("##################"); 22 | 23 | //Java Hash-Map foreach supports BiConsumer 24 | HashMap dummyValues = new HashMap<>(); 25 | dummyValues.put("One", 1); 26 | dummyValues.put("Two", 2); 27 | dummyValues.put("Three", 3); 28 | 29 | dummyValues.forEach((key,value) -> System.out.println(key+"-"+value)); 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/winterbe/java8/samples/lambda/Person.java: -------------------------------------------------------------------------------- 1 | package winterbe.java8.samples.lambda; 2 | 3 | /** 4 | * @author Benjamin Winterberg 5 | */ 6 | public class Person { 7 | public String firstName; 8 | public String lastName; 9 | 10 | public Person() {} 11 | 12 | public Person(String firstName, String lastName) { 13 | this.firstName = firstName; 14 | this.lastName = lastName; 15 | } 16 | } -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/winterbe/java8/samples/nashorn/Nashorn10.java: -------------------------------------------------------------------------------- 1 | package winterbe.java8.samples.nashorn; 2 | 3 | import jdk.nashorn.api.scripting.NashornScriptEngine; 4 | 5 | import javax.script.ScriptEngineManager; 6 | import javax.script.ScriptException; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | /** 10 | * @author Benjamin Winterberg 11 | */ 12 | public class Nashorn10 { 13 | 14 | public static void main(String[] args) throws ScriptException, NoSuchMethodException { 15 | NashornScriptEngine engine = (NashornScriptEngine) new ScriptEngineManager().getEngineByName("nashorn"); 16 | engine.eval("load('res/nashorn10.js')"); 17 | 18 | long t0 = System.nanoTime(); 19 | 20 | for (int i = 0; i < 100000; i++) { 21 | engine.invokeFunction("testPerf"); 22 | } 23 | 24 | long took = System.nanoTime() - t0; 25 | System.out.format("Elapsed time: %d ms", TimeUnit.NANOSECONDS.toMillis(took)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/winterbe/java8/samples/nashorn/Nashorn3.java: -------------------------------------------------------------------------------- 1 | package winterbe.java8.samples.nashorn; 2 | 3 | import javax.script.ScriptEngine; 4 | import javax.script.ScriptEngineManager; 5 | 6 | /** 7 | * Working with java types from javascript. 8 | * 9 | * @author Benjamin Winterberg 10 | */ 11 | public class Nashorn3 { 12 | 13 | public static void main(String[] args) throws Exception { 14 | ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn"); 15 | engine.eval("load('res/nashorn3.js')"); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/winterbe/java8/samples/nashorn/Nashorn4.java: -------------------------------------------------------------------------------- 1 | package winterbe.java8.samples.nashorn; 2 | 3 | import javax.script.ScriptEngine; 4 | import javax.script.ScriptEngineManager; 5 | 6 | /** 7 | * Working with java types from javascript. 8 | * 9 | * @author Benjamin Winterberg 10 | */ 11 | public class Nashorn4 { 12 | 13 | public static void main(String[] args) throws Exception { 14 | ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn"); 15 | engine.eval("loadWithNewGlobal('res/nashorn4.js')"); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/winterbe/java8/samples/nashorn/Nashorn5.java: -------------------------------------------------------------------------------- 1 | package winterbe.java8.samples.nashorn; 2 | 3 | import javax.script.Invocable; 4 | import javax.script.ScriptEngine; 5 | import javax.script.ScriptEngineManager; 6 | 7 | /** 8 | * Bind java objects to custom javascript objects. 9 | * 10 | * @author Benjamin Winterberg 11 | */ 12 | public class Nashorn5 { 13 | 14 | public static void main(String[] args) throws Exception { 15 | ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn"); 16 | engine.eval("load('res/nashorn5.js')"); 17 | 18 | Invocable invocable = (Invocable) engine; 19 | 20 | Product product = new Product(); 21 | product.setName("Rubber"); 22 | product.setPrice(1.99); 23 | product.setStock(1037); 24 | 25 | Object result = invocable.invokeFunction("getValueOfGoods", product); 26 | System.out.println(result); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/winterbe/java8/samples/nashorn/Nashorn8.java: -------------------------------------------------------------------------------- 1 | package winterbe.java8.samples.nashorn; 2 | 3 | import winterbe.java8.samples.lambda.Person; 4 | import jdk.nashorn.api.scripting.NashornScriptEngine; 5 | 6 | import javax.script.ScriptEngineManager; 7 | import javax.script.ScriptException; 8 | 9 | /** 10 | * @author Benjamin Winterberg 11 | */ 12 | public class Nashorn8 { 13 | public static void main(String[] args) throws ScriptException, NoSuchMethodException { 14 | NashornScriptEngine engine = (NashornScriptEngine) new ScriptEngineManager().getEngineByName("nashorn"); 15 | engine.eval("load('res/nashorn8.js')"); 16 | 17 | engine.invokeFunction("evaluate1"); // [object global] 18 | engine.invokeFunction("evaluate2"); // [object Object] 19 | engine.invokeFunction("evaluate3", "Foobar"); // Foobar 20 | engine.invokeFunction("evaluate3", new Person("John", "Doe")); // [object global] <- ??????? 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/winterbe/java8/samples/nashorn/Nashorn9.java: -------------------------------------------------------------------------------- 1 | package winterbe.java8.samples.nashorn; 2 | 3 | import jdk.nashorn.api.scripting.NashornScriptEngine; 4 | 5 | import javax.script.ScriptEngineManager; 6 | import javax.script.ScriptException; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | /** 10 | * @author Benjamin Winterberg 11 | */ 12 | public class Nashorn9 { 13 | 14 | public static void main(String[] args) throws ScriptException, NoSuchMethodException { 15 | NashornScriptEngine engine = (NashornScriptEngine) new ScriptEngineManager().getEngineByName("nashorn"); 16 | engine.eval("load('res/nashorn9.js')"); 17 | 18 | long t0 = System.nanoTime(); 19 | 20 | double result = 0; 21 | for (int i = 0; i < 1000; i++) { 22 | double num = (double) engine.invokeFunction("testPerf"); 23 | result += num; 24 | } 25 | 26 | System.out.println(result > 0); 27 | 28 | long took = System.nanoTime() - t0; 29 | System.out.format("Elapsed time: %d ms", TimeUnit.NANOSECONDS.toMillis(took)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/winterbe/java8/samples/nashorn/Product.java: -------------------------------------------------------------------------------- 1 | package winterbe.java8.samples.nashorn; 2 | 3 | /** 4 | * @author Benjamin Winterberg 5 | */ 6 | public class Product { 7 | private String name; 8 | private double price; 9 | private int stock; 10 | private double valueOfGoods; 11 | 12 | public double getValueOfGoods() { 13 | return valueOfGoods; 14 | } 15 | 16 | public void setValueOfGoods(double valueOfGoods) { 17 | this.valueOfGoods = valueOfGoods; 18 | } 19 | 20 | public String getName() { 21 | return name; 22 | } 23 | 24 | public void setName(String name) { 25 | this.name = name; 26 | } 27 | 28 | public double getPrice() { 29 | return price; 30 | } 31 | 32 | public void setPrice(double price) { 33 | this.price = price; 34 | } 35 | 36 | public int getStock() { 37 | return stock; 38 | } 39 | 40 | public void setStock(int stock) { 41 | this.stock = stock; 42 | } 43 | } -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/winterbe/java8/samples/nashorn/SuperRunner.java: -------------------------------------------------------------------------------- 1 | package winterbe.java8.samples.nashorn; 2 | 3 | /** 4 | * @author Benjamin Winterberg 5 | */ 6 | public class SuperRunner implements Runnable { 7 | 8 | @Override 9 | public void run() { 10 | System.out.println("super run"); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/winterbe/java8/samples/stream/Optional1.java: -------------------------------------------------------------------------------- 1 | package winterbe.java8.samples.stream; 2 | 3 | import java.util.Optional; 4 | 5 | /** 6 | * @author Benjamin Winterberg 7 | */ 8 | public class Optional1 { 9 | 10 | public static void main(String[] args) { 11 | Optional optional = Optional.of("bam"); 12 | 13 | optional.isPresent(); // true 14 | optional.get(); // "bam" 15 | optional.orElse("fallback"); // "bam" 16 | 17 | optional.ifPresent((s) -> System.out.println(s.charAt(0))); // "b" 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/winterbe/java8/samples/stream/Streams13.java: -------------------------------------------------------------------------------- 1 | package winterbe.java8.samples.stream; 2 | 3 | import java.security.SecureRandom; 4 | import java.util.Arrays; 5 | import java.util.stream.IntStream; 6 | 7 | /** 8 | * @author Benjamin Winterberg 9 | */ 10 | public class Streams13 { 11 | 12 | public static void main(String[] args) { 13 | SecureRandom secureRandom = new SecureRandom(new byte[]{1, 3, 3, 7}); 14 | int[] randoms = IntStream.generate(secureRandom::nextInt) 15 | .filter(n -> n > 0) 16 | .limit(10) 17 | .toArray(); 18 | System.out.println(Arrays.toString(randoms)); 19 | 20 | 21 | int[] nums = IntStream.iterate(1, n -> n * 2) 22 | .limit(11) 23 | .toArray(); 24 | System.out.println(Arrays.toString(nums)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/winterbe/java8/samples/stream/Streams2.java: -------------------------------------------------------------------------------- 1 | package winterbe.java8.samples.stream; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * @author Benjamin Winterberg 8 | */ 9 | public class Streams2 { 10 | 11 | public static void main(String[] args) { 12 | 13 | List stringCollection = new ArrayList<>(); 14 | stringCollection.add("ddd2"); 15 | stringCollection.add("aaa2"); 16 | stringCollection.add("bbb1"); 17 | stringCollection.add("aaa1"); 18 | stringCollection.add("bbb3"); 19 | stringCollection.add("ccc"); 20 | stringCollection.add("bbb2"); 21 | stringCollection.add("ddd1"); 22 | 23 | 24 | // sorting 25 | 26 | stringCollection 27 | .stream() 28 | .sorted() 29 | .forEach(System.out::println); 30 | 31 | System.out.println(stringCollection); 32 | 33 | 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/java/winterbe/java8/samples/stream/Streams9.java: -------------------------------------------------------------------------------- 1 | package winterbe.java8.samples.stream; 2 | 3 | import java.util.Arrays; 4 | 5 | /** 6 | * @author Benjamin Winterberg 7 | */ 8 | public class Streams9 { 9 | 10 | public static void main(String[] args) { 11 | Arrays.asList("a1", "a2", "b1", "c2", "c1") 12 | .stream() 13 | .filter(s -> s.startsWith("c")) 14 | .map(String::toUpperCase) 15 | .sorted() 16 | .forEach(System.out::println); 17 | 18 | // C1 19 | // C2 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/resources/lambdasinaction/chap3/data.txt: -------------------------------------------------------------------------------- 1 | Java 2 | 8 3 | Lambdas 4 | In 5 | Action -------------------------------------------------------------------------------- /04fx/Java8inAction/src/main/resources/lambdasinaction/chap5/data.txt: -------------------------------------------------------------------------------- 1 | The quick brown fox jumped over the lazy dog 2 | The lazy dog jumped over the quick brown fox 3 | -------------------------------------------------------------------------------- /04fx/demo/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /04fx/demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/04fx/demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /04fx/demo/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /04fx/demo/src/main/java/A.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Description for this class. 3 | * 4 | * @Author : kimmking(kimmking@apache.org) 5 | * @create 2022/12/16 10:55 6 | */ 7 | public class A { 8 | } 9 | -------------------------------------------------------------------------------- /04fx/demo/src/main/java/io/kimmking/javacourse/demo/ConsConfig.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.javacourse.demo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | /** 7 | * Description for this class. 8 | * 9 | * @Author : kimmking(kimmking@apache.org) 10 | * @create 2022/11/29 16:05 11 | */ 12 | @Data 13 | public class ConsConfig { 14 | 15 | private String demoName; 16 | private String demoDesc; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /04fx/demo/src/main/java/io/kimmking/javacourse/demo/ConsConfigs.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.javacourse.demo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Description for this class. 10 | * 11 | * @Author : kimmking(kimmking@apache.org) 12 | * @create 2022/12/22 16:47 13 | */ 14 | @Data 15 | @AllArgsConstructor 16 | public class ConsConfigs { 17 | 18 | private List config; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /04fx/demo/src/main/java/io/kimmking/javacourse/demo/DemoConfig.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.javacourse.demo; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * Description for this class. 7 | * 8 | * @Author : kimmking(kimmking@apache.org) 9 | * @create 2022/11/29 16:05 10 | */ 11 | @Data 12 | public class DemoConfig { 13 | 14 | private String demoName; 15 | private String demoDesc; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /04fx/demo/src/main/java/io/kimmking/javacourse/demo/EnableDemoConfigBindings.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.javacourse.demo; 2 | 3 | import org.springframework.context.annotation.Import; 4 | 5 | import java.lang.annotation.*; 6 | 7 | /** 8 | * Description for this class. 9 | * 10 | * @Author : kimmking(kimmking@apache.org) 11 | * @create 2022/11/29 16:10 12 | */ 13 | @Target({ElementType.TYPE}) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Documented 16 | @Import(DemoConfigBindingsRegistrar.class) 17 | public @interface EnableDemoConfigBindings { 18 | /** 19 | * The name prefix of the properties that are valid to bind. 20 | * 21 | * @return the name prefix of the properties to bind 22 | */ 23 | String prefix(); 24 | 25 | /** 26 | * @return The binding type. 27 | */ 28 | Class type(); 29 | 30 | /** 31 | * It indicates whether {@link #prefix()} binding to multiple Spring Beans. 32 | * 33 | * @return the default value is true 34 | */ 35 | boolean multiple() default true; 36 | } 37 | -------------------------------------------------------------------------------- /04fx/demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | demo.config.a1.demoName = d1 3 | demo.config.a1.demoDesc = demo1 4 | 5 | demo.config.a2.demoName = d2 6 | demo.config.a2.demoDesc = demo2 7 | 8 | demo.config.a3.demoName = d3 9 | demo.config.a3.demoDesc = demo3 -------------------------------------------------------------------------------- /04fx/dtx01/src/main/java/io/kimmking/dtx01/Dtx01Application.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.dtx01; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cache.annotation.EnableCaching; 7 | 8 | @SpringBootApplication(scanBasePackages = "io.kimmking.dtx01") 9 | @MapperScan("io.kimmking.dtx01.mapper") 10 | @EnableCaching 11 | public class Dtx01Application { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(Dtx01Application.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /04fx/dtx01/src/main/java/io/kimmking/dtx01/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.dtx01.controller; 2 | 3 | import io.kimmking.dtx01.entity.User; 4 | import io.kimmking.dtx01.service.UserService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import java.util.List; 11 | 12 | @RestController 13 | @EnableAutoConfiguration 14 | public class UserController { 15 | 16 | @Autowired 17 | UserService userService; 18 | 19 | @RequestMapping("/user/find") 20 | User find(Long id) { 21 | return userService.find(id); 22 | //return new User(1,"KK", 28); 23 | } 24 | 25 | @RequestMapping("/user/list") 26 | List list() { 27 | return userService.list(); 28 | // return Arrays.asList(new User(1,"KK", 28), 29 | // new User(2,"CC", 18)); 30 | } 31 | } -------------------------------------------------------------------------------- /04fx/dtx01/src/main/java/io/kimmking/dtx01/entity/User.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.dtx01.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.io.Serializable; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class User implements Serializable { 13 | private Long id; 14 | private String name; 15 | private Integer age; 16 | } -------------------------------------------------------------------------------- /04fx/dtx01/src/main/java/io/kimmking/dtx01/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.dtx01.mapper; 2 | 3 | import io.kimmking.dtx01.entity.User; 4 | import org.apache.ibatis.annotations.Param; 5 | import org.apache.ibatis.annotations.Select; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | @Repository 11 | public interface UserMapper { 12 | 13 | @Select("select * from user where id = #{id};") 14 | User find(@Param("id") Long id); 15 | 16 | @Select("select * from user;") 17 | List list(); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /04fx/dtx01/src/main/java/io/kimmking/dtx01/service/UserService.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.dtx01.service; 2 | 3 | import io.kimmking.dtx01.entity.User; 4 | 5 | import java.util.List; 6 | 7 | public interface UserService { 8 | 9 | User find(Long id); 10 | 11 | List list(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /04fx/dtx01/src/main/java/io/kimmking/dtx01/service/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.dtx01.service; 2 | 3 | import io.kimmking.dtx01.entity.User; 4 | import io.kimmking.dtx01.mapper.UserMapper; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | 10 | @Service 11 | public class UserServiceImpl implements UserService { 12 | 13 | @Autowired 14 | UserMapper userMapper; //DAO // Repository 15 | 16 | public User find(Long id) { 17 | System.out.println(" ==> find " + id); 18 | return userMapper.find(id); 19 | } 20 | 21 | public List list(){ 22 | return userMapper.list(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /04fx/dtx01/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | 4 | spring: 5 | datasource: 6 | username: root 7 | password: 8 | url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false 9 | driver-class-name: com.mysql.jdbc.Driver 10 | # cache: 11 | # type: redis 12 | # redis: 13 | # host: localhost 14 | # lettuce: 15 | # pool: 16 | # max-active: 16 17 | # max-wait: 10ms 18 | 19 | # type: ehcache 20 | # ehcache: 21 | # config: ehcache.xml 22 | 23 | #mybatis: 24 | # mapper-locations: classpath:mapper/*Mapper.xml 25 | # type-aliases-package: io.kimmking.dtx01.entity 26 | 27 | logging: 28 | level: 29 | io: 30 | kimmking: 31 | cache : info 32 | -------------------------------------------------------------------------------- /04fx/dtx01/src/test/java/io/kimmking/dtx01/Dtx01ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.dtx01; 2 | 3 | import org.junit.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class Dtx01ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /04fx/java8/src/main/java/io/kimmking/java8/A.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.java8; 2 | 3 | import lombok.*; 4 | import lombok.extern.slf4j.Slf4j; 5 | 6 | @ToString 7 | @NoArgsConstructor 8 | @AllArgsConstructor 9 | @Slf4j 10 | @Builder 11 | @Getter 12 | @Setter 13 | public class A { 14 | 15 | private int age; 16 | 17 | private String name; 18 | 19 | // public void test(){ 20 | // log.info("this message is logged by lombok"); 21 | // System.out.println(this.toString()); 22 | // } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /04fx/java8/src/main/java/io/kimmking/java8/ForeachDemo.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.java8; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | public class ForeachDemo { 7 | 8 | private int x=1; 9 | 10 | public static void main(String[] args) { 11 | 12 | ForeachDemo demo = new ForeachDemo(); 13 | 14 | demo.test(); 15 | 16 | System.out.println(demo.x); 17 | } 18 | 19 | private void test() { 20 | List list = Arrays.asList(1,2); 21 | int y = 1; 22 | list.forEach(e -> { 23 | x=2; 24 | //y=2; // can't be compiled 25 | }); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /04fx/java8/src/main/java/io/kimmking/java8/LombokDemo.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.java8; 2 | 3 | import lombok.extern.java.Log; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.io.IOException; 7 | 8 | @Log 9 | public class LombokDemo { 10 | 11 | public static void main(String[] args) throws IOException { 12 | 13 | // Spring IoC 14 | // ServiceLoader.load SPI 15 | // Listener/Callback 16 | // EventBus 17 | 18 | A a = new A(1, "KK"); 19 | System.out.println(a.toString()); 20 | A b = A.builder().age(1).name("KKK").build(); 21 | 22 | new LombokDemo().demo(); 23 | 24 | Student student1 = new Student(); 25 | student1.setId(1); 26 | student1.setName("KK01"); 27 | System.out.println(student1.toString()); 28 | 29 | Student student2 = new Student(2, "KK02"); 30 | //student2.init(); 31 | System.out.println(student2.toString()); 32 | } 33 | 34 | private void demo() { 35 | log.info("demo in log."); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /04fx/java8/src/main/resources/conf/a.properties: -------------------------------------------------------------------------------- 1 | a=1 2 | b=2 -------------------------------------------------------------------------------- /04fx/java8/src/test/java/io/kimmking/java8/StudentTest.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.java8; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | import org.mockito.Mockito; 6 | 7 | public class StudentTest { 8 | 9 | private Student class1; 10 | 11 | @Test 12 | public void KlassTest(){ 13 | class1 = Mockito.mock(Student.class, Mockito.RETURNS_DEEP_STUBS); 14 | Mockito.when(class1.getApplicationContext().getId()).thenReturn("10"); 15 | Assert.assertEquals("10", (class1.getApplicationContext().getId())); 16 | } 17 | // 单元测试 18 | } 19 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/DemoMethodIncepter.java: -------------------------------------------------------------------------------- 1 | package io.kimmking; 2 | 3 | import org.aopalliance.intercept.MethodInterceptor; 4 | import org.aopalliance.intercept.MethodInvocation; 5 | 6 | public class DemoMethodIncepter implements MethodInterceptor { 7 | 8 | public Object invoke(MethodInvocation invocation) throws Throwable { 9 | 10 | long s = System.currentTimeMillis(); 11 | System.out.println(" *****====> " + s + " " + invocation.getMethod().getName()); 12 | Object result = invocation.proceed(); 13 | System.out.println(" *****====> " + (System.currentTimeMillis() - s) + " ms"); 14 | return result; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/anno/IA1.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.anno; 2 | 3 | 4 | @IAnno2("anno2") 5 | public interface IA1 { 6 | 7 | void a1(); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/anno/IA2.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.anno; 2 | 3 | 4 | @IAnnotation 5 | public interface IA2 extends IA1 { 6 | 7 | void a2(); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/anno/IAnno2.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.anno; 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 | @Target({ElementType.TYPE}) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface IAnno2 { 11 | 12 | String value(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/anno/IAnnotation.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.anno; 2 | 3 | 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Target({ElementType.TYPE}) 10 | @Retention(RetentionPolicy.RUNTIME) 11 | public @interface IAnnotation { 12 | } 13 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/aop/ISchool.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.aop; 2 | 3 | public interface ISchool { 4 | 5 | void ding(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/spring01/A.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.spring01; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class A { 7 | 8 | private int age; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/spring01/LombokDemo.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.spring01; 2 | 3 | import lombok.extern.java.Log; 4 | 5 | import java.io.IOException; 6 | 7 | @Log 8 | public class LombokDemo { 9 | 10 | public static void main(String[] args) throws IOException { 11 | 12 | new LombokDemo().demo(); 13 | 14 | Student student1 = new Student(); 15 | student1.setId(1); 16 | student1.setName("KK01"); 17 | System.out.println(student1.toString()); 18 | 19 | Student student2 = Student.create(); 20 | System.out.println(student2.toString()); 21 | } 22 | 23 | private void demo() { 24 | log.info("demo in log."); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/spring02/Aop1.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.spring02; 2 | 3 | import org.aspectj.lang.ProceedingJoinPoint; 4 | 5 | public class Aop1 { 6 | 7 | //前置通知 8 | public void startTransaction(){ 9 | System.out.println(" ====>begin ding... "); //2 10 | } 11 | 12 | //后置通知 13 | public void commitTransaction(){ 14 | System.out.println(" ====>finish ding... "); //4 15 | } 16 | 17 | //环绕通知 18 | public void around(ProceedingJoinPoint joinPoint) throws Throwable{ 19 | System.out.println(" ====>around begin ding"); //1 20 | //调用process()方法才会真正的执行实际被代理的方法 21 | joinPoint.proceed(); 22 | 23 | System.out.println(" ====>around finish ding"); //3 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/spring02/Klass.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.spring02; 2 | 3 | import io.kimmking.spring01.Student; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | @Data 9 | public class Klass { 10 | 11 | List students; 12 | 13 | public void dong(){ 14 | System.out.println(this.getStudents()); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/spring02/School.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.spring02; 2 | 3 | import io.kimmking.aop.ISchool; 4 | import io.kimmking.spring01.Student; 5 | import lombok.Data; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.context.annotation.Bean; 8 | 9 | import javax.annotation.PostConstruct; 10 | import javax.annotation.Resource; 11 | 12 | @Data 13 | public class School implements ISchool { 14 | 15 | // Resource 16 | @Autowired(required = true) //primary 17 | Klass class1; 18 | 19 | @Resource(name = "student100") 20 | Student student100; 21 | 22 | @Override 23 | public void ding(){ 24 | 25 | System.out.println("Class1 have " + this.class1.getStudents().size() + " students and one is " + this.student100); 26 | 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/spring03/Spring03Main.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.spring03; 2 | 3 | import org.springframework.context.ApplicationContext; 4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 5 | 6 | public class Spring03Main { 7 | 8 | public static void main(String[] args) { 9 | ApplicationContext context = new AnnotationConfigApplicationContext(Spring03Main.class.getPackage().getName()); 10 | TestService1 testService1 = context.getBean(TestService1.class); 11 | testService1.test1(); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/spring03/TestService1.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.spring03; 2 | 3 | import lombok.Data; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.scheduling.annotation.Async; 6 | import org.springframework.scheduling.annotation.EnableAsync; 7 | import org.springframework.stereotype.Service; 8 | 9 | @Service 10 | @Data 11 | @EnableAsync 12 | public class TestService1 { // TODO rename this class to TestService6 and it works well. 13 | 14 | @Autowired 15 | private TestService2 service2; 16 | 17 | @Async 18 | public void test1() { 19 | System.out.println("test1"); 20 | System.out.println(this.getClass().getCanonicalName()); 21 | System.out.println(Thread.currentThread().getName()); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/spring03/TestService2.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.spring03; 2 | 3 | import lombok.Data; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | 7 | @Service 8 | @Data 9 | public class TestService2 { 10 | 11 | @Autowired 12 | private TestService1 service1; 13 | 14 | public void test2() { 15 | System.out.println("test2"); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/spring04/ABCPlugin.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.spring04; 2 | 3 | import org.springframework.core.Ordered; 4 | 5 | public interface ABCPlugin extends Ordered { 6 | 7 | void startup() throws Exception; 8 | void shutdown() throws Exception; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/spring04/ABCStartup.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.spring04; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Component; 5 | 6 | import javax.annotation.PreDestroy; 7 | import java.util.List; 8 | 9 | @Component 10 | public class ABCStartup { 11 | 12 | @Autowired 13 | private List services; 14 | 15 | public void call () { 16 | services.forEach(System.out::println); 17 | } 18 | 19 | @PreDestroy 20 | public void destroy() { 21 | 22 | System.out.println(Thread.currentThread().getName()+"-destroy:" + this.getClass().getSimpleName()); 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/spring04/MockABCPlugin2.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.spring04; 2 | 3 | import org.springframework.core.Ordered; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component() 7 | public class MockABCPlugin2 implements ABCPlugin { 8 | 9 | @Override 10 | public String toString() { 11 | return this.getClass().getSimpleName(); 12 | } 13 | 14 | @Override 15 | public int getOrder() { 16 | return 2; 17 | } 18 | 19 | @Override 20 | public void startup() throws Exception { 21 | System.out.println(this.toString()+" started."); 22 | } 23 | 24 | @Override 25 | public void shutdown() throws Exception { 26 | System.out.println(this.toString()+" stopped."); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/spring04/Spring04Main.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.spring04; 2 | 3 | import org.springframework.context.ApplicationEvent; 4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 5 | 6 | public class Spring04Main { 7 | 8 | public static void main(String[] args) { 9 | AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spring04Main.class.getPackage().getName()); 10 | ABCStartup abc = context.getBean(ABCStartup.class); 11 | abc.call(); 12 | 13 | context.publishEvent(new ApplicationEvent("myEvent") {}); 14 | 15 | context.close(); 16 | // context.destroy(); 17 | // context.stop(); // 这3个有什么区别? 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/springjms/JmsListener.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.springjms; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import javax.jms.JMSException; 6 | import javax.jms.Message; 7 | import javax.jms.MessageListener; 8 | import javax.jms.ObjectMessage; 9 | 10 | @Component(value = "jmsListener") 11 | public class JmsListener implements MessageListener { 12 | 13 | //收到信息时的动作 14 | @Override 15 | public void onMessage(Message m) { 16 | ObjectMessage message = (ObjectMessage) m; 17 | try { 18 | System.out.println("收到的信息:" + message.getObject()); 19 | } catch (JMSException e) { 20 | e.printStackTrace(); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/springjms/JmsReceiver.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.springjms; 2 | 3 | import io.kimmking.spring01.Student; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | import java.io.IOException; 8 | 9 | public class JmsReceiver { 10 | 11 | public static void main( String[] args ) throws IOException { 12 | 13 | ApplicationContext context = new ClassPathXmlApplicationContext("classpath:springjms-receiver.xml"); 14 | 15 | System.in.read(); 16 | 17 | System.out.println("send successfully, please visit http://localhost:8161/admin to see it"); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/springjms/JmsSender.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.springjms; 2 | 3 | import io.kimmking.spring01.Student; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.support.ClassPathXmlApplicationContext; 6 | 7 | public class JmsSender { 8 | 9 | public static void main( String[] args ) 10 | { 11 | Student student2 = Student.create(); 12 | 13 | ApplicationContext context = new ClassPathXmlApplicationContext("classpath:springjms-sender.xml"); 14 | 15 | SendService sendService = (SendService)context.getBean("sendService"); 16 | 17 | student2.setName("KK103"); 18 | 19 | sendService.send(student2); 20 | 21 | System.out.println("send successfully, please visit http://localhost:8161/admin to see it"); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /04fx/spring01/src/main/java/io/kimmking/springjms/SendService.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.springjms; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import io.kimmking.spring01.Student; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.jms.core.JmsTemplate; 7 | import org.springframework.jms.core.MessageCreator; 8 | import org.springframework.stereotype.Component; 9 | 10 | import javax.jms.JMSException; 11 | import javax.jms.Message; 12 | import javax.jms.Session; 13 | 14 | @Component 15 | public class SendService { 16 | @Autowired 17 | JmsTemplate jmsTemplate; 18 | 19 | public void send(final Student user) { 20 | jmsTemplate.send("test.queue", new MessageCreator() { 21 | 22 | public Message createMessage(Session session) throws JMSException { 23 | return session.createObjectMessage(JSON.toJSONString(user)); 24 | } 25 | }); 26 | } 27 | } -------------------------------------------------------------------------------- /04fx/spring01/src/test/java/Spring02Test.java: -------------------------------------------------------------------------------- 1 | import io.kimmking.spring02.Klass; 2 | import org.junit.Assert; 3 | import org.junit.Test; 4 | import static org.mockito.Mockito.*; 5 | 6 | public class Spring02Test { 7 | 8 | private Klass class1; 9 | 10 | @Test 11 | public void KlassTest(){ 12 | class1 = mock(Klass.class, RETURNS_DEEP_STUBS); 13 | when(class1.getStudents().size()).thenReturn(2); 14 | Assert.assertEquals(2, class1.getStudents().size()); 15 | } 16 | 17 | // 单元测试 18 | } 19 | -------------------------------------------------------------------------------- /04fx/spring01/src/test/java/Sprint01Test.java: -------------------------------------------------------------------------------- 1 | import io.kimmking.spring02.Klass; 2 | import org.junit.Assert; 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.test.context.ContextConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @ContextConfiguration(locations = {"classpath:applicationContext.xml"}) 11 | public class Sprint01Test { 12 | 13 | @Autowired 14 | private Klass class1; 15 | 16 | @Test 17 | public void KlassTest(){ 18 | Assert.assertEquals(2, class1.getStudents().size()); 19 | } 20 | 21 | // 集成测试 22 | } 23 | -------------------------------------------------------------------------------- /04fx/springboot01/src/main/java/io/kimmking/springboot01/Springboot01Application.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.springboot01; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; 7 | import org.springframework.jms.annotation.EnableJms; 8 | 9 | @SpringBootApplication 10 | //@EnableJms //启动消息队列 11 | //@EnableMongoRepositories 12 | public class Springboot01Application { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(Springboot01Application.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /04fx/springboot01/src/main/java/io/kimmking/springboot01/jms/QueueConsumerListener.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.springboot01.jms; 2 | 3 | import org.springframework.jms.annotation.JmsListener; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component 7 | public class QueueConsumerListener { 8 | //queue模式的消费者 9 | @JmsListener(destination = "${spring.activemq.queue-name}", containerFactory = "queueListener") 10 | public void readActiveQueue(String message) { 11 | System.out.println("queue接受到:" + message); 12 | } 13 | } -------------------------------------------------------------------------------- /04fx/springboot01/src/main/java/io/kimmking/springboot01/jms/TopicConsumerListener.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.springboot01.jms; 2 | 3 | import org.springframework.jms.annotation.JmsListener; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component 7 | public class TopicConsumerListener { 8 | //topic模式的消费者 9 | @JmsListener(destination = "${spring.activemq.topic-name}", containerFactory = "topicListener") 10 | public void readActiveQueue(String message) { 11 | System.out.println("topic接受到:" + message); 12 | } 13 | } -------------------------------------------------------------------------------- /04fx/springboot01/src/test/java/io/kimmking/springboot01/Springboot01ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.springboot01; 2 | 3 | import org.junit.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class Springboot01ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /06db/shardingsphere/config-replica-query.yaml: -------------------------------------------------------------------------------- 1 | 2 | schemaName: replica_query_db 3 | 4 | dataSourceCommon: 5 | username: root 6 | password: 7 | connectionTimeoutMilliseconds: 30000 8 | idleTimeoutMilliseconds: 60000 9 | maxLifetimeMilliseconds: 1800000 10 | maxPoolSize: 10 11 | minPoolSize: 1 12 | maintenanceIntervalMilliseconds: 30000 13 | 14 | dataSources: 15 | primary_ds: 16 | url: jdbc:mysql://127.0.0.1:3306/demo_master?serverTimezone=UTC&useSSL=false 17 | replica_ds_0: 18 | url: jdbc:mysql://127.0.0.1:3306/demo_slave_0?serverTimezone=UTC&useSSL=false 19 | replica_ds_1: 20 | url: jdbc:mysql://127.0.0.1:3306/demo_slave_1?serverTimezone=UTC&useSSL=false 21 | 22 | rules: 23 | - !REPLICA_QUERY 24 | dataSources: 25 | pr_ds: 26 | name: pr_ds 27 | primaryDataSourceName: primary_ds 28 | replicaDataSourceNames: 29 | - replica_ds_0 30 | - replica_ds_1 31 | -------------------------------------------------------------------------------- /07rpc/mysql-demo/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /07rpc/mysql-demo/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.1' 2 | 3 | services: 4 | 5 | mysql: 6 | image: mysql:5.7 7 | command: --default-authentication-plugin=mysql_native_password 8 | ports: 9 | - 13306:3306 10 | environment: 11 | MYSQL_ROOT_PASSWORD: 123456 12 | volumes: 13 | - ./docker_data/docker-entrypoint-initdb.d/:/docker-entrypoint-initdb.d 14 | - ./docker_data/var/lib/mysql/:/var/lib/mysql 15 | -------------------------------------------------------------------------------- /07rpc/mysql-demo/docker_data/docker-entrypoint-initdb.d/01-mysql_demo-init.ddl.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE IF NOT EXISTS `mysql_demo`; 2 | 3 | USE `mysql_demo`; 4 | 5 | -- 业务订单表 6 | CREATE TABLE `t_biz_order` ( 7 | `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增主键;订单id', 8 | `user_id` bigint(20) NOT NULL COMMENT '用户userId', 9 | `state` int(8) NOT NULL DEFAULT '0' COMMENT '订单状态;参考OrderStateEnum', 10 | `create_time` bigint(20) NOT NULL COMMENT '下单时间', 11 | `update_time` bigint(20) NOT NULL COMMENT '更新时间', 12 | PRIMARY KEY (`id`), 13 | KEY `idx_user_id` (`user_id`) 14 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='订单信息表'; 15 | 16 | -- 订单-商品信息表; 17 | -------------------------------------------------------------------------------- /07rpc/mysql-demo/generateMapper.sh: -------------------------------------------------------------------------------- 1 | 2 | echo mvn clean -U -DskipTests 3 | mvn clean -U -DskipTests 4 | 5 | echo mvn mybatis-generator:generate -X -e 6 | mvn mybatis-generator:generate -X -e 7 | -------------------------------------------------------------------------------- /07rpc/mysql-demo/src/main/java/com/cncounter/mysqldemo/MysqlDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.cncounter.mysqldemo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class MysqlDemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(MysqlDemoApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /07rpc/mysql-demo/src/test/java/com/cncounter/mysqldemo/MysqlDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.cncounter.mysqldemo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class MysqlDemoApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /07rpc/rpc01/client-rest.http: -------------------------------------------------------------------------------- 1 | http://127.0.0.1:8091/api/hello -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-core/src/main/java/io/kimmking/rpcfx/annotation/RpcfxReference.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Description for this class. 7 | * 8 | * @Author : kimmking(kimmking@apache.org) 9 | * @create 2024/1/1 20:00 10 | */ 11 | @Documented 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target(ElementType.FIELD) 14 | @Inherited 15 | public @interface RpcfxReference { 16 | 17 | } -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-core/src/main/java/io/kimmking/rpcfx/annotation/RpcfxService.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Description for this class. 7 | * 8 | * @Author : kimmking(kimmking@apache.org) 9 | * @create 2024/1/1 20:00 10 | */ 11 | 12 | @Documented 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Target(ElementType.TYPE) 15 | @Inherited 16 | public @interface RpcfxService { 17 | 18 | } -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-core/src/main/java/io/kimmking/rpcfx/api/Filter.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.api; 2 | 3 | public interface Filter { 4 | 5 | RpcfxResponse prefilter(RpcfxRequest request); 6 | 7 | RpcfxResponse postfilter(RpcfxRequest request, RpcfxResponse response); 8 | 9 | // Filter next(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-core/src/main/java/io/kimmking/rpcfx/api/LoadBalancer.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.api; 2 | 3 | import io.kimmking.rpcfx.meta.InstanceMeta; 4 | 5 | import java.util.List; 6 | 7 | public interface LoadBalancer { 8 | 9 | InstanceMeta select(List instances); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-core/src/main/java/io/kimmking/rpcfx/api/Router.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.api; 2 | 3 | import io.kimmking.rpcfx.meta.InstanceMeta; 4 | 5 | import java.util.List; 6 | 7 | public interface Router { 8 | 9 | List route(List instances); 10 | } 11 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-core/src/main/java/io/kimmking/rpcfx/api/RpcContext.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.api; 2 | 3 | import io.kimmking.rpcfx.meta.ProviderMeta; 4 | import lombok.Getter; 5 | import lombok.Setter; 6 | import org.springframework.util.LinkedMultiValueMap; 7 | import org.springframework.util.MultiValueMap; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * Description for this class. 14 | * 15 | * @Author : kimmking(kimmking@apache.org) 16 | * @create 2024/1/13 20:34 17 | */ 18 | public class RpcContext { 19 | 20 | @Getter 21 | private final MultiValueMap providerHolder = new LinkedMultiValueMap<>(); 22 | 23 | @Getter 24 | private final Map consumerHolder = new HashMap<>(); 25 | 26 | @Getter 27 | private final Map parameters = new HashMap<>(); 28 | 29 | @Getter 30 | @Setter 31 | private Router router; 32 | 33 | @Getter 34 | @Setter 35 | private LoadBalancer loadBalancer; 36 | 37 | @Getter 38 | @Setter 39 | private Filter[] filters; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-core/src/main/java/io/kimmking/rpcfx/api/RpcfxRequest.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.api; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class RpcfxRequest { 7 | private String serviceClass; 8 | private String methodSign; 9 | private Object[] params; 10 | } 11 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-core/src/main/java/io/kimmking/rpcfx/api/RpcfxResponse.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.api; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class RpcfxResponse { 7 | private Object result; 8 | private boolean status; 9 | private Exception exception; 10 | } 11 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-core/src/main/java/io/kimmking/rpcfx/api/ServiceProviderDesc.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.api; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | 6 | @Data 7 | @Builder 8 | public class ServiceProviderDesc { 9 | 10 | private String host; 11 | private Integer port; 12 | private String serviceClass; 13 | 14 | // group 15 | // version 16 | } 17 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-core/src/main/java/io/kimmking/rpcfx/meta/ProviderMeta.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.meta; 2 | 3 | import lombok.Data; 4 | 5 | import java.lang.reflect.Method; 6 | 7 | /** 8 | * @author lirui 9 | */ 10 | @Data 11 | public class ProviderMeta { 12 | 13 | private Object serviceImpl; 14 | 15 | private Method method; 16 | 17 | private String methodSign; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-core/src/main/java/io/kimmking/rpcfx/meta/ServerMeta.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.meta; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | import lombok.NoArgsConstructor; 7 | 8 | /** 9 | * Description for this class. 10 | * 11 | * @Author : kimmking(kimmking@apache.org) 12 | * @create 2024/4/13 21:43 13 | */ 14 | 15 | @Data 16 | @NoArgsConstructor 17 | @AllArgsConstructor 18 | @EqualsAndHashCode(of = {"url"}) 19 | public class ServerMeta { 20 | private String url; 21 | private boolean leader; 22 | private boolean status; 23 | private long version; 24 | } 25 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-core/src/main/java/io/kimmking/rpcfx/meta/ServiceMeta.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.meta; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | 6 | /** 7 | * Description for this class. 8 | * 9 | * @Author : kimmking(kimmking@apache.org) 10 | * @create 2024/2/8 19:46 11 | */ 12 | @Data 13 | @Builder 14 | public class ServiceMeta { 15 | 16 | private String app; 17 | private String namespace; 18 | private String env; 19 | private String name; 20 | 21 | @Override 22 | public String toString() { 23 | return String.format("%s_%s_%s_%s", app, namespace, env, name); 24 | } 25 | } -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-core/src/main/java/io/kimmking/rpcfx/registry/ChangedListener.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.registry; 2 | 3 | /** 4 | * Description for this class. 5 | * 6 | * @Author : kimmking(kimmking@apache.org) 7 | * @create 2024/2/8 20:19 8 | */ 9 | public interface ChangedListener { 10 | 11 | void fireEvent(Event e); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-core/src/main/java/io/kimmking/rpcfx/registry/Event.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.registry; 2 | 3 | import io.kimmking.rpcfx.meta.InstanceMeta; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Description for this class. 11 | * 12 | * @Author : kimmking(kimmking@apache.org) 13 | * @create 2024/2/8 20:20 14 | */ 15 | public interface Event { 16 | 17 | T getData(); 18 | 19 | static Event> withData(List list) { 20 | return new ChangedEvent(list); 21 | } 22 | 23 | @Data 24 | @AllArgsConstructor 25 | class ChangedEvent implements Event> { 26 | List data; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-core/src/main/java/io/kimmking/rpcfx/registry/RegistryConfiguration.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.registry; 2 | 3 | import io.kimmking.rpcfx.registry.kkregistry.KKRegistryCenter; 4 | import io.kimmking.rpcfx.registry.zookeeper.ZookeeperRegistryCenter; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | /** 9 | * Description for this class. 10 | * 11 | * @Author : kimmking(kimmking@apache.org) 12 | * @create 2024/2/9 01:05 13 | */ 14 | 15 | @Configuration 16 | public class RegistryConfiguration { 17 | 18 | @Bean 19 | RegistryCenter createRC() { 20 | return new KKRegistryCenter(); 21 | //return new ZookeeperRegistryCenter(); //KKRegistryCenter(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-core/src/main/java/io/kimmking/rpcfx/stub/MockHandler.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.stub; 2 | 3 | import io.kimmking.rpcfx.utils.MockUtils; 4 | 5 | import java.lang.reflect.InvocationHandler; 6 | import java.lang.reflect.Method; 7 | import java.lang.reflect.Proxy; 8 | 9 | /** 10 | * Description for this class. 11 | * 12 | * @Author : kimmking(kimmking@apache.org) 13 | * @create 2024/2/11 02:57 14 | */ 15 | public class MockHandler implements InvocationHandler { 16 | 17 | @Override 18 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 19 | Class type = method.getReturnType(); 20 | System.out.println("invoke by mock handler..."); 21 | return MockUtils.mock(type, null); 22 | } 23 | 24 | public static T createMock(Class serviceClass) { 25 | //final ServiceMeta sm, Router router, LoadBalancer loadBalance, Filter filter) { 26 | return (T) Proxy.newProxyInstance(MockHandler.class.getClassLoader(), 27 | new Class[]{serviceClass}, new MockHandler()); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-core/src/main/java/io/kimmking/rpcfx/utils/MethodUtils.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.utils; 2 | 3 | import org.springframework.util.DigestUtils; 4 | 5 | import java.lang.reflect.Method; 6 | import java.util.Arrays; 7 | 8 | public class MethodUtils { 9 | 10 | public static String methodSign(Method method) { 11 | if (method != null) { 12 | StringBuilder builder = new StringBuilder(); 13 | String name = method.getName(); 14 | builder.append(name); 15 | builder.append("@"); 16 | int count = method.getParameterCount(); 17 | builder.append(count); 18 | builder.append("_"); 19 | if (count > 0) { 20 | Class[] classes = method.getParameterTypes(); 21 | Arrays.stream(classes).forEach(c -> builder.append(c.getName() + ",")); 22 | } 23 | return builder.toString(); 24 | // String string = builder.toString(); 25 | // return DigestUtils.md5DigestAsHex(string.getBytes()); 26 | } 27 | return ""; 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-demo-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | io.kimmking 7 | rpcfx 8 | 0.0.1-SNAPSHOT 9 | 10 | 11 | io.kimmking 12 | rpcfx-demo-api 13 | 0.0.1-SNAPSHOT 14 | rpcfx-demo-api 15 | 16 | 17 | 1.8 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-demo-api/src/main/java/io/kimmking/rpcfx/demo/api/Order.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.demo.api; 2 | 3 | public class Order { 4 | 5 | private int id; 6 | 7 | private String name; 8 | 9 | private float amount; 10 | 11 | public Order(int id, String name, float amount) { 12 | this.id = id; 13 | this.name = name; 14 | this.amount = amount; 15 | } 16 | 17 | public int getId() { 18 | return id; 19 | } 20 | 21 | public void setId(int id) { 22 | this.id = id; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public void setName(String name) { 30 | this.name = name; 31 | } 32 | 33 | public float getAmount() { 34 | return amount; 35 | } 36 | 37 | public void setAmount(float amount) { 38 | this.amount = amount; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-demo-api/src/main/java/io/kimmking/rpcfx/demo/api/OrderService.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.demo.api; 2 | 3 | public interface OrderService { 4 | 5 | Order findOrderById(int id); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-demo-api/src/main/java/io/kimmking/rpcfx/demo/api/User.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.demo.api; 2 | 3 | public class User { 4 | 5 | public User(){} 6 | 7 | public User(int id, String name) { 8 | this.id = id; 9 | this.name = name; 10 | } 11 | 12 | private int id; 13 | private String name; 14 | 15 | public int getId() { 16 | return id; 17 | } 18 | 19 | public void setId(int id) { 20 | this.id = id; 21 | } 22 | 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | public void setName(String name) { 28 | this.name = name; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-demo-api/src/main/java/io/kimmking/rpcfx/demo/api/UserService.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.demo.api; 2 | 3 | public interface UserService { 4 | 5 | User findById(int id); 6 | 7 | User find(int timeout); 8 | 9 | //User findById(int id, String name); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-demo-consumer/src/main/java/io/kimmking/rpcfx/demo/consumer/HelloController.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.demo.consumer; 2 | 3 | import io.kimmking.rpcfx.annotation.RpcfxReference; 4 | import io.kimmking.rpcfx.demo.api.User; 5 | import io.kimmking.rpcfx.demo.api.UserService; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * Description for this class. 11 | * 12 | * @Author : kimmking(kimmking@apache.org) 13 | * @create 2024/1/14 00:35 14 | */ 15 | 16 | @RestController 17 | public class HelloController { 18 | @RpcfxReference 19 | UserService userService2;// = Rpcfx.createFromRegistry(UserService.class, "localhost:2181", new TagRouter(), new RandomLoadBalancer(), new CuicuiFilter()); 20 | 21 | @GetMapping("/api/hello") 22 | public User invoke() { 23 | return userService2.findById(100); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-demo-consumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | shutdown: graceful 4 | 5 | spring: 6 | lifecycle: 7 | timeout-per-shutdown-phase: 20s 8 | main: 9 | allow-circular-references: true 10 | task: 11 | execution: 12 | pool: 13 | core-size: 32 14 | max-size: 128 15 | 16 | app: 17 | id: app2 18 | namespace: ns1 19 | env: sit 20 | mock: false 21 | cache: false 22 | retry: 2 23 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-demo-provider/src/main/java/io/kimmking/rpcfx/demo/provider/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.rpcfx.demo.provider; 2 | 3 | import io.kimmking.rpcfx.annotation.RpcfxService; 4 | import io.kimmking.rpcfx.demo.api.Order; 5 | import io.kimmking.rpcfx.demo.api.OrderService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.core.env.Environment; 8 | import org.springframework.stereotype.Component; 9 | 10 | @RpcfxService 11 | @Component 12 | public class OrderServiceImpl implements OrderService { 13 | 14 | @Autowired 15 | Environment environment; 16 | 17 | @Override 18 | public Order findOrderById(int id) { 19 | return new Order(id, "KK-" 20 | + environment.getProperty("server.port") + "_Order" + System.currentTimeMillis(), 9.9f); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /07rpc/rpc01/rpcfx-demo-provider/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8083 3 | shutdown: graceful 4 | 5 | spring: 6 | lifecycle: 7 | timeout-per-shutdown-phase: 20s 8 | main: 9 | allow-circular-references: true 10 | 11 | app: 12 | id: app2 13 | namespace: ns1 14 | env: sit -------------------------------------------------------------------------------- /07rpc/rpc02/dubbo-demo-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | io.kimmking 7 | dubbo-demo 8 | 0.0.1-SNAPSHOT 9 | 10 | 11 | io.kimmking 12 | dubbo-demo-api 13 | 0.0.1-SNAPSHOT 14 | dubbo-demo-api 15 | 16 | 17 | 1.8 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /07rpc/rpc02/dubbo-demo-api/src/main/java/io/kimmking/dubbo/demo/api/Order.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.dubbo.demo.api; 2 | 3 | public class Order implements java.io.Serializable { 4 | 5 | private int id; 6 | 7 | private String name; 8 | 9 | private float amount; 10 | 11 | public Order(int id, String name, float amount) { 12 | this.id = id; 13 | this.name = name; 14 | this.amount = amount; 15 | } 16 | 17 | public int getId() { 18 | return id; 19 | } 20 | 21 | public void setId(int id) { 22 | this.id = id; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public void setName(String name) { 30 | this.name = name; 31 | } 32 | 33 | public float getAmount() { 34 | return amount; 35 | } 36 | 37 | public void setAmount(float amount) { 38 | this.amount = amount; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /07rpc/rpc02/dubbo-demo-api/src/main/java/io/kimmking/dubbo/demo/api/OrderService.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.dubbo.demo.api; 2 | 3 | public interface OrderService { 4 | 5 | Order findOrderById(int id); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /07rpc/rpc02/dubbo-demo-api/src/main/java/io/kimmking/dubbo/demo/api/User.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.dubbo.demo.api; 2 | 3 | public class User implements java.io.Serializable { 4 | 5 | public User(){} 6 | 7 | public User(int id, String name) { 8 | this.id = id; 9 | this.name = name; 10 | } 11 | 12 | private int id; 13 | private String name; 14 | 15 | public int getId() { 16 | return id; 17 | } 18 | 19 | public void setId(int id) { 20 | this.id = id; 21 | } 22 | 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | public void setName(String name) { 28 | this.name = name; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /07rpc/rpc02/dubbo-demo-api/src/main/java/io/kimmking/dubbo/demo/api/UserService.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.dubbo.demo.api; 2 | 3 | public interface UserService { 4 | 5 | User findById(int id); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /07rpc/rpc02/dubbo-demo-consumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | spring: 3 | application: 4 | name: dubbo-demo-consumer 5 | main: 6 | allow-bean-definition-overriding: true 7 | web-application-type: none 8 | dubbo: 9 | scan: 10 | base-packages: io.kimmking.dubbo.demo.consumer 11 | registry: 12 | address: zookeeper://localhost:2181 13 | metadata-report: 14 | address: zookeeper://localhost:2181 15 | logging: 16 | level: 17 | root: debug 18 | org: debug 19 | sun: info 20 | com: info -------------------------------------------------------------------------------- /07rpc/rpc02/dubbo-demo-provider/src/main/java/io/kimmking/dubbo/demo/provider/DubboServerApplication.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.dubbo.demo.provider; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class DubboServerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(DubboServerApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /07rpc/rpc02/dubbo-demo-provider/src/main/java/io/kimmking/dubbo/demo/provider/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.dubbo.demo.provider; 2 | 3 | import io.kimmking.dubbo.demo.api.Order; 4 | import io.kimmking.dubbo.demo.api.OrderService; 5 | import org.apache.dubbo.config.annotation.DubboService; 6 | 7 | 8 | @DubboService(version = "1.0.0", tag = "red", weight = 100) 9 | public class OrderServiceImpl implements OrderService { 10 | 11 | @Override 12 | public Order findOrderById(int id) { 13 | return new Order(id, "Order" + System.currentTimeMillis(), 9.9f); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /07rpc/rpc02/dubbo-demo-provider/src/main/java/io/kimmking/dubbo/demo/provider/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.dubbo.demo.provider; 2 | 3 | import io.kimmking.dubbo.demo.api.User; 4 | import io.kimmking.dubbo.demo.api.UserService; 5 | import org.apache.dubbo.config.annotation.DubboService; 6 | 7 | @DubboService(version = "1.0.0") 8 | public class UserServiceImpl implements UserService { 9 | 10 | @Override 11 | public User findById(int id) { 12 | // try { 13 | // System.out.println(" ==>" + id); 14 | // Thread.sleep(1010); 15 | // } catch (InterruptedException e) { 16 | // e.printStackTrace(); 17 | // } 18 | return new User(id, "KK" + System.currentTimeMillis()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /07rpc/rpc02/dubbo-demo-provider/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8088 3 | 4 | spring: 5 | application: 6 | name: dubbo-demo-provider 7 | 8 | 9 | dubbo: 10 | scan: 11 | base-packages: io.kimmking.dubbo.demo.provider 12 | protocol: 13 | name: dubbo 14 | port: 12345 15 | payload: 134217728 16 | registry: 17 | address: zookeeper://localhost:2181 18 | metadata-report: 19 | address: zookeeper://localhost:2181 20 | application: 21 | qosEnable: true 22 | qosPort: 22222 23 | qosAcceptForeignIp: true 24 | qos-enable-compatible: true 25 | qos-host-compatible: localhost 26 | qos-port-compatible: 22222 27 | qos-accept-foreign-ip-compatible: true 28 | qos-host: localhost 29 | logging: 30 | level: 31 | root: debug -------------------------------------------------------------------------------- /08cache/README.md: -------------------------------------------------------------------------------- 1 | # 第8周作业 2 | 3 | 4 | ## 作业内容 5 | 6 | > Week08 作业题目: 7 | 8 | ###Week08 作业题目 9 | 10 | 1. (选做)分析前面作业设计的表,是否可以做垂直拆分。 11 | 2. (必做)设计对前面的订单表数据进行水平分库分表,拆分 2 个库,每个库 16 张表。并在新结构在演示常见的增删改查操作。代码、sql 和配置文件,上传到 Github。 12 | 3. (选做)模拟 1000 万的订单单表数据,迁移到上面作业 2 的分库分表中。 13 | 4. (选做)重新搭建一套 4 个库各 64 个表的分库分表,将作业 2 中的数据迁移到新分库。 14 | 5. (选做)列举常见的分布式事务,简单分析其使用场景和优缺点。 15 | 6. (必做)基于 hmily TCC 或 ShardingSphere 的 Atomikos XA 实现一个简单的分布式事务应用 demo(二选一),提交到 Github。 16 | 7. (选做)基于 ShardingSphere narayana XA 实现一个简单的分布式事务 demo。 17 | 8. (选做)基于 seata 框架实现 TCC 或 AT 模式的分布式事务 demo。 18 | 9. (选做☆)设计实现一个简单的 XA 分布式事务框架 demo,只需要能管理和调用 2 个 MySQL 的本地事务即可,不需要考虑全局事务的持久化和恢复、高可用等。 19 | 10. (选做☆)设计实现一个 TCC 分布式事务框架的简单 Demo,需要实现事务管理器,不需要实现全局事务的持久化和恢复、高可用等。 20 | 11. (选做☆)设计实现一个 AT 分布式事务框架的简单 Demo,仅需要支持根据主键 id 进行的单个删改操作的 SQL 或插入操作的事务。 21 | 22 | ### 作业提交规范: 23 | 24 | 1. 作业不要打包 ; 25 | 2. 同学们写在 md 文件里,而不要发 Word, Excel , PDF 等 ; 26 | 3. 代码类作业需提交完整 Java 代码,不能是片段; 27 | 4. 作业按课时分目录,仅上传作业相关,笔记分开记录; 28 | 5. 画图类作业提交可直接打开的图片或 md,手画的图手机拍照上传后太大,难以查看,推荐画图(推荐 PPT、Keynote); 29 | 6. 提交记录最好要标明明确的含义(比如第几题作业)。 30 | 31 | 32 | ## 操作步骤 33 | 34 | 35 | ### 第八周-作业1. (选做) 36 | -------------------------------------------------------------------------------- /08cache/cache/src/main/java/io/kimmking/cache/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.cache.controller; 2 | 3 | import io.kimmking.cache.entity.User; 4 | import io.kimmking.cache.service.UserService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import java.util.List; 11 | 12 | @RestController 13 | @EnableAutoConfiguration 14 | public class UserController { 15 | 16 | @Autowired 17 | UserService userService; 18 | 19 | @RequestMapping("/user/find") 20 | User find(Integer id) { 21 | return userService.find(id); 22 | //return new User(1,"KK", 28); 23 | } 24 | 25 | @RequestMapping("/user/list") 26 | List list() { 27 | return userService.list(); 28 | // return Arrays.asList(new User(1,"KK", 28), 29 | // new User(2,"CC", 18)); 30 | } 31 | } -------------------------------------------------------------------------------- /08cache/cache/src/main/java/io/kimmking/cache/entity/User.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.cache.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.io.Serializable; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class User implements Serializable { 13 | private Integer id; 14 | private String name; 15 | private Integer age; 16 | } -------------------------------------------------------------------------------- /08cache/cache/src/main/java/io/kimmking/cache/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.cache.mapper; 2 | 3 | import io.kimmking.cache.entity.User; 4 | import org.apache.ibatis.annotations.Mapper; 5 | 6 | import java.util.List; 7 | 8 | @Mapper 9 | public interface UserMapper { 10 | 11 | User find(int id); 12 | 13 | List list(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /08cache/cache/src/main/java/io/kimmking/cache/service/UserService.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.cache.service; 2 | 3 | import io.kimmking.cache.entity.User; 4 | import org.springframework.cache.annotation.CacheConfig; 5 | 6 | import java.util.List; 7 | 8 | @CacheConfig(cacheNames = "users") 9 | public interface UserService { 10 | 11 | User find(int id); 12 | 13 | List list(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /08cache/cache/src/main/java/io/kimmking/cache/service/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.cache.service; 2 | 3 | import io.kimmking.cache.entity.User; 4 | import io.kimmking.cache.mapper.UserMapper; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.cache.annotation.Cacheable; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | 11 | @Service 12 | public class UserServiceImpl implements UserService { 13 | 14 | @Autowired 15 | UserMapper userMapper; //DAO // Repository 16 | 17 | // 开启spring cache 18 | @Cacheable(key="#id",value="userCache") 19 | public User find(int id) { 20 | System.out.println(" ==> find " + id); 21 | return userMapper.find(id); 22 | } 23 | 24 | // 开启spring cache 25 | @Cacheable //(key="methodName",value="userCache") 26 | public List list(){ 27 | return userMapper.list(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /08cache/cache/src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 20 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /08cache/ha/conf/sentinel0.conf: -------------------------------------------------------------------------------- 1 | sentinel myid 8d992c54df8f8677b0b345825f61fb733c73d14c 2 | sentinel deny-scripts-reconfig yes 3 | sentinel monitor mymaster 127.0.0.1 6380 1 4 | sentinel down-after-milliseconds mymaster 2000 5 | # Generated by CONFIG REWRITE 6 | protected-mode no 7 | port 26379 8 | user default on nopass sanitize-payload ~* &* +@all 9 | dir "/Users/kimmking/kimmking/JavaCourseCodes/08cache/ha/conf" 10 | sentinel config-epoch mymaster 4 11 | sentinel leader-epoch mymaster 5 12 | sentinel known-sentinel mymaster 127.0.0.1 26380 8d992c54df8f8677b0b345825f61fb733c73d14d 13 | sentinel current-epoch 5 14 | sentinel known-replica mymaster 127.0.0.1 6379 15 | -------------------------------------------------------------------------------- /08cache/ha/conf/sentinel1.conf: -------------------------------------------------------------------------------- 1 | sentinel myid 8d992c54df8f8677b0b345825f61fb733c73d14d 2 | sentinel deny-scripts-reconfig yes 3 | sentinel monitor mymaster 127.0.0.1 6380 1 4 | port 26380 5 | sentinel down-after-milliseconds mymaster 2000 6 | # Generated by CONFIG REWRITE 7 | protected-mode no 8 | user default on nopass sanitize-payload ~* &* +@all 9 | dir "/Users/kimmking/kimmking/JavaCourseCodes/08cache/ha/conf" 10 | sentinel config-epoch mymaster 4 11 | sentinel leader-epoch mymaster 5 12 | sentinel known-sentinel mymaster 127.0.0.1 26379 8d992c54df8f8677b0b345825f61fb733c73d14c 13 | sentinel current-epoch 5 14 | sentinel known-replica mymaster 127.0.0.1 6379 15 | -------------------------------------------------------------------------------- /08cache/redis/src/main/java/io/kimmking/cache/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.cache.controller; 2 | 3 | import io.kimmking.cache.entity.User; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import java.util.Arrays; 9 | import java.util.List; 10 | 11 | @RestController 12 | @EnableAutoConfiguration 13 | public class UserController { 14 | 15 | 16 | @RequestMapping("/user/find") 17 | User find(Integer id) { 18 | return new User(1,"KK", 28); 19 | } 20 | 21 | @RequestMapping("/user/list") 22 | List list() { 23 | return Arrays.asList(new User(1,"KK", 28), 24 | new User(2,"CC", 18)); 25 | } 26 | } -------------------------------------------------------------------------------- /08cache/redis/src/main/java/io/kimmking/cache/entity/User.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.cache.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @NoArgsConstructor 9 | @AllArgsConstructor 10 | public class User { 11 | private Integer id; 12 | private String name; 13 | private Integer age; 14 | } -------------------------------------------------------------------------------- /08cache/redis/src/main/java/io/kimmking/cache/hazelcast/HazelcastDemo.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.cache.hazelcast; 2 | 3 | public class HazelcastDemo { 4 | 5 | public static void main(String[] args) { 6 | 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /08cache/redis/src/main/java/io/kimmking/cache/redission/RedissionDemo1.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.cache.redission; 2 | 3 | import org.redisson.Redisson; 4 | import org.redisson.api.RLock; 5 | import org.redisson.api.RMap; 6 | import org.redisson.api.RedissonClient; 7 | import org.redisson.config.Config; 8 | 9 | public class RedissionDemo1 { 10 | 11 | public static void main(String[] args) { 12 | Config config = new Config(); 13 | config.useSingleServer().setAddress("redis://127.0.0.1:6379"); 14 | 15 | final RedissonClient client = Redisson.create(config); 16 | RLock lock = client.getLock("lock1"); 17 | 18 | try{ 19 | lock.lock(); 20 | 21 | RMap rmap = client.getMap("map1"); 22 | 23 | for (int i = 0; i < 15; i++) { 24 | rmap.put("rkey:"+i, "rvalue:22222-"+i); 25 | } 26 | 27 | System.out.println(rmap.get("rkey:10")); 28 | 29 | }finally{ 30 | lock.unlock(); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /08cache/redis/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | 4 | logging: 5 | level: 6 | io: 7 | kimmking: 8 | cache : info 9 | 10 | # 作业,在这里使用spring boot配置各项内容, 11 | -------------------------------------------------------------------------------- /09mq/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /09mq/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/09mq/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /09mq/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /09mq/activemq-demo/src/main/java/io/kimmking/javacourse/mq/activemq/ActiveMQServer.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.javacourse.mq.activemq; 2 | 3 | public class ActiveMQServer { 4 | 5 | public static void main(String[] args) { 6 | // 尝试用java代码启动一个ActiveMQ broker server 7 | // 然后用前面的测试demo代码,连接这个嵌入式的server 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /09mq/activemq-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /09mq/activemq-demo/src/test/java/io/kimmking/javacourse/mq/activemq/ActivemqApplicationTests.java: -------------------------------------------------------------------------------- 1 | //package io.kimmking.javacourse.mq.activemq; 2 | // 3 | //import org.junit.jupiter.api.Test; 4 | //import org.springframework.boot.test.context.SpringBootTest; 5 | // 6 | //@SpringBootTest 7 | //class ActivemqApplicationTests { 8 | // 9 | // @Test 10 | // void contextLoads() { 11 | // } 12 | // 13 | //} 14 | -------------------------------------------------------------------------------- /09mq/kafka-demo/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | .idea 26 | *.iml 27 | -------------------------------------------------------------------------------- /09mq/kafka-demo/README.md: -------------------------------------------------------------------------------- 1 | # 消息队列培训-Kafka进阶 2 | 3 | ## 作业:具体场景下的Kafka接口设计实现 4 | 5 | ### 背景 6 | 请各位同学结合定序 & 撮合的业务特点, 练习 Producer + Consuer 的用法: 7 | - 定序要求: 数据有序并且不丢失 8 | - 撮合要求: 可重放, 顺序消费, 消息仅处理一次 9 | 10 | ### 消息格式 11 | 消息的内容格式为:// 见本仓库的代码 12 | ``` 13 | public class Order{ 14 | private Long id; 15 | private Long ts; 16 | private String symbol; 17 | private Double price; 18 | 19 | // 省略setter getter... 20 | } 21 | ``` 22 | 23 | ### 作业要求 24 | 1. `Producer`接口应该有序发送消息 25 | 2. `Producer`接口应该不丢失消息 26 | 3. `Consumer`接口应该顺序消费消息 27 | 4. `Consumer`接口应该支持从offset重新接收消息 28 | 5. `Consumer`接口应该支持消息的幂等处理,即根据id去重 29 | 6. 设计挑战:尝试接口对外暴露的使用方式,完全屏蔽了kafka的原生接口和类 30 | 7. 编码挑战:实现程序都正确,而且写了单元测试 31 | 32 | ### 提交方式:过程分(3分) 33 | 1. 设计一个 `io.kimmking.javacourse.自己姓名拼音.Producer` 接口,需满足以上要求,并尝试实现 34 | 2. 设计一个 `io.kimmking.javacourse.自己姓名拼音.Consumer` 接口,需满足以上要求,并尝试实现 35 | 3. 提交以上代码,并提交一个Pull Request到本仓库,在钉钉群回复已经完成,1分 36 | 37 | 38 | -------------------------------------------------------------------------------- /09mq/kafka-demo/src/main/java/io/kimmking/javacourse/kafka/KafkaConsumerDemo.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.javacourse.kafka; 2 | 3 | import io.kimmking.javacourse.kafka.kimmking.ConsumerImpl; 4 | 5 | public class KafkaConsumerDemo { 6 | 7 | public static void main(String[] args) { 8 | testConsumer(); 9 | } 10 | 11 | private static void testConsumer() { 12 | ConsumerImpl consumer = new ConsumerImpl(); 13 | consumer.consumeOrder(); 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /09mq/kafka-demo/src/main/java/io/kimmking/javacourse/kafka/KafkaProducerDemo.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.javacourse.kafka; 2 | 3 | import io.kimmking.javacourse.kafka.kimmking.ProducerImpl; 4 | 5 | public class KafkaProducerDemo { 6 | 7 | public static void main(String[] args) { 8 | testProducer(); 9 | } 10 | 11 | private static void testProducer() { 12 | ProducerImpl producer = new ProducerImpl(); 13 | for (int i = 0; i < 1000; i++) { 14 | producer.send(new Order(1000L + i,System.currentTimeMillis(),"USD2CNY", 6.5d)); 15 | producer.send(new Order(2000L + i,System.currentTimeMillis(),"USD2CNY", 6.51d)); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /09mq/kafka-demo/src/main/java/io/kimmking/javacourse/kafka/Order.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.javacourse.kafka; 2 | 3 | 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | 9 | @NoArgsConstructor 10 | @AllArgsConstructor 11 | @Data 12 | public class Order { // 此类型为需要使用的消息内容 13 | 14 | private Long id; 15 | private Long ts; 16 | private String symbol; 17 | private Double price; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /09mq/kafka-demo/src/main/java/io/kimmking/javacourse/kafka/kimmking/Consumer.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.javacourse.kafka.kimmking; 2 | 3 | import io.kimmking.javacourse.kafka.Order; 4 | 5 | public interface Consumer { 6 | 7 | void consumeOrder(); 8 | 9 | void close(); 10 | 11 | // add your interface method here 12 | 13 | // and then implement it 14 | 15 | } 16 | -------------------------------------------------------------------------------- /09mq/kafka-demo/src/main/java/io/kimmking/javacourse/kafka/kimmking/Producer.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.javacourse.kafka.kimmking; 2 | 3 | import io.kimmking.javacourse.kafka.Order; 4 | 5 | public interface Producer { 6 | 7 | void send(Order order); 8 | 9 | void close(); 10 | 11 | // add your interface method here 12 | 13 | // and then implement it 14 | 15 | } 16 | -------------------------------------------------------------------------------- /09mq/kafka-demo/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /09mq/kmq-core/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | 35 | *.dat 36 | -------------------------------------------------------------------------------- /09mq/kmq-core/README.md: -------------------------------------------------------------------------------- 1 | ## 说明 2 | 3 | 第一个版本,完全基于内存queue的消息队列,实现了最基础的三个功能: 4 | 5 | - 创建topic 6 | - 订阅topic和poll消息 7 | - 发送消息到topic 8 | 9 | 具体参见demo.KmqDemo -------------------------------------------------------------------------------- /09mq/kmq-core/src/main/java/io/kimmking/kmq/KmqApplication.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.kmq; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class KmqApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(KmqApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /09mq/kmq-core/src/main/java/io/kimmking/kmq/core/KmqBroker.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.kmq.core; 2 | 3 | import java.util.Map; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | import java.util.concurrent.atomic.AtomicInteger; 6 | 7 | public final class KmqBroker { // Broker+Connection 8 | 9 | public static final int CAPACITY = 10000; 10 | 11 | private final Map kmqMap = new ConcurrentHashMap<>(64); 12 | 13 | public void createTopic(String name){ 14 | kmqMap.putIfAbsent(name, new Kmq(name,CAPACITY)); 15 | } 16 | 17 | public Kmq findKmq(String topic) { 18 | return this.kmqMap.get(topic); 19 | } 20 | 21 | public KmqProducer createProducer() { 22 | return new KmqProducer(this); 23 | } 24 | 25 | final AtomicInteger consumerId = new AtomicInteger(0); 26 | public KmqConsumer createConsumer() { 27 | return new KmqConsumer("CID" + consumerId.getAndIncrement(), this); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /09mq/kmq-core/src/main/java/io/kimmking/kmq/core/KmqConsumer.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.kmq.core; 2 | 3 | import lombok.Getter; 4 | 5 | public class KmqConsumer { 6 | 7 | private final KmqBroker broker; 8 | 9 | @Getter 10 | private final String id; 11 | 12 | private Kmq kmq; 13 | 14 | public KmqConsumer(String id, KmqBroker broker) { 15 | this.id = id; 16 | this.broker = broker; 17 | } 18 | 19 | public void subscribe(String topic) { 20 | this.kmq = this.broker.findKmq(topic); 21 | if (null == kmq) throw new RuntimeException("Topic[" + topic + "] doesn't exist."); 22 | } 23 | 24 | public void subscribe(String topic, MessageListener listener) { 25 | this.kmq = this.broker.findKmq(topic); 26 | if (null == kmq) throw new RuntimeException("Topic[" + topic + "] doesn't exist."); 27 | this.kmq.addListener(listener); 28 | } 29 | 30 | public KmqMessage poll(long timeout) { 31 | return kmq.poll(timeout); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /09mq/kmq-core/src/main/java/io/kimmking/kmq/core/KmqMessage.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.kmq.core; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.HashMap; 8 | import java.util.concurrent.atomic.AtomicLong; 9 | 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | @Data 13 | public class KmqMessage { 14 | 15 | static AtomicLong MID = new AtomicLong(0); 16 | 17 | private HashMap headers = new HashMap<>(); 18 | private String topic; 19 | private Long id; 20 | private T body; 21 | 22 | public KmqMessage(String topic, T body) { 23 | this.topic = topic; 24 | this.body = body; 25 | this.id = MID.getAndIncrement(); 26 | } 27 | 28 | public static KmqMessage from(String topic, T body) { 29 | return new KmqMessage<>(topic, body); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /09mq/kmq-core/src/main/java/io/kimmking/kmq/core/KmqProducer.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.kmq.core; 2 | 3 | public class KmqProducer { 4 | 5 | private KmqBroker broker; 6 | 7 | public KmqProducer(KmqBroker broker) { 8 | this.broker = broker; 9 | } 10 | 11 | public boolean send(String topic, KmqMessage message) { 12 | Kmq kmq = this.broker.findKmq(topic); 13 | if (null == kmq) throw new RuntimeException("Topic[" + topic + "] doesn't exist."); 14 | return kmq.send(message); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /09mq/kmq-core/src/main/java/io/kimmking/kmq/core/MessageListener.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.kmq.core; 2 | 3 | /** 4 | * Description for this class. 5 | * 6 | * @Author : kimmking(kimmking@apache.org) 7 | * @create 2024/6/13 下午3:29 8 | */ 9 | public interface MessageListener { 10 | 11 | void onMessage(KmqMessage message) throws Exception; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /09mq/kmq-core/src/main/java/io/kimmking/kmq/demo/Order.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.kmq.demo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @NoArgsConstructor 8 | @AllArgsConstructor 9 | @Data 10 | public class Order { 11 | 12 | private Long id; 13 | private Long ts; 14 | private String symbol; 15 | private Double price; 16 | 17 | } -------------------------------------------------------------------------------- /09mq/kmq-core/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /09mq/kmq-core/src/test/java/io/kimmking/kmq/core/KmqApplicationTests.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.kmq.core; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class KmqApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /09mq/pulsar/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /09mq/pulsar/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/09mq/pulsar/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /09mq/pulsar/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /09mq/pulsar/src/main/java/io/kimmking/mq/pulsar/Config.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.mq.pulsar; 2 | 3 | import lombok.SneakyThrows; 4 | import org.apache.pulsar.client.api.PulsarClient; 5 | 6 | public class Config { 7 | 8 | @SneakyThrows 9 | public static PulsarClient createClient() { 10 | return PulsarClient.builder() 11 | .serviceUrl("pulsar://localhost:6650") 12 | .build(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /09mq/pulsar/src/main/java/io/kimmking/mq/pulsar/PulsarApplication.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.mq.pulsar; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.ApplicationRunner; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.context.annotation.Bean; 8 | 9 | @SpringBootApplication 10 | public class PulsarApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(PulsarApplication.class, args); 14 | } 15 | 16 | 17 | @Autowired 18 | ProducerDemo producer; 19 | 20 | @Autowired 21 | ConsumerDemo consumer; 22 | 23 | @Bean 24 | ApplicationRunner run() { 25 | return args -> { 26 | new Thread(() -> { 27 | consumer.consume(); 28 | }).start(); 29 | 30 | producer.sendMessage(); 31 | 32 | }; 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /09mq/pulsar/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /09mq/pulsar/src/test/java/io/kimmking/mq/pulsar/PulsarApplicationTests.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.mq.pulsar; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class PulsarApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /09mq/rabbit/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /09mq/rabbit/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/09mq/rabbit/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /09mq/rabbit/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /09mq/rabbit/src/main/java/io/kimmking/mq/camel/README.md: -------------------------------------------------------------------------------- 1 | 使用代码方式,实现camel的操作。 2 | -------------------------------------------------------------------------------- /09mq/rabbit/src/main/java/io/kimmking/mq/rabbit/MessageReceiverA.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.mq.rabbit; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; 5 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 6 | import org.springframework.stereotype.Component; 7 | 8 | @Component 9 | @RabbitListener(queues = RabbitConfig.QUEUE_A) 10 | @Slf4j 11 | public class MessageReceiverA { //guava , EventBus 的一些语法糖 12 | 13 | @RabbitHandler 14 | public void process(String content) { 15 | log.info("接收处理队列A当中的消息: " + content); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /09mq/rabbit/src/main/java/io/kimmking/mq/rabbit/MessageReceiverB.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.mq.rabbit; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; 5 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 6 | import org.springframework.stereotype.Component; 7 | 8 | @Component 9 | @RabbitListener(queues = RabbitConfig.QUEUE_B) 10 | @Slf4j 11 | public class MessageReceiverB { 12 | 13 | @RabbitHandler 14 | public void process(String content) { 15 | log.info("接收处理队列B当中的消息: " + content); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /09mq/rabbit/src/main/java/io/kimmking/mq/rabbit/RabbitApplication.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.mq.rabbit; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.ApplicationRunner; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.context.annotation.Bean; 8 | 9 | @SpringBootApplication 10 | public class RabbitApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(RabbitApplication.class, args); 14 | } 15 | 16 | @Autowired 17 | MessageProducer producer; 18 | 19 | @Bean 20 | ApplicationRunner run() { 21 | return args -> { 22 | for (int i = 0; i < 1000; i++) { 23 | producer.sendMessage(i+" message by cuicuilaoshi."); 24 | } 25 | }; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /09mq/rabbit/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | rabbitmq: 3 | host: localhost 4 | username: admin 5 | password: admin 6 | port: 5672 7 | 8 | -------------------------------------------------------------------------------- /09mq/rabbit/src/test/java/io/kimmking/mq/rabbit/RabbitApplicationTests.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.mq.rabbit; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class RabbitApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /09mq/rocket/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /09mq/rocket/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/09mq/rocket/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /09mq/rocket/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /09mq/rocket/src/main/java/io/kimmking/mq/rocket/Order.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.mq.rocket; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @NoArgsConstructor 9 | @AllArgsConstructor 10 | public class Order { 11 | 12 | private long id; 13 | private String symbol; 14 | private double price; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /09mq/rocket/src/main/java/io/kimmking/mq/rocket/OrderConsumerDemo.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.mq.rocket; 2 | 3 | import org.apache.rocketmq.spring.annotation.ConsumeMode; 4 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; 5 | import org.apache.rocketmq.spring.core.RocketMQReplyListener; 6 | import org.springframework.stereotype.Component; 7 | 8 | @Component 9 | @RocketMQMessageListener(consumerGroup = "test2", topic = "test-k2") 10 | public class OrderConsumerDemo implements RocketMQReplyListener { 11 | 12 | @Override 13 | public String onMessage(Order order) { // request-response 14 | System.out.println(this.getClass().getName() + " -> " + order); 15 | return "Process&Return [" + order + "]."; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /09mq/rocket/src/main/java/io/kimmking/mq/rocket/StringConsumerDemo.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.mq.rocket; 2 | 3 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; 4 | import org.apache.rocketmq.spring.core.RocketMQListener; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | @RocketMQMessageListener(consumerGroup = "test1", topic = "test-k1") 9 | public class StringConsumerDemo implements RocketMQListener { 10 | 11 | @Override 12 | public void onMessage(String message) { // one way 13 | System.out.println(this.getClass().getName() + " -> " + message); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /09mq/rocket/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | rocketmq.name-server=localhost:9876 3 | rocketmq.producer.group=my-group1 4 | rocketmq.producer.sendMessageTimeout=300000 5 | 6 | -------------------------------------------------------------------------------- /09mq/rocket/src/test/java/io/kimmking/mq/rocket/RocketApplicationTests.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.mq.rocket; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class RocketApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /09mq/spring-kafka-demo/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /09mq/spring-kafka-demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/09mq/spring-kafka-demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /09mq/spring-kafka-demo/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /09mq/spring-kafka-demo/src/main/java/io/kimmking/javacourse/kafkademo/KafkaDemoApplication.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.javacourse.kafkademo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class KafkaDemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(KafkaDemoApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /09mq/spring-kafka-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /09mq/spring-kafka-demo/src/test/java/io/kimmking/javacourse/kafkademo/KafkaDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package io.kimmking.javacourse.kafkademo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class KafkaDemoApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /11dfs/dfs/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /11dfs/dfs/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/11dfs/dfs/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /11dfs/dfs/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /11dfs/dfs/app/pic/1.txt: -------------------------------------------------------------------------------- 1 | 111 -------------------------------------------------------------------------------- /11dfs/dfs/app/pic/1644038685842-moon.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/11dfs/dfs/app/pic/1644038685842-moon.jpeg -------------------------------------------------------------------------------- /11dfs/dfs/app/pic/1644048593861-moon.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/11dfs/dfs/app/pic/1644048593861-moon.jpeg -------------------------------------------------------------------------------- /11dfs/dfs/app/pic/1644051049289-IMG_0987.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/11dfs/dfs/app/pic/1644051049289-IMG_0987.JPG -------------------------------------------------------------------------------- /11dfs/dfs/app/pic/1644051171701-houyiqibing.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/11dfs/dfs/app/pic/1644051171701-houyiqibing.jpeg -------------------------------------------------------------------------------- /11dfs/dfs/app/pic/1644051228263-houyiqibing.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/11dfs/dfs/app/pic/1644051228263-houyiqibing.jpeg -------------------------------------------------------------------------------- /11dfs/dfs/app/pic/1644051550427-houyiqibing.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/11dfs/dfs/app/pic/1644051550427-houyiqibing.jpeg -------------------------------------------------------------------------------- /11dfs/dfs/app/pic/1646313820045-image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/11dfs/dfs/app/pic/1646313820045-image1.png -------------------------------------------------------------------------------- /11dfs/dfs/app/pic/1646485079290-renshijian.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/11dfs/dfs/app/pic/1646485079290-renshijian.jpeg -------------------------------------------------------------------------------- /11dfs/dfs/app/pic/1646485131332-renshijian.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/11dfs/dfs/app/pic/1646485131332-renshijian.jpeg -------------------------------------------------------------------------------- /11dfs/dfs/app/pic/1646490487023-renshijian.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/11dfs/dfs/app/pic/1646490487023-renshijian.jpeg -------------------------------------------------------------------------------- /11dfs/dfs/app/pic/1646490663637-yushengjiexuan7.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/11dfs/dfs/app/pic/1646490663637-yushengjiexuan7.jpeg -------------------------------------------------------------------------------- /11dfs/dfs/app/pic/1646491143115-yushengjiexuan7.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/11dfs/dfs/app/pic/1646491143115-yushengjiexuan7.jpeg -------------------------------------------------------------------------------- /11dfs/dfs/app/pic/jiajia.txt: -------------------------------------------------------------------------------- 1 | jiajia,nihao -------------------------------------------------------------------------------- /11dfs/dfs/src/main/java/io/github/kimmking/javacourse/dfs/DfsApplication.java: -------------------------------------------------------------------------------- 1 | package io.github.kimmking.javacourse.dfs; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @MapperScan("io.github.kimmking.javacourse.dfs.mapper") 8 | @SpringBootApplication 9 | public class DfsApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(DfsApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /11dfs/dfs/src/main/java/io/github/kimmking/javacourse/dfs/FastDfsClientConfig.java: -------------------------------------------------------------------------------- 1 | package io.github.kimmking.javacourse.dfs; 2 | 3 | import com.github.tobato.fastdfs.FdfsClientConfig; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.EnableMBeanExport; 6 | import org.springframework.context.annotation.Import; 7 | import org.springframework.jmx.support.RegistrationPolicy; 8 | 9 | @Configuration 10 | @Import(FdfsClientConfig.class) 11 | @EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING) 12 | public class FastDfsClientConfig { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /11dfs/dfs/src/main/java/io/github/kimmking/javacourse/dfs/JavaConfig.java: -------------------------------------------------------------------------------- 1 | package io.github.kimmking.javacourse.dfs; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.multipart.commons.CommonsMultipartResolver; 6 | 7 | @Configuration 8 | public class JavaConfig { 9 | @Bean 10 | CommonsMultipartResolver createCommonsMultipartResolver() { 11 | CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver(); 12 | commonsMultipartResolver.setMaxUploadSize(4*1024*1024); 13 | commonsMultipartResolver.setMaxInMemorySize(4*1024*1024); 14 | commonsMultipartResolver.setDefaultEncoding("UTF-8"); 15 | return commonsMultipartResolver; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /11dfs/dfs/src/main/java/io/github/kimmking/javacourse/dfs/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package io.github.kimmking.javacourse.dfs.mapper; 2 | 3 | import io.github.kimmking.javacourse.dfs.model.User; 4 | import org.springframework.stereotype.Repository; 5 | 6 | @Repository 7 | public interface UserMapper { 8 | int create(User user); 9 | User findById(Long id); 10 | } 11 | -------------------------------------------------------------------------------- /11dfs/dfs/src/main/java/io/github/kimmking/javacourse/dfs/model/User.java: -------------------------------------------------------------------------------- 1 | package io.github.kimmking.javacourse.dfs.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class User { 11 | private Long id; 12 | private String name; 13 | private String picPath; 14 | } 15 | -------------------------------------------------------------------------------- /11dfs/dfs/src/main/java/io/github/kimmking/javacourse/dfs/service/UserService.java: -------------------------------------------------------------------------------- 1 | package io.github.kimmking.javacourse.dfs.service; 2 | 3 | import io.github.kimmking.javacourse.dfs.mapper.UserMapper; 4 | import io.github.kimmking.javacourse.dfs.model.User; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | @Service 9 | public class UserService { 10 | 11 | @Autowired 12 | UserMapper userMapper; 13 | 14 | public User create(User user){ 15 | int result = this.userMapper.create(user); 16 | System.out.println("create user[" + user + "],result=" + result); 17 | return result>0 ? user : null; 18 | } 19 | 20 | public User findById(Long id){ 21 | return this.userMapper.findById(id); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /11dfs/dfs/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8011 3 | # tomcat: 4 | # basedir: app 5 | 6 | spring: 7 | # mvc: 8 | # static-path-pattern: /** 9 | # web: 10 | # resources: 11 | # static-locations: file:/Users/kimmking/kimmking/JavaCourseCodes/11dfs/dfs/pic/ 12 | # # ## classpath:/META-INF/static/,classpath:/META-INF/public/,classpath:/META-INF/resources/, 13 | datasource: 14 | url: jdbc:mysql://localhost:3306/test?serverTimezone=Asia/Shanghai&useServerPrepStmts=true&cachePrepStmts=true 15 | username: root 16 | password: 17 | druid: 18 | initial-size: 5 19 | max-active: 5 20 | 21 | mybatis: 22 | mapper-locations: classpath:mapper/*Mapper.xml 23 | 24 | logging: 25 | level: 26 | root: info 27 | 28 | fdfs: 29 | so-timeout: 3000 30 | connect-timeout: 1000 31 | tracker-list: 32 | - 62.234.122.77:22122 33 | -------------------------------------------------------------------------------- /11dfs/dfs/src/main/resources/mapper/userMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | insert into user(id,name,pic_path) values(#{id},#{name},#{picPath}); 17 | 18 | 19 | -------------------------------------------------------------------------------- /11dfs/dfs/src/main/resources/static/index-dfs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 测试上传文件 6 | 7 | 8 |
9 |

请选择上传文件

10 | 11 |
12 | 13 |
14 | 15 |
16 | 17 | -------------------------------------------------------------------------------- /11dfs/dfs/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 测试上传文件 6 | 7 | 8 |
9 |

请选择上传文件

10 | 11 |
12 | 13 |
14 | 15 |
16 | 17 | -------------------------------------------------------------------------------- /11dfs/dfs/src/test/java/io/github/kimmking/javacourse/dfs/DfsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package io.github.kimmking.javacourse.dfs; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class DfsApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JavaCourse 2 | Java进阶训练营示例代码。此处代码,一方面作为作业的基本版本,另一方面需要大家通过调整加深自己对技术点的认识。 3 | 4 | 本课程的三个要素: 5 | 6 | 1)40%是课程,包括预习、听课、复习总结,形成自己对知识体系的认识和经验,这是最基本的学习方法。 7 | 8 | 2)30%是作业,作业包括基础版本的必做作业,补充的选做作业,高难度的挑战作业。基本上完成必做可以通过P6的技术面试,完成选做可以通过P7的技术面试,高难度的话可以达到P7+/P8的技术面试水平。这是通过练习,得到第一手的体验。 9 | 10 | 3)30%是活动,包括且不限于源码分析学习小组,技术文章活动,读书活动,线下技术沙龙,线上技术分享等。通过一群愿意学习的人,在更好的学习氛围中,实现长期深入学习。 11 | 12 | ## 挑战作业 13 | 14 | 每个模块的挑战作业:[homework2.0.md](./homework2.0.md) , 能做出来70%的题目,直接联系我,给你推荐一线大厂工作。 -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /app/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/app/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /app/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/app/App.java: -------------------------------------------------------------------------------- 1 | package com.example.app; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.annotation.Bean; 7 | 8 | @SpringBootApplication 9 | public class App { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(App.class, args); 13 | } 14 | 15 | 16 | 17 | // ==== 测试自动配置 ==== 18 | @Autowired 19 | WebInfo info; 20 | 21 | @Bean 22 | public void printInfo(){ 23 | System.out.println(info.getName()); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/app/WebAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.example.app; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.context.annotation.Import; 8 | 9 | @Configuration 10 | @Import(WebConfiguration.class) 11 | @EnableConfigurationProperties(WebProperties.class) 12 | public class WebAutoConfiguration { 13 | 14 | @Autowired 15 | WebProperties properties; 16 | 17 | @Autowired 18 | WebConfiguration configuration; 19 | 20 | @Bean 21 | public WebInfo creatInfo(){ 22 | return new WebInfo(configuration.name + "-"+properties.getA()); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/app/WebConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.example.app; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | 5 | @Configuration 6 | public class WebConfiguration { 7 | 8 | public String name = "java"; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/app/WebInfo.java: -------------------------------------------------------------------------------- 1 | package com.example.app; 2 | 3 | public class WebInfo { 4 | 5 | public WebInfo(String name) { 6 | this.name = name; 7 | } 8 | 9 | private String name; 10 | 11 | public String getName() { 12 | return name; 13 | } 14 | 15 | public void setName(String name) { 16 | this.name = name; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/app/WebProperties.java: -------------------------------------------------------------------------------- 1 | package com.example.app; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | 5 | @ConfigurationProperties(prefix = "web") 6 | public class WebProperties { 7 | 8 | private String a = "aaa"; 9 | 10 | public String getA() { 11 | return a; 12 | } 13 | 14 | public void setA(String a) { 15 | this.a = a; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/app/src/main/resources/META-INF/spring.factories -------------------------------------------------------------------------------- /app/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | web.a=kimmking 2 | -------------------------------------------------------------------------------- /app/src/test/java/com/example/app/AppApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.app; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class AppApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /demo/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /demo/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /demo/src/main/java/com/example/demo/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class DemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(DemoApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /demo/src/main/java/com/example/demo/controller/DemoController.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.controller; 2 | 3 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | 7 | @Controller 8 | @EnableAutoConfiguration 9 | @RequestMapping("/demo") 10 | public class DemoController { 11 | 12 | @RequestMapping("/hello") 13 | public String hello() { 14 | return "KK-" + System.currentTimeMillis(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /demo/src/main/java/com/example/demo/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.example.demo.controller; 2 | 3 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | 7 | @Controller 8 | @EnableAutoConfiguration 9 | @RequestMapping("/user") 10 | public class UserController { 11 | 12 | @RequestMapping("/list") 13 | public String list() { 14 | return "KK-" + System.currentTimeMillis(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /demo/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | -------------------------------------------------------------------------------- /demo/src/test/java/com/example/demo/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class DemoApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /demoidea/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /demoidea/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/demoidea/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /demoidea/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /demoidea/src/main/java/io/github/kimmking/demoidea/DemoideaApplication.java: -------------------------------------------------------------------------------- 1 | package io.github.kimmking.demoidea; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class DemoideaApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(DemoideaApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /demoidea/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demoidea/src/test/java/io/github/kimmking/demoidea/DemoideaApplicationTests.java: -------------------------------------------------------------------------------- 1 | package io.github.kimmking.demoidea; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class DemoideaApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /java11/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /java11/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/java11/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /java11/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /java11/klass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/java11/klass.png -------------------------------------------------------------------------------- /java11/list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/java11/list.png -------------------------------------------------------------------------------- /java11/map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/java11/map.png -------------------------------------------------------------------------------- /java11/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /java11/src/test/java/com/example/demo/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | //package com.example.demo; 2 | // 3 | //import org.junit.jupiter.api.Test; 4 | //import org.springframework.boot.test.context.SpringBootTest; 5 | // 6 | //@SpringBootTest 7 | //class DemoApplicationTests { 8 | // 9 | // @Test 10 | // void contextLoads() { 11 | // } 12 | // 13 | //} 14 | -------------------------------------------------------------------------------- /java11/user.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JavaCourse00/JavaCourseCodes/58bb7d3a90e97a37963f1b016d1c44db3dffe0d4/java11/user.png -------------------------------------------------------------------------------- /test.txt: -------------------------------------------------------------------------------- 1 | nohup java -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnSafepointTimeout -XX:+ShowMessageBoxOnError -Xmx1g -Xms1g -XX:+SafepointTimeout -XX:SafepointTimeoutDelay=100 -Xlog:gc*=trace,heap*=trace,safepoint*=trace,logging*=trace:file=gc-%p-%t.log:pid,utctime,level,tags:filecount=100,filesize=10m -jar gateway-server-0.0.1-SNAPSHOT.jar & --------------------------------------------------------------------------------