├── Sentinel ├── src │ ├── main │ │ ├── resources │ │ │ ├── SystemRule.json │ │ │ ├── application.properties │ │ │ ├── META-INF │ │ │ │ └── services │ │ │ │ │ └── com.alibaba.csp.sentinel.init.InitFunc │ │ │ ├── DegradeRule.json │ │ │ └── FlowRule.json │ │ └── java │ │ │ └── top │ │ │ └── itning │ │ │ └── sentinel │ │ │ ├── service │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ │ └── UserServiceImpl.java │ │ │ ├── dto │ │ │ └── UserDTO.java │ │ │ ├── config │ │ │ ├── annotation │ │ │ │ └── SentinelResourcePro.java │ │ │ ├── datasource │ │ │ │ ├── FileWritableDataSourceWithLog.java │ │ │ │ └── FileRefreshableDataSourceWithLog.java │ │ │ └── SentinelConfig.java │ │ │ ├── SentinelApplication.java │ │ │ └── controller │ │ │ └── UserController.java │ └── test │ │ └── java │ │ └── top │ │ └── itning │ │ └── sentinel │ │ └── SentinelApplicationTests.java └── .gitignore ├── Disruptor ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── top │ │ │ └── itning │ │ │ └── disruptor │ │ │ ├── DisruptorApplication.java │ │ │ ├── quickstart │ │ │ ├── OrderEventFactory.java │ │ │ ├── OrderEventHandler.java │ │ │ ├── OrderEvent.java │ │ │ └── OrderEventProducer.java │ │ │ ├── high │ │ │ ├── Handler2.java │ │ │ ├── Handler3.java │ │ │ ├── Handler4.java │ │ │ ├── Handler5.java │ │ │ ├── Handler1.java │ │ │ ├── TradePushlisher.java │ │ │ └── Trade.java │ │ │ └── multi │ │ │ ├── Order.java │ │ │ ├── Producer.java │ │ │ └── Consumer.java │ └── test │ │ └── java │ │ └── top │ │ └── itning │ │ └── disruptor │ │ └── DisruptorApplicationTests.java └── .gitignore ├── EasyRule ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── top │ │ │ └── itning │ │ │ └── easyrule │ │ │ ├── rule1 │ │ │ ├── UserDTO.java │ │ │ └── rule │ │ │ │ ├── AddTelRule.java │ │ │ │ ├── AddIdRule.java │ │ │ │ ├── AddAddressRule.java │ │ │ │ ├── AddNameRule.java │ │ │ │ └── FinallyUserRule.java │ │ │ └── EasyRuleApplication.java │ └── test │ │ └── java │ │ └── top │ │ └── itning │ │ └── easyrule │ │ └── EasyRuleApplicationTests.java └── .gitignore ├── RabbitMQ ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── top │ │ │ └── itning │ │ │ └── rabbitmq │ │ │ ├── RabbitmqApplication.java │ │ │ └── quickstart │ │ │ └── Consumer.java │ └── test │ │ └── java │ │ └── top │ │ └── itning │ │ └── rabbitmq │ │ └── RabbitmqApplicationTests.java ├── .gitignore └── pom.xml ├── Nio ├── src │ └── main │ │ ├── resources │ │ └── test.txt │ │ └── java │ │ └── top │ │ └── itning │ │ └── nio │ │ ├── FileTest.java │ │ └── ServerSocketClient.java └── pom.xml ├── pic ├── dev.png └── 全栈开发.xmind ├── Elasticsearch ├── README.md ├── src │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── top │ │ └── itning │ │ └── elasticsearch │ │ ├── dao │ │ └── UserRepository.java │ │ ├── ElasticsearchApplication.java │ │ └── service │ │ └── UserService.java └── pom.xml ├── .gitignore ├── NettyWithSpringBoot ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── top │ │ │ └── itning │ │ │ └── netty │ │ │ ├── service │ │ │ ├── UserInfoService.java │ │ │ └── impl │ │ │ │ └── UserInfoServiceImpl.java │ │ │ ├── NettyWithSpringBootApplication.java │ │ │ ├── model │ │ │ └── User.java │ │ │ └── http │ │ │ └── GlobalExceptionHandler.java │ └── test │ │ └── java │ │ └── top │ │ └── itning │ │ └── netty │ │ └── NettyWithSpringBootApplicationTests.java ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties └── .gitignore ├── DesignPatterns ├── src │ └── main │ │ └── java │ │ ├── 桥接模式 │ │ ├── package-info.java │ │ └── coffee │ │ │ ├── ICoffeeAdditives.java │ │ │ ├── Milk.java │ │ │ ├── Sugar.java │ │ │ ├── Coffee.java │ │ │ ├── LargeCoffee.java │ │ │ ├── Test.java │ │ │ └── RefinedCoffee.java │ │ ├── 装饰器模式 │ │ ├── package-info.java │ │ └── text │ │ │ ├── TextNode.java │ │ │ ├── BoldDecorator.java │ │ │ ├── SpanNode.java │ │ │ ├── Test.java │ │ │ └── NodeDecorator.java │ │ ├── 适配器模式 │ │ ├── package-info.java │ │ └── task │ │ │ ├── Test.java │ │ │ ├── Task.java │ │ │ └── RunnableAdapter.java │ │ └── 策略模式 │ │ ├── book │ │ ├── MemberStrategy.java │ │ ├── PrimaryMemberStrategy.java │ │ ├── AdvancedMemberStrategy.java │ │ ├── IntermediateMemberStrategy.java │ │ ├── Test.java │ │ └── Price.java │ │ └── package-info.java └── pom.xml ├── Scala ├── src │ └── main │ │ └── java │ │ └── top │ │ └── itning │ │ └── basis │ │ ├── ListTest.scala │ │ ├── entity │ │ ├── User.scala │ │ └── P.scala │ │ ├── TupleTest.scala │ │ ├── ObjectTest.scala │ │ ├── MapTest.scala │ │ ├── ArrayTest.scala │ │ ├── Basis.scala │ │ └── Fun.scala └── pom.xml ├── Proxy ├── src │ └── main │ │ └── java │ │ └── proxy │ │ ├── cglib │ │ ├── OriginalObject.java │ │ ├── OriginalObjectImpl.java │ │ ├── ProxyMain.java │ │ └── ProxyObject.java │ │ └── jdk │ │ ├── OriginalObject.java │ │ ├── ProxyMain.java │ │ ├── OriginalObjectImpl.java │ │ └── ProxyObject.java └── pom.xml ├── Algorithm ├── src │ └── main │ │ └── java │ │ └── top │ │ └── itning │ │ ├── integrity │ │ ├── Solution.java │ │ └── Solution2.java │ │ ├── recursive │ │ ├── Solution3.java │ │ ├── Solution4.java │ │ ├── Solution2.java │ │ └── Solution.java │ │ ├── bit │ │ └── Solution.java │ │ ├── abstracts │ │ ├── Solution2.java │ │ └── Solution.java │ │ ├── string │ │ └── Solution.java │ │ ├── robustness │ │ ├── Solution3.java │ │ ├── Solution2.java │ │ └── Solution.java │ │ ├── find │ │ └── Solution.java │ │ ├── stack │ │ └── Solution.java │ │ ├── array │ │ └── Solution.java │ │ └── linked │ │ └── Solution.java └── pom.xml ├── Guava ├── src │ └── main │ │ └── java │ │ └── top │ │ └── itning │ │ └── bigdata │ │ └── guava │ │ ├── collections │ │ ├── CollectionhelperSexplainedTest.java │ │ ├── UtilsTest.java │ │ └── ImmutableCollectionsTest.java │ │ ├── reflection │ │ └── ReflectionTest.java │ │ ├── throwables │ │ └── ThrowablesTest.java │ │ ├── ordering │ │ └── OrderingTest.java │ │ ├── precondition │ │ └── PreconditionsTest.java │ │ ├── optional │ │ └── AvoidNullTest.java │ │ ├── objects │ │ └── ObjectsTest.java │ │ └── caches │ │ └── CachesTest.java └── pom.xml ├── Hadoop └── src │ ├── main │ ├── resources │ │ └── log4j.properties │ └── java │ │ ├── log │ │ ├── LogReducer.java │ │ ├── LogMapper.java │ │ └── LogRunner.java │ │ ├── mr │ │ ├── WordCountReducer.java │ │ ├── WordCountMapper.java │ │ └── WordCountRunner.java │ │ ├── flow │ │ ├── FlowCountReducer.java │ │ └── FlowCountMapper.java │ │ ├── join │ │ ├── JoinReducer.java │ │ ├── JoinMapper.java │ │ └── JoinRunner.java │ │ └── mysql │ │ ├── MysqlRunner.java │ │ └── MysqlRecord.java │ └── test │ └── java │ └── Test.java ├── Reactor ├── src │ └── main │ │ └── java │ │ └── top │ │ └── itning │ │ └── reactor │ │ └── EchoReactorSingleServerBootStrap.java └── pom.xml ├── Concurrent ├── src │ └── main │ │ └── java │ │ ├── concurrent │ │ ├── threadrandom │ │ │ └── ThreadRandomTest.java │ │ ├── atomic │ │ │ ├── AdderTest.java │ │ │ ├── AccumulatorTest.java │ │ │ ├── AtomicMarkableReferenceTest.java │ │ │ └── AtomicNumber.java │ │ ├── ThreadPoolWithRunable.java │ │ ├── thread │ │ │ └── FutureTaskTest.java │ │ ├── cyclicbarrier │ │ │ └── CyclicBarrierTest.java │ │ ├── completablefuture │ │ │ ├── CompletableFutureTest.java │ │ │ └── CompletableFutureTest2.java │ │ ├── threadpool │ │ │ ├── ScheduledThreadPoolTest.java │ │ │ ├── SingleThreadScheduledExecutorTest.java │ │ │ ├── SingleThreadPoolTest.java │ │ │ ├── ManualThreadPoolTest.java │ │ │ └── FixedThreadPoolTest.java │ │ ├── ThreadPoolWithCallable.java │ │ ├── lock │ │ │ └── LockSupportTest.java │ │ ├── observer │ │ │ └── ObservableTest.java │ │ └── semaphore │ │ │ └── SemaphoreTest.java │ │ ├── voliatle │ │ └── TestVolatile.java │ │ └── threadlocal │ │ └── ThreadLocalTest.java └── pom.xml ├── Activemq ├── src │ └── main │ │ └── java │ │ └── activemq │ │ ├── ProducerTest.java │ │ └── ConsumerTest.java └── pom.xml ├── Blockingqueue ├── src │ └── main │ │ └── java │ │ └── blockingqueue │ │ ├── ConcurrentLinkedQueueTest.java │ │ ├── PriorityBlockingQueueTest.java │ │ └── DelayQueueTest.java └── pom.xml ├── Spark ├── src │ └── main │ │ └── java │ │ └── top │ │ └── itning │ │ └── TestWordCount.scala └── pom.xml ├── Kafka └── src │ └── main │ └── resources │ └── logback.xml ├── Leetcode ├── src │ └── test │ │ └── java │ │ └── top │ │ └── itning │ │ └── test │ │ ├── RegularExpressionMatchingTest.java │ │ ├── ReverseIntegerTest.java │ │ ├── ZigzagConversionTest.java │ │ ├── PalindromeNumberTest.java │ │ ├── LengthOfLastWordTest.java │ │ ├── RemoveElementTest.java │ │ ├── LongestSubstringWithoutRepeatingCharactersTest.java │ │ ├── LongestPalindromicSubstringTest.java │ │ ├── RemoveDuplicatesFromSortedListTest.java │ │ ├── ImplementStrstrTest.java │ │ ├── PlusOneTest.java │ │ └── LongestCommonPrefixTest.java └── pom.xml ├── WrittenExamination ├── pom.xml └── src │ └── main │ └── java │ └── top │ └── itning │ └── w │ └── RandomWordGenerate.java ├── Netty └── src │ └── main │ ├── java │ └── top │ │ └── itning │ │ └── netty │ │ ├── chat │ │ ├── codec │ │ │ ├── ChatEncoder.java │ │ │ └── ChatDecoder.java │ │ ├── client │ │ │ └── ChatClientHandler.java │ │ └── server │ │ │ └── ChatServer.java │ │ ├── simple │ │ └── client │ │ │ ├── SimpleClientHandler.java │ │ │ └── SimpleClient.java │ │ └── websocket │ │ ├── HeartBeatHandler.java │ │ └── WebSocketChatServerHandler.java │ └── resources │ └── chatTest.html ├── UDP ├── pom.xml └── src │ └── main │ └── java │ └── top │ └── itning │ └── udp │ └── UdpClient.java ├── Aio └── pom.xml ├── LICENSE ├── Storm ├── src │ └── main │ │ └── java │ │ └── top │ │ └── itning │ │ └── storm │ │ └── wordcount │ │ ├── WordCountTopology.java │ │ ├── WordCountSplitBolt.java │ │ └── WordCountCountBolt.java └── pom.xml ├── Kafka2Storm └── src │ └── main │ └── java │ └── top │ └── itning │ └── kafka2storm │ ├── WordCountBolt.java │ └── WordCountSplitBolt.java ├── Zookeeper └── pom.xml └── Jmh ├── src └── main │ └── java │ └── top │ └── itning │ └── test │ └── StringBuilderBenchmark.java └── pom.xml /Sentinel/src/main/resources/SystemRule.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /Disruptor/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /EasyRule/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /RabbitMQ/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Nio/src/main/resources/test.txt: -------------------------------------------------------------------------------- 1 | A 2 | B 3 | C 4 | D 5 | E 6 | F -------------------------------------------------------------------------------- /pic/dev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/BigData/master/pic/dev.png -------------------------------------------------------------------------------- /pic/全栈开发.xmind: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/BigData/master/pic/全栈开发.xmind -------------------------------------------------------------------------------- /Elasticsearch/README.md: -------------------------------------------------------------------------------- 1 | 这是一个**通讯录**系统 2 | 3 | 使用ES进行搜索 4 | 5 | 展示ES与Spring Boot结合的能力 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | target/ 4 | *.iml 5 | .idea/ 6 | logs/ 7 | out/ 8 | sentinel_log/ -------------------------------------------------------------------------------- /NettyWithSpringBoot/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | logging.level.io.netty=debug 2 | -------------------------------------------------------------------------------- /Sentinel/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=sentinel-test 2 | server.port=8888 -------------------------------------------------------------------------------- /Sentinel/src/main/resources/META-INF/services/com.alibaba.csp.sentinel.init.InitFunc: -------------------------------------------------------------------------------- 1 | top.itning.sentinel.config.init.DataSourceInitFunc -------------------------------------------------------------------------------- /NettyWithSpringBoot/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/BigData/master/NettyWithSpringBoot/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Elasticsearch/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/BigData/master/Elasticsearch/src/main/resources/application.properties -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/桥接模式/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 桥接模式 3 | * 主要解决A变化B也变化的问题 4 | * 5 | * @author itning 6 | * @since 2021/12/21 18:17 7 | */ 8 | package 桥接模式; -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/装饰器模式/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 动态地给一个对象添加一些额外的职责。就增加功能来说,相比生成子类更为灵活 3 | * 4 | * @author itning 5 | * @since 2021/12/22 10:25 6 | */ 7 | package 装饰器模式; -------------------------------------------------------------------------------- /Sentinel/src/main/resources/DegradeRule.json: -------------------------------------------------------------------------------- 1 | [{"count":0.2,"grade":1,"limitApp":"default","minRequestAmount":5,"resource":"test","slowRatioThreshold":1.0,"statIntervalMs":1000,"timeWindow":5}] -------------------------------------------------------------------------------- /Scala/src/main/java/top/itning/basis/ListTest.scala: -------------------------------------------------------------------------------- 1 | package top.itning.basis 2 | 3 | object ListTest { 4 | def main(args: Array[String]): Unit = { 5 | val list = List(1,2,3) 6 | println(0 :: list) 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/适配器模式/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 将一个类的接口转换成客户希望的另外一个接口,使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。 3 | * 不改变原有接口实现类的情况下适配另一个接口 4 | * 5 | * @author itning 6 | * @since 2021/12/22 10:11 7 | */ 8 | package 适配器模式; -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/桥接模式/coffee/ICoffeeAdditives.java: -------------------------------------------------------------------------------- 1 | package 桥接模式.coffee; 2 | 3 | /** 4 | * @author itning 5 | * @since 2021/12/21 18:04 6 | */ 7 | public interface ICoffeeAdditives { 8 | void addSomething(); 9 | } 10 | -------------------------------------------------------------------------------- /Scala/src/main/java/top/itning/basis/entity/User.scala: -------------------------------------------------------------------------------- 1 | package top.itning.basis.entity 2 | 3 | class User { 4 | var id: String = _ 5 | //其它包无法访问 6 | private var password: String = _ 7 | } 8 | 9 | object User { 10 | def apply(): User = new User() 11 | } 12 | -------------------------------------------------------------------------------- /NettyWithSpringBoot/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.3/apache-maven-3.8.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 | -------------------------------------------------------------------------------- /Proxy/src/main/java/proxy/cglib/OriginalObject.java: -------------------------------------------------------------------------------- 1 | package proxy.cglib; 2 | 3 | /** 4 | * 业务接口 5 | * 6 | * @author itning 7 | */ 8 | public interface OriginalObject { 9 | /** 10 | * 获取年龄 11 | * 12 | * @return 年龄 13 | */ 14 | int getAge(); 15 | } 16 | -------------------------------------------------------------------------------- /Proxy/src/main/java/proxy/jdk/OriginalObject.java: -------------------------------------------------------------------------------- 1 | package proxy.jdk; 2 | 3 | /** 4 | * 业务接口 5 | * 6 | * @author itning 7 | */ 8 | public interface OriginalObject { 9 | /** 10 | * 获取年龄 11 | * 12 | * @return 年龄 13 | */ 14 | int getAge(); 15 | } 16 | -------------------------------------------------------------------------------- /Scala/src/main/java/top/itning/basis/entity/P.scala: -------------------------------------------------------------------------------- 1 | package top.itning.basis.entity 2 | 3 | import scala.io.Source 4 | 5 | class P(val id: String) { 6 | try { 7 | Source.fromFile("").mkString 8 | } catch { 9 | case e: Exception => e.printStackTrace() 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/装饰器模式/text/TextNode.java: -------------------------------------------------------------------------------- 1 | package 装饰器模式.text; 2 | 3 | /** 4 | * @author itning 5 | * @since 2021/12/22 10:30 6 | */ 7 | public interface TextNode { 8 | // 设置text: 9 | void setText(String text); 10 | // 获取text: 11 | String getText(); 12 | } 13 | -------------------------------------------------------------------------------- /Scala/src/main/java/top/itning/basis/TupleTest.scala: -------------------------------------------------------------------------------- 1 | package top.itning.basis 2 | 3 | object TupleTest { 4 | def main(args: Array[String]): Unit = { 5 | val tuple = ("a", 2, 3.4) 6 | println(tuple._1) 7 | val t, (x, y, z) = ("a", 2, 3.4) 8 | println(t, x, y, z) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Sentinel/src/main/java/top/itning/sentinel/service/UserService.java: -------------------------------------------------------------------------------- 1 | package top.itning.sentinel.service; 2 | 3 | import top.itning.sentinel.dto.UserDTO; 4 | 5 | /** 6 | * @author itning 7 | * @date 2020/8/22 15:29 8 | */ 9 | public interface UserService { 10 | UserDTO getRandomUser(); 11 | } 12 | -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/桥接模式/coffee/Milk.java: -------------------------------------------------------------------------------- 1 | package 桥接模式.coffee; 2 | 3 | /** 4 | * @author itning 5 | * @since 2021/12/21 18:06 6 | */ 7 | public class Milk implements ICoffeeAdditives{ 8 | @Override 9 | public void addSomething() { 10 | System.out.println("加奶"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/桥接模式/coffee/Sugar.java: -------------------------------------------------------------------------------- 1 | package 桥接模式.coffee; 2 | 3 | /** 4 | * @author itning 5 | * @since 2021/12/21 18:06 6 | */ 7 | public class Sugar implements ICoffeeAdditives { 8 | @Override 9 | public void addSomething() { 10 | System.out.println("加糖"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Sentinel/src/main/resources/FlowRule.json: -------------------------------------------------------------------------------- 1 | [{"clusterConfig":{"fallbackToLocalWhenFail":true,"sampleCount":10,"strategy":0,"thresholdType":0,"windowIntervalMs":1000},"clusterMode":false,"controlBehavior":0,"count":2.0,"grade":1,"limitApp":"default","maxQueueingTimeMs":500,"resource":"test","strategy":0,"warmUpPeriodSec":10}] -------------------------------------------------------------------------------- /Proxy/src/main/java/proxy/jdk/ProxyMain.java: -------------------------------------------------------------------------------- 1 | package proxy.jdk; 2 | 3 | /** 4 | * 动态代理 主方法 5 | * 6 | * @author itning 7 | */ 8 | public class ProxyMain { 9 | public static void main(String[] args) { 10 | OriginalObject o = ProxyObject.getProxyObject(); 11 | System.out.println(o.getAge()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /EasyRule/src/test/java/top/itning/easyrule/EasyRuleApplicationTests.java: -------------------------------------------------------------------------------- 1 | package top.itning.easyrule; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class EasyRuleApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Sentinel/src/test/java/top/itning/sentinel/SentinelApplicationTests.java: -------------------------------------------------------------------------------- 1 | package top.itning.sentinel; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SentinelApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/策略模式/book/MemberStrategy.java: -------------------------------------------------------------------------------- 1 | package 策略模式.book; 2 | 3 | /** 4 | * @author itning 5 | * @since 2021/12/22 15:08 6 | */ 7 | public interface MemberStrategy { 8 | /** 9 | * 计算图书的价格 10 | * 11 | * @param booksPrice 图书的原价 12 | * @return 计算出打折后的价格 13 | */ 14 | double calcPrice(double booksPrice); 15 | } 16 | -------------------------------------------------------------------------------- /Scala/src/main/java/top/itning/basis/ObjectTest.scala: -------------------------------------------------------------------------------- 1 | package top.itning.basis 2 | 3 | import top.itning.basis.entity.{P, User} 4 | 5 | class ObjectTest { 6 | 7 | } 8 | 9 | object ObjectTest { 10 | def main(args: Array[String]): Unit = { 11 | val user = new User 12 | println(user) 13 | val p = new P("") 14 | println(p) 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /NettyWithSpringBoot/src/test/java/top/itning/netty/NettyWithSpringBootApplicationTests.java: -------------------------------------------------------------------------------- 1 | package top.itning.netty; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class NettyWithSpringBootApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Proxy/src/main/java/proxy/jdk/OriginalObjectImpl.java: -------------------------------------------------------------------------------- 1 | package proxy.jdk; 2 | 3 | /** 4 | * 原来对象 5 | * 6 | * @author itning 7 | */ 8 | public class OriginalObjectImpl implements OriginalObject { 9 | /** 10 | * 普通业务方法 11 | * 12 | * @return 返回年龄信息 13 | */ 14 | @Override 15 | public int getAge() { 16 | return 15; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Proxy/src/main/java/proxy/cglib/OriginalObjectImpl.java: -------------------------------------------------------------------------------- 1 | package proxy.cglib; 2 | 3 | /** 4 | * 原来对象 5 | * 6 | * @author itning 7 | */ 8 | public class OriginalObjectImpl implements OriginalObject { 9 | /** 10 | * 普通业务方法 11 | * 12 | * @return 返回年龄信息 13 | */ 14 | @Override 15 | public int getAge() { 16 | return 15; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /NettyWithSpringBoot/src/main/java/top/itning/netty/service/UserInfoService.java: -------------------------------------------------------------------------------- 1 | package top.itning.netty.service; 2 | 3 | import top.itning.netty.model.User; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author itning 9 | * @since 2021/12/9 13:11 10 | */ 11 | public interface UserInfoService { 12 | List getAll(); 13 | 14 | User findById(Long id); 15 | } 16 | -------------------------------------------------------------------------------- /Algorithm/src/main/java/top/itning/integrity/Solution.java: -------------------------------------------------------------------------------- 1 | package top.itning.integrity; 2 | 3 | /** 4 | * 给定一个double类型的浮点数base和int类型的整数exponent。 5 | * 求base的exponent次方。 6 | * 7 | * @author itning 8 | * @date 2019/7/7 21:42 9 | */ 10 | public class Solution { 11 | public double Power(double base, int exponent) { 12 | return Math.pow(base, exponent); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /EasyRule/src/main/java/top/itning/easyrule/rule1/UserDTO.java: -------------------------------------------------------------------------------- 1 | package top.itning.easyrule.rule1; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @author itning 7 | * @date 2020/11/7 10:15 8 | */ 9 | @Data 10 | public class UserDTO { 11 | 12 | private String name; 13 | 14 | private Integer id; 15 | 16 | private String address; 17 | 18 | private String tel; 19 | } 20 | -------------------------------------------------------------------------------- /Guava/src/main/java/top/itning/bigdata/guava/collections/CollectionhelperSexplainedTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.bigdata.guava.collections; 2 | 3 | import org.junit.Test; 4 | 5 | /** 6 | * 集合扩展工具类 7 | * 让实现和扩展集合类变得更容易,比如创建Collection的装饰器,或实现迭代器 8 | * 9 | * @author itning 10 | */ 11 | public class CollectionhelperSexplainedTest { 12 | @Test 13 | public void test() { 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Hadoop/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Set root logger level to DEBUG and its only appender to A1. 2 | log4j.rootLogger=INFO, A1 3 | 4 | # A1 is set to be a ConsoleAppender. 5 | log4j.appender.A1=org.apache.log4j.ConsoleAppender 6 | 7 | # A1 uses PatternLayout. 8 | log4j.appender.A1.layout=org.apache.log4j.PatternLayout 9 | log4j.appender.A1.layout.ConversionPattern= [%d{MM-dd HH:mm:ss}] [%p] [%c:%L] %m%n -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/桥接模式/coffee/Coffee.java: -------------------------------------------------------------------------------- 1 | package 桥接模式.coffee; 2 | 3 | /** 4 | * @author itning 5 | * @since 2021/12/21 18:04 6 | */ 7 | public abstract class Coffee { 8 | protected ICoffeeAdditives additives; 9 | 10 | public Coffee(ICoffeeAdditives additives) { 11 | this.additives = additives; 12 | } 13 | 14 | public abstract void orderCoffee(int count); 15 | } 16 | -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/策略模式/book/PrimaryMemberStrategy.java: -------------------------------------------------------------------------------- 1 | package 策略模式.book; 2 | 3 | /** 4 | * @author itning 5 | * @since 2021/12/22 15:08 6 | */ 7 | public class PrimaryMemberStrategy implements MemberStrategy { 8 | 9 | @Override 10 | public double calcPrice(double booksPrice) { 11 | 12 | System.out.println("对于初级会员的没有折扣"); 13 | return booksPrice; 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/策略模式/book/AdvancedMemberStrategy.java: -------------------------------------------------------------------------------- 1 | package 策略模式.book; 2 | 3 | /** 4 | * @author itning 5 | * @since 2021/12/22 15:09 6 | */ 7 | public class AdvancedMemberStrategy implements MemberStrategy { 8 | 9 | @Override 10 | public double calcPrice(double booksPrice) { 11 | 12 | System.out.println("对于高级会员的折扣为20%"); 13 | return booksPrice * 0.8; 14 | } 15 | } -------------------------------------------------------------------------------- /Elasticsearch/src/main/java/top/itning/elasticsearch/dao/UserRepository.java: -------------------------------------------------------------------------------- 1 | package top.itning.elasticsearch.dao; 2 | 3 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; 4 | import top.itning.elasticsearch.entity.User; 5 | 6 | /** 7 | * @author itning 8 | * @date 2019/6/5 14:03 9 | */ 10 | public interface UserRepository extends ElasticsearchRepository { 11 | } 12 | -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/策略模式/book/IntermediateMemberStrategy.java: -------------------------------------------------------------------------------- 1 | package 策略模式.book; 2 | 3 | /** 4 | * @author itning 5 | * @since 2021/12/22 15:09 6 | */ 7 | public class IntermediateMemberStrategy implements MemberStrategy { 8 | 9 | @Override 10 | public double calcPrice(double booksPrice) { 11 | 12 | System.out.println("对于中级会员的折扣为10%"); 13 | return booksPrice * 0.9; 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/装饰器模式/text/BoldDecorator.java: -------------------------------------------------------------------------------- 1 | package 装饰器模式.text; 2 | 3 | /** 4 | * @author itning 5 | * @since 2021/12/22 10:31 6 | */ 7 | public class BoldDecorator extends NodeDecorator{ 8 | protected BoldDecorator(TextNode target) { 9 | super(target); 10 | } 11 | 12 | @Override 13 | public String getText() { 14 | return "" + target.getText() + ""; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Proxy/src/main/java/proxy/cglib/ProxyMain.java: -------------------------------------------------------------------------------- 1 | package proxy.cglib; 2 | 3 | /** 4 | * 动态代理 主方法 5 | * 6 | * @author itning 7 | */ 8 | public class ProxyMain { 9 | public static void main(String[] args) { 10 | ProxyObject cglib = new ProxyObject(); 11 | OriginalObjectImpl originalObject = cglib.getInstance(new OriginalObjectImpl()); 12 | System.out.println(originalObject.getAge()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /EasyRule/src/main/java/top/itning/easyrule/EasyRuleApplication.java: -------------------------------------------------------------------------------- 1 | package top.itning.easyrule; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class EasyRuleApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(EasyRuleApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Reactor/src/main/java/top/itning/reactor/EchoReactorSingleServerBootStrap.java: -------------------------------------------------------------------------------- 1 | package top.itning.reactor; 2 | 3 | /** 4 | * @author itning 5 | * @since 2021/11/3 13:50 6 | */ 7 | public class EchoReactorSingleServerBootStrap { 8 | public static void main(String[] args) { 9 | Thread thread = new Thread(new EchoReactorSingleServer()); 10 | thread.setDaemon(false); 11 | thread.start(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Scala/src/main/java/top/itning/basis/MapTest.scala: -------------------------------------------------------------------------------- 1 | package top.itning.basis 2 | 3 | import scala.collection.mutable 4 | 5 | object MapTest { 6 | def main(args: Array[String]): Unit = { 7 | val map = Map("a" -> 1, "b" -> 2) 8 | println(map) 9 | val m = mutable.Map[String, Int]("1" -> 1) 10 | m("2") = 2 11 | m += ("3" -> 3) 12 | println(m) 13 | println(("3" -> 3).getClass.getSimpleName) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Disruptor/.gitignore: -------------------------------------------------------------------------------- 1 | .mvn/ 2 | /target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | .sts4-cache 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.iml 18 | *.ipr 19 | 20 | ### NetBeans ### 21 | /nbproject/private/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ 26 | /build/ 27 | 28 | ### VS Code ### 29 | .vscode/ 30 | -------------------------------------------------------------------------------- /Disruptor/src/main/java/top/itning/disruptor/DisruptorApplication.java: -------------------------------------------------------------------------------- 1 | package top.itning.disruptor; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class DisruptorApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(DisruptorApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/装饰器模式/text/SpanNode.java: -------------------------------------------------------------------------------- 1 | package 装饰器模式.text; 2 | 3 | /** 4 | * @author itning 5 | * @since 2021/12/22 10:30 6 | */ 7 | public class SpanNode implements TextNode { 8 | private String text; 9 | 10 | @Override 11 | public void setText(String text) { 12 | this.text = text; 13 | } 14 | 15 | @Override 16 | public String getText() { 17 | return "" + text + ""; 18 | } 19 | } -------------------------------------------------------------------------------- /RabbitMQ/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | 27 | ### VS Code ### 28 | .vscode/ 29 | 30 | .mvn/ 31 | -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/策略模式/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 这个模式涉及到三个角色: 3 | *

4 | *   ●  环境(Context)角色:持有一个Strategy的引用。 5 | *

6 | *   ●  抽象策略(Strategy)角色:这是一个抽象角色,通常由一个接口或抽象类实现。此角色给出所有的具体策略类所需的接口。 7 | *

8 | *   ●  具体策略(ConcreteStrategy)角色:包装了相关的算法或行为。 9 | * 策略模式属于对象的行为模式。其用意是针对一组算法,将每一个算法封装到具有共同接口的独立的类中,从而使得它们可以相互替换。 10 | * 策略模式使得算法可以在不影响到客户端的情况下发生变化。 11 | * 12 | * @author itning 13 | * @since 2021/12/22 15:07 14 | */ 15 | package 策略模式; -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/装饰器模式/text/Test.java: -------------------------------------------------------------------------------- 1 | package 装饰器模式.text; 2 | 3 | /** 4 | * 对某个节点进行装饰 增加功能 5 | * 6 | * @author itning 7 | * @since 2021/12/22 10:31 8 | */ 9 | public class Test { 10 | public static void main(String[] args) { 11 | TextNode n1 = new SpanNode(); 12 | n1.setText("aa"); 13 | BoldDecorator boldDecorator = new BoldDecorator(n1); 14 | System.out.println(boldDecorator.getText()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/装饰器模式/text/NodeDecorator.java: -------------------------------------------------------------------------------- 1 | package 装饰器模式.text; 2 | 3 | /** 4 | * @author itning 5 | * @since 2021/12/22 10:31 6 | */ 7 | public abstract class NodeDecorator implements TextNode { 8 | protected final TextNode target; 9 | 10 | protected NodeDecorator(TextNode target) { 11 | this.target = target; 12 | } 13 | 14 | @Override 15 | public void setText(String text) { 16 | this.target.setText(text); 17 | } 18 | } -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/适配器模式/task/Test.java: -------------------------------------------------------------------------------- 1 | package 适配器模式.task; 2 | 3 | import java.util.concurrent.Callable; 4 | 5 | /** 6 | * @author itning 7 | * @since 2021/12/22 10:17 8 | */ 9 | public class Test { 10 | public static void main(String[] args) { 11 | Callable callable = new Task(123450000L); 12 | // RunnableAdapter适配器做了适配 13 | Thread thread = new Thread(new RunnableAdapter(callable)); 14 | thread.start(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Guava/src/main/java/top/itning/bigdata/guava/reflection/ReflectionTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.bigdata.guava.reflection; 2 | 3 | import com.google.common.reflect.TypeToken; 4 | import org.junit.Test; 5 | 6 | /** 7 | * @author itning 8 | */ 9 | public class ReflectionTest { 10 | @Test 11 | public void test() { 12 | TypeToken stringTok = TypeToken.of(String.class); 13 | TypeToken intTok = TypeToken.of(Integer.class); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Disruptor/src/main/java/top/itning/disruptor/quickstart/OrderEventFactory.java: -------------------------------------------------------------------------------- 1 | package top.itning.disruptor.quickstart; 2 | 3 | import com.lmax.disruptor.EventFactory; 4 | 5 | /** 6 | * 工厂类 7 | * 8 | * @author itning 9 | * @date 2019/5/8 17:51 10 | */ 11 | public class OrderEventFactory implements EventFactory { 12 | @Override 13 | public OrderEvent newInstance() { 14 | //这个方法就是返回空的数据对象(event) 15 | return new OrderEvent(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /NettyWithSpringBoot/src/main/java/top/itning/netty/NettyWithSpringBootApplication.java: -------------------------------------------------------------------------------- 1 | package top.itning.netty; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class NettyWithSpringBootApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(NettyWithSpringBootApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /NettyWithSpringBoot/src/main/java/top/itning/netty/model/User.java: -------------------------------------------------------------------------------- 1 | package top.itning.netty.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.io.Serializable; 8 | 9 | /** 10 | * @author itning 11 | * @since 2021/12/9 11:28 12 | */ 13 | @Data 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | public class User implements Serializable { 17 | private Long id; 18 | private String name; 19 | } 20 | -------------------------------------------------------------------------------- /RabbitMQ/src/test/java/top/itning/rabbitmq/RabbitmqApplicationTests.java: -------------------------------------------------------------------------------- 1 | package top.itning.rabbitmq; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class RabbitmqApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Disruptor/src/test/java/top/itning/disruptor/DisruptorApplicationTests.java: -------------------------------------------------------------------------------- 1 | package top.itning.disruptor; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class DisruptorApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/concurrent/threadrandom/ThreadRandomTest.java: -------------------------------------------------------------------------------- 1 | package concurrent.threadrandom; 2 | 3 | import java.util.concurrent.ThreadLocalRandom; 4 | 5 | /** 6 | * @author itning 7 | */ 8 | public class ThreadRandomTest { 9 | public static void main(String[] args) { 10 | System.out.println(ThreadLocalRandom.current().nextInt()); 11 | // 返回指定原点(含)和指定边界(排除)之间的伪随机 int值。 12 | System.out.println(ThreadLocalRandom.current().nextInt(0,100)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/桥接模式/coffee/LargeCoffee.java: -------------------------------------------------------------------------------- 1 | package 桥接模式.coffee; 2 | 3 | /** 4 | * @author itning 5 | * @since 2021/12/21 18:07 6 | */ 7 | public class LargeCoffee extends RefinedCoffee { 8 | 9 | public LargeCoffee(ICoffeeAdditives iCoffeeAdditives) { 10 | super(iCoffeeAdditives); 11 | } 12 | 13 | @Override 14 | public void orderCoffee(int count) { 15 | additives.addSomething(); 16 | System.out.println("大杯咖啡" + count + "杯"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Activemq/src/main/java/activemq/ProducerTest.java: -------------------------------------------------------------------------------- 1 | package activemq; 2 | 3 | import javax.jms.JMSException; 4 | 5 | public class ProducerTest { 6 | 7 | /** 8 | * @param args 9 | * @throws Exception 10 | * @throws JMSException 11 | */ 12 | public static void main(String[] args) throws JMSException, Exception { 13 | ProducerTool producer = new ProducerTool(); 14 | producer.produceMessage("Hello, world!"); 15 | producer.close(); 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/策略模式/book/Test.java: -------------------------------------------------------------------------------- 1 | package 策略模式.book; 2 | 3 | /** 4 | * @author itning 5 | * @since 2021/12/22 15:09 6 | */ 7 | public class Test { 8 | public static void main(String[] args) { 9 | //选择并创建需要使用的策略对象 10 | MemberStrategy strategy = new AdvancedMemberStrategy(); 11 | //创建环境 12 | Price price = new Price(strategy); 13 | //计算价格 14 | double quote = price.quote(300); 15 | System.out.println("图书的最终价格为:" + quote); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Elasticsearch/src/main/java/top/itning/elasticsearch/ElasticsearchApplication.java: -------------------------------------------------------------------------------- 1 | package top.itning.elasticsearch; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author itning 8 | */ 9 | @SpringBootApplication 10 | public class ElasticsearchApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(ElasticsearchApplication.class, args); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Sentinel/src/main/java/top/itning/sentinel/dto/UserDTO.java: -------------------------------------------------------------------------------- 1 | package top.itning.sentinel.dto; 2 | 3 | /** 4 | * @author itning 5 | * @date 2020/8/22 15:22 6 | */ 7 | public class UserDTO { 8 | private String name; 9 | 10 | public UserDTO() { 11 | } 12 | 13 | public UserDTO(String name) { 14 | this.name = name; 15 | } 16 | 17 | public String getName() { 18 | return name; 19 | } 20 | 21 | public void setName(String name) { 22 | this.name = name; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Disruptor/src/main/java/top/itning/disruptor/high/Handler2.java: -------------------------------------------------------------------------------- 1 | package top.itning.disruptor.high; 2 | 3 | 4 | import com.lmax.disruptor.EventHandler; 5 | 6 | /** 7 | * @author itning 8 | * @date 2019/5/10 8:50 9 | */ 10 | public class Handler2 implements EventHandler { 11 | 12 | @Override 13 | public void onEvent(Trade event, long sequence, boolean endOfBatch) throws Exception { 14 | System.out.println("消费者2: " + event + " sequence: " + sequence + " endOfBatch: " + endOfBatch); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Disruptor/src/main/java/top/itning/disruptor/high/Handler3.java: -------------------------------------------------------------------------------- 1 | package top.itning.disruptor.high; 2 | 3 | 4 | import com.lmax.disruptor.EventHandler; 5 | 6 | /** 7 | * @author itning 8 | * @date 2019/5/10 8:50 9 | */ 10 | public class Handler3 implements EventHandler { 11 | 12 | @Override 13 | public void onEvent(Trade event, long sequence, boolean endOfBatch) throws Exception { 14 | System.out.println("消费者3: " + event + " sequence: " + sequence + " endOfBatch: " + endOfBatch); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Disruptor/src/main/java/top/itning/disruptor/high/Handler4.java: -------------------------------------------------------------------------------- 1 | package top.itning.disruptor.high; 2 | 3 | 4 | import com.lmax.disruptor.EventHandler; 5 | 6 | /** 7 | * @author itning 8 | * @date 2019/5/10 8:50 9 | */ 10 | public class Handler4 implements EventHandler { 11 | 12 | @Override 13 | public void onEvent(Trade event, long sequence, boolean endOfBatch) throws Exception { 14 | System.out.println("消费者4: " + event + " sequence: " + sequence + " endOfBatch: " + endOfBatch); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Disruptor/src/main/java/top/itning/disruptor/high/Handler5.java: -------------------------------------------------------------------------------- 1 | package top.itning.disruptor.high; 2 | 3 | 4 | import com.lmax.disruptor.EventHandler; 5 | 6 | /** 7 | * @author itning 8 | * @date 2019/5/10 8:50 9 | */ 10 | public class Handler5 implements EventHandler { 11 | 12 | @Override 13 | public void onEvent(Trade event, long sequence, boolean endOfBatch) throws Exception { 14 | System.out.println("消费者5: " + event + " sequence: " + sequence + " endOfBatch: " + endOfBatch); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Algorithm/src/main/java/top/itning/recursive/Solution3.java: -------------------------------------------------------------------------------- 1 | package top.itning.recursive; 2 | 3 | /** 4 | * . 5 | * 一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。 6 | * 求该青蛙跳上一个n级的台阶总共有多少种跳法。 7 | * 8 | * @author itning 9 | * @date 2019/7/7 20:57 10 | */ 11 | public class Solution3 { 12 | public int JumpFloorII(int target) { 13 | if (target == 1) { 14 | return 1; 15 | } 16 | if (target == 2) { 17 | return 2; 18 | } 19 | return 2 * JumpFloorII(target - 1); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Hadoop/src/test/java/Test.java: -------------------------------------------------------------------------------- 1 | import org.apache.commons.lang.math.NumberUtils; 2 | 3 | public class Test { 4 | @org.junit.Test 5 | public void test() { 6 | String s = "1363157985066 \t13726230503\t00-FD-07-A4-72-B8:CMCC\t120.196.100.82\ti02.c.aliimg.com\t\t24\t27\t2481\t24681\t200"; 7 | String[] strings = s.split("\t"); 8 | System.out.println(strings[1]); 9 | System.out.println(NumberUtils.isDigits(strings[1])); 10 | System.out.println(Long.parseLong(strings[1])); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Sentinel/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### STS ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | 15 | ### IntelliJ IDEA ### 16 | .idea 17 | *.iws 18 | *.iml 19 | *.ipr 20 | 21 | ### NetBeans ### 22 | /nbproject/private/ 23 | /nbbuild/ 24 | /dist/ 25 | /nbdist/ 26 | /.nb-gradle/ 27 | build/ 28 | !**/src/main/**/build/ 29 | !**/src/test/**/build/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | -------------------------------------------------------------------------------- /Disruptor/src/main/java/top/itning/disruptor/multi/Order.java: -------------------------------------------------------------------------------- 1 | package top.itning.disruptor.multi; 2 | 3 | /** 4 | * @author itning 5 | * @date 2019/5/10 9:38 6 | */ 7 | public class Order { 8 | private String id; 9 | 10 | public String getId() { 11 | return id; 12 | } 13 | 14 | public void setId(String id) { 15 | this.id = id; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return "Order{" + 21 | "id='" + id + '\'' + 22 | '}'; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Disruptor/src/main/java/top/itning/disruptor/quickstart/OrderEventHandler.java: -------------------------------------------------------------------------------- 1 | package top.itning.disruptor.quickstart; 2 | 3 | import com.lmax.disruptor.EventHandler; 4 | 5 | /** 6 | * @author itning 7 | * @date 2019/5/8 17:52 8 | */ 9 | public class OrderEventHandler implements EventHandler { 10 | @Override 11 | public void onEvent(OrderEvent event, long sequence, boolean endOfBatch) throws Exception { 12 | System.out.println("消费者: " + event + " sequence: " + sequence + " endOfBatch: " + endOfBatch); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Blockingqueue/src/main/java/blockingqueue/ConcurrentLinkedQueueTest.java: -------------------------------------------------------------------------------- 1 | package blockingqueue; 2 | 3 | import java.util.concurrent.ConcurrentLinkedQueue; 4 | 5 | /** 6 | * 并发非阻塞队列 7 | * 8 | * @author itning 9 | */ 10 | public class ConcurrentLinkedQueueTest { 11 | public static void main(String[] args) { 12 | ConcurrentLinkedQueue concurrentLinkedQueue = new ConcurrentLinkedQueue<>(); 13 | concurrentLinkedQueue.add("1"); 14 | String peek = concurrentLinkedQueue.peek(); 15 | System.out.println(peek); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/桥接模式/coffee/Test.java: -------------------------------------------------------------------------------- 1 | package 桥接模式.coffee; 2 | 3 | /** 4 | * 咖啡分为大中小,还分为加糖和加奶,杯型和添加内容独立变化所以可以使用桥接模式 5 | * 6 | * @author itning 7 | * @since 2021/12/21 18:06 8 | */ 9 | public class Test { 10 | public static void main(String[] args) { 11 | //点两杯加奶的大杯咖啡 12 | RefinedCoffee largeWithMilk = new LargeCoffee(new Milk()); 13 | largeWithMilk.orderCoffee(2); 14 | largeWithMilk.checkQuality(); 15 | 16 | RefinedCoffee s = new LargeCoffee(new Sugar()); 17 | s.orderCoffee(1); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Sentinel/src/main/java/top/itning/sentinel/config/annotation/SentinelResourcePro.java: -------------------------------------------------------------------------------- 1 | package top.itning.sentinel.config.annotation; 2 | 3 | import com.alibaba.csp.sentinel.EntryType; 4 | 5 | import java.lang.annotation.*; 6 | 7 | /** 8 | * @author itning 9 | * @date 2020/8/22 16:56 10 | */ 11 | @Documented 12 | @Target({ElementType.METHOD, ElementType.TYPE}) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Inherited 15 | public @interface SentinelResourcePro { 16 | String value() default ""; 17 | 18 | EntryType entryType() default EntryType.OUT; 19 | } 20 | -------------------------------------------------------------------------------- /Guava/src/main/java/top/itning/bigdata/guava/throwables/ThrowablesTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.bigdata.guava.throwables; 2 | 3 | import com.google.common.base.Throwables; 4 | import org.junit.Test; 5 | 6 | /** 7 | * @author itning 8 | * @see Throwables 9 | */ 10 | public class ThrowablesTest { 11 | @Test 12 | public void test() { 13 | //有时候,你会想把捕获到的异常再次抛出。 14 | //这种情况通常发生在Error或RuntimeException被捕获的时候, 15 | //你没想捕获它们,但是声明捕获Throwable和Exception的时候, 16 | //也包括了了Error或RuntimeException。Guava提供了若干方法,来判断异常类型并且重新传播异常。 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /NettyWithSpringBoot/.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 | -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/桥接模式/coffee/RefinedCoffee.java: -------------------------------------------------------------------------------- 1 | package 桥接模式.coffee; 2 | 3 | import java.util.Random; 4 | 5 | /** 6 | * @author itning 7 | * @since 2021/12/21 18:05 8 | */ 9 | public abstract class RefinedCoffee extends Coffee { 10 | 11 | public RefinedCoffee(ICoffeeAdditives additives) { 12 | super(additives); 13 | } 14 | 15 | public void checkQuality() { 16 | Random ran = new Random(); 17 | System.out.println(String.format("%s 添加%s", additives.getClass().getSimpleName(), ran.nextBoolean() ? "太多" : "正常")); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Algorithm/src/main/java/top/itning/bit/Solution.java: -------------------------------------------------------------------------------- 1 | package top.itning.bit; 2 | 3 | /** 4 | * 输入一个整数,输出该数二进制表示中1的个数。其中负数用补码表示。 5 | * 6 | * @author itning 7 | * @date 2019/7/7 21:24 8 | */ 9 | public class Solution { 10 | public static void main(String[] args) { 11 | int i = new Solution().NumberOf1(-12); 12 | System.out.println(i); 13 | } 14 | 15 | public int NumberOf1(int n) { 16 | int count = 0; 17 | while (n != 0) { 18 | n &= (n - 1); 19 | ++count; 20 | }//while 21 | return count; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /EasyRule/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | .mvn/ 7 | mvnw.cmd 8 | mvnw 9 | 10 | ### STS ### 11 | .apt_generated 12 | .classpath 13 | .factorypath 14 | .project 15 | .settings 16 | .springBeans 17 | .sts4-cache 18 | 19 | ### IntelliJ IDEA ### 20 | .idea 21 | *.iws 22 | *.iml 23 | *.ipr 24 | 25 | ### NetBeans ### 26 | /nbproject/private/ 27 | /nbbuild/ 28 | /dist/ 29 | /nbdist/ 30 | /.nb-gradle/ 31 | build/ 32 | !**/src/main/**/build/ 33 | !**/src/test/**/build/ 34 | 35 | ### VS Code ### 36 | .vscode/ 37 | -------------------------------------------------------------------------------- /Spark/src/main/java/top/itning/TestWordCount.scala: -------------------------------------------------------------------------------- 1 | package top.itning 2 | 3 | import org.apache.spark.{SparkConf, SparkContext} 4 | 5 | /** 6 | * -Dspark.master=local[*] -Dhadoop.home.dir=G:\\winutils\\hadoop-2.8.3 7 | */ 8 | object TestWordCount { 9 | def main(args: Array[String]): Unit = { 10 | val sparkConf = new SparkConf().setAppName("wordCount") 11 | val sc = new SparkContext(sparkConf) 12 | val array = sc.parallelize(Array(1, 4, 6, 3, 2, 7)).map(_ * 10).collect() 13 | println("start") 14 | println(array.toBuffer) 15 | println("end") 16 | sc.stop() 17 | } 18 | } -------------------------------------------------------------------------------- /Algorithm/src/main/java/top/itning/recursive/Solution4.java: -------------------------------------------------------------------------------- 1 | package top.itning.recursive; 2 | 3 | /** 4 | * 我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。 5 | * 请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? 6 | * 7 | * @author itning 8 | * @date 2019/7/7 21:01 9 | */ 10 | public class Solution4 { 11 | public int RectCover(int target) { 12 | if (target == 0) { 13 | return 0; 14 | } else if (target == 1) { 15 | return 1; 16 | } else if (target == 2) { 17 | return 2; 18 | } 19 | return RectCover(target - 1) + RectCover(target - 2); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Sentinel/src/main/java/top/itning/sentinel/SentinelApplication.java: -------------------------------------------------------------------------------- 1 | package top.itning.sentinel; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SentinelApplication { 8 | 9 | public static void main(String[] args) { 10 | System.setProperty("csp.sentinel.dashboard.server", "localhost:8080"); 11 | System.setProperty("csp.sentinel.log.dir", "sentinel_log"); 12 | 13 | SpringApplication.run(SentinelApplication.class, args); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Algorithm/src/main/java/top/itning/recursive/Solution2.java: -------------------------------------------------------------------------------- 1 | package top.itning.recursive; 2 | 3 | /** 4 | * 一只青蛙一次可以跳上1级台阶,也可以跳上2级。 5 | * 求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果)。 6 | * 7 | * @author itning 8 | * @date 2019/7/7 20:40 9 | */ 10 | public class Solution2 { 11 | public static void main(String[] args) { 12 | 13 | } 14 | 15 | public int JumpFloor(int target) { 16 | if (target == 1) { 17 | return 1; 18 | } 19 | if (target == 2) { 20 | return 2; 21 | } 22 | return JumpFloor(target - 1) + JumpFloor(target - 2); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/适配器模式/task/Task.java: -------------------------------------------------------------------------------- 1 | package 适配器模式.task; 2 | 3 | import java.util.concurrent.Callable; 4 | 5 | /** 6 | * @author itning 7 | * @since 2021/12/22 10:16 8 | */ 9 | public class Task implements Callable { 10 | private long num; 11 | 12 | public Task(long num) { 13 | this.num = num; 14 | } 15 | 16 | @Override 17 | public Long call() throws Exception { 18 | long r = 0; 19 | for (long n = 1; n <= this.num; n++) { 20 | r = r + n; 21 | } 22 | System.out.println("Result: " + r); 23 | return r; 24 | } 25 | } -------------------------------------------------------------------------------- /Kafka/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 7 | utf8 8 | 9 | 10 | 11 |       12 |   13 | 14 | -------------------------------------------------------------------------------- /Leetcode/src/test/java/top/itning/test/RegularExpressionMatchingTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.test; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | /** 6 | * 10. 正则表达式匹配 7 | * 给你一个字符串 s 和一个字符规律 p,请你来实现一个支持 '.' 和 '*' 的正则表达式匹配。 8 | *

9 | * '.' 匹配任意单个字符 10 | * '*' 匹配零个或多个前面的那一个元素 11 | * 所谓匹配,是要涵盖 整个 字符串 s的,而不是部分字符串。 12 | * 13 | * @author itning 14 | * @since 2021/12/6 20:21 15 | */ 16 | public class RegularExpressionMatchingTest { 17 | @Test 18 | void regularExpressionMatchingTest() { 19 | 20 | } 21 | 22 | public boolean isMatch(String s, String p) { 23 | return false; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Reactor/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | top.itning 8 | reactor 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 8 13 | 8 14 | 15 | 16 | -------------------------------------------------------------------------------- /Disruptor/src/main/java/top/itning/disruptor/quickstart/OrderEvent.java: -------------------------------------------------------------------------------- 1 | package top.itning.disruptor.quickstart; 2 | 3 | /** 4 | * 订单 5 | * 6 | * @author itning 7 | * @date 2019/5/8 17:50 8 | */ 9 | public class OrderEvent { 10 | /** 11 | * 价格 12 | */ 13 | private long price; 14 | 15 | public long getPrice() { 16 | return price; 17 | } 18 | 19 | public void setPrice(long price) { 20 | this.price = price; 21 | } 22 | 23 | @Override 24 | public String toString() { 25 | return "OrderEvent{" + 26 | "price=" + price + 27 | '}'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /DesignPatterns/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | top.itning 8 | designpatterns 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 8 13 | 8 14 | 15 | 16 | -------------------------------------------------------------------------------- /WrittenExamination/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | top.itning 8 | written-examination 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 8 13 | 8 14 | 15 | 16 | -------------------------------------------------------------------------------- /Guava/src/main/java/top/itning/bigdata/guava/ordering/OrderingTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.bigdata.guava.ordering; 2 | 3 | import com.google.common.collect.Ordering; 4 | import org.junit.Test; 5 | 6 | /** 7 | * 排序 8 | * 9 | * @author itning 10 | */ 11 | public class OrderingTest { 12 | @Test 13 | public void test() { 14 | //创建排序器:常见的排序器可以由下面的静态方法创建 15 | //对可排序类型做自然排序,如数字按大小,日期按先后排序 16 | Ordering natural = Ordering.natural(); 17 | //按对象的字符串形式做字典排序[lexicographical ordering] 18 | Ordering objectOrdering = Ordering.usingToString(); 19 | //把给定的Comparator转化为排序器 20 | //Ordering.from(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/策略模式/book/Price.java: -------------------------------------------------------------------------------- 1 | package 策略模式.book; 2 | 3 | /** 4 | * @author itning 5 | * @since 2021/12/22 15:09 6 | */ 7 | public class Price { 8 | //持有一个具体的策略对象 9 | private final MemberStrategy strategy; 10 | 11 | /** 12 | * 构造函数,传入一个具体的策略对象 13 | * 14 | * @param strategy 具体的策略对象 15 | */ 16 | public Price(MemberStrategy strategy) { 17 | this.strategy = strategy; 18 | } 19 | 20 | /** 21 | * 计算图书的价格 22 | * 23 | * @param booksPrice 图书的原价 24 | * @return 计算出打折后的价格 25 | */ 26 | public double quote(double booksPrice) { 27 | return this.strategy.calcPrice(booksPrice); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /DesignPatterns/src/main/java/适配器模式/task/RunnableAdapter.java: -------------------------------------------------------------------------------- 1 | package 适配器模式.task; 2 | 3 | import java.util.concurrent.Callable; 4 | 5 | /** 6 | * @author itning 7 | * @since 2021/12/22 10:17 8 | */ 9 | public class RunnableAdapter implements Runnable { 10 | // 引用待转换接口: 11 | private Callable callable; 12 | 13 | public RunnableAdapter(Callable callable) { 14 | this.callable = callable; 15 | } 16 | 17 | // 实现指定接口: 18 | @Override 19 | public void run() { 20 | // 将指定接口调用委托给转换接口调用: 21 | try { 22 | callable.call(); 23 | } catch (Exception e) { 24 | throw new RuntimeException(e); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Netty/src/main/java/top/itning/netty/chat/codec/ChatEncoder.java: -------------------------------------------------------------------------------- 1 | package top.itning.netty.chat.codec; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.handler.codec.MessageToByteEncoder; 6 | import org.apache.commons.lang3.SerializationUtils; 7 | import top.itning.netty.chat.entity.ChatMessage; 8 | 9 | /** 10 | * 编码器 11 | * 12 | * @author itning 13 | */ 14 | public class ChatEncoder extends MessageToByteEncoder { 15 | @Override 16 | protected void encode(ChannelHandlerContext ctx, ChatMessage msg, ByteBuf out) throws Exception { 17 | out.writeBytes(SerializationUtils.serialize(msg)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Sentinel/src/main/java/top/itning/sentinel/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package top.itning.sentinel.service.impl; 2 | 3 | import org.springframework.stereotype.Service; 4 | import top.itning.sentinel.config.annotation.SentinelResourcePro; 5 | import top.itning.sentinel.dto.UserDTO; 6 | import top.itning.sentinel.service.UserService; 7 | 8 | import java.util.UUID; 9 | 10 | /** 11 | * @author itning 12 | * @date 2020/8/22 15:30 13 | */ 14 | @Service 15 | public class UserServiceImpl implements UserService { 16 | @SentinelResourcePro(value = "test") 17 | @Override 18 | public UserDTO getRandomUser() { 19 | return new UserDTO(UUID.randomUUID().toString()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Leetcode/src/test/java/top/itning/test/ReverseIntegerTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.test; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | /** 6 | * @author itning 7 | * @since 2021/12/6 14:13 8 | */ 9 | public class ReverseIntegerTest { 10 | @Test 11 | void reverseIntegerTest() { 12 | reverse(-123); 13 | } 14 | 15 | public int reverse(int x) { 16 | String s = new StringBuilder(String.valueOf(Math.abs(x))).reverse().toString(); 17 | if (x < 0) { 18 | s = "-" + s; 19 | } 20 | try { 21 | return Integer.parseInt(s); 22 | } catch (NumberFormatException e) { 23 | return 0; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Algorithm/src/main/java/top/itning/abstracts/Solution2.java: -------------------------------------------------------------------------------- 1 | package top.itning.abstracts; 2 | 3 | import java.util.Stack; 4 | 5 | /** 6 | * 输入两个整数序列,第一个序列表示栈的压入顺序, 7 | * 请判断第二个序列是否可能为该栈的弹出顺序。 8 | * 假设压入栈的所有数字均不相等。 9 | * 例如序列1,2,3,4,5是某栈的压入顺序, 10 | * 序列4,5,3,2,1是该压栈序列对应的一个弹出序列, 11 | * 但4,3,5,1,2就不可能是该压栈序列的弹出序列。 12 | * (注意:这两个序列的长度是相等的) 13 | * 5 14 | * 4 15 | * 3 16 | * 2 17 | * 1 18 | * 19 | * @author itning 20 | * @date 2019/7/8 13:32 21 | */ 22 | public class Solution2 { 23 | public static void main(String[] args) { 24 | 25 | } 26 | 27 | public boolean IsPopOrder(int[] pushA, int[] popA) { 28 | Stack stack = new Stack<>(); 29 | return false; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Disruptor/src/main/java/top/itning/disruptor/multi/Producer.java: -------------------------------------------------------------------------------- 1 | package top.itning.disruptor.multi; 2 | 3 | import com.lmax.disruptor.RingBuffer; 4 | 5 | /** 6 | * @author itning 7 | * @date 2019/5/10 10:08 8 | */ 9 | public class Producer { 10 | private RingBuffer ringBuffer; 11 | 12 | public Producer(RingBuffer ringBuffer) { 13 | this.ringBuffer = ringBuffer; 14 | } 15 | 16 | public void sendData(String uuid) { 17 | long sequence = ringBuffer.next(); 18 | try { 19 | Order order = ringBuffer.get(sequence); 20 | order.setId(uuid); 21 | } finally { 22 | ringBuffer.publish(sequence); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Disruptor/src/main/java/top/itning/disruptor/high/Handler1.java: -------------------------------------------------------------------------------- 1 | package top.itning.disruptor.high; 2 | 3 | 4 | import com.lmax.disruptor.EventHandler; 5 | import com.lmax.disruptor.WorkHandler; 6 | 7 | /** 8 | * @author itning 9 | * @date 2019/5/10 8:50 10 | */ 11 | public class Handler1 implements EventHandler, WorkHandler { 12 | 13 | @Override 14 | public void onEvent(Trade event, long sequence, boolean endOfBatch) throws Exception { 15 | System.out.println("消费者1: " + event + " sequence: " + sequence + " endOfBatch: " + endOfBatch); 16 | } 17 | 18 | @Override 19 | public void onEvent(Trade event) throws Exception { 20 | System.out.println("消费者1: " + event); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/concurrent/atomic/AdderTest.java: -------------------------------------------------------------------------------- 1 | package concurrent.atomic; 2 | 3 | import java.util.concurrent.atomic.LongAdder; 4 | 5 | /** 6 | * 自增计数求和操作 7 | * 8 | * @author itning 9 | * @date 2020/5/22 19:32 10 | * @see java.util.concurrent.atomic.LongAdder 11 | * @see java.util.concurrent.atomic.DoubleAdder 12 | */ 13 | public class AdderTest { 14 | private static final LongAdder LONG_ADDER = new LongAdder(); 15 | 16 | public static void main(String[] args) { 17 | LONG_ADDER.increment(); 18 | LONG_ADDER.add(5L); 19 | // will call sum() 20 | System.out.println(LONG_ADDER.longValue()); 21 | System.out.println(LONG_ADDER.sum()); 22 | System.out.println(LONG_ADDER.sumThenReset()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Leetcode/src/test/java/top/itning/test/ZigzagConversionTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.test; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | /** 6 | * https://leetcode-cn.com/problems/zigzag-conversion/ 7 | * 6. Z 字形变换 8 | * 将一个给定字符串 s 根据给定的行数 numRows ,以从上往下、从左到右进行 Z 字形排列。 9 | *

10 | * 比如输入字符串为 "PAYPALISHIRING" 行数为 3 时,排列如下: 11 | *

12 | * P A H N 13 | * A P L S I I G 14 | * Y I R 15 | * 之后,你的输出需要从左往右逐行读取,产生出一个新的字符串,比如:"PAHNAPLSIIGYIR"。 16 | *

17 | * 请你实现这个将字符串进行指定行数变换的函数: 18 | * 19 | * @author itning 20 | * @since 2021/12/6 14:03 21 | */ 22 | public class ZigzagConversionTest { 23 | @Test 24 | void zigzagConversionTest() { 25 | 26 | } 27 | 28 | public String convert(String s, int numRows) { 29 | return ""; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Netty/src/main/java/top/itning/netty/chat/client/ChatClientHandler.java: -------------------------------------------------------------------------------- 1 | package top.itning.netty.chat.client; 2 | 3 | import io.netty.channel.ChannelHandlerContext; 4 | import io.netty.channel.SimpleChannelInboundHandler; 5 | import top.itning.netty.chat.entity.ChatMessage; 6 | 7 | /** 8 | * 聊天服务器客户端规则处理器 9 | * 10 | * @author itning 11 | */ 12 | public class ChatClientHandler extends SimpleChannelInboundHandler { 13 | @Override 14 | public void channelActive(ChannelHandlerContext ctx) throws Exception { 15 | System.out.println("ChatClientHandler::channelActive"); 16 | } 17 | 18 | @Override 19 | protected void channelRead0(ChannelHandlerContext ctx, ChatMessage msg) throws Exception { 20 | System.out.println(msg); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Blockingqueue/src/main/java/blockingqueue/PriorityBlockingQueueTest.java: -------------------------------------------------------------------------------- 1 | package blockingqueue; 2 | 3 | import java.util.concurrent.PriorityBlockingQueue; 4 | 5 | /** 6 | * PriorityBlockingQueue 是一个支持优先级的无界阻塞队列。默认情况下元素采用自然顺序进行排序, 7 | * 也可以通过自定义类实现 compareTo() 方法来指定元素排序规则, 8 | * 或者初始化时通过构造器参数 Comparator 来指定排序规则。 9 | * 10 | * @author itning 11 | */ 12 | public class PriorityBlockingQueueTest { 13 | public static void main(String[] args) { 14 | PriorityBlockingQueue priorityBlockingQueue = new PriorityBlockingQueue<>(); 15 | priorityBlockingQueue.add(3); 16 | priorityBlockingQueue.add(2); 17 | priorityBlockingQueue.add(6); 18 | for (Integer i : priorityBlockingQueue) { 19 | System.out.println(i); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /NettyWithSpringBoot/src/main/java/top/itning/netty/http/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package top.itning.netty.http; 2 | 3 | import io.netty.channel.ChannelHandler; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.channel.ChannelInboundHandlerAdapter; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * @author itning 11 | * @since 2021/12/21 10:16 12 | */ 13 | @Slf4j 14 | @Component 15 | @ChannelHandler.Sharable 16 | public class GlobalExceptionHandler extends ChannelInboundHandlerAdapter { 17 | 18 | @Override 19 | public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { 20 | log.error("捕获错误", cause); 21 | ctx.writeAndFlush(HttpResponseUtils.internalServerError()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/concurrent/atomic/AccumulatorTest.java: -------------------------------------------------------------------------------- 1 | package concurrent.atomic; 2 | 3 | import java.util.concurrent.atomic.LongAccumulator; 4 | 5 | /** 6 | * 可以实现求和,最大值,最小值等等 7 | * 8 | * @author itning 9 | * @date 2020/5/22 19:40 10 | * @see java.util.concurrent.atomic.LongAccumulator 11 | * @see java.util.concurrent.atomic.DoubleAccumulator 12 | */ 13 | public class AccumulatorTest { 14 | private static final LongAccumulator LONG_ACCUMULATOR = new LongAccumulator(Long::max, 5L); 15 | 16 | public static void main(String[] args) { 17 | LONG_ACCUMULATOR.accumulate(1L); 18 | LONG_ACCUMULATOR.accumulate(6L); 19 | LONG_ACCUMULATOR.accumulate(12L); 20 | LONG_ACCUMULATOR.accumulate(8L); 21 | System.out.println(LONG_ACCUMULATOR.get()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/voliatle/TestVolatile.java: -------------------------------------------------------------------------------- 1 | package voliatle; 2 | 3 | /** 4 | * volatile 测试 5 | * 6 | * @author itning 7 | */ 8 | @SuppressWarnings("all") 9 | public class TestVolatile { 10 | private static volatile int num = 0; 11 | 12 | public static void main(String[] args) throws InterruptedException { 13 | for (int i = 0; i < 100; i++) { 14 | new Thread(new Runnable() { 15 | @Override 16 | public void run() { 17 | for (int i = 0; i < 100; i++) { 18 | // ++操作并不是原子操作 19 | num++; 20 | } 21 | } 22 | }).start(); 23 | } 24 | Thread.sleep(2000); 25 | //并不是线程安全 26 | System.out.println(num); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Hadoop/src/main/java/log/LogReducer.java: -------------------------------------------------------------------------------- 1 | package log; 2 | 3 | import org.apache.hadoop.io.LongWritable; 4 | import org.apache.hadoop.io.Text; 5 | import org.apache.hadoop.mapreduce.Reducer; 6 | 7 | import java.io.IOException; 8 | 9 | public class LogReducer extends Reducer { 10 | private static final LongWritable LONG_WRITABLE = new LongWritable(); 11 | 12 | @Override 13 | protected void reduce(Text key, Iterable values, Context context) throws IOException, InterruptedException { 14 | LONG_WRITABLE.set(0); 15 | long sum = 0; 16 | for (LongWritable longWritable : values) { 17 | sum += longWritable.get(); 18 | } 19 | LONG_WRITABLE.set(sum); 20 | context.write(key, LONG_WRITABLE); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /NettyWithSpringBoot/src/main/java/top/itning/netty/service/impl/UserInfoServiceImpl.java: -------------------------------------------------------------------------------- 1 | package top.itning.netty.service.impl; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.stereotype.Service; 5 | import top.itning.netty.model.User; 6 | import top.itning.netty.service.UserInfoService; 7 | 8 | import java.util.Arrays; 9 | import java.util.List; 10 | 11 | /** 12 | * @author itning 13 | * @since 2021/12/9 13:11 14 | */ 15 | @Slf4j 16 | @Service 17 | public class UserInfoServiceImpl implements UserInfoService { 18 | @Override 19 | public List getAll() { 20 | log.info("获取所有用户信息"); 21 | return Arrays.asList(new User(1L, "张三"), new User(2L, "王五")); 22 | } 23 | 24 | @Override 25 | public User findById(Long id) { 26 | return null; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Hadoop/src/main/java/log/LogMapper.java: -------------------------------------------------------------------------------- 1 | package log; 2 | 3 | import org.apache.hadoop.io.LongWritable; 4 | import org.apache.hadoop.io.Text; 5 | import org.apache.hadoop.mapreduce.Mapper; 6 | 7 | import java.io.IOException; 8 | 9 | public class LogMapper extends Mapper { 10 | private static final Text TEXT = new Text(); 11 | private static final LongWritable LONG_WRITABLE = new LongWritable(); 12 | 13 | @Override 14 | protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { 15 | TEXT.clear(); 16 | LONG_WRITABLE.set(0); 17 | String ip = value.toString().split(" ")[0]; 18 | TEXT.set(ip); 19 | LONG_WRITABLE.set(1); 20 | context.write(TEXT, LONG_WRITABLE); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Algorithm/src/main/java/top/itning/string/Solution.java: -------------------------------------------------------------------------------- 1 | package top.itning.string; 2 | 3 | /** 4 | * 请实现一个函数,将一个字符串中的每个空格替换成“%20”。 5 | * 例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。 6 | * 7 | * @author itning 8 | * @date 2019/7/7 17:30 9 | */ 10 | public class Solution { 11 | public static void main(String[] args) { 12 | String s = new Solution().replaceSpace(new StringBuffer("We Are Happy")); 13 | System.out.println(s); 14 | } 15 | 16 | public String replaceSpace(StringBuffer str) { 17 | int index; 18 | do { 19 | index = str.indexOf(" "); 20 | if (index != -1) { 21 | str.deleteCharAt(index); 22 | str.insert(index, "%20"); 23 | } 24 | } while (index != -1); 25 | return str.toString(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Netty/src/main/java/top/itning/netty/chat/codec/ChatDecoder.java: -------------------------------------------------------------------------------- 1 | package top.itning.netty.chat.codec; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.handler.codec.ByteToMessageDecoder; 6 | import org.apache.commons.lang3.SerializationUtils; 7 | import top.itning.netty.chat.entity.ChatMessage; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * 解码器 13 | * 14 | * @author itning 15 | */ 16 | public class ChatDecoder extends ByteToMessageDecoder { 17 | @Override 18 | protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { 19 | byte[] bytes = new byte[in.readableBytes()]; 20 | in.readBytes(bytes); 21 | ChatMessage chatMessage = SerializationUtils.deserialize(bytes); 22 | out.add(chatMessage); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Sentinel/src/main/java/top/itning/sentinel/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package top.itning.sentinel.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | import top.itning.sentinel.dto.UserDTO; 7 | import top.itning.sentinel.service.UserService; 8 | 9 | /** 10 | * @author itning 11 | * @date 2020/8/22 15:23 12 | */ 13 | @RestController 14 | public class UserController { 15 | private final UserService userService; 16 | 17 | @Autowired 18 | public UserController(UserService userService) { 19 | this.userService = userService; 20 | } 21 | 22 | @GetMapping("/test") 23 | public UserDTO test() { 24 | return userService.getRandomUser(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Scala/src/main/java/top/itning/basis/ArrayTest.scala: -------------------------------------------------------------------------------- 1 | package top.itning.basis 2 | 3 | import scala.collection.mutable.ArrayBuffer 4 | 5 | object ArrayTest { 6 | def main(args: Array[String]): Unit = { 7 | val array = new Array[Int](10) 8 | array(0) = 1 9 | array(2) = 3 10 | println(array.toBuffer) 11 | println() 12 | //泛型 [] 13 | //下标 () 14 | val a = Array[Int](1, 2, 3) 15 | println(a.toBuffer) 16 | //变长数组 17 | //mutable 可变 18 | val arrayBuffer = new ArrayBuffer[Int]() 19 | arrayBuffer += 1 20 | //追加元组 21 | arrayBuffer += (2, 3, 4) 22 | //追加Array 23 | arrayBuffer ++= a 24 | arrayBuffer.insert(0, 9, 8, 7) 25 | arrayBuffer remove 0 26 | println(s"arrayBuffer: $arrayBuffer") 27 | a.sortBy(x => x) 28 | a.sortWith(_ > _) 29 | a.sortWith((a, b) => a > b) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/concurrent/atomic/AtomicMarkableReferenceTest.java: -------------------------------------------------------------------------------- 1 | package concurrent.atomic; 2 | 3 | import java.util.concurrent.atomic.AtomicMarkableReference; 4 | 5 | /** 6 | *

AtomicMarkableReference可以理解为上面AtomicStampedReference的简化版, 7 | *

就是不关心修改过几次,仅仅关心是否修改过。 8 | *

因此变量mark是boolean类型,仅记录值是否有过修改。 9 | * 10 | * @author itning 11 | * @date 2020/5/22 19:27 12 | * @see AtomicStampedReferenceTest 13 | */ 14 | public class AtomicMarkableReferenceTest { 15 | private static final Integer A = 1; 16 | private static final AtomicMarkableReference ATOMIC_MARKABLE_REFERENCE = new AtomicMarkableReference<>(A, false); 17 | 18 | public static void main(String[] args) { 19 | ATOMIC_MARKABLE_REFERENCE.compareAndSet(A, 2, false, true); 20 | System.out.println(ATOMIC_MARKABLE_REFERENCE.getReference()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/concurrent/ThreadPoolWithRunable.java: -------------------------------------------------------------------------------- 1 | package concurrent; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | 6 | /** 7 | * 提交 Runnable ,任务完成后 Future 对象返回 null 8 | * 调用excute,提交任务, 匿名Runable重写run方法, run方法里是业务逻辑 9 | * 10 | * @author itning 11 | */ 12 | @SuppressWarnings("all") 13 | public class ThreadPoolWithRunable { 14 | public static void main(String[] args) { 15 | ExecutorService cachedThreadPool = Executors.newCachedThreadPool(); 16 | for (int i = 1; i < 5; i++) { 17 | cachedThreadPool.execute(new Runnable() { 18 | @Override 19 | public void run() { 20 | System.out.println(Thread.currentThread().getName()); 21 | } 22 | }); 23 | } 24 | cachedThreadPool.shutdown(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/concurrent/thread/FutureTaskTest.java: -------------------------------------------------------------------------------- 1 | package concurrent.thread; 2 | 3 | import java.util.concurrent.Callable; 4 | import java.util.concurrent.ExecutionException; 5 | import java.util.concurrent.FutureTask; 6 | 7 | /** 8 | * 使用FutureTask创建线程 9 | * 10 | * @author itning 11 | */ 12 | public class FutureTaskTest implements Callable { 13 | public static void main(String[] args) throws ExecutionException, InterruptedException { 14 | FutureTask futureTask = new FutureTask<>(new FutureTaskTest()); 15 | Thread thread = new Thread(futureTask, "线程1"); 16 | thread.start(); 17 | System.out.println(futureTask.get()); 18 | } 19 | 20 | @Override 21 | public String call() throws Exception { 22 | System.out.println(Thread.currentThread().getName()); 23 | return Thread.currentThread().getName() + "返回结果"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Disruptor/src/main/java/top/itning/disruptor/multi/Consumer.java: -------------------------------------------------------------------------------- 1 | package top.itning.disruptor.multi; 2 | 3 | import com.lmax.disruptor.WorkHandler; 4 | 5 | import java.util.Random; 6 | import java.util.concurrent.atomic.AtomicInteger; 7 | 8 | /** 9 | * @author itning 10 | * @date 2019/5/10 9:42 11 | */ 12 | public class Consumer implements WorkHandler { 13 | private String consumerId; 14 | private static AtomicInteger count = new AtomicInteger(0); 15 | private Random random = new Random(); 16 | 17 | public Consumer(String consumerId) { 18 | this.consumerId = consumerId; 19 | } 20 | 21 | @Override 22 | public void onEvent(Order event) throws Exception { 23 | Thread.sleep(random.nextInt(5)); 24 | System.out.println("consumerId: " + consumerId + event); 25 | } 26 | 27 | public int getCount() { 28 | return count.get(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Algorithm/src/main/java/top/itning/recursive/Solution.java: -------------------------------------------------------------------------------- 1 | package top.itning.recursive; 2 | 3 | /** 4 | * 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0)。 5 | * n<=39 6 | * 7 | * @author itning 8 | * @date 2019/7/7 20:14 9 | */ 10 | public class Solution { 11 | public static void main(String[] args) { 12 | int fibonacci = new Solution().Fibonacci(4); 13 | System.out.println(fibonacci); 14 | } 15 | 16 | public int Fibonacci(int n) { 17 | if (n == 0) { 18 | return 0; 19 | } 20 | if (n < 3) { 21 | return 1; 22 | } 23 | return f(n); 24 | } 25 | 26 | /** 27 | * F(n)=F(n-1)+F(n-2) 28 | * 29 | * @param n n 30 | * @return F(n) 31 | */ 32 | private int f(int n) { 33 | if (n == 1 || n == 2) { 34 | return 1; 35 | } 36 | return f(n - 1) + f(n - 2); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Elasticsearch/src/main/java/top/itning/elasticsearch/service/UserService.java: -------------------------------------------------------------------------------- 1 | package top.itning.elasticsearch.service; 2 | 3 | import org.springframework.data.domain.Page; 4 | import org.springframework.data.domain.Pageable; 5 | import top.itning.elasticsearch.entity.User; 6 | 7 | /** 8 | * @author itning 9 | * @date 2019/6/5 14:04 10 | */ 11 | public interface UserService { 12 | /** 13 | * 添加用户 14 | * 15 | * @param name 姓名 16 | * @param tel 电话 17 | * @param address 地址 18 | * @return 新增的用户 19 | */ 20 | User addUser(String name, int tel, String address); 21 | 22 | /** 23 | * 删除用户 24 | * 25 | * @param id 用户ID 26 | */ 27 | void delUser(String id); 28 | 29 | /** 30 | * 搜索 31 | * 32 | * @param search 关键字 33 | * @param pageable 分页 34 | * @return 搜索结果 35 | */ 36 | Page search(String search, Pageable pageable); 37 | } 38 | -------------------------------------------------------------------------------- /EasyRule/src/main/java/top/itning/easyrule/rule1/rule/AddTelRule.java: -------------------------------------------------------------------------------- 1 | package top.itning.easyrule.rule1.rule; 2 | 3 | import org.jeasy.rules.api.Facts; 4 | import org.jeasy.rules.core.BasicRule; 5 | import top.itning.easyrule.rule1.UserDTO; 6 | 7 | import java.util.UUID; 8 | 9 | /** 10 | * 添加电话规则 11 | * 12 | * @author itning 13 | * @date 2020/11/7 10:39 14 | */ 15 | public class AddTelRule extends BasicRule { 16 | 17 | public AddTelRule() { 18 | this.priority = 4; 19 | } 20 | 21 | @Override 22 | public boolean evaluate(Facts facts) { 23 | Object user = facts.get("user"); 24 | if (user instanceof UserDTO) { 25 | return ((UserDTO) user).getTel() == null; 26 | } 27 | return false; 28 | } 29 | 30 | @Override 31 | public void execute(Facts facts) throws Exception { 32 | UserDTO user = facts.get("user"); 33 | user.setTel(UUID.randomUUID().toString().replace("-", "")); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/concurrent/cyclicbarrier/CyclicBarrierTest.java: -------------------------------------------------------------------------------- 1 | package concurrent.cyclicbarrier; 2 | 3 | import java.util.concurrent.BrokenBarrierException; 4 | import java.util.concurrent.CyclicBarrier; 5 | import java.util.concurrent.TimeoutException; 6 | 7 | /** 8 | * 循环栅栏 9 | * CyclicBarrier 的字面意思是可循环使用(Cyclic)的屏障(Barrier) 10 | * 它要做的事情是,让一组线程到达一个屏障(也可以叫同步点)时被阻塞, 11 | * 直到最后一个线程到达屏障时,屏障才会开门, 12 | * 所有被屏障拦截的线程才会继续干活。 13 | * CyclicBarrier默认的构造方法是 CyclicBarrier(int parties), 14 | * 其参数表示屏障拦截的线程数量, 15 | * 每个线程调用await方法告诉 CyclicBarrier 我已经到达了屏障,然后当前线程被阻塞。 16 | * 17 | * @author itning 18 | */ 19 | public class CyclicBarrierTest { 20 | public static void main(String[] args) throws BrokenBarrierException, InterruptedException, TimeoutException { 21 | CyclicBarrier cyclicBarrier = new CyclicBarrier(5); 22 | //等待所有线程到达屏障 23 | //cyclicBarrier.await(); 24 | //等待60S 25 | //cyclicBarrier.await(60, TimeUnit.SECONDS); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Guava/src/main/java/top/itning/bigdata/guava/precondition/PreconditionsTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.bigdata.guava.precondition; 2 | 3 | import com.google.common.base.Preconditions; 4 | import org.junit.Test; 5 | 6 | import java.util.Random; 7 | 8 | import static com.google.common.base.Preconditions.checkArgument; 9 | 10 | /** 11 | * 前置条件 12 | * Guava在Preconditions类中提供了若干前置条件判断的实用方法 13 | * 每个方法都有三个变种: 14 | * 没有额外参数:抛出的异常中没有错误消息; 15 | * 有一个Object对象作为额外参数:抛出的异常使用Object.toString() 作为错误消息; 16 | * 有一个String对象作为额外参数,并且有一组任意数量的附加Object对象:这个变种处理异常消息的方式有点类似printf,但考虑GWT的兼容性和效率,只支持%s指示符。 17 | * 18 | * @author itning 19 | * @see Preconditions 20 | */ 21 | public class PreconditionsTest { 22 | @Test 23 | public void test() { 24 | int i = new Random().nextInt(); 25 | int j = new Random().nextInt(); 26 | checkArgument(i >= 0, "Argument was %s but expected nonnegative", i); 27 | checkArgument(i < j, "Expected i < j, but %s > %s", i, j); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Sentinel/src/main/java/top/itning/sentinel/config/datasource/FileWritableDataSourceWithLog.java: -------------------------------------------------------------------------------- 1 | package top.itning.sentinel.config.datasource; 2 | 3 | import com.alibaba.csp.sentinel.datasource.Converter; 4 | import com.alibaba.csp.sentinel.datasource.FileWritableDataSource; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | /** 9 | *

拉模式 10 | *

主要功能是将从控制台的新配置写入到文件中以便下次重启APP时规则还在 11 | * 12 | * @author itning 13 | * @date 2020/8/22 16:31 14 | */ 15 | public class FileWritableDataSourceWithLog extends FileWritableDataSource { 16 | private static final Logger logger = LoggerFactory.getLogger(FileWritableDataSourceWithLog.class); 17 | 18 | public FileWritableDataSourceWithLog(String filePath, Converter configEncoder) { 19 | super(filePath, configEncoder); 20 | } 21 | 22 | @Override 23 | public void write(T value) throws Exception { 24 | logger.info("write: {}", value); 25 | super.write(value); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Leetcode/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | top.itning 8 | leetcode 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 8 13 | 8 14 | 15 | 16 | 17 | 18 | 19 | org.junit.jupiter 20 | junit-jupiter-api 21 | 5.8.2 22 | test 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Guava/src/main/java/top/itning/bigdata/guava/collections/UtilsTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.bigdata.guava.collections; 2 | 3 | import org.junit.Test; 4 | 5 | /** 6 | * 集合工具类 7 | * 8 | * @author itning 9 | */ 10 | public class UtilsTest { 11 | @Test 12 | public void test() { 13 | //集合接口 属于JDK还是Guava 对应的Guava工具类 14 | //Collection JDK Collections2:不要和java.util.Collections混淆 15 | //List JDK Lists 16 | //Set JDK Sets 17 | //SortedSet JDK Sets 18 | //Map JDK Maps 19 | //SortedMap JDK Maps 20 | //Queue JDK Queues 21 | //Multiset Guava Multisets 22 | //Multimap Guava Multimaps 23 | //BiMap Guava Maps 24 | //Table Guava Tables 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Leetcode/src/test/java/top/itning/test/PalindromeNumberTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.test; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | /** 7 | * 9. 回文数 8 | * 给你一个整数 x ,如果 x 是一个回文整数,返回 true ;否则,返回 false 。 9 | *

10 | * 回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。例如,121 是回文,而 123 不是。 11 | * 12 | * @author itning 13 | * @since 2021/12/6 19:37 14 | */ 15 | public class PalindromeNumberTest { 16 | @Test 17 | void palindromeNumberTest() { 18 | Assertions.assertTrue(isPalindrome(121)); 19 | Assertions.assertFalse(isPalindrome(1211)); 20 | } 21 | 22 | public boolean isPalindrome(int x) { 23 | return isPalindromic(String.valueOf(x)); 24 | } 25 | 26 | public boolean isPalindromic(String s) { 27 | int len = s.length(); 28 | for (int i = 0; i < len / 2; i++) { 29 | if (s.charAt(i) != s.charAt(len - i - 1)) { 30 | return false; 31 | } 32 | } 33 | return true; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Scala/src/main/java/top/itning/basis/Basis.scala: -------------------------------------------------------------------------------- 1 | package top.itning.basis 2 | 3 | object Basis { 4 | def main(args: Array[String]): Unit = { 5 | varVal() 6 | ifElse() 7 | forOfTo() 8 | } 9 | 10 | def varVal(): Unit = { 11 | //var 可以改变 12 | var i = 1 13 | //val 不可以改变 14 | val j = 2 15 | //指定类型 16 | val str: String = "" 17 | } 18 | 19 | def ifElse(): Unit = { 20 | var x = 1 21 | val y = if (x > 1) x else x - 1 22 | //缺失else 23 | val z = if (x != 1) x 24 | println(s"ifElse Method invoked: z==$z " + z.getClass.getSimpleName) 25 | } 26 | 27 | def forOfTo(): Unit = { 28 | println(1 to 10) 29 | for (i <- 1 to 10) { 30 | print(i + " ") 31 | } 32 | println() 33 | for (i <- 1 to 3; j <- 1 to 3 if i != j) { 34 | print(i + "" + j + " ") 35 | } 36 | println() 37 | val v = for (i <- 1 to 10) yield i * 10 38 | println(s"v is: $v") 39 | for (i <- 1 until 10) { 40 | print(i + " ") 41 | } 42 | println() 43 | } 44 | } -------------------------------------------------------------------------------- /Disruptor/src/main/java/top/itning/disruptor/quickstart/OrderEventProducer.java: -------------------------------------------------------------------------------- 1 | package top.itning.disruptor.quickstart; 2 | 3 | import com.lmax.disruptor.RingBuffer; 4 | 5 | import java.nio.ByteBuffer; 6 | 7 | /** 8 | * @author itning 9 | * @date 2019/5/8 18:07 10 | */ 11 | public class OrderEventProducer { 12 | private RingBuffer ringBuffer; 13 | 14 | public OrderEventProducer(RingBuffer ringBuffer) { 15 | this.ringBuffer = ringBuffer; 16 | } 17 | 18 | public void sendData(ByteBuffer byteBuffer) { 19 | //1.在生产者发送消息的时候,首先需要从我们的ringBuffer获取一个可用的序号 20 | long sequence = ringBuffer.next(); 21 | try { 22 | //2.根据这个序号,找到具体的 OrderEvent 元素 23 | //此时OrderEvent对象是刚被初始化的对象 24 | OrderEvent orderEvent = ringBuffer.get(sequence); 25 | //3.赋值 26 | orderEvent.setPrice(byteBuffer.getLong(0)); 27 | } finally { 28 | //4.提交操作 29 | ringBuffer.publish(sequence); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Leetcode/src/test/java/top/itning/test/LengthOfLastWordTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.test; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | /** 7 | * 给你一个字符串 s,由若干单词组成,单词前后用一些空格字符隔开。返回字符串中最后一个单词的长度。 8 | *

9 | * 单词 是指仅由字母组成、不包含任何空格字符的最大子字符串。 10 | * 11 | * @author itning 12 | * @since 2022/2/14 10:42 13 | */ 14 | public class LengthOfLastWordTest { 15 | @Test 16 | void lengthOfLastWordTest() { 17 | Assertions.assertEquals(5, lengthOfLastWord("Hello World")); 18 | Assertions.assertEquals(4, lengthOfLastWord(" fly me to the moon ")); 19 | } 20 | 21 | public int lengthOfLastWord(String s) { 22 | int length = 0; 23 | for (int i = s.toCharArray().length - 1; i >= 0; i--) { 24 | if (s.charAt(i) == ' ') { 25 | if (length != 0) { 26 | break; 27 | } 28 | } else { 29 | length++; 30 | } 31 | } 32 | return length; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /UDP/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | top.itning.bigdata 7 | 0.0.1-SNAPSHOT 8 | udp 9 | 10 | 11 | 12 | org.apache.maven.plugins 13 | maven-compiler-plugin 14 | 3.8.1 15 | 16 | 1.8 17 | 1.8 18 | UTF-8 19 | true 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Aio/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | top.itning.bigdata 8 | 0.0.1-SNAPSHOT 9 | aio 10 | 11 | 12 | 13 | 14 | org.apache.maven.plugins 15 | maven-compiler-plugin 16 | 3.8.1 17 | 18 | 1.8 19 | 1.8 20 | UTF-8 21 | true 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Algorithm/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | top.itning.bigdata 7 | 0.0.1-SNAPSHOT 8 | algorithm 9 | 10 | 11 | 12 | org.apache.maven.plugins 13 | maven-compiler-plugin 14 | 3.8.1 15 | 16 | 1.8 17 | 1.8 18 | UTF-8 19 | true 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Guava/src/main/java/top/itning/bigdata/guava/collections/ImmutableCollectionsTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.bigdata.guava.collections; 2 | 3 | import com.google.common.collect.ImmutableCollection; 4 | import com.google.common.collect.ImmutableSet; 5 | import org.junit.Test; 6 | 7 | import java.awt.*; 8 | 9 | /** 10 | * 不可变集合 11 | * 12 | * @author itning 13 | * @see ImmutableCollection 14 | */ 15 | public class ImmutableCollectionsTest { 16 | private static final ImmutableSet COLOR_NAMES = ImmutableSet.of( 17 | "red", 18 | "orange", 19 | "yellow", 20 | "green", 21 | "blue", 22 | "purple"); 23 | 24 | private static final ImmutableSet GOOGLE_COLORS = ImmutableSet.builder() 25 | //.addAll(WEBSAFE_COLORS) 26 | .add(new Color(0, 191, 255)) 27 | .build(); 28 | 29 | 30 | @Test 31 | public void test() { 32 | //will throw UnsupportedOperationException; 33 | COLOR_NAMES.add(""); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Guava/src/main/java/top/itning/bigdata/guava/optional/AvoidNullTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.bigdata.guava.optional; 2 | 3 | import com.google.common.base.Optional; 4 | import org.junit.Test; 5 | 6 | import java.util.Set; 7 | 8 | /** 9 | * 避免空指针 10 | * 大多数情况下,开发人员使用null表明的是某种缺失情形: 11 | * 可能是已经有一个默认值,或没有值,或找不到值。 12 | * 例如,Map.get返回null就表示找不到给定键对应的值。 13 | * 14 | * @author itning 15 | */ 16 | @SuppressWarnings("ResultOfMethodCallIgnored") 17 | public class AvoidNullTest { 18 | @Test 19 | public void testOptional() { 20 | //创建引用缺失的Optional实例 21 | Optional.absent(); 22 | //创建指定引用的Optional实例,若引用为null则表示缺失 23 | Optional.fromNullable(""); 24 | //创建指定引用的Optional实例,若引用为null则抛出NullPointerException 25 | Optional possible = Optional.of(5); 26 | possible.isPresent(); // 引用存在,返回true 27 | possible.get(); // 返回Optional所包含的引用,若引用缺失,则抛出java.lang.IllegalStateException 28 | Set set = possible.asSet(); 29 | Integer or = possible.or(6); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Nio/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | top.itning.bigdata 8 | 0.0.1-SNAPSHOT 9 | nio 10 | 11 | 12 | 13 | 14 | org.apache.maven.plugins 15 | maven-compiler-plugin 16 | 3.8.1 17 | 18 | 1.8 19 | 1.8 20 | UTF-8 21 | true 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Blockingqueue/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | top.itning.bigdata 7 | 0.0.1-SNAPSHOT 8 | blockingqueue 9 | 10 | 11 | 12 | 13 | org.apache.maven.plugins 14 | maven-compiler-plugin 15 | 3.8.1 16 | 17 | 1.8 18 | 1.8 19 | UTF-8 20 | true 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /EasyRule/src/main/java/top/itning/easyrule/rule1/rule/AddIdRule.java: -------------------------------------------------------------------------------- 1 | package top.itning.easyrule.rule1.rule; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.jeasy.rules.annotation.Action; 5 | import org.jeasy.rules.annotation.Condition; 6 | import org.jeasy.rules.annotation.Fact; 7 | import org.jeasy.rules.annotation.Rule; 8 | import top.itning.easyrule.rule1.UserDTO; 9 | 10 | /** 11 | * 添加ID规则 12 | * 13 | * @author itning 14 | * @date 2020/11/7 9:55 15 | */ 16 | @Slf4j 17 | @Rule(name = "AddIdRule", description = "添加ID规则", priority = 1) 18 | public class AddIdRule { 19 | @Condition 20 | public boolean when(@Fact("user") UserDTO user) { 21 | log.info("when {}", user); 22 | return null == user.getId(); 23 | } 24 | 25 | @Action(order = 1) 26 | public void then(@Fact("user") UserDTO user) throws Exception { 27 | log.info("then"); 28 | user.setId(1); 29 | } 30 | 31 | @Action(order = 2) 32 | public void doFinally() throws Exception { 33 | log.info("doFinally"); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Proxy/src/main/java/proxy/jdk/ProxyObject.java: -------------------------------------------------------------------------------- 1 | package proxy.jdk; 2 | 3 | import java.lang.reflect.InvocationHandler; 4 | import java.lang.reflect.Method; 5 | import java.lang.reflect.Proxy; 6 | 7 | /** 8 | * 代理对象实现 9 | * 10 | * @author itning 11 | */ 12 | public class ProxyObject { 13 | /** 14 | * 获取代理实例 15 | * 16 | * @return OriginalObjectImpl 17 | */ 18 | public static OriginalObject getProxyObject() { 19 | //newProxyInstance 第一个参数 代理对象; 第二个参数 接口列表 20 | Object instance = Proxy.newProxyInstance(OriginalObjectImpl.class.getClassLoader(), new Class[]{OriginalObject.class}, new InvocationHandler() { 21 | @Override 22 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 23 | //method:原实现类的方法 args:原实现类的参数列表 result:原实现类方法返回值 24 | Object result = method.invoke(new OriginalObjectImpl(), args); 25 | return (int) result + 10; 26 | } 27 | }); 28 | return (OriginalObject) instance; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Scala/src/main/java/top/itning/basis/Fun.scala: -------------------------------------------------------------------------------- 1 | package top.itning.basis 2 | 3 | object Fun { 4 | 5 | def main(args: Array[String]): Unit = { 6 | defFun() 7 | map() 8 | arr() 9 | method2fun() 10 | } 11 | 12 | def defFun(): Unit = { 13 | val f = (x: Int, y: Int) => { 14 | x + y 15 | } 16 | println(f) 17 | println(f(1, 3)) 18 | } 19 | 20 | def map(): Unit = { 21 | println((1 to 10).map((r: Int) => r * 10)) 22 | println((1 to 10).map(r => r * 10)) 23 | println((1 to 10).map(_ * 10)) 24 | } 25 | 26 | def methodOfFunNo(f: () => Unit): Unit = { 27 | f() 28 | } 29 | 30 | def methodOfFun(f: Int => Int): Unit = { 31 | f(3) 32 | } 33 | 34 | def methodOfFun2(f: Int => Int, f2: (Int, String) => Double): Unit = { 35 | f(3) 36 | f2(1, "2") 37 | } 38 | 39 | def method2fun(): Unit = { 40 | val mapfun = map _ 41 | methodOfFunNo(mapfun) 42 | methodOfFunNo(map) 43 | } 44 | 45 | 46 | def arr(): Unit = { 47 | val a = Array(1, 2, 3) 48 | println(a.map(_ * 10).toBuffer) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /RabbitMQ/src/main/java/top/itning/rabbitmq/RabbitmqApplication.java: -------------------------------------------------------------------------------- 1 | package top.itning.rabbitmq; 2 | 3 | import com.rabbitmq.client.Connection; 4 | import com.rabbitmq.client.ConnectionFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | import java.io.IOException; 9 | import java.util.concurrent.TimeoutException; 10 | 11 | @SpringBootApplication 12 | public class RabbitmqApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(RabbitmqApplication.class, args); 16 | } 17 | 18 | public static Connection get() throws IOException, TimeoutException { 19 | ConnectionFactory connectionFactory = new ConnectionFactory(); 20 | connectionFactory.setHost("10.0.75.2"); 21 | connectionFactory.setPort(5672); 22 | connectionFactory.setVirtualHost("/"); 23 | connectionFactory.setUsername("guest"); 24 | connectionFactory.setPassword("guest"); 25 | return connectionFactory.newConnection(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /EasyRule/src/main/java/top/itning/easyrule/rule1/rule/AddAddressRule.java: -------------------------------------------------------------------------------- 1 | package top.itning.easyrule.rule1.rule; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.jeasy.rules.annotation.Action; 5 | import org.jeasy.rules.annotation.Condition; 6 | import org.jeasy.rules.annotation.Fact; 7 | import org.jeasy.rules.annotation.Rule; 8 | import top.itning.easyrule.rule1.UserDTO; 9 | 10 | /** 11 | * 添加地址规则 12 | * 13 | * @author itning 14 | * @date 2020/11/7 9:55 15 | */ 16 | @Slf4j 17 | @Rule(name = "AddAddressRule", description = "添加地址规则", priority = 3) 18 | public class AddAddressRule { 19 | @Condition 20 | public boolean when(@Fact("user") UserDTO user) { 21 | log.info("when {}", user); 22 | return null == user.getAddress(); 23 | } 24 | 25 | @Action(order = 1) 26 | public void then(@Fact("user") UserDTO user) throws Exception { 27 | log.info("then"); 28 | user.setAddress("address"); 29 | } 30 | 31 | @Action(order = 2) 32 | public void doFinally() throws Exception { 33 | log.info("doFinally"); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Algorithm/src/main/java/top/itning/robustness/Solution3.java: -------------------------------------------------------------------------------- 1 | package top.itning.robustness; 2 | 3 | /** 4 | * 输入两个单调递增的链表,输出两个链表合成后的链表, 5 | * 当然我们需要合成后的链表满足单调不减规则。 6 | * 7 | * @author itning 8 | * @date 2019/7/8 13:07 9 | */ 10 | public class Solution3 { 11 | public static void main(String[] args) { 12 | 13 | 14 | } 15 | 16 | public ListNode Merge(ListNode list1, ListNode list2) { 17 | if (list1 == null) { 18 | return list2; 19 | } 20 | if (list2 == null) { 21 | return list1; 22 | } 23 | 24 | ListNode listNode; 25 | if (list1.val <= list2.val) { 26 | listNode = list1; 27 | listNode.next = Merge(list1.next, list2); 28 | } else { 29 | listNode = list2; 30 | listNode.next = Merge(list1, list2.next); 31 | } 32 | return listNode; 33 | } 34 | 35 | public static class ListNode { 36 | int val; 37 | ListNode next = null; 38 | 39 | ListNode(int val) { 40 | this.val = val; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Activemq/src/main/java/activemq/ConsumerTest.java: -------------------------------------------------------------------------------- 1 | package activemq; 2 | 3 | 4 | public class ConsumerTest implements Runnable { 5 | static Thread t1 = null; 6 | 7 | public static void main(String[] args) throws InterruptedException { 8 | 9 | t1 = new Thread(new ConsumerTest()); 10 | t1.start(); 11 | while (true) { 12 | System.out.println(t1.isAlive()); 13 | if (!t1.isAlive()) { 14 | t1 = new Thread(new ConsumerTest()); 15 | t1.start(); 16 | System.out.println("重新启动"); 17 | } 18 | Thread.sleep(5000); 19 | } 20 | // 延时500毫秒之后停止接受消息 21 | // Thread.sleep(500); 22 | // consumer.close(); 23 | } 24 | 25 | @Override 26 | public void run() { 27 | try { 28 | ConsumerTool consumer = new ConsumerTool(); 29 | consumer.consumeMessage(); 30 | while (ConsumerTool.isconnection) { 31 | //System.out.println(123); 32 | } 33 | } catch (Exception e) { 34 | } 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Hadoop/src/main/java/mr/WordCountReducer.java: -------------------------------------------------------------------------------- 1 | package mr; 2 | 3 | import org.apache.hadoop.io.LongWritable; 4 | import org.apache.hadoop.io.Text; 5 | import org.apache.hadoop.mapreduce.Reducer; 6 | 7 | import java.io.IOException; 8 | 9 | /** 10 | * @author itning 11 | */ 12 | public class WordCountReducer extends Reducer { 13 | private static final LongWritable LONG_WRITABLE = new LongWritable(); 14 | 15 | /** 16 | * 每个KEY调用一次reduce 17 | * 18 | * @param key 同一组的KEY 19 | * @param values 所有的可迭代的值 20 | * @param context 上下文 21 | * @throws IOException IOException 22 | * @throws InterruptedException InterruptedException 23 | */ 24 | @Override 25 | protected void reduce(Text key, Iterable values, Context context) throws IOException, InterruptedException { 26 | long count = 0; 27 | for (LongWritable longWritable : values) { 28 | count += longWritable.get(); 29 | } 30 | LONG_WRITABLE.set(count); 31 | context.write(key, LONG_WRITABLE); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Algorithm/src/main/java/top/itning/abstracts/Solution.java: -------------------------------------------------------------------------------- 1 | package top.itning.abstracts; 2 | 3 | import java.util.Stack; 4 | import java.util.TreeSet; 5 | 6 | /** 7 | * 定义栈的数据结构, 8 | * 请在该类型中实现一个能够得到栈中所含最小元素的min函数(时间复杂度应为O(1))。 9 | * 10 | * @author itning 11 | * @date 2019/7/8 13:24 12 | */ 13 | public class Solution { 14 | 15 | public static void main(String[] args) { 16 | Solution solution = new Solution(); 17 | solution.push(6); 18 | solution.push(5); 19 | solution.push(4); 20 | solution.push(3); 21 | solution.push(2); 22 | solution.push(8); 23 | int min = solution.min(); 24 | System.out.println(min); 25 | } 26 | 27 | Stack stack = new Stack<>(); 28 | 29 | public void push(int node) { 30 | stack.push(node); 31 | } 32 | 33 | public void pop() { 34 | stack.pop(); 35 | } 36 | 37 | public int top() { 38 | return stack.peek(); 39 | } 40 | 41 | public int min() { 42 | TreeSet set = new TreeSet<>(stack); 43 | return set.first(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Algorithm/src/main/java/top/itning/find/Solution.java: -------------------------------------------------------------------------------- 1 | package top.itning.find; 2 | 3 | import java.util.Arrays; 4 | 5 | /** 6 | * 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。 7 | * 输入一个非减排序的数组的一个旋转,输出旋转数组的最小元素。 8 | * 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。 9 | * NOTE:给出的所有元素都大于0,若数组大小为0,请返回0。 10 | * ??? 11 | * 12 | * @author itning 13 | * @date 2019/7/7 19:25 14 | */ 15 | public class Solution { 16 | public static void main(String[] args) { 17 | int[] array = {3, 4, 5, 1, 2}; 18 | int i = new Solution().minNumberInRotateArray(array); 19 | System.out.println(i); 20 | } 21 | 22 | public int minNumberInRotateArray(int[] array) { 23 | if (array == null || array.length == 0) { 24 | return 0; 25 | } 26 | // int min = array[0]; 27 | // int minIndex = 0; 28 | // for (int i = 0; i < array.length; i++) { 29 | // if (array[i] < min) { 30 | // minIndex = i; 31 | // min = array[i]; 32 | // } 33 | // } 34 | // if(minIndex) 35 | Arrays.sort(array); 36 | return array[0]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 itning 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /EasyRule/src/main/java/top/itning/easyrule/rule1/rule/AddNameRule.java: -------------------------------------------------------------------------------- 1 | package top.itning.easyrule.rule1.rule; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.jeasy.rules.annotation.Action; 5 | import org.jeasy.rules.annotation.Condition; 6 | import org.jeasy.rules.annotation.Fact; 7 | import org.jeasy.rules.annotation.Rule; 8 | import top.itning.easyrule.rule1.UserDTO; 9 | 10 | import java.util.UUID; 11 | 12 | /** 13 | * 添加名字规则 14 | * 15 | * @author itning 16 | * @date 2020/11/7 9:55 17 | */ 18 | @Slf4j 19 | @Rule(name = "AddNameRule", description = "添加名字规则", priority = 2) 20 | public class AddNameRule { 21 | @Condition 22 | public boolean when(@Fact("user") UserDTO user) throws Exception { 23 | log.info("when {}", user); 24 | return null == user.getName(); 25 | } 26 | 27 | @Action(order = 1) 28 | public void then(@Fact("user") UserDTO user) throws Exception { 29 | log.info("then"); 30 | user.setName(UUID.randomUUID().toString()); 31 | } 32 | 33 | @Action(order = 2) 34 | public void doFinally() throws Exception { 35 | log.info("doFinally"); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Leetcode/src/test/java/top/itning/test/RemoveElementTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.test; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.util.Arrays; 6 | 7 | /** 8 | * 给你一个数组 nums和一个值 val,你需要 原地 移除所有数值等于val的元素,并返回移除后数组的新长度。 9 | *

10 | * 不要使用额外的数组空间,你必须仅使用 O(1) 额外空间并 原地 修改输入数组。 11 | *

12 | * 元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。 13 | *

14 | * 来源:力扣(LeetCode) 15 | * 链接:https://leetcode-cn.com/problems/remove-element 16 | * 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 17 | * 18 | * @author itning 19 | * @since 2022/2/13 20:29 20 | */ 21 | public class RemoveElementTest { 22 | @Test 23 | void removeElementTest() { 24 | int[] ints = {0,1,2,2,3,0,4,2}; 25 | int i = removeElement(ints, 2); 26 | System.out.println(i); 27 | System.out.println(Arrays.toString(ints)); 28 | } 29 | 30 | public int removeElement(int[] nums, int val) { 31 | int temp = 0; 32 | for (int i = 0; i < nums.length; i++) { 33 | if (nums[i] != val) { 34 | nums[temp] = nums[i]; 35 | temp++; 36 | } 37 | } 38 | return temp; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Hadoop/src/main/java/flow/FlowCountReducer.java: -------------------------------------------------------------------------------- 1 | package flow; 2 | 3 | import org.apache.hadoop.io.LongWritable; 4 | import org.apache.hadoop.mapreduce.Reducer; 5 | 6 | import java.io.IOException; 7 | 8 | public class FlowCountReducer extends Reducer { 9 | private static final FlowCountBean FLOW_COUNT_BEAN = new FlowCountBean(); 10 | 11 | @Override 12 | protected void reduce(LongWritable key, Iterable values, Context context) throws IOException, InterruptedException { 13 | FLOW_COUNT_BEAN.clear(); 14 | long upload = 0; 15 | long download = 0; 16 | long sum = 0; 17 | for (FlowCountBean flowCountBean : values) { 18 | upload += flowCountBean.getUpload(); 19 | download += flowCountBean.getDownload(); 20 | sum += flowCountBean.getSum(); 21 | } 22 | FLOW_COUNT_BEAN.setTel(key.get()); 23 | FLOW_COUNT_BEAN.setUpload(upload); 24 | FLOW_COUNT_BEAN.setDownload(download); 25 | FLOW_COUNT_BEAN.setSum(sum); 26 | context.write(key, FLOW_COUNT_BEAN); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/concurrent/completablefuture/CompletableFutureTest.java: -------------------------------------------------------------------------------- 1 | package concurrent.completablefuture; 2 | 3 | import java.util.concurrent.CompletableFuture; 4 | import java.util.concurrent.CountDownLatch; 5 | 6 | /** 7 | * 解决回调问题 8 | * 9 | * @author itning 10 | */ 11 | public class CompletableFutureTest { 12 | public static void main(String[] args) throws InterruptedException { 13 | long l = System.currentTimeMillis(); 14 | CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> { 15 | System.out.println("执行耗时操作..."); 16 | timeConsumingOperation(); 17 | return 100; 18 | }); 19 | completableFuture.whenComplete((result, e) -> { 20 | System.out.println("结果:" + result); 21 | }); 22 | System.out.println("主线程运算耗时:" + (System.currentTimeMillis() - l) + "ms"); 23 | new CountDownLatch(1).await(); 24 | } 25 | 26 | private static void timeConsumingOperation() { 27 | try { 28 | Thread.sleep(3000); 29 | } catch (Exception e) { 30 | e.printStackTrace(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Algorithm/src/main/java/top/itning/stack/Solution.java: -------------------------------------------------------------------------------- 1 | package top.itning.stack; 2 | 3 | import java.util.Stack; 4 | 5 | /** 6 | * 用两个栈来实现一个队列,完成队列的Push和Pop操作。 7 | * 队列中的元素为int类型。 8 | * 4 9 | * 8 10 | * 6 11 | * 3 12 | * 1 13 | * 14 | * @author itning 15 | * @date 2019/7/7 19:01 16 | */ 17 | public class Solution { 18 | public static void main(String[] args) { 19 | Solution solution = new Solution(); 20 | solution.push(1); 21 | solution.push(3); 22 | solution.push(6); 23 | solution.push(8); 24 | solution.push(4); 25 | System.out.println(solution.pop()); 26 | System.out.println(solution.pop()); 27 | } 28 | 29 | Stack stack1 = new Stack<>(); 30 | Stack stack2 = new Stack<>(); 31 | 32 | public void push(int node) { 33 | stack1.push(node); 34 | } 35 | 36 | public int pop() { 37 | while (!stack1.empty()) { 38 | stack2.push(stack1.pop()); 39 | } 40 | int re = stack2.pop(); 41 | 42 | while (!stack2.empty()) { 43 | stack1.push(stack2.pop()); 44 | } 45 | return re; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Algorithm/src/main/java/top/itning/integrity/Solution2.java: -------------------------------------------------------------------------------- 1 | package top.itning.integrity; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | import java.util.List; 6 | import java.util.stream.Stream; 7 | 8 | /** 9 | * 输入一个整数数组,实现一个函数来调整该数组中数字的顺序, 10 | * 使得所有的奇数位于数组的前半部分,所有的偶数位于数组的后半部分, 11 | * 并保证奇数和奇数,偶数和偶数之间的相对位置不变。 12 | * 13 | * @author itning 14 | * @date 2019/7/7 21:44 15 | */ 16 | public class Solution2 { 17 | public static void main(String[] args) { 18 | new Solution2().reOrderArray(new int[]{4, 67, 1, 6, 7}); 19 | } 20 | 21 | public void reOrderArray(int[] array) { 22 | List odd = new ArrayList<>(array.length); 23 | List even = new ArrayList<>(array.length); 24 | for (int item : array) { 25 | if (item % 2 == 0) { 26 | even.add(item); 27 | } else { 28 | odd.add(item); 29 | } 30 | } 31 | Integer[] toArray = Stream.of(odd, even).flatMap(Collection::stream).toArray(Integer[]::new); 32 | for (int i = 0; i < array.length; i++) { 33 | array[i] = toArray[i]; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/concurrent/threadpool/ScheduledThreadPoolTest.java: -------------------------------------------------------------------------------- 1 | package concurrent.threadpool; 2 | 3 | import java.util.concurrent.Executors; 4 | import java.util.concurrent.ScheduledExecutorService; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | /** 8 | * 调度线程池 9 | * 10 | * @author itning 11 | */ 12 | @SuppressWarnings("all") 13 | public class ScheduledThreadPoolTest { 14 | public static void main(String[] args) throws InterruptedException { 15 | ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(2); 16 | scheduledExecutorService.scheduleAtFixedRate(new Runnable() { 17 | @Override 18 | public void run() { 19 | System.out.println(Thread.currentThread().getName()); 20 | System.out.println(Math.random()); 21 | try { 22 | Thread.sleep(1000); 23 | } catch (InterruptedException e) { 24 | e.printStackTrace(); 25 | } 26 | } 27 | }, 1000, 2000, TimeUnit.MILLISECONDS); 28 | Thread.sleep(5000); 29 | scheduledExecutorService.shutdown(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Nio/src/main/java/top/itning/nio/FileTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.nio; 2 | 3 | import java.io.FileInputStream; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.nio.channels.FileChannel; 7 | import java.util.Objects; 8 | 9 | /** 10 | * 文件读写 11 | * 12 | * @author itning 13 | */ 14 | public class FileTest { 15 | public static void main(String[] args) { 16 | String inFile = Objects.requireNonNull(FileTest.class.getClassLoader().getResource("test.txt")).getFile(); 17 | try (FileInputStream fin = new FileInputStream(inFile); 18 | FileChannel fc = fin.getChannel(); 19 | FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\itning\\Desktop\\out.txt"); 20 | FileChannel outputStreamChannel = fileOutputStream.getChannel()) { 21 | // ByteBuffer buffer = ByteBuffer.allocate(1024); 22 | // fc.read(buffer); 23 | // System.out.println(new String(buffer.array())); 24 | System.out.println(fc.size()); 25 | outputStreamChannel.transferFrom(fc, 0, fc.size()); 26 | } catch (IOException e) { 27 | e.printStackTrace(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/concurrent/threadpool/SingleThreadScheduledExecutorTest.java: -------------------------------------------------------------------------------- 1 | package concurrent.threadpool; 2 | 3 | import java.util.concurrent.Executors; 4 | import java.util.concurrent.ScheduledExecutorService; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | /** 8 | * 单线程调度池 9 | * 10 | * @author itning 11 | */ 12 | @SuppressWarnings("all") 13 | public class SingleThreadScheduledExecutorTest { 14 | public static void main(String[] args) throws InterruptedException { 15 | ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); 16 | scheduledExecutorService.scheduleAtFixedRate(new Runnable() { 17 | @Override 18 | public void run() { 19 | System.out.println(Thread.currentThread().getName()); 20 | System.out.println(Math.random()); 21 | try { 22 | Thread.sleep(1000); 23 | } catch (InterruptedException e) { 24 | e.printStackTrace(); 25 | } 26 | } 27 | }, 1000, 2000, TimeUnit.MILLISECONDS); 28 | Thread.sleep(5000); 29 | scheduledExecutorService.shutdown(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Guava/src/main/java/top/itning/bigdata/guava/objects/ObjectsTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.bigdata.guava.objects; 2 | 3 | import org.junit.Test; 4 | 5 | /** 6 | * @author itning 7 | */ 8 | public class ObjectsTest { 9 | @Test 10 | public void test() { 11 | //当一个对象中的字段可以为null时,实现Object.equals方法会很痛苦,因为不得不分别对它们进行null检查。 12 | //使用Objects.equal帮助你执行null敏感的equals判断,从而避免抛出NullPointerException。例如: 13 | com.google.common.base.Objects.equal("a", "a"); // returns true 14 | com.google.common.base.Objects.equal(null, "a"); // returns false 15 | com.google.common.base.Objects.equal("a", null); // returns false 16 | com.google.common.base.Objects.equal(null, null); // returns true 17 | //注意:JDK7引入的Objects类提供了一样的方法Objects.equals。 18 | 19 | //hashCode 20 | //用对象的所有字段作散列[hash]运算应当更简单。Guava的Objects.hashCode(Object...)会对传入的字段序列计算出合理的、顺序敏感的散列值。 21 | // 你可以使用Objects.hashCode(field1, field2, …, fieldn)来代替手动计算散列值。 22 | //注意:JDK7引入的Objects类提供了一样的方法Objects.hash(Object...) 23 | 24 | //toString 25 | 26 | //好的toString方法在调试时是无价之宝,但是编写toString方法有时候却很痛苦。 27 | //使用 Objects.toStringHelper可以轻松编写有用的toString方法。例如: 28 | java.util.Objects.toString(""); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/concurrent/ThreadPoolWithCallable.java: -------------------------------------------------------------------------------- 1 | package concurrent; 2 | 3 | import java.util.concurrent.*; 4 | 5 | /** 6 | * 提交 Callable,该方法返回一个 Future 实例表示任务的状态 7 | * 调用submit提交任务, 匿名Callable,重写call方法, 有返回值, 获取返回值会阻塞,一直要等到线程任务返回结果 8 | * 9 | * @author itning 10 | */ 11 | @SuppressWarnings("all") 12 | public class ThreadPoolWithCallable { 13 | public static void main(String[] args) throws ExecutionException, InterruptedException { 14 | int processors = Runtime.getRuntime().availableProcessors(); 15 | System.out.println("当前CPU核数:" + processors); 16 | ExecutorService pool = Executors.newFixedThreadPool(processors); 17 | for (int i = 1; i < 10; i++) { 18 | int finalI = i; 19 | Future submit = pool.submit(new Callable() { 20 | @Override 21 | public String call() throws Exception { 22 | String s = Thread.currentThread().getName(); 23 | System.out.println(s); 24 | return s + "--" + finalI + "返回消息"; 25 | } 26 | }); 27 | //获取返回的消息会阻塞,直到获取到 28 | System.out.println(submit.get()); 29 | } 30 | pool.shutdown(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Storm/src/main/java/top/itning/storm/wordcount/WordCountTopology.java: -------------------------------------------------------------------------------- 1 | package top.itning.storm.wordcount; 2 | 3 | import org.apache.storm.Config; 4 | import org.apache.storm.LocalCluster; 5 | import org.apache.storm.topology.TopologyBuilder; 6 | import org.apache.storm.tuple.Fields; 7 | 8 | /** 9 | * Topology:Storm中运行的一个实时应用程序的名称(拓扑) 10 | * 11 | * @author itning 12 | */ 13 | public class WordCountTopology { 14 | public static void main(String[] args) { 15 | TopologyBuilder topologyBuilder = new TopologyBuilder(); 16 | topologyBuilder.setSpout("wcSpout", new WordCountSpout(), 2); 17 | topologyBuilder.setBolt("wcSplit", new WordCountSplitBolt(), 3).shuffleGrouping("wcSpout"); 18 | topologyBuilder.setBolt("wcCount", new WordCountCountBolt(), 4).fieldsGrouping("wcSplit", new Fields("splitWord")); 19 | Config config = new Config(); 20 | config.setNumWorkers(4); 21 | 22 | LocalCluster localCluster = new LocalCluster(); 23 | localCluster.submitTopology("mywordcount", config, topologyBuilder.createTopology()); 24 | //StormSubmitter.submitTopology("mywordcount",config,topologyBuilder.createTopology()); 25 | //Utils.sleep(10000); 26 | //localCluster.shutdown(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /EasyRule/src/main/java/top/itning/easyrule/rule1/rule/FinallyUserRule.java: -------------------------------------------------------------------------------- 1 | package top.itning.easyrule.rule1.rule; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.jeasy.rules.annotation.Action; 5 | import org.jeasy.rules.annotation.Condition; 6 | import org.jeasy.rules.annotation.Fact; 7 | import org.jeasy.rules.annotation.Rule; 8 | import top.itning.easyrule.rule1.UserDTO; 9 | 10 | import java.util.concurrent.atomic.AtomicInteger; 11 | 12 | /** 13 | * 最终规则 14 | * 15 | * @author itning 16 | * @date 2020/11/7 10:19 17 | */ 18 | @Slf4j 19 | @Rule(name = "FinallyUserRule", description = "最终规则", priority = Integer.MAX_VALUE) 20 | public class FinallyUserRule { 21 | private static final AtomicInteger TIME = new AtomicInteger(); 22 | 23 | @Condition 24 | public boolean when(@Fact("user") UserDTO user) { 25 | if (TIME.get() > 0) { 26 | return false; 27 | } 28 | TIME.incrementAndGet(); 29 | return true; 30 | } 31 | 32 | @Action(order = 1) 33 | public void then(@Fact("user") UserDTO user) throws Exception { 34 | log.info("then {}", user); 35 | } 36 | 37 | @Action(order = 2) 38 | public void doFinally() throws Exception { 39 | log.info("doFinally"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Netty/src/main/java/top/itning/netty/simple/client/SimpleClientHandler.java: -------------------------------------------------------------------------------- 1 | package top.itning.netty.simple.client; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.channel.ChannelInboundHandlerAdapter; 6 | import io.netty.util.CharsetUtil; 7 | import io.netty.util.ReferenceCountUtil; 8 | 9 | /** 10 | * 简单客户端规则处理器 11 | * 12 | * @author itning 13 | */ 14 | public class SimpleClientHandler extends ChannelInboundHandlerAdapter { 15 | @Override 16 | public void channelActive(ChannelHandlerContext ctx) throws Exception { 17 | ByteBuf byteBuf = ctx.alloc().buffer().writeBytes("客户端消息".getBytes()); 18 | ctx.writeAndFlush(byteBuf); 19 | } 20 | 21 | @Override 22 | public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { 23 | ByteBuf m = (ByteBuf) msg; 24 | try { 25 | System.out.println(m.toString(CharsetUtil.UTF_8)); 26 | } finally { 27 | ReferenceCountUtil.release(msg); 28 | } 29 | } 30 | 31 | 32 | @Override 33 | public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { 34 | cause.printStackTrace(); 35 | ctx.close(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Disruptor/src/main/java/top/itning/disruptor/high/TradePushlisher.java: -------------------------------------------------------------------------------- 1 | package top.itning.disruptor.high; 2 | 3 | import com.lmax.disruptor.EventTranslator; 4 | import com.lmax.disruptor.dsl.Disruptor; 5 | 6 | import java.util.Random; 7 | import java.util.concurrent.CountDownLatch; 8 | 9 | /** 10 | * @author itning 11 | * @date 2019/5/10 8:33 12 | */ 13 | public class TradePushlisher implements Runnable { 14 | private CountDownLatch countDownLatch; 15 | private Disruptor disruptor; 16 | 17 | public TradePushlisher(CountDownLatch countDownLatch, Disruptor disruptor) { 18 | this.countDownLatch = countDownLatch; 19 | this.disruptor = disruptor; 20 | } 21 | 22 | @Override 23 | public void run() { 24 | TradeEventTranslator tradeEventTranslator = new TradeEventTranslator(); 25 | for (int i = 0; i < 100; i++) { 26 | disruptor.publishEvent(tradeEventTranslator); 27 | } 28 | countDownLatch.countDown(); 29 | } 30 | 31 | class TradeEventTranslator implements EventTranslator { 32 | 33 | @Override 34 | public void translateTo(Trade event, long sequence) { 35 | event.setPrice(new Random().nextDouble() * 9999); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Hadoop/src/main/java/mr/WordCountMapper.java: -------------------------------------------------------------------------------- 1 | package mr; 2 | 3 | import org.apache.hadoop.io.LongWritable; 4 | import org.apache.hadoop.io.Text; 5 | import org.apache.hadoop.mapreduce.Mapper; 6 | 7 | import java.io.IOException; 8 | 9 | /** 10 | * Mappper 11 | * 泛型参数 12 | * 1->LongWritable 文本偏移量 13 | * 2->Text 所读到一行文本内容 14 | * 3->Text 用户输出的KEY 15 | * 4->LongWritable 用户输出的VALUE 16 | * 17 | * @author itning 18 | */ 19 | public class WordCountMapper extends Mapper { 20 | private static final Text TEXT = new Text(); 21 | private static final LongWritable LONG_WRITABLE = new LongWritable(); 22 | 23 | /** 24 | * 每一行输入调用一次map 25 | * 26 | * @param key 文本偏移量 27 | * @param value 所读到一行文本内容 28 | * @param context 上下文 29 | * @throws IOException IOException 30 | * @throws InterruptedException InterruptedException 31 | */ 32 | @Override 33 | protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { 34 | String[] strings = value.toString().split(" "); 35 | for (String str : strings) { 36 | TEXT.set(str); 37 | LONG_WRITABLE.set(1); 38 | context.write(TEXT, LONG_WRITABLE); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/threadlocal/ThreadLocalTest.java: -------------------------------------------------------------------------------- 1 | package threadlocal; 2 | 3 | /** 4 | * main value 5 | * 初始化值 6 | * 初始化值 7 | * 初始化值 8 | * 初始化值 9 | * 10 | * @author itning 11 | */ 12 | public class ThreadLocalTest { 13 | private static ThreadLocal stringThreadLocal = new ThreadLocal() { 14 | @Override 15 | protected String initialValue() { 16 | return "初始化值"; 17 | } 18 | }; 19 | 20 | private static ThreadLocal integerThreadLocal = ThreadLocal.withInitial(() -> 1); 21 | 22 | public static void main(String[] args) { 23 | new ThreadTest().start(); 24 | new ThreadTest().start(); 25 | new ThreadTest().start(); 26 | new ThreadTest().start(); 27 | stringThreadLocal.set("main value"); 28 | System.out.println(stringThreadLocal.get() + " " + integerThreadLocal.get()); 29 | //stringThreadLocal.remove(); 30 | } 31 | 32 | static class ThreadTest extends Thread { 33 | @Override 34 | public void run() { 35 | if ("Thread-0".equals(Thread.currentThread().getName())) { 36 | integerThreadLocal.set(2); 37 | } 38 | System.out.println(stringThreadLocal.get() + " " + integerThreadLocal.get()); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Proxy/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | top.itning.bigdata 7 | 0.0.1-SNAPSHOT 8 | proxy 9 | 10 | 11 | 12 | 13 | cglib 14 | cglib 15 | 3.2.10 16 | 17 | 18 | 19 | 20 | 21 | org.apache.maven.plugins 22 | maven-compiler-plugin 23 | 3.8.1 24 | 25 | 1.8 26 | 1.8 27 | UTF-8 28 | true 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Proxy/src/main/java/proxy/cglib/ProxyObject.java: -------------------------------------------------------------------------------- 1 | package proxy.cglib; 2 | 3 | import net.sf.cglib.proxy.Enhancer; 4 | import net.sf.cglib.proxy.MethodInterceptor; 5 | import net.sf.cglib.proxy.MethodProxy; 6 | 7 | import java.lang.reflect.Method; 8 | 9 | /** 10 | * JDK的动态代理机制只能代理实现了接口的类, 11 | * 而不能实现接口的类就不能实现JDK的动态代理, 12 | * cglib是针对类来实现代理的, 13 | * 他的原理是对指定的目标类生成一个子类, 14 | * 并覆盖其中方法实现增强, 15 | * 但因为采用的是继承, 16 | * 所以不能对final修饰的类进行代理。 17 | * 18 | * @author itning 19 | * @date 2019/4/16 14:48 20 | */ 21 | public class ProxyObject implements MethodInterceptor { 22 | /** 23 | * 创建代理对象 24 | * 25 | * @param t 要代理的类 26 | * @return 代理对象 27 | */ 28 | @SuppressWarnings("unchecked") 29 | public T getInstance(T t) { 30 | Enhancer enhancer = new Enhancer(); 31 | enhancer.setSuperclass(t.getClass()); 32 | // 回调方法 33 | enhancer.setCallback(this); 34 | // 创建代理对象(无参) 35 | return (T) enhancer.create(); 36 | } 37 | 38 | @Override 39 | public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable { 40 | System.out.println("事物开始"); 41 | Object invokeSuper = methodProxy.invokeSuper(o, objects); 42 | System.out.println("事物结束"); 43 | return (int) invokeSuper + 10; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /WrittenExamination/src/main/java/top/itning/w/RandomWordGenerate.java: -------------------------------------------------------------------------------- 1 | package top.itning.w; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.FileWriter; 5 | import java.io.IOException; 6 | 7 | /** 8 | * 随机单词生成器 9 | * 10 | * @author itning 11 | * @since 2021/12/3 10:42 12 | */ 13 | public class RandomWordGenerate { 14 | 15 | private final static int MIN_LETTERS = 3; 16 | private final static int MAX_LETTERS = 5; 17 | 18 | public static void main(String[] args) throws IOException { 19 | BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("D:\\data1.txt", false)); 20 | 21 | for (int i = 0; i < 50000000; i++) { 22 | String word = createWord(MIN_LETTERS, MAX_LETTERS); 23 | bufferedWriter.write(word); 24 | if (Math.random() > 0.5) { 25 | bufferedWriter.write("\n"); 26 | } 27 | } 28 | bufferedWriter.flush(); 29 | bufferedWriter.close(); 30 | } 31 | 32 | public static String createWord(int min, int max) { 33 | int count = (int) (Math.random() * (max - min + 1)) + min; 34 | StringBuilder str = new StringBuilder(); 35 | for (int i = 0; i < count; i++) { 36 | str.append((char) ((int) (Math.random() * 26) + 'a')); 37 | } 38 | return str.toString(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Algorithm/src/main/java/top/itning/robustness/Solution2.java: -------------------------------------------------------------------------------- 1 | package top.itning.robustness; 2 | 3 | /** 4 | * 输入一个链表,反转链表后,输出新链表的表头。 5 | * 6 | * @author itning 7 | * @date 2019/7/8 8:32 8 | */ 9 | public class Solution2 { 10 | public static void main(String[] args) { 11 | ListNode listNode1 = new ListNode(67); 12 | ListNode listNode2 = new ListNode(0); 13 | ListNode listNode3 = new ListNode(24); 14 | ListNode listNode4 = new ListNode(58); 15 | listNode1.next = listNode2; 16 | listNode2.next = listNode3; 17 | listNode3.next = listNode4; 18 | ListNode listNode = new Solution2().ReverseList(listNode1); 19 | System.out.println(listNode.val); 20 | } 21 | 22 | public ListNode ReverseList(ListNode head) { 23 | ListNode newHead = null; 24 | ListNode next; 25 | // 1>2>3>4 1.next 2 next 3 next 4 26 | // 1<2<3<4 4 next 3 next 2 next 1 27 | while (head != null) { 28 | next = head.next; 29 | head.next = newHead; 30 | newHead = head; 31 | head = next; 32 | } 33 | return newHead; 34 | } 35 | 36 | public static class ListNode { 37 | int val; 38 | ListNode next = null; 39 | 40 | ListNode(int val) { 41 | this.val = val; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Guava/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | top.itning.bigdata 7 | 0.0.1-SNAPSHOT 8 | guava 9 | 10 | 11 | 12 | 13 | com.google.guava 14 | guava 15 | 27.1-jre 16 | 17 | 18 | 19 | 20 | 21 | org.apache.maven.plugins 22 | maven-compiler-plugin 23 | 3.8.1 24 | 25 | 1.8 26 | 1.8 27 | UTF-8 28 | true 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Hadoop/src/main/java/join/JoinReducer.java: -------------------------------------------------------------------------------- 1 | package join; 2 | 3 | import org.apache.hadoop.io.Text; 4 | import org.apache.hadoop.mapreduce.Reducer; 5 | 6 | import java.io.IOException; 7 | 8 | public class JoinReducer extends Reducer { 9 | @Override 10 | protected void reduce(Text key, Iterable values, Context context) throws IOException, InterruptedException { 11 | JoinOutBean joinOutBean = new JoinOutBean(); 12 | boolean flag = true; 13 | for (JoinBean joinBean : values) { 14 | if (joinBean.getOid() == 0) { 15 | joinOutBean.setName(joinBean.getPname()); 16 | joinOutBean.setCid(joinBean.getCategory_id()); 17 | joinOutBean.setPrice(joinBean.getPrice()); 18 | if (joinOutBean.getDate() == null) { 19 | continue; 20 | } else { 21 | flag = false; 22 | } 23 | } 24 | if (flag) { 25 | joinOutBean.setId(joinBean.getOid()); 26 | joinOutBean.setDate(joinBean.getOdate()); 27 | } 28 | if (joinOutBean.getDate() != null && joinOutBean.getCid() != null) { 29 | context.write(new Text(joinOutBean.getId() + ""), joinOutBean); 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Concurrent/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | top.itning.bigdata 7 | 0.0.1-SNAPSHOT 8 | concurrent 9 | 10 | 11 | 12 | 13 | com.google.guava 14 | guava 15 | 29.0-jre 16 | 17 | 18 | 19 | 20 | 21 | org.apache.maven.plugins 22 | maven-compiler-plugin 23 | 3.8.1 24 | 25 | 1.8 26 | 1.8 27 | UTF-8 28 | true 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/concurrent/lock/LockSupportTest.java: -------------------------------------------------------------------------------- 1 | package concurrent.lock; 2 | 3 | import java.util.concurrent.locks.LockSupport; 4 | 5 | /** 6 | *

{@link LockSupport#park()}: 7 | * 阻塞当前线程,如果调用unpark方法或者当前线程被中断,从能从park()方法中返回 8 | * 9 | *

{@link LockSupport#park(Object)}: 10 | * 功能同方法1,入参增加一个Object对象,用来记录导致线程阻塞的阻塞对象,方便进行问题排查; 11 | * 12 | *

{@link LockSupport#parkNanos(long)}: 13 | * 阻塞当前线程,最长不超过nanos纳秒,增加了超时返回的特性; 14 | * 15 | *

{@link LockSupport#parkNanos(Object, long)}: 16 | * 功能同方法3,入参增加一个Object对象,用来记录导致线程阻塞的阻塞对象,方便进行问题排查; 17 | * 18 | *

{@link LockSupport#parkUntil(long)}: 19 | * 阻塞当前线程,知道deadline; 20 | * 21 | *

{@link LockSupport#parkUntil(Object, long)}: 22 | * 功能同方法5,入参增加一个Object对象,用来记录导致线程阻塞的阻塞对象,方便进行问题排查; 23 | * 24 | * @author itning 25 | * @date 2020/5/23 12:51 26 | * @see java.util.concurrent.locks.LockSupport 27 | */ 28 | public class LockSupportTest { 29 | public static void main(String[] args) { 30 | Thread thread = new Thread(() -> { 31 | LockSupport.park(); 32 | System.out.println(Thread.currentThread().getName() + "被唤醒"); 33 | }); 34 | thread.start(); 35 | try { 36 | Thread.sleep(3000); 37 | } catch (InterruptedException e) { 38 | e.printStackTrace(); 39 | } 40 | LockSupport.unpark(thread); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/concurrent/observer/ObservableTest.java: -------------------------------------------------------------------------------- 1 | package concurrent.observer; 2 | 3 | import java.util.Observable; 4 | import java.util.Observer; 5 | 6 | /** 7 | * 在 Java 中,内置了 Observable 类和 Observer 接口来实现观察者模式。 8 | * 使用时,Observable 作为被观察对象,通过调用 addObserver 方法来增加观察者,当状态变化时, 9 | * 被观察者调用 setChanged 方法来标识状态变化,然后调用 notifyObservers 方法来通知观察者。 10 | * Observer 接口用于实现观察者,只有一个方法 update, 11 | * 当状态变化时,观察者的 update 方法被调用,从而获知状态变化。 12 | * 13 | * @author itning 14 | */ 15 | public class ObservableTest extends Observable { 16 | public static void main(String[] args) { 17 | ObservableTest observable = new ObservableTest(); 18 | observable.addObserver(new ObserverWatch(1)); 19 | observable.addObserver(new ObserverWatch(2)); 20 | observable.addObserver(new ObserverWatch(3)); 21 | System.out.println(String.format("有%d个观察者", observable.countObservers())); 22 | observable.setChanged(); 23 | observable.notifyObservers("新事件"); 24 | 25 | } 26 | 27 | static class ObserverWatch implements Observer { 28 | private int id; 29 | 30 | ObserverWatch(int id) { 31 | this.id = id; 32 | } 33 | 34 | @Override 35 | public void update(Observable o, Object arg) { 36 | System.out.println(String.format("%d %s %s", id, o, arg)); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Scala/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | top.itning.bigdata 7 | 0.0.1-SNAPSHOT 8 | scala 9 | 10 | 11 | 12 | org.scala-lang 13 | scala-library 14 | 2.12.6 15 | 16 | 17 | 18 | 19 | 20 | 21 | org.apache.maven.plugins 22 | maven-compiler-plugin 23 | 3.8.1 24 | 25 | 1.8 26 | 1.8 27 | UTF-8 28 | true 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Spark/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | top.itning.bigdata 7 | 0.0.1-SNAPSHOT 8 | spark 9 | 10 | 11 | 12 | org.apache.spark 13 | spark-core_2.11 14 | 2.4.0 15 | 16 | 17 | 18 | 19 | 20 | 21 | org.apache.maven.plugins 22 | maven-compiler-plugin 23 | 3.8.1 24 | 25 | 1.8 26 | 1.8 27 | UTF-8 28 | true 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Storm/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | top.itning.bigdata 7 | 0.0.1-SNAPSHOT 8 | storm 9 | 10 | 11 | 12 | 13 | org.apache.storm 14 | storm-core 15 | 1.2.2 16 | 17 | 18 | 19 | 20 | 21 | 22 | org.apache.maven.plugins 23 | maven-compiler-plugin 24 | 3.8.1 25 | 26 | 1.8 27 | 1.8 28 | UTF-8 29 | true 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Activemq/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | activemq 8 | top.itning.bigdata 9 | 0.0.1-SNAPSHOT 10 | 11 | 12 | 13 | org.apache.activemq 14 | activemq-core 15 | 5.7.0 16 | 17 | 18 | 19 | 20 | 21 | 22 | org.apache.maven.plugins 23 | maven-compiler-plugin 24 | 3.8.1 25 | 26 | 1.8 27 | 1.8 28 | UTF-8 29 | true 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Leetcode/src/test/java/top/itning/test/LongestSubstringWithoutRepeatingCharactersTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.test; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /** 10 | * 3. 无重复字符的最长子串 11 | * 给定一个字符串 s ,请你找出其中不含有重复字符的 最长子串 的长度。 12 | * 13 | * @author itning 14 | * @since 2021/12/6 19:00 15 | */ 16 | public class LongestSubstringWithoutRepeatingCharactersTest { 17 | @Test 18 | void longestSubstringWithoutRepeatingCharactersTest() { 19 | Assertions.assertEquals(3, lengthOfLongestSubstring("abcabcbb")); 20 | } 21 | 22 | public int lengthOfLongestSubstring(String s) { 23 | Map map = new HashMap<>(); 24 | int left = 0; 25 | int length = 0; 26 | for (int i = 0; i < s.length(); i++) { 27 | char item = s.charAt(i); 28 | Integer index = map.get(item); 29 | if (index != null) { 30 | for (int j = left; j < index; j++) { 31 | map.remove(s.charAt(j)); 32 | } 33 | left = index + 1; 34 | map.put(item, i); 35 | } else { 36 | map.put(item, i); 37 | length = Math.max(length, i - left + 1); 38 | } 39 | } 40 | return length; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Netty/src/main/java/top/itning/netty/websocket/HeartBeatHandler.java: -------------------------------------------------------------------------------- 1 | package top.itning.netty.websocket; 2 | 3 | import io.netty.channel.ChannelHandlerContext; 4 | import io.netty.channel.ChannelInboundHandlerAdapter; 5 | import io.netty.handler.timeout.IdleStateEvent; 6 | 7 | /** 8 | * @author itning 9 | * @date 2020/4/7 12:55 10 | */ 11 | public class HeartBeatHandler extends ChannelInboundHandlerAdapter { 12 | @Override 13 | public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { 14 | if (evt instanceof IdleStateEvent) { 15 | IdleStateEvent idleStateEvent = (IdleStateEvent) evt; 16 | switch (idleStateEvent.state()) { 17 | case READER_IDLE: { 18 | System.out.println("读空闲事件触发"); 19 | break; 20 | } 21 | case WRITER_IDLE: { 22 | System.out.println("写空闲事件触发"); 23 | break; 24 | } 25 | case ALL_IDLE: { 26 | // 在这里关闭连接 27 | //ctx.channel().close(); 28 | System.out.println("读写空闲事件触发"); 29 | break; 30 | } 31 | default: 32 | super.userEventTriggered(ctx, evt); 33 | } 34 | } else { 35 | super.userEventTriggered(ctx, evt); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Netty/src/main/resources/chatTest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 聊天室测试 6 | 7 | 8 | 9 | 10 | 11 |

12 |

接收到的消息:

13 |
14 |
15 | 47 | 48 | -------------------------------------------------------------------------------- /Hadoop/src/main/java/log/LogRunner.java: -------------------------------------------------------------------------------- 1 | package log; 2 | 3 | import org.apache.hadoop.conf.Configuration; 4 | import org.apache.hadoop.fs.Path; 5 | import org.apache.hadoop.io.LongWritable; 6 | import org.apache.hadoop.io.Text; 7 | import org.apache.hadoop.mapreduce.Job; 8 | import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; 9 | import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; 10 | import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; 11 | 12 | import java.io.IOException; 13 | 14 | public class LogRunner { 15 | public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException { 16 | Configuration configuration = new Configuration(); 17 | Job job = Job.getInstance(configuration); 18 | 19 | job.setJarByClass(LogRunner.class); 20 | 21 | job.setMapperClass(LogMapper.class); 22 | job.setReducerClass(LogReducer.class); 23 | 24 | job.setMapOutputKeyClass(Text.class); 25 | job.setMapOutputValueClass(LongWritable.class); 26 | 27 | job.setOutputKeyClass(Text.class); 28 | job.setOutputValueClass(LongWritable.class); 29 | 30 | job.setInputFormatClass(TextInputFormat.class); 31 | 32 | FileInputFormat.setInputPaths(job, "hdfs://192.168.1.11:9000/rizhi"); 33 | FileOutputFormat.setOutputPath(job, new Path("hdfs://192.168.1.11:9000/out/rizhi")); 34 | 35 | job.waitForCompletion(true); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Storm/src/main/java/top/itning/storm/wordcount/WordCountSplitBolt.java: -------------------------------------------------------------------------------- 1 | package top.itning.storm.wordcount; 2 | 3 | import org.apache.storm.task.OutputCollector; 4 | import org.apache.storm.task.TopologyContext; 5 | import org.apache.storm.topology.OutputFieldsDeclarer; 6 | import org.apache.storm.topology.base.BaseRichBolt; 7 | import org.apache.storm.tuple.Fields; 8 | import org.apache.storm.tuple.Tuple; 9 | import org.apache.storm.tuple.Values; 10 | 11 | import java.util.Map; 12 | 13 | /** 14 | * 接受数据然后执行处理的组件,用户可以在其中执行自己想要的操作。
15 | * 字符串进行分割操作 16 | * 17 | * @author itning 18 | */ 19 | public class WordCountSplitBolt extends BaseRichBolt { 20 | 21 | private OutputCollector collector; 22 | 23 | @Override 24 | public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { 25 | this.collector = collector; 26 | } 27 | 28 | @Override 29 | public void execute(Tuple input) { 30 | try { 31 | String word = input.getString(0); 32 | String[] s = word.split(" "); 33 | for (String str : s) { 34 | collector.emit(new Values(str)); 35 | } 36 | collector.ack(input); 37 | } catch (Exception e) { 38 | collector.fail(input); 39 | } 40 | } 41 | 42 | @Override 43 | public void declareOutputFields(OutputFieldsDeclarer declarer) { 44 | declarer.declare(new Fields("splitWord")); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /RabbitMQ/src/main/java/top/itning/rabbitmq/quickstart/Consumer.java: -------------------------------------------------------------------------------- 1 | package top.itning.rabbitmq.quickstart; 2 | 3 | import com.rabbitmq.client.*; 4 | import top.itning.rabbitmq.RabbitmqApplication; 5 | 6 | import java.io.IOException; 7 | import java.util.concurrent.TimeoutException; 8 | 9 | /** 10 | * @author itning 11 | * @date 2019/5/7 8:54 12 | */ 13 | public class Consumer { 14 | public static void main(String[] args) throws IOException, TimeoutException { 15 | Connection connection = RabbitmqApplication.get(); 16 | Channel channel = connection.createChannel(); 17 | 18 | String queue = "test001"; 19 | channel.queueDeclare(queue, true, false, false, null); 20 | 21 | DeliverCallback deliverCallback = (consumerTag, message) -> { 22 | System.out.println("consumerTag " + consumerTag); 23 | Object my1 = message.getProperties().getHeaders().get("my1"); 24 | System.out.println(my1); 25 | System.out.println("message " + new String(message.getBody())); 26 | 27 | channel.basicAck(message.getEnvelope().getDeliveryTag(), false); 28 | 29 | //channel.basicNack(message.getEnvelope().getDeliveryTag(), false, false); 30 | }; 31 | 32 | CancelCallback cancelCallback = consumerTag -> System.out.println("consumerTag " + consumerTag); 33 | 34 | channel.basicQos(0, 3, false); 35 | 36 | channel.basicConsume(queue, false, deliverCallback, cancelCallback); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/concurrent/threadpool/SingleThreadPoolTest.java: -------------------------------------------------------------------------------- 1 | package concurrent.threadpool; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | 6 | /** 7 | * 单线程池
8 | * 排队执行
9 | * 因为是单线程池,线程名字都相同 10 | * 11 | * @author itning 12 | */ 13 | @SuppressWarnings("all") 14 | public class SingleThreadPoolTest { 15 | public static void main(String[] args) { 16 | ExecutorService executorService = Executors.newSingleThreadExecutor(); 17 | executorService.submit(new Runnable() { 18 | @Override 19 | public void run() { 20 | System.out.println(Thread.currentThread().getName()); 21 | System.out.println(Math.random()); 22 | try { 23 | Thread.sleep(1000); 24 | } catch (InterruptedException e) { 25 | e.printStackTrace(); 26 | } 27 | } 28 | }); 29 | executorService.submit(new Runnable() { 30 | @Override 31 | public void run() { 32 | System.out.println(Thread.currentThread().getName()); 33 | System.out.println(Math.random()); 34 | try { 35 | Thread.sleep(1000); 36 | } catch (InterruptedException e) { 37 | e.printStackTrace(); 38 | } 39 | } 40 | }); 41 | executorService.shutdown(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Storm/src/main/java/top/itning/storm/wordcount/WordCountCountBolt.java: -------------------------------------------------------------------------------- 1 | package top.itning.storm.wordcount; 2 | 3 | import org.apache.storm.task.OutputCollector; 4 | import org.apache.storm.task.TopologyContext; 5 | import org.apache.storm.topology.OutputFieldsDeclarer; 6 | import org.apache.storm.topology.base.BaseRichBolt; 7 | import org.apache.storm.tuple.Tuple; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * 累加计数 14 | * 15 | * @author itning 16 | */ 17 | public class WordCountCountBolt extends BaseRichBolt { 18 | 19 | private HashMap countMap = new HashMap<>(); 20 | private OutputCollector collector; 21 | 22 | @Override 23 | public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { 24 | this.collector = collector; 25 | } 26 | 27 | @Override 28 | public void execute(Tuple input) { 29 | try { 30 | String s = input.getString(0); 31 | //存在 32 | if (countMap.containsKey(s)) { 33 | countMap.replace(s, countMap.get(s) + 1); 34 | } else { 35 | countMap.put(s, 1); 36 | } 37 | System.out.println("countMap-->" + countMap.toString()); 38 | collector.ack(input); 39 | } catch (Exception e) { 40 | collector.fail(input); 41 | } 42 | } 43 | 44 | @Override 45 | public void declareOutputFields(OutputFieldsDeclarer declarer) { 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Sentinel/src/main/java/top/itning/sentinel/config/datasource/FileRefreshableDataSourceWithLog.java: -------------------------------------------------------------------------------- 1 | package top.itning.sentinel.config.datasource; 2 | 3 | import com.alibaba.csp.sentinel.datasource.Converter; 4 | import com.alibaba.csp.sentinel.datasource.FileRefreshableDataSource; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.io.FileNotFoundException; 9 | 10 | /** 11 | *

拉模式 12 | *

内部实现线程池自动轮询检查文件是否变化 13 | * 14 | * @author itning 15 | * @date 2020/8/22 15:58 16 | */ 17 | public class FileRefreshableDataSourceWithLog extends FileRefreshableDataSource { 18 | private static final Logger logger = LoggerFactory.getLogger(FileRefreshableDataSourceWithLog.class); 19 | 20 | public FileRefreshableDataSourceWithLog(String fileName, Converter configParser) throws FileNotFoundException { 21 | super(fileName, configParser); 22 | } 23 | 24 | @Override 25 | public String readSource() throws Exception { 26 | String source = super.readSource(); 27 | logger.info("Read Source: {}", source); 28 | return source; 29 | } 30 | 31 | @Override 32 | protected boolean isModified() { 33 | boolean modified = super.isModified(); 34 | if (modified) { 35 | logger.info("Is Modified: true"); 36 | } 37 | return modified; 38 | } 39 | 40 | @Override 41 | public void close() throws Exception { 42 | logger.info("close"); 43 | super.close(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /UDP/src/main/java/top/itning/udp/UdpClient.java: -------------------------------------------------------------------------------- 1 | package top.itning.udp; 2 | 3 | import java.io.IOException; 4 | import java.net.DatagramPacket; 5 | import java.net.DatagramSocket; 6 | import java.nio.charset.StandardCharsets; 7 | 8 | /** 9 | * @author itning 10 | * @date 2019/4/25 16:30 11 | */ 12 | public class UdpClient { 13 | public static void main(String[] args) throws IOException { 14 | //接收10000端口的UDP数据 15 | DatagramSocket socket = new DatagramSocket(10000); 16 | final byte[] buf = new byte[1024]; 17 | DatagramPacket packet = new DatagramPacket(buf, buf.length); 18 | while (true) { 19 | socket.receive(packet); 20 | byte[] data = packet.getData(); 21 | String stringBuilder = "udp://" + 22 | packet.getAddress().getHostAddress() + 23 | ":" + 24 | packet.getPort() + 25 | " " + 26 | new String(data, 0, packet.getLength(), StandardCharsets.UTF_8) + 27 | " and length " + 28 | packet.getLength(); 29 | System.out.println(stringBuilder); 30 | 31 | //回传给服务器 32 | final byte[] back = ("Client Get Data Length " + packet.getLength()).getBytes(); 33 | DatagramPacket backPack = new DatagramPacket(back, back.length, packet.getAddress(), packet.getPort()); 34 | backPack.setData(back); 35 | socket.send(backPack); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/concurrent/threadpool/ManualThreadPoolTest.java: -------------------------------------------------------------------------------- 1 | package concurrent.threadpool; 2 | 3 | import com.google.common.util.concurrent.ThreadFactoryBuilder; 4 | 5 | import java.util.concurrent.*; 6 | 7 | /** 8 | * 手动创建线程池 9 | * 10 | * @author itning 11 | */ 12 | public class ManualThreadPoolTest { 13 | public static void main(String[] args) { 14 | ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("demo-pool-%d").build(); 15 | ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor( 16 | //核心线程池大小 17 | 0, 18 | //线程池最大线程数 19 | Integer.MAX_VALUE, 20 | //表示线程没有任务执行时最多保持多久时间会终止,然后线程池的数目维持在corePoolSize 大小 21 | 60L, 22 | //参数keepAliveTime的时间单位 23 | TimeUnit.SECONDS, 24 | //一个阻塞队列,用来存储等待执行的任务,如果当前对线程的需求超过了corePoolSize大小,才会放在这里 25 | new SynchronousQueue<>(), 26 | //线程工厂,主要用来创建线程,比如可以指定线程的名字 27 | namedThreadFactory, 28 | //如果线程池已满,新的任务的处理方式 29 | new RejectedExecutionHandler() { 30 | 31 | @Override 32 | public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { 33 | // 34 | } 35 | }); 36 | threadPoolExecutor.execute(() -> { 37 | System.out.println(Thread.currentThread().getName()); 38 | }); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/concurrent/completablefuture/CompletableFutureTest2.java: -------------------------------------------------------------------------------- 1 | package concurrent.completablefuture; 2 | 3 | import java.util.concurrent.CompletableFuture; 4 | import java.util.concurrent.CountDownLatch; 5 | 6 | /** 7 | * @author itning 8 | */ 9 | public class CompletableFutureTest2 { 10 | public static void main(String[] args) throws InterruptedException { 11 | long l = System.currentTimeMillis(); 12 | CompletableFuture completableFuture = CompletableFuture.supplyAsync(() -> { 13 | System.out.println("在回调中执行耗时操作..."); 14 | timeConsumingOperation(); 15 | return 100; 16 | }); 17 | // 使用 thenCompose 或者 thenComposeAsync 等方法可以实现回调的回调,且写出来的方法易于维护。 18 | completableFuture = completableFuture.thenCompose(i -> { 19 | return CompletableFuture.supplyAsync(() -> { 20 | System.out.println("在回调的回调中执行耗时操作..."); 21 | timeConsumingOperation(); 22 | return i + 100; 23 | }); 24 | }); 25 | completableFuture.whenComplete((result, e) -> { 26 | System.out.println("计算结果:" + result); 27 | }); 28 | System.out.println("主线程运算耗时:" + (System.currentTimeMillis() - l)+ "ms"); 29 | new CountDownLatch(1).await(); 30 | } 31 | 32 | private static void timeConsumingOperation() { 33 | try { 34 | Thread.sleep(3000); 35 | } catch (Exception e) { 36 | e.printStackTrace(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Hadoop/src/main/java/mr/WordCountRunner.java: -------------------------------------------------------------------------------- 1 | package mr; 2 | 3 | import org.apache.hadoop.conf.Configuration; 4 | import org.apache.hadoop.fs.Path; 5 | import org.apache.hadoop.io.LongWritable; 6 | import org.apache.hadoop.io.Text; 7 | import org.apache.hadoop.mapreduce.Job; 8 | import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; 9 | import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; 10 | import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; 11 | 12 | import java.io.IOException; 13 | 14 | /** 15 | * @author itning 16 | */ 17 | public class WordCountRunner { 18 | public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException { 19 | Configuration configuration = new Configuration(); 20 | Job job = Job.getInstance(configuration); 21 | 22 | job.setJarByClass(WordCountRunner.class); 23 | 24 | job.setMapperClass(WordCountMapper.class); 25 | job.setReducerClass(WordCountReducer.class); 26 | 27 | job.setMapOutputKeyClass(Text.class); 28 | job.setMapOutputValueClass(LongWritable.class); 29 | 30 | job.setOutputKeyClass(Text.class); 31 | job.setOutputValueClass(LongWritable.class); 32 | 33 | job.setInputFormatClass(TextInputFormat.class); 34 | 35 | FileInputFormat.setInputPaths(job, "hdfs://192.168.1.11:9000/in2"); 36 | FileOutputFormat.setOutputPath(job, new Path("hdfs://192.168.1.11:9000/out/wordcount")); 37 | 38 | job.waitForCompletion(true); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Nio/src/main/java/top/itning/nio/ServerSocketClient.java: -------------------------------------------------------------------------------- 1 | package top.itning.nio; 2 | 3 | import java.io.IOException; 4 | import java.net.InetSocketAddress; 5 | import java.nio.ByteBuffer; 6 | import java.nio.channels.SocketChannel; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | /** 10 | * @author itning 11 | */ 12 | public class ServerSocketClient { 13 | public static void main(String[] args) { 14 | ByteBuffer buffer = ByteBuffer.allocate(1024); 15 | try (SocketChannel socketChannel = SocketChannel.open()) { 16 | //是否阻塞 17 | socketChannel.configureBlocking(false); 18 | socketChannel.connect(new InetSocketAddress("localhost", 8080)); 19 | if (socketChannel.finishConnect()) { 20 | int i = 0; 21 | //循环发送 22 | while (i < 5) { 23 | TimeUnit.SECONDS.sleep(1); 24 | String info = "I'm " + i++ + "-th information from client"; 25 | buffer.clear(); 26 | buffer.put(info.getBytes()); 27 | //翻转 使可读 28 | buffer.flip(); 29 | while (buffer.hasRemaining()) { 30 | System.out.println(buffer); 31 | socketChannel.write(buffer); 32 | } 33 | } 34 | socketChannel.close(); 35 | } 36 | } catch (IOException | InterruptedException e) { 37 | e.printStackTrace(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Blockingqueue/src/main/java/blockingqueue/DelayQueueTest.java: -------------------------------------------------------------------------------- 1 | package blockingqueue; 2 | 3 | import java.util.concurrent.DelayQueue; 4 | import java.util.concurrent.Delayed; 5 | import java.util.concurrent.TimeUnit; 6 | 7 | /** 8 | * 延迟阻塞队列 9 | * 10 | * @author itning 11 | */ 12 | public class DelayQueueTest { 13 | public static void main(String[] args) throws Exception { 14 | DelayQueue delayQueue = new DelayQueue<>(); 15 | long now = System.currentTimeMillis(); 16 | delayQueue.put(new Task(now + 3000)); 17 | delayQueue.put(new Task(now + 4000)); 18 | delayQueue.put(new Task(now + 6000)); 19 | delayQueue.put(new Task(now + 1000)); 20 | System.out.println(delayQueue); 21 | 22 | for (int i = 0; i < 4; i++) { 23 | System.out.println(delayQueue.take()); 24 | } 25 | 26 | } 27 | 28 | static class Task implements Delayed { 29 | long time; 30 | 31 | Task(long time) { 32 | this.time = time; 33 | } 34 | 35 | @Override 36 | public int compareTo(Delayed o) { 37 | return Long.compare(this.getDelay(TimeUnit.MILLISECONDS), o.getDelay(TimeUnit.MILLISECONDS)); 38 | } 39 | 40 | @Override 41 | public long getDelay(TimeUnit unit) { 42 | return unit.convert(time - System.currentTimeMillis(), TimeUnit.MILLISECONDS); 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "" + time; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/concurrent/semaphore/SemaphoreTest.java: -------------------------------------------------------------------------------- 1 | package concurrent.semaphore; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | import java.util.concurrent.Semaphore; 6 | 7 | /** 8 | * 信号量 9 | * 10 | * @author itning 11 | */ 12 | @SuppressWarnings("all") 13 | public class SemaphoreTest { 14 | // 请求的数量 15 | private static final int THREAD_COUNT = 550; 16 | 17 | public static void main(String[] args) { 18 | // 创建一个具有固定线程数量的线程池对象(如果这里线程池的线程数量给太少的话你会发现执行的很慢) 19 | ExecutorService threadPool = Executors.newFixedThreadPool(300); 20 | // 一次只能允许执行的线程数量。 21 | final Semaphore semaphore = new Semaphore(20); 22 | 23 | for (int i = 0; i < THREAD_COUNT; i++) { 24 | final int threadnum = i; 25 | threadPool.execute(() -> {// Lambda 表达式的运用 26 | try { 27 | semaphore.acquire();// 获取一个许可,所以可运行线程数量为20/1=20 28 | test(threadnum); 29 | semaphore.release();// 释放一个许可 30 | } catch (InterruptedException e) { 31 | e.printStackTrace(); 32 | } 33 | 34 | }); 35 | } 36 | threadPool.shutdown(); 37 | System.out.println("finish"); 38 | } 39 | 40 | public static void test(int threadnum) throws InterruptedException { 41 | Thread.sleep(1000);// 模拟请求的耗时操作 42 | System.out.println("threadnum:" + threadnum); 43 | Thread.sleep(1000);// 模拟请求的耗时操作 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Disruptor/src/main/java/top/itning/disruptor/high/Trade.java: -------------------------------------------------------------------------------- 1 | package top.itning.disruptor.high; 2 | 3 | import java.util.concurrent.atomic.AtomicInteger; 4 | 5 | /** 6 | * 交易 7 | * 8 | * @author itning 9 | * @date 2019/5/9 21:27 10 | */ 11 | public class Trade { 12 | /** 13 | * id 14 | */ 15 | private String id; 16 | /** 17 | * 交易名 18 | */ 19 | private String name; 20 | /** 21 | * 价格 22 | */ 23 | private double price; 24 | /** 25 | * 统计 26 | */ 27 | private AtomicInteger count = new AtomicInteger(0); 28 | 29 | public String getId() { 30 | return id; 31 | } 32 | 33 | public void setId(String id) { 34 | this.id = id; 35 | } 36 | 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | public double getPrice() { 46 | return price; 47 | } 48 | 49 | public void setPrice(double price) { 50 | this.price = price; 51 | } 52 | 53 | public AtomicInteger getCount() { 54 | return count; 55 | } 56 | 57 | public void setCount(AtomicInteger count) { 58 | this.count = count; 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "Trade{" + 64 | "id='" + id + '\'' + 65 | ", name='" + name + '\'' + 66 | ", price=" + price + 67 | ", count=" + count + 68 | '}'; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Netty/src/main/java/top/itning/netty/simple/client/SimpleClient.java: -------------------------------------------------------------------------------- 1 | package top.itning.netty.simple.client; 2 | 3 | import io.netty.bootstrap.Bootstrap; 4 | import io.netty.channel.ChannelInitializer; 5 | import io.netty.channel.ChannelOption; 6 | import io.netty.channel.EventLoopGroup; 7 | import io.netty.channel.nio.NioEventLoopGroup; 8 | import io.netty.channel.socket.SocketChannel; 9 | import io.netty.channel.socket.nio.NioSocketChannel; 10 | 11 | /** 12 | * 简单客户端 13 | * 14 | * @author itning 15 | */ 16 | public class SimpleClient { 17 | public static void main(String[] args) throws Exception { 18 | EventLoopGroup loopGroup = new NioEventLoopGroup(); 19 | try { 20 | new Bootstrap() 21 | .group(loopGroup) 22 | .channel(NioSocketChannel.class) 23 | .option(ChannelOption.SO_KEEPALIVE, true) 24 | .handler(new ChannelInitializer() { 25 | @Override 26 | protected void initChannel(SocketChannel ch) throws Exception { 27 | ch.pipeline().addLast(new SimpleClientHandler()); 28 | } 29 | }) 30 | .connect("127.0.0.1", 8080) 31 | .sync() 32 | // 等待连接关闭 33 | .channel() 34 | .closeFuture() 35 | .sync(); 36 | } finally { 37 | loopGroup.shutdownGracefully(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Algorithm/src/main/java/top/itning/robustness/Solution.java: -------------------------------------------------------------------------------- 1 | package top.itning.robustness; 2 | 3 | import java.util.LinkedList; 4 | 5 | /** 6 | * 输入一个链表,输出该链表中倒数第k个结点。 7 | * 8 | * @author itning 9 | * @date 2019/7/7 22:07 10 | */ 11 | public class Solution { 12 | public static void main(String[] args) { 13 | ListNode listNode1 = new ListNode(67); 14 | ListNode listNode2 = new ListNode(0); 15 | ListNode listNode3 = new ListNode(24); 16 | ListNode listNode4 = new ListNode(58); 17 | listNode1.next = listNode2; 18 | listNode2.next = listNode3; 19 | listNode3.next = listNode4; 20 | ListNode listNode = new Solution().FindKthToTail(listNode1, 4); 21 | System.out.println(listNode.val); 22 | } 23 | 24 | public ListNode FindKthToTail(ListNode head, int k) { 25 | if (k < 1) { 26 | return null; 27 | } 28 | if (head == null) { 29 | return null; 30 | } 31 | LinkedList linkedList = new LinkedList<>(); 32 | ListNode next = head; 33 | do { 34 | linkedList.add(next); 35 | next = next.next; 36 | } while (next != null); 37 | if (k > linkedList.size()) { 38 | return null; 39 | } 40 | return linkedList.get(linkedList.size() - k); 41 | } 42 | 43 | public static class ListNode { 44 | int val; 45 | ListNode next = null; 46 | 47 | ListNode(int val) { 48 | this.val = val; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Leetcode/src/test/java/top/itning/test/LongestPalindromicSubstringTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.test; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | /** 7 | * 5. 最长回文子串 8 | * 给你一个字符串 s,找到 s 中最长的回文子串。 9 | * 10 | * @author itning 11 | * @since 2021/12/6 11:10 12 | */ 13 | public class LongestPalindromicSubstringTest { 14 | @Test 15 | void longestPalindromeTest() { 16 | Assertions.assertEquals("bb", longestPalindrome("cbbd")); 17 | Assertions.assertEquals("bab", longestPalindrome("babad")); 18 | Assertions.assertEquals("a", longestPalindrome("a")); 19 | Assertions.assertEquals("a", longestPalindrome("ac")); 20 | } 21 | 22 | public String longestPalindrome(String s) { 23 | String ans = ""; 24 | int max = 0; 25 | int len = s.length(); 26 | for (int i = 0; i < len; i++) 27 | for (int j = i + 1; j <= len; j++) { 28 | String test = s.substring(i, j); 29 | if (isPalindromic(test) && test.length() > max) { 30 | ans = s.substring(i, j); 31 | max = Math.max(max, ans.length()); 32 | } 33 | } 34 | return ans; 35 | } 36 | 37 | public boolean isPalindromic(String s) { 38 | int len = s.length(); 39 | for (int i = 0; i < len / 2; i++) { 40 | if (s.charAt(i) != s.charAt(len - i - 1)) { 41 | return false; 42 | } 43 | } 44 | return true; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Guava/src/main/java/top/itning/bigdata/guava/caches/CachesTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.bigdata.guava.caches; 2 | 3 | import com.google.common.cache.*; 4 | import org.junit.Test; 5 | 6 | import javax.annotation.ParametersAreNonnullByDefault; 7 | import java.util.concurrent.ExecutionException; 8 | import java.util.concurrent.TimeUnit; 9 | 10 | /** 11 | * 缓存 12 | * 13 | * @author itning 14 | */ 15 | public class CachesTest { 16 | @Test 17 | public void test() throws ExecutionException { 18 | LoadingCache graphs = CacheBuilder.newBuilder() 19 | .maximumSize(1000) 20 | .expireAfterWrite(10, TimeUnit.MINUTES) 21 | .removalListener(new RemovalListener() { 22 | @Override 23 | @ParametersAreNonnullByDefault 24 | public void onRemoval(RemovalNotification notification) { 25 | System.out.println(notification); 26 | } 27 | }) 28 | .build(new CacheLoader() { 29 | @Override 30 | @ParametersAreNonnullByDefault 31 | public String load(String key) throws Exception { 32 | return "k:" + key; 33 | } 34 | }); 35 | 36 | Cache cache = CacheBuilder.newBuilder() 37 | .build(); 38 | String kk = graphs.get("kk"); 39 | System.out.println(kk); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Leetcode/src/test/java/top/itning/test/RemoveDuplicatesFromSortedListTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.test; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | /** 6 | * 给定一个已排序的链表的头 head , 删除所有重复的元素,使每个元素只出现一次 。返回 已排序的链表 。 7 | * 8 | * @author itning 9 | * @since 2022/2/14 13:09 10 | */ 11 | public class RemoveDuplicatesFromSortedListTest { 12 | @Test 13 | void removeDuplicatesFromSortedListTest() { 14 | ListNode listNode = deleteDuplicates(new ListNode(1, new ListNode(1))); 15 | System.out.println(listNode); 16 | } 17 | 18 | public ListNode deleteDuplicates(ListNode head) { 19 | if (head == null) { 20 | return null; 21 | } 22 | ListNode first = new ListNode(head.val); 23 | ListNode listNode = first; 24 | while (head != null) { 25 | if (listNode.val != head.val) { 26 | listNode.next = new ListNode(head.val); 27 | listNode = listNode.next; 28 | } 29 | head = head.next; 30 | } 31 | return first; 32 | } 33 | 34 | public class ListNode { 35 | int val; 36 | ListNode next; 37 | 38 | ListNode() { 39 | } 40 | 41 | ListNode(int val) { 42 | this.val = val; 43 | } 44 | 45 | ListNode(int val, ListNode next) { 46 | this.val = val; 47 | this.next = next; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return "val=" + val + ", next=" + next; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Leetcode/src/test/java/top/itning/test/ImplementStrstrTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.test; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | /** 7 | * 实现strStr()函数。 8 | *

9 | * 给你两个字符串haystack 和 needle ,请你在 haystack 字符串中找出 needle 字符串出现的第一个位置(下标从 0 开始)。如果不存在,则返回 -1 。 10 | *

11 | * 来源:力扣(LeetCode) 12 | * 链接:https://leetcode-cn.com/problems/implement-strstr 13 | * 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 14 | * 15 | * @author itning 16 | * @since 2022/2/14 9:48 17 | */ 18 | public class ImplementStrstrTest { 19 | @Test 20 | void implementStrstrTest() { 21 | Assertions.assertEquals(2, strStr("hello", "ll")); 22 | Assertions.assertEquals(-1, strStr("aaaaa", "bba")); 23 | Assertions.assertEquals(0, strStr("", "")); 24 | } 25 | 26 | public int strStr(String haystack, String needle) { 27 | if (needle.length() == 0) { 28 | return 0; 29 | } 30 | if (needle.length() > haystack.length()) { 31 | return -1; 32 | } 33 | 34 | a: 35 | for (int i = 0; i < haystack.toCharArray().length; i++) { 36 | for (int i1 = 0; i1 < needle.toCharArray().length; i1++) { 37 | try { 38 | if (haystack.charAt(i + i1) != needle.charAt(i1)) { 39 | continue a; 40 | } 41 | } catch (Exception e) { 42 | continue a; 43 | } 44 | } 45 | return i; 46 | } 47 | return -1; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Kafka2Storm/src/main/java/top/itning/kafka2storm/WordCountBolt.java: -------------------------------------------------------------------------------- 1 | package top.itning.kafka2storm; 2 | 3 | import org.apache.storm.task.OutputCollector; 4 | import org.apache.storm.task.TopologyContext; 5 | import org.apache.storm.topology.OutputFieldsDeclarer; 6 | import org.apache.storm.topology.base.BaseRichBolt; 7 | import org.apache.storm.tuple.Tuple; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * @author itning 14 | */ 15 | public class WordCountBolt extends BaseRichBolt { 16 | 17 | private OutputCollector collector; 18 | private HashMap countMap = new HashMap<>(); 19 | 20 | @Override 21 | public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { 22 | this.collector = collector; 23 | } 24 | 25 | @Override 26 | public void execute(Tuple input) { 27 | try { 28 | String word = input.getStringByField("word"); 29 | System.out.println("WordCountBolt get->" + word + " !" + word.length()); 30 | if (countMap.containsKey(word)) { 31 | countMap.replace(word, countMap.get(word) + 1); 32 | } else { 33 | countMap.put(word, 1); 34 | } 35 | System.out.println(countMap); 36 | collector.ack(input); 37 | } catch (Exception e) { 38 | collector.reportError(e); 39 | collector.fail(input); 40 | } 41 | } 42 | 43 | @Override 44 | public void declareOutputFields(OutputFieldsDeclarer declarer) { 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/concurrent/threadpool/FixedThreadPoolTest.java: -------------------------------------------------------------------------------- 1 | package concurrent.threadpool; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | 6 | /** 7 | * 固定线程池 8 | * 9 | * @author itning 10 | */ 11 | @SuppressWarnings("all") 12 | public class FixedThreadPoolTest { 13 | public static void main(String[] args) { 14 | int processors = Runtime.getRuntime().availableProcessors(); 15 | System.out.println("当前CPU核数:" + processors); 16 | ExecutorService executorService = Executors.newFixedThreadPool(processors); 17 | executorService.submit(new Runnable() { 18 | @Override 19 | public void run() { 20 | System.out.println(Thread.currentThread().getName()); 21 | System.out.println(Math.random()); 22 | try { 23 | Thread.sleep(1000); 24 | } catch (InterruptedException e) { 25 | e.printStackTrace(); 26 | } 27 | } 28 | }); 29 | executorService.submit(new Runnable() { 30 | @Override 31 | public void run() { 32 | System.out.println(Thread.currentThread().getName()); 33 | System.out.println(Math.random()); 34 | try { 35 | Thread.sleep(1000); 36 | } catch (InterruptedException e) { 37 | e.printStackTrace(); 38 | } 39 | } 40 | }); 41 | executorService.shutdown(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Kafka2Storm/src/main/java/top/itning/kafka2storm/WordCountSplitBolt.java: -------------------------------------------------------------------------------- 1 | package top.itning.kafka2storm; 2 | 3 | import org.apache.storm.task.OutputCollector; 4 | import org.apache.storm.task.TopologyContext; 5 | import org.apache.storm.topology.OutputFieldsDeclarer; 6 | import org.apache.storm.topology.base.BaseRichBolt; 7 | import org.apache.storm.tuple.Fields; 8 | import org.apache.storm.tuple.Tuple; 9 | import org.apache.storm.tuple.Values; 10 | 11 | import java.util.Map; 12 | 13 | /** 14 | * @author itning 15 | */ 16 | public class WordCountSplitBolt extends BaseRichBolt { 17 | 18 | private OutputCollector collector; 19 | 20 | @Override 21 | public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { 22 | this.collector = collector; 23 | } 24 | 25 | @Override 26 | public void execute(Tuple input) { 27 | //"topic", "partition", "offset", "key", "value" 28 | try { 29 | String value = input.getStringByField("value"); 30 | System.out.println("WordCountSplitBolt get->" + value); 31 | char[] chars = value.toCharArray(); 32 | for (char c : chars) { 33 | collector.emit(new Values(String.valueOf(c))); 34 | } 35 | collector.ack(input); 36 | } catch (Exception e) { 37 | collector.reportError(e); 38 | collector.fail(input); 39 | } 40 | } 41 | 42 | @Override 43 | public void declareOutputFields(OutputFieldsDeclarer declarer) { 44 | declarer.declare(new Fields("word")); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Netty/src/main/java/top/itning/netty/websocket/WebSocketChatServerHandler.java: -------------------------------------------------------------------------------- 1 | package top.itning.netty.websocket; 2 | 3 | import io.netty.channel.Channel; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.channel.SimpleChannelInboundHandler; 6 | import io.netty.channel.group.ChannelGroup; 7 | import io.netty.channel.group.DefaultChannelGroup; 8 | import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; 9 | import io.netty.util.concurrent.GlobalEventExecutor; 10 | 11 | /** 12 | * @author itning 13 | * @date 2020/4/6 14:12 14 | */ 15 | public class WebSocketChatServerHandler extends SimpleChannelInboundHandler { 16 | private static final ChannelGroup CHANNELS = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); 17 | 18 | @Override 19 | protected void channelRead0(ChannelHandlerContext ctx, TextWebSocketFrame msg) throws Exception { 20 | String text = System.currentTimeMillis() + ": " + msg.text(); 21 | CHANNELS.forEach(channel -> channel.writeAndFlush(new TextWebSocketFrame(text))); 22 | } 23 | 24 | @Override 25 | public void handlerAdded(ChannelHandlerContext ctx) throws Exception { 26 | final Channel channel = ctx.channel(); 27 | System.out.println("up: " + channel.remoteAddress()); 28 | CHANNELS.add(channel); 29 | } 30 | 31 | @Override 32 | public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { 33 | final Channel channel = ctx.channel(); 34 | System.out.println("down: " + channel.remoteAddress()); 35 | CHANNELS.remove(channel); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /RabbitMQ/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.4.RELEASE 9 | 10 | 11 | top.itning 12 | rabbitmq 13 | 0.0.1-SNAPSHOT 14 | rabbitmq 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-amqp 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-test 30 | test 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-maven-plugin 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Hadoop/src/main/java/flow/FlowCountMapper.java: -------------------------------------------------------------------------------- 1 | package flow; 2 | 3 | import org.apache.commons.lang.math.NumberUtils; 4 | import org.apache.hadoop.io.LongWritable; 5 | import org.apache.hadoop.io.Text; 6 | import org.apache.hadoop.mapreduce.Mapper; 7 | 8 | import java.io.IOException; 9 | 10 | public class FlowCountMapper extends Mapper { 11 | private static final LongWritable LONG_WRITABLE = new LongWritable(); 12 | private static final FlowCountBean FLOW_COUNT_BEAN = new FlowCountBean(); 13 | 14 | @Override 15 | protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { 16 | LONG_WRITABLE.set(0); 17 | FLOW_COUNT_BEAN.clear(); 18 | String[] strings = value.toString().split("\t"); 19 | long tel = 0; 20 | long upload = 0; 21 | long download = 0; 22 | if (NumberUtils.isDigits(strings[1])) { 23 | tel = Long.parseLong(strings[1]); 24 | } 25 | if (NumberUtils.isDigits(strings[strings.length - 3])) { 26 | upload = Long.parseLong(strings[strings.length - 3]); 27 | } 28 | if (NumberUtils.isDigits(strings[strings.length - 2])) { 29 | download = Long.parseLong(strings[strings.length - 2]); 30 | } 31 | FLOW_COUNT_BEAN.setTel(tel); 32 | FLOW_COUNT_BEAN.setUpload(upload); 33 | FLOW_COUNT_BEAN.setDownload(download); 34 | FLOW_COUNT_BEAN.setSum(upload + download); 35 | LONG_WRITABLE.set(tel); 36 | context.write(LONG_WRITABLE, FLOW_COUNT_BEAN); 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Netty/src/main/java/top/itning/netty/chat/server/ChatServer.java: -------------------------------------------------------------------------------- 1 | package top.itning.netty.chat.server; 2 | 3 | import io.netty.bootstrap.ServerBootstrap; 4 | import io.netty.channel.ChannelInitializer; 5 | import io.netty.channel.ChannelOption; 6 | import io.netty.channel.nio.NioEventLoopGroup; 7 | import io.netty.channel.socket.SocketChannel; 8 | import io.netty.channel.socket.nio.NioServerSocketChannel; 9 | 10 | /** 11 | * 聊天服务器服务端 12 | * 13 | * @author itning 14 | */ 15 | public class ChatServer { 16 | public static void main(String[] args) throws Exception { 17 | NioEventLoopGroup boss = new NioEventLoopGroup(); 18 | NioEventLoopGroup worker = new NioEventLoopGroup(); 19 | try { 20 | new ServerBootstrap() 21 | .group(boss, worker) 22 | .channel(NioServerSocketChannel.class) 23 | .childHandler(new ChannelInitializer() { 24 | @Override 25 | protected void initChannel(SocketChannel ch) { 26 | ch.pipeline().addLast(new ChatServerHandler()); 27 | } 28 | }) 29 | .option(ChannelOption.SO_BACKLOG, 128) 30 | .childOption(ChannelOption.SO_KEEPALIVE, true) 31 | .bind(8866) 32 | .sync() 33 | .channel() 34 | .closeFuture() 35 | .sync(); 36 | } finally { 37 | worker.shutdownGracefully(); 38 | boss.shutdownGracefully(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Zookeeper/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | top.itning.bigdata 7 | 0.0.1-SNAPSHOT 8 | zookeeper 9 | 10 | 11 | 12 | 13 | org.apache.zookeeper 14 | zookeeper 15 | 3.4.11 16 | 17 | 18 | 19 | junit 20 | junit 21 | 4.13 22 | 23 | 24 | 25 | 26 | 27 | 28 | org.apache.maven.plugins 29 | maven-compiler-plugin 30 | 3.8.1 31 | 32 | 1.8 33 | 1.8 34 | UTF-8 35 | true 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Elasticsearch/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.5.RELEASE 9 | 10 | 11 | 4.0.0 12 | 13 | elasticsearch 14 | 15 | 1.8 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-data-elasticsearch 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-test 29 | test 30 | 31 | 32 | 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-maven-plugin 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Hadoop/src/main/java/mysql/MysqlRunner.java: -------------------------------------------------------------------------------- 1 | package mysql; 2 | 3 | import org.apache.hadoop.conf.Configuration; 4 | import org.apache.hadoop.fs.Path; 5 | import org.apache.hadoop.mapreduce.Job; 6 | import org.apache.hadoop.mapreduce.lib.db.DBConfiguration; 7 | import org.apache.hadoop.mapreduce.lib.db.DBInputFormat; 8 | import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; 9 | 10 | import java.io.IOException; 11 | 12 | 13 | public class MysqlRunner { 14 | public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException { 15 | System.setProperty("hadoop.home.dir", "G:\\winutils\\hadoop-2.8.3"); 16 | Configuration configuration = new Configuration(); 17 | 18 | Job job = Job.getInstance(configuration); 19 | 20 | job.setJar("G:\\ProjectData\\IdeaProjects\\BigData\\Hadoop\\target\\Hadoop-0.0.1-SNAPSHOT.jar"); 21 | 22 | //job.setJarByClass(MysqlRunner.class); 23 | 24 | job.setInputFormatClass(DBInputFormat.class); 25 | 26 | DBConfiguration.configureDB(configuration, "com.mysql.cj.jdbc.Driver", 27 | "jdbc:mysql://localhost:3306/bigdata?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true&failOverReadOnly=false&connectTimeout=0&serverTimezone=UTC", "root", "kingston"); 28 | String[] fields = {"id", "date", "pid", "amount"}; 29 | DBInputFormat.setInput(job, MysqlRecord.class, "t_order", null, null, fields); 30 | 31 | FileOutputFormat.setOutputPath(job, new Path("C:\\Users\\itning\\Desktop\\b")); 32 | 33 | job.waitForCompletion(true); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Hadoop/src/main/java/join/JoinMapper.java: -------------------------------------------------------------------------------- 1 | package join; 2 | 3 | import org.apache.hadoop.io.LongWritable; 4 | import org.apache.hadoop.io.Text; 5 | import org.apache.hadoop.mapreduce.Mapper; 6 | import org.apache.hadoop.mapreduce.lib.input.FileSplit; 7 | 8 | import java.io.IOException; 9 | 10 | public class JoinMapper extends Mapper { 11 | @Override 12 | protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { 13 | String[] strings = value.toString().split("\t"); 14 | JoinBean joinBean = new JoinBean(); 15 | if ("t_order.txt".equals(((FileSplit) context.getInputSplit()).getPath().getName())) { 16 | joinBean.setOid(Long.parseLong(strings[0])); 17 | joinBean.setOdate(strings[1]); 18 | joinBean.setOpid(strings[2]); 19 | joinBean.setOamount(Long.parseLong(strings[3])); 20 | 21 | joinBean.setPid(""); 22 | joinBean.setPname(""); 23 | joinBean.setCategory_id(""); 24 | joinBean.setPrice(0); 25 | 26 | context.write(new Text(strings[2]), joinBean); 27 | } else { 28 | joinBean.setPid(strings[0]); 29 | joinBean.setPname(strings[1]); 30 | joinBean.setCategory_id(strings[2]); 31 | joinBean.setPrice(Long.parseLong(strings[3])); 32 | 33 | joinBean.setOid(0); 34 | joinBean.setOdate(""); 35 | joinBean.setOpid(""); 36 | joinBean.setOamount(0); 37 | 38 | context.write(new Text(strings[0]), joinBean); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Jmh/src/main/java/top/itning/test/StringBuilderBenchmark.java: -------------------------------------------------------------------------------- 1 | package top.itning.test; 2 | 3 | import org.openjdk.jmh.annotations.*; 4 | import org.openjdk.jmh.infra.Blackhole; 5 | import org.openjdk.jmh.runner.Runner; 6 | import org.openjdk.jmh.runner.RunnerException; 7 | import org.openjdk.jmh.runner.options.Options; 8 | import org.openjdk.jmh.runner.options.OptionsBuilder; 9 | 10 | import java.util.concurrent.TimeUnit; 11 | 12 | /** 13 | * @author itning 14 | */ 15 | @BenchmarkMode(Mode.Throughput) 16 | @Warmup(iterations = 3) 17 | @Measurement(iterations = 10, time = 5, timeUnit = TimeUnit.SECONDS) 18 | @Threads(8) 19 | @Fork(2) 20 | @OutputTimeUnit(TimeUnit.MILLISECONDS) 21 | public class StringBuilderBenchmark { 22 | @Benchmark 23 | public void testStringAdd() { 24 | String a = ""; 25 | for (int i = 0; i < 10; i++) { 26 | a += i; 27 | } 28 | print(a); 29 | } 30 | 31 | @Benchmark 32 | public void testStringBuilderAdd(Blackhole bh) { 33 | // Blackhole会消费传进来的值,不提供任何信息来确定这些值是否在之后被实际使用 34 | StringBuilder sb = new StringBuilder(); 35 | for (int i = 0; i < 10; i++) { 36 | sb.append(i); 37 | } 38 | //bh.consume(sb.toString()); 39 | print(sb.toString()); 40 | } 41 | 42 | private void print(String a) { 43 | } 44 | 45 | public static void main(String[] args) throws RunnerException { 46 | Options options = new OptionsBuilder() 47 | .include(StringBuilderBenchmark.class.getSimpleName()) 48 | .output("E:/Benchmark.log") 49 | .build(); 50 | new Runner(options).run(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Concurrent/src/main/java/concurrent/atomic/AtomicNumber.java: -------------------------------------------------------------------------------- 1 | package concurrent.atomic; 2 | 3 | import java.util.concurrent.atomic.AtomicInteger; 4 | 5 | /** 6 | * Atomic 翻译成中文是原子的意思。在化学上,我们知道原子是构成一般物质的最小单位,在化学反应中是不可分割的。 7 | * 在我们这里 Atomic 是指一个操作是不可中断的。即使是在多个线程一起执行的时候,一个操作一旦开始,就不会被其他线程干扰。 8 | *

9 | * 所以,所谓原子类说简单点就是具有原子/原子操作特征的类。 10 | * 11 | * @author itning 12 | * @see java.util.concurrent.atomic.AtomicInteger 13 | * @see java.util.concurrent.atomic.AtomicBoolean 14 | * @see java.util.concurrent.atomic.AtomicLong 15 | * @see java.util.concurrent.atomic.AtomicReference 16 | * @see java.util.concurrent.atomic.AtomicIntegerArray 17 | * @see java.util.concurrent.atomic.AtomicLongArray 18 | * @see java.util.concurrent.atomic.AtomicReferenceArray 19 | */ 20 | public class AtomicNumber { 21 | public static void main(String[] args) { 22 | AtomicInteger atomicInteger = new AtomicInteger(10); 23 | System.out.println("获取当前的值: " + atomicInteger.get()); 24 | System.out.println("获取当前的值,并设置新的值: " + atomicInteger.getAndSet(20)); 25 | System.out.println("获取当前的值,并自增: " + atomicInteger.getAndIncrement()); 26 | System.out.println("获取当前的值,并自减: " + atomicInteger.getAndDecrement()); 27 | System.out.println("获取当前的值,并加上预期的值: " + atomicInteger.getAndAdd(5)); 28 | //AtomicIntegerFieldUpdater newUpdater = AtomicIntegerFieldUpdater.newUpdater(Class < U > tclass, String fieldName); 29 | //AtomicIntegerFieldUpdater:原子更新整形字段的更新器 30 | //AtomicLongFieldUpdater:原子更新长整形字段的更新器 31 | //AtomicStampedReference :原子更新带有版本号的引用类型。 32 | // 该类将整数值与引用关联起来,可用于解决原子的更新数据和数据的版本号,可以解决使用 CAS 进行原子更新时可能出现的 ABA 问题。 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Algorithm/src/main/java/top/itning/array/Solution.java: -------------------------------------------------------------------------------- 1 | package top.itning.array; 2 | 3 | import java.util.Arrays; 4 | import java.util.HashSet; 5 | 6 | /** 7 | * 在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序, 8 | * 每一列都按照从上到下递增的顺序排序。 9 | * 请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 10 | * 1 2 3 4 5 11 | * 2 3 4 5 6 12 | * 3 4 5 6 7 13 | * 4 5 6 7 8 14 | * 5 6 7 8 9 15 | * 16 | * @author itning 17 | * @date 2019/7/7 16:32 18 | */ 19 | public class Solution { 20 | public static void main(String[] args) { 21 | int[][] array = { 22 | {}, 23 | {2, 8, 13, 39, 100}, 24 | {3, 10, 16, 44, 101} 25 | }; 26 | boolean find = new Solution().Find(8, array); 27 | System.out.println(find); 28 | } 29 | 30 | public boolean Find(int target, int[][] array) { 31 | int oneLength = array[0].length; 32 | int twoLength = array.length; 33 | if (oneLength == 0 ) { 34 | return false; 35 | } 36 | int min = array[0][0]; 37 | int max = array[twoLength - 1][oneLength - 1]; 38 | if (target == max || target == min) { 39 | return true; 40 | } else { 41 | if (max < target) { 42 | //大于最大值 43 | return false; 44 | } else if (min > target) { 45 | //小于最小值 46 | return false; 47 | } else { 48 | HashSet set = new HashSet<>(oneLength * twoLength); 49 | Arrays.stream(array).flatMapToInt(Arrays::stream).forEach(set::add); 50 | return set.contains(target); 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Hadoop/src/main/java/join/JoinRunner.java: -------------------------------------------------------------------------------- 1 | package join; 2 | 3 | import org.apache.hadoop.conf.Configuration; 4 | import org.apache.hadoop.fs.Path; 5 | import org.apache.hadoop.io.Text; 6 | import org.apache.hadoop.mapreduce.Job; 7 | import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; 8 | import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; 9 | import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; 10 | 11 | import java.io.IOException; 12 | 13 | public class JoinRunner { 14 | public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException { 15 | System.setProperty("hadoop.home.dir", "G:\\winutils\\hadoop-2.8.3"); 16 | Configuration configuration = new Configuration(); 17 | 18 | Job job = Job.getInstance(configuration); 19 | 20 | job.setJarByClass(JoinRunner.class); 21 | 22 | job.setMapperClass(JoinMapper.class); 23 | job.setReducerClass(JoinReducer.class); 24 | 25 | job.setMapOutputKeyClass(Text.class); 26 | job.setMapOutputValueClass(JoinBean.class); 27 | 28 | job.setOutputKeyClass(Text.class); 29 | job.setOutputValueClass(JoinOutBean.class); 30 | 31 | job.setInputFormatClass(TextInputFormat.class); 32 | 33 | /*FileInputFormat.setInputPaths(job, "hdfs://192.168.1.11:9000/in"); 34 | FileOutputFormat.setOutputPath(job, new Path("hdfs://192.168.1.11:9000/out/flowcount"));*/ 35 | 36 | FileInputFormat.setInputPaths(job, new Path("C:\\Users\\itning\\Desktop\\a")); 37 | FileOutputFormat.setOutputPath(job, new Path("C:\\Users\\itning\\Desktop\\b")); 38 | 39 | job.waitForCompletion(true); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Leetcode/src/test/java/top/itning/test/PlusOneTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.test; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.util.Arrays; 6 | 7 | /** 8 | * 给定一个由 整数 组成的 非空 数组所表示的非负整数,在该数的基础上加一。 9 | *

10 | * 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字。 11 | *

12 | * 你可以假设除了整数 0 之外,这个整数不会以零开头。 13 | *

14 | * 来源:力扣(LeetCode) 15 | * 链接:https://leetcode-cn.com/problems/plus-one 16 | * 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 17 | * 18 | * @author itning 19 | * @since 2022/2/14 10:51 20 | */ 21 | public class PlusOneTest { 22 | @Test 23 | void plusOneTest() { 24 | System.out.println(Arrays.toString(plusOne(new int[]{1, 2, 4}))); 25 | System.out.println(Arrays.toString(plusOne(new int[]{1, 2, 9}))); 26 | System.out.println(Arrays.toString(plusOne(new int[]{9}))); 27 | } 28 | 29 | public int[] plusOne(int[] digits) { 30 | if (digits.length == 1 && digits[0] == 0) { 31 | digits[0] = 1; 32 | return digits; 33 | } 34 | int less = 0; 35 | for (int i = digits.length - 1; i >= 0; i--) { 36 | if (less != 0) { 37 | less = 0; 38 | } 39 | if (digits[i] + 1 == 10) { 40 | digits[i] = 0; 41 | less = 1; 42 | } else { 43 | digits[i] = digits[i] + 1; 44 | break; 45 | } 46 | } 47 | if (less == 1) { 48 | int[] result = new int[digits.length + 1]; 49 | result[0] = 1; 50 | System.arraycopy(digits, 0, result, 1, result.length - 1); 51 | return result; 52 | } 53 | return digits; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Sentinel/src/main/java/top/itning/sentinel/config/SentinelConfig.java: -------------------------------------------------------------------------------- 1 | package top.itning.sentinel.config; 2 | 3 | import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect; 4 | import com.alibaba.csp.sentinel.slots.block.RuleConstant; 5 | import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; 6 | import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import top.itning.sentinel.config.annotation.SentinelResourceProAspect; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | /** 17 | * @author itning 18 | * @date 2020/8/22 15:34 19 | */ 20 | @Configuration 21 | public class SentinelConfig { 22 | private static final Logger logger = LoggerFactory.getLogger(SentinelConfig.class); 23 | 24 | @Bean 25 | public SentinelResourceAspect sentinelResourceAspect() { 26 | initFlowRules(); 27 | return new SentinelResourceAspect(); 28 | } 29 | 30 | @Bean 31 | public SentinelResourceProAspect sentinelResourceProAspect() { 32 | return new SentinelResourceProAspect(); 33 | } 34 | 35 | public void initFlowRules() { 36 | List rules = new ArrayList<>(); 37 | FlowRule rule = new FlowRule(); 38 | rule.setResource("test"); 39 | rule.setGrade(RuleConstant.FLOW_GRADE_QPS); 40 | // Set limit QPS to 20. 41 | rule.setCount(5); 42 | rules.add(rule); 43 | FlowRuleManager.loadRules(rules); 44 | logger.info("Init Flow Rules Success"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Jmh/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | top.itning.bigdata 7 | 0.0.1-SNAPSHOT 8 | jmh 9 | 10 | 11 | 12 | 13 | org.openjdk.jmh 14 | jmh-core 15 | 1.21 16 | 17 | 18 | 19 | org.openjdk.jmh 20 | jmh-generator-annprocess 21 | 1.21 22 | provided 23 | 24 | 25 | 26 | 27 | 28 | 29 | org.apache.maven.plugins 30 | maven-compiler-plugin 31 | 3.8.1 32 | 33 | 1.8 34 | 1.8 35 | UTF-8 36 | true 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Hadoop/src/main/java/mysql/MysqlRecord.java: -------------------------------------------------------------------------------- 1 | package mysql; 2 | 3 | import org.apache.hadoop.io.Text; 4 | import org.apache.hadoop.io.Writable; 5 | import org.apache.hadoop.mapreduce.lib.db.DBWritable; 6 | 7 | import java.io.DataInput; 8 | import java.io.DataOutput; 9 | import java.io.IOException; 10 | import java.sql.Date; 11 | import java.sql.PreparedStatement; 12 | import java.sql.ResultSet; 13 | import java.sql.SQLException; 14 | 15 | public class MysqlRecord implements Writable, DBWritable { 16 | private int id; 17 | private Date date; 18 | private String pid; 19 | private int amount; 20 | 21 | @Override 22 | public void write(DataOutput out) throws IOException { 23 | out.writeInt(id); 24 | out.write(date.toString().getBytes()); 25 | Text.writeString(out, this.pid); 26 | out.write(amount); 27 | } 28 | 29 | @Override 30 | public void readFields(DataInput in) throws IOException { 31 | this.id = in.readInt(); 32 | this.date = Date.valueOf(Text.readString(in)); 33 | this.pid = in.readUTF(); 34 | this.amount = in.readInt(); 35 | } 36 | 37 | @Override 38 | public void write(PreparedStatement statement) throws SQLException { 39 | statement.setInt(1, this.id); 40 | statement.setDate(2, this.date); 41 | statement.setString(3, this.pid); 42 | statement.setInt(4, this.amount); 43 | } 44 | 45 | @Override 46 | public void readFields(ResultSet resultSet) throws SQLException { 47 | this.id = resultSet.getInt(1); 48 | this.date = resultSet.getDate(2); 49 | this.pid = resultSet.getString(3); 50 | this.amount = resultSet.getInt(4); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Leetcode/src/test/java/top/itning/test/LongestCommonPrefixTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.test; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | 6 | /** 7 | * 14. 最长公共前缀 8 | * 编写一个函数来查找字符串数组中的最长公共前缀。 9 | *

10 | * 如果不存在公共前缀,返回空字符串 ""。 11 | * 12 | * @author itning 13 | * @since 2021/12/7 14:27 14 | */ 15 | public class LongestCommonPrefixTest { 16 | @Test 17 | void longestCommonPrefixTest() { 18 | Assertions.assertEquals("fl", longestCommonPrefix(new String[]{"flower", "flow", "flight"})); 19 | Assertions.assertEquals("", longestCommonPrefix(new String[]{"dog", "racecar", "car"})); 20 | Assertions.assertEquals("", longestCommonPrefix(new String[]{"", "racecar", "car"})); 21 | } 22 | 23 | public String longestCommonPrefix(String[] strs) { 24 | // 1 <= strs.length <= 200 25 | // 0 <= strs[i].length <= 200 26 | // strs[i] 仅由小写英文字母组成 27 | int l = Integer.MAX_VALUE; 28 | for (String str : strs) { 29 | l = Math.min(l, str.length()); 30 | } 31 | if (l == Integer.MAX_VALUE || l == 0) { 32 | return ""; 33 | } 34 | StringBuilder sb = new StringBuilder(); 35 | a: 36 | for (int i = 0; i < l; i++) { 37 | for (int j = 0; j < strs.length; j++) { 38 | char c = strs[j].charAt(i); 39 | if (j + 1 != strs.length) { 40 | char cc = strs[j + 1].charAt(i); 41 | if (cc != c) { 42 | break a; 43 | } 44 | } 45 | } 46 | sb.append(strs[0].charAt(i)); 47 | } 48 | return sb.toString(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Algorithm/src/main/java/top/itning/linked/Solution.java: -------------------------------------------------------------------------------- 1 | package top.itning.linked; 2 | 3 | import java.util.ArrayDeque; 4 | import java.util.ArrayList; 5 | import java.util.Deque; 6 | 7 | /** 8 | * 输入一个链表,按链表值从尾到头的顺序返回一个ArrayList。 9 | * 10 | * @author itning 11 | * @date 2019/7/7 17:37 12 | */ 13 | public class Solution { 14 | public static void main(String[] args) { 15 | //67,0,24,58 16 | ListNode listNode1 = new ListNode(67); 17 | ListNode listNode2 = new ListNode(0); 18 | ListNode listNode3 = new ListNode(24); 19 | ListNode listNode4 = new ListNode(58); 20 | listNode1.next = listNode2; 21 | listNode2.next = listNode3; 22 | listNode3.next = listNode4; 23 | ArrayList arrayList = new Solution().printListFromTailToHead(listNode1); 24 | System.out.println(arrayList); 25 | } 26 | 27 | public ArrayList printListFromTailToHead(ListNode listNode) { 28 | if (listNode == null) { 29 | return new ArrayList<>(0); 30 | } 31 | Deque deque = new ArrayDeque<>(); 32 | ListNode next = listNode; 33 | do { 34 | deque.push(next.val); 35 | next = next.next; 36 | } while (next != null); 37 | ArrayList arrayList = new ArrayList<>(deque.size()); 38 | Integer last = deque.poll(); 39 | while (last != null) { 40 | arrayList.add(last); 41 | last = deque.poll(); 42 | } 43 | return arrayList; 44 | } 45 | 46 | public static class ListNode { 47 | int val; 48 | ListNode next = null; 49 | 50 | ListNode(int val) { 51 | this.val = val; 52 | } 53 | } 54 | } 55 | --------------------------------------------------------------------------------