├── .gitignore ├── CNAME ├── D: └── com │ └── brmayi │ └── repository │ └── com │ └── brmayi │ └── epiphany │ ├── 0.15 │ ├── epiphany-0.15-javadoc.jar │ ├── epiphany-0.15-javadoc.jar.md5 │ ├── epiphany-0.15-javadoc.jar.sha1 │ ├── epiphany-0.15-sources.jar │ ├── epiphany-0.15-sources.jar.md5 │ ├── epiphany-0.15-sources.jar.sha1 │ ├── epiphany-0.15.jar │ ├── epiphany-0.15.jar.md5 │ ├── epiphany-0.15.jar.sha1 │ ├── epiphany-0.15.pom │ ├── epiphany-0.15.pom.md5 │ ├── epiphany-0.15.pom.sha1 │ ├── epiphany-0.15.tar.gz │ ├── epiphany-0.15.tar.gz.md5 │ └── epiphany-0.15.tar.gz.sha1 │ ├── maven-metadata.xml │ ├── maven-metadata.xml.md5 │ └── maven-metadata.xml.sha1 ├── README.md ├── assembly.xml ├── pom.xml └── src └── main └── java └── com └── brmayi └── epiphany ├── business ├── FullBusinessTask.java ├── FullStartupTask.java ├── IncrementBusinessTask.java ├── NiceQueueTask.java ├── common │ └── RedisUtils.java └── socket │ └── ManuallyHttpServer.java ├── common └── Startup.java ├── exception └── EpiphanyException.java ├── model └── KeyValue.java ├── pool ├── LimitedKeyedPoolableObjectFactory.java └── UnlimitedKeyedPoolableObjectFactory.java ├── serializer └── ObjectRedisSerializer.java ├── service └── DataService.java └── util ├── EpiphanyFileUtil.java ├── GzCompressUtil.java ├── TimerUtil.java └── sub └── GzCompress.java /.gitignore: -------------------------------------------------------------------------------- 1 | **/*.class 2 | 3 | target/** 4 | 5 | **/*.iml 6 | 7 | .idea/** 8 | 9 | **/.DS_Store 10 | 11 | .settings/** 12 | 13 | **/.settings/** 14 | 15 | .project 16 | 17 | target 18 | 19 | .classpath 20 | 21 | /bin/ 22 | /target/ 23 | -------------------------------------------------------------------------------- /CNAME: -------------------------------------------------------------------------------- 1 | www.brmayi.com 2 | -------------------------------------------------------------------------------- /D:/com/brmayi/repository/com/brmayi/epiphany/0.15/epiphany-0.15-javadoc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiexiaojing/epiphany/451de5acd4704736c778ec2370ddf322dd129b09/D:/com/brmayi/repository/com/brmayi/epiphany/0.15/epiphany-0.15-javadoc.jar -------------------------------------------------------------------------------- /D:/com/brmayi/repository/com/brmayi/epiphany/0.15/epiphany-0.15-javadoc.jar.md5: -------------------------------------------------------------------------------- 1 | 32896111f1f55c01e09ad0cfe11d87c1 -------------------------------------------------------------------------------- /D:/com/brmayi/repository/com/brmayi/epiphany/0.15/epiphany-0.15-javadoc.jar.sha1: -------------------------------------------------------------------------------- 1 | 5debcdabacee42ba39a825f0250f19fc2f737b60 -------------------------------------------------------------------------------- /D:/com/brmayi/repository/com/brmayi/epiphany/0.15/epiphany-0.15-sources.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiexiaojing/epiphany/451de5acd4704736c778ec2370ddf322dd129b09/D:/com/brmayi/repository/com/brmayi/epiphany/0.15/epiphany-0.15-sources.jar -------------------------------------------------------------------------------- /D:/com/brmayi/repository/com/brmayi/epiphany/0.15/epiphany-0.15-sources.jar.md5: -------------------------------------------------------------------------------- 1 | 92f0b4915537a55a7d361dce574e7246 -------------------------------------------------------------------------------- /D:/com/brmayi/repository/com/brmayi/epiphany/0.15/epiphany-0.15-sources.jar.sha1: -------------------------------------------------------------------------------- 1 | 4bc869e314c5a7baece475edf20938afec909477 -------------------------------------------------------------------------------- /D:/com/brmayi/repository/com/brmayi/epiphany/0.15/epiphany-0.15.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiexiaojing/epiphany/451de5acd4704736c778ec2370ddf322dd129b09/D:/com/brmayi/repository/com/brmayi/epiphany/0.15/epiphany-0.15.jar -------------------------------------------------------------------------------- /D:/com/brmayi/repository/com/brmayi/epiphany/0.15/epiphany-0.15.jar.md5: -------------------------------------------------------------------------------- 1 | bd6cfe9b2510f90139ae9b33669c337d -------------------------------------------------------------------------------- /D:/com/brmayi/repository/com/brmayi/epiphany/0.15/epiphany-0.15.jar.sha1: -------------------------------------------------------------------------------- 1 | 8401ed20b3309bb7844ca5fa24122eb578ada918 -------------------------------------------------------------------------------- /D:/com/brmayi/repository/com/brmayi/epiphany/0.15/epiphany-0.15.pom: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.brmayi 7 | epiphany 8 | jar 9 | 0.15 10 | epiphany 11 | 12 | 13 | UTF-8 14 | 3.2.8.RELEASE 15 | 1.0.2-RELEASE 16 | 17 | 18 | 19 | 20 | org.springframework 21 | spring-core 22 | ${spring.version} 23 | 24 | 25 | org.slf4j 26 | slf4j-api 27 | 1.7.21 28 | 29 | 30 | org.slf4j 31 | jcl-over-slf4j 32 | 1.7.21 33 | 34 | 35 | org.slf4j 36 | jul-to-slf4j 37 | 1.7.21 38 | 39 | 40 | org.slf4j 41 | log4j-over-slf4j 42 | 1.7.21 43 | 44 | 45 | ch.qos.logback 46 | logback-core 47 | 1.1.7 48 | 49 | 50 | ch.qos.logback 51 | logback-classic 52 | 1.1.7 53 | 54 | 55 | org.apache.commons 56 | commons-lang3 57 | 3.1 58 | 59 | 60 | org.springframework 61 | spring-aop 62 | ${spring.version} 63 | 64 | 65 | org.springframework 66 | spring-aspects 67 | ${spring.version} 68 | 69 | 70 | org.springframework 71 | spring-beans 72 | ${spring.version} 73 | 74 | 75 | org.springframework 76 | spring-context 77 | ${spring.version} 78 | 79 | 80 | org.springframework 81 | spring-context-support 82 | ${spring.version} 83 | 84 | 85 | org.springframework 86 | spring-jms 87 | ${spring.version} 88 | 89 | 90 | org.springframework 91 | spring-jdbc 92 | ${spring.version} 93 | 94 | 95 | org.apache.qpid 96 | qpid-client 97 | 0.24 98 | 99 | 100 | org.springframework 101 | spring-web 102 | ${spring.version} 103 | 104 | 105 | org.springframework 106 | spring-webmvc 107 | ${spring.version} 108 | 109 | 110 | org.springframework.data 111 | spring-data-redis 112 | 1.8.4.RELEASE 113 | 114 | 115 | redis.clients 116 | jedis 117 | 2.9.0 118 | 119 | 120 | com.alibaba 121 | fastjson 122 | 1.1.41 123 | 124 | 125 | mysql 126 | mysql-connector-java 127 | 5.1.26 128 | 129 | 130 | commons-dbcp 131 | commons-dbcp 132 | 1.4 133 | 134 | 135 | com.googlecode.log4jdbc 136 | log4jdbc 137 | 1.2 138 | 139 | 140 | org.jfaster 141 | mango 142 | 1.4.1 143 | 144 | 145 | org.codehaus.janino 146 | janino 147 | 2.7.8 148 | 149 | 150 | commons-pool 151 | commons-pool 152 | 1.6 153 | 154 | 155 | io.netty 156 | netty-all 157 | 4.1.7.Final 158 | 159 | 160 | net.sf.json-lib 161 | json-lib 162 | 2.4 163 | jdk15 164 | 165 | 166 | javax.jms 167 | javax.jms-api 168 | 2.0.1 169 | 170 | 171 | xerces 172 | xercesImpl 173 | 2.11.0 174 | 175 | 176 | org.perf4j 177 | perf4j 178 | 0.9.16 179 | 180 | 181 | 182 | 183 | epiphany 184 | 185 | 186 | ../lib 187 | src/main/resources 188 | 189 | lib/*.jar 190 | 191 | 192 | 193 | src/main/resources 194 | 195 | spring/ 196 | properties/* 197 | spring/* 198 | *.xml 199 | deploy/* 200 | 201 | true 202 | 203 | 204 | src/main/resources 205 | true 206 | 207 | deploy/* 208 | 209 | ${project.build.directory} 210 | 211 | 212 | 213 | 214 | org.apache.maven.plugins 215 | maven-assembly-plugin 216 | 2.3 217 | 218 | false 219 | 220 | assembly.xml 221 | 222 | 223 | 224 | 225 | make-assembly 226 | package 227 | 228 | single 229 | 230 | 231 | 232 | 233 | 234 | org.apache.maven.plugins 235 | maven-surefire-plugin 236 | 2.16 237 | 238 | true 239 | 240 | 241 | 242 | maven-resources-plugin 243 | 244 | 245 | maven-compiler-plugin 246 | 247 | 248 | maven-source-plugin 249 | 250 | 251 | maven-javadoc-plugin 252 | 253 | 254 | maven-deploy-plugin 255 | 256 | 257 | 258 | 259 | 260 | org.apache.maven.plugins 261 | maven-compiler-plugin 262 | 2.3.2 263 | 264 | 1.7 265 | 1.7 266 | UTF-8 267 | true 268 | 1g 269 | 2g 270 | 271 | 272 | 273 | org.mortbay.jetty 274 | maven-jetty-plugin 275 | 6.1.7 276 | 277 | 278 | org.apache.maven.plugins 279 | maven-resources-plugin 280 | 2.5 281 | 282 | UTF-8 283 | ${project.build.outputDirectory} 284 | 285 | 286 | 287 | org.apache.maven.plugins 288 | maven-jar-plugin 289 | 2.3 290 | 291 | 292 | maven-source-plugin 293 | 2.1.2 294 | 295 | 296 | attach-sources 297 | deploy 298 | 299 | jar 300 | 301 | 302 | 303 | 304 | 305 | maven-javadoc-plugin 306 | 2.8.1 307 | 308 | 309 | attach-javadocs 310 | deploy 311 | 312 | jar 313 | 314 | 315 | 316 | 317 | 318 | maven-deploy-plugin 319 | 2.7 320 | 321 | 322 | deploy 323 | deploy 324 | 325 | deploy 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | maven-repo-master 336 | https://raw.githubusercontent.com/xiexiaojing/maven-repo/master/ 337 | 338 | true 339 | always 340 | 341 | 342 | 343 | 344 | 345 | jboss-public-repository-group 346 | JBoss Public Repository Group 347 | http://repository.jboss.org/nexus/content/groups/public/ 348 | 349 | true 350 | 351 | 352 | true 353 | 354 | 355 | 356 | 357 | 358 | localRepository 359 | file:D:/com/brmayi/repository 360 | 361 | 362 | 363 | -------------------------------------------------------------------------------- /D:/com/brmayi/repository/com/brmayi/epiphany/0.15/epiphany-0.15.pom.md5: -------------------------------------------------------------------------------- 1 | cff98cf46cfffdf7231c9dac1fb6132f -------------------------------------------------------------------------------- /D:/com/brmayi/repository/com/brmayi/epiphany/0.15/epiphany-0.15.pom.sha1: -------------------------------------------------------------------------------- 1 | c242fafbe97851e9e99ea3934620a080f539488c -------------------------------------------------------------------------------- /D:/com/brmayi/repository/com/brmayi/epiphany/0.15/epiphany-0.15.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiexiaojing/epiphany/451de5acd4704736c778ec2370ddf322dd129b09/D:/com/brmayi/repository/com/brmayi/epiphany/0.15/epiphany-0.15.tar.gz -------------------------------------------------------------------------------- /D:/com/brmayi/repository/com/brmayi/epiphany/0.15/epiphany-0.15.tar.gz.md5: -------------------------------------------------------------------------------- 1 | 12184815f944349ba0b249e462c812bc -------------------------------------------------------------------------------- /D:/com/brmayi/repository/com/brmayi/epiphany/0.15/epiphany-0.15.tar.gz.sha1: -------------------------------------------------------------------------------- 1 | 290a0c0dcc566721797434894d250ecba3c54031 -------------------------------------------------------------------------------- /D:/com/brmayi/repository/com/brmayi/epiphany/maven-metadata.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | com.brmayi 4 | epiphany 5 | 6 | 0.15 7 | 8 | 0.15 9 | 10 | 20170829093547 11 | 12 | 13 | -------------------------------------------------------------------------------- /D:/com/brmayi/repository/com/brmayi/epiphany/maven-metadata.xml.md5: -------------------------------------------------------------------------------- 1 | e3d94ec577bec8376c4193e5b8dd3020 -------------------------------------------------------------------------------- /D:/com/brmayi/repository/com/brmayi/epiphany/maven-metadata.xml.sha1: -------------------------------------------------------------------------------- 1 | d1ea285b16d930b18bf8c425cdc8e3bbc888ae25 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # epiphany 2 | 3 | D:\xiexiaoing>mvn deploy -DlocalRepositoryPath=/com/brmayi/repository -DcreateChecksum=true 4 | 5 | cd /com/brmayi 6 | git add . 7 | git commit -m "注释" 8 | git push origin master 9 | -------------------------------------------------------------------------------- /assembly.xml: -------------------------------------------------------------------------------- 1 | 5 | bin 6 | 7 | tar.gz 8 | 9 | 10 | 11 | ${project.basedir} 12 | / 13 | 14 | README* 15 | LICENSE* 16 | NOTICE* 17 | 18 | 19 | 20 | 21 | ${project.build.directory}/classes 22 | conf 23 | 24 | 25 | 26 | 27 | 28 | lib 29 | true 30 | 31 | 32 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.brmayi 7 | epiphany 8 | jar 9 | 0.15 10 | epiphany 11 | 12 | 13 | UTF-8 14 | 3.2.8.RELEASE 15 | 1.0.2-RELEASE 16 | 17 | 18 | 19 | 20 | org.springframework 21 | spring-core 22 | ${spring.version} 23 | 24 | 25 | org.slf4j 26 | slf4j-api 27 | 1.7.21 28 | 29 | 30 | org.slf4j 31 | jcl-over-slf4j 32 | 1.7.21 33 | 34 | 35 | org.slf4j 36 | jul-to-slf4j 37 | 1.7.21 38 | 39 | 40 | org.slf4j 41 | log4j-over-slf4j 42 | 1.7.21 43 | 44 | 45 | ch.qos.logback 46 | logback-core 47 | 1.1.7 48 | 49 | 50 | ch.qos.logback 51 | logback-classic 52 | 1.1.7 53 | 54 | 55 | org.apache.commons 56 | commons-lang3 57 | 3.1 58 | 59 | 60 | org.springframework 61 | spring-aop 62 | ${spring.version} 63 | 64 | 65 | org.springframework 66 | spring-aspects 67 | ${spring.version} 68 | 69 | 70 | org.springframework 71 | spring-beans 72 | ${spring.version} 73 | 74 | 75 | org.springframework 76 | spring-context 77 | ${spring.version} 78 | 79 | 80 | org.springframework 81 | spring-context-support 82 | ${spring.version} 83 | 84 | 85 | org.springframework 86 | spring-jms 87 | ${spring.version} 88 | 89 | 90 | org.springframework 91 | spring-jdbc 92 | ${spring.version} 93 | 94 | 95 | org.apache.qpid 96 | qpid-client 97 | 0.24 98 | 99 | 100 | org.springframework 101 | spring-web 102 | ${spring.version} 103 | 104 | 105 | org.springframework 106 | spring-webmvc 107 | ${spring.version} 108 | 109 | 110 | org.springframework.data 111 | spring-data-redis 112 | 1.8.4.RELEASE 113 | 114 | 115 | redis.clients 116 | jedis 117 | 2.9.0 118 | 119 | 120 | com.alibaba 121 | fastjson 122 | 1.1.41 123 | 124 | 125 | mysql 126 | mysql-connector-java 127 | 5.1.26 128 | 129 | 130 | commons-dbcp 131 | commons-dbcp 132 | 1.4 133 | 134 | 135 | com.googlecode.log4jdbc 136 | log4jdbc 137 | 1.2 138 | 139 | 140 | org.jfaster 141 | mango 142 | 1.4.1 143 | 144 | 145 | org.codehaus.janino 146 | janino 147 | 2.7.8 148 | 149 | 150 | commons-pool 151 | commons-pool 152 | 1.6 153 | 154 | 155 | io.netty 156 | netty-all 157 | 4.1.7.Final 158 | 159 | 160 | net.sf.json-lib 161 | json-lib 162 | 2.4 163 | jdk15 164 | 165 | 166 | javax.jms 167 | javax.jms-api 168 | 2.0.1 169 | 170 | 171 | xerces 172 | xercesImpl 173 | 2.11.0 174 | 175 | 176 | org.perf4j 177 | perf4j 178 | 0.9.16 179 | 180 | 181 | 182 | 183 | epiphany 184 | 185 | 186 | ../lib 187 | src/main/resources 188 | 189 | lib/*.jar 190 | 191 | 192 | 193 | src/main/resources 194 | 195 | spring/ 196 | properties/* 197 | spring/* 198 | *.xml 199 | deploy/* 200 | 201 | true 202 | 203 | 204 | src/main/resources 205 | true 206 | 207 | deploy/* 208 | 209 | ${project.build.directory} 210 | 211 | 212 | 213 | 214 | org.apache.maven.plugins 215 | maven-assembly-plugin 216 | 2.3 217 | 218 | false 219 | 220 | assembly.xml 221 | 222 | 223 | 224 | 225 | make-assembly 226 | package 227 | 228 | single 229 | 230 | 231 | 232 | 233 | 234 | org.apache.maven.plugins 235 | maven-surefire-plugin 236 | 2.16 237 | 238 | true 239 | 240 | 241 | 242 | maven-resources-plugin 243 | 244 | 245 | maven-compiler-plugin 246 | 247 | 248 | maven-source-plugin 249 | 250 | 251 | maven-javadoc-plugin 252 | 253 | 254 | maven-deploy-plugin 255 | 256 | 257 | 258 | 259 | 260 | org.apache.maven.plugins 261 | maven-compiler-plugin 262 | 2.3.2 263 | 264 | 1.7 265 | 1.7 266 | UTF-8 267 | true 268 | 1g 269 | 2g 270 | 271 | 272 | 273 | org.mortbay.jetty 274 | maven-jetty-plugin 275 | 6.1.7 276 | 277 | 278 | org.apache.maven.plugins 279 | maven-resources-plugin 280 | 2.5 281 | 282 | UTF-8 283 | ${project.build.outputDirectory} 284 | 285 | 286 | 287 | org.apache.maven.plugins 288 | maven-jar-plugin 289 | 2.3 290 | 291 | 292 | maven-source-plugin 293 | 2.1.2 294 | 295 | 296 | attach-sources 297 | deploy 298 | 299 | jar 300 | 301 | 302 | 303 | 304 | 305 | maven-javadoc-plugin 306 | 2.8.1 307 | 308 | 309 | attach-javadocs 310 | deploy 311 | 312 | jar 313 | 314 | 315 | 316 | 317 | 318 | maven-deploy-plugin 319 | 2.7 320 | 321 | 322 | deploy 323 | deploy 324 | 325 | deploy 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | maven-repo-master 336 | https://raw.githubusercontent.com/xiexiaojing/maven-repo/master/ 337 | 338 | true 339 | always 340 | 341 | 342 | 343 | 344 | 345 | jboss-public-repository-group 346 | JBoss Public Repository Group 347 | http://repository.jboss.org/nexus/content/groups/public/ 348 | 349 | true 350 | 351 | 352 | true 353 | 354 | 355 | 356 | 357 | 358 | localRepository 359 | file:D:/com/brmayi/repository 360 | 361 | 362 | 363 | -------------------------------------------------------------------------------- /src/main/java/com/brmayi/epiphany/business/FullBusinessTask.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.brmayi.epiphany.business; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import javax.annotation.Resource; 10 | 11 | import org.perf4j.StopWatch; 12 | import org.perf4j.slf4j.Slf4JStopWatch; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | import org.springframework.data.redis.core.RedisTemplate; 16 | 17 | import com.brmayi.epiphany.business.common.RedisUtils; 18 | import com.brmayi.epiphany.common.Startup; 19 | import com.brmayi.epiphany.exception.EpiphanyException; 20 | import com.brmayi.epiphany.service.DataService; 21 | import com.brmayi.epiphany.util.EpiphanyFileUtil; 22 | import com.brmayi.epiphany.util.GzCompressUtil; 23 | 24 | /** 25 | * 26 | * 27 | * .==. .==. 28 | * //'^\\ //^'\\ 29 | * // ^^\(\__/)/^ ^^\\ 30 | * //^ ^^ ^/6 6\ ^^^ \\ 31 | * //^ ^^ ^/( .. )\^ ^^ \\ 32 | * // ^^ ^/\|v""v|/\^^ ^ \\ 33 | * // ^^/\/ / '~~' \ \/\^ ^\\ 34 | * ---------------------------------------- 35 | * HERE BE DRAGONS WHICH CAN CREATE MIRACLE 36 | * 37 | * @author 静儿(987489055@qq.com) 38 | * 39 | */ 40 | public class FullBusinessTask implements Runnable { 41 | private final static Logger LOGGER = LoggerFactory.getLogger(FullBusinessTask.class); 42 | 43 | private static final String EMPTY = ""; 44 | private int threadNo=0; 45 | private String fullPath="/data/epiphany"; 46 | @Resource 47 | private RedisTemplate redisTemplate; 48 | private DataService dataService=null; 49 | private long minId=0; 50 | private long maxId=20000; 51 | private int dealOneTime = 200; 52 | private String redisNoKey = "epiphanyNo"; 53 | 54 | private boolean hasPriority = false; 55 | 56 | public void setMinId(long minId) { 57 | this.minId = minId; 58 | } 59 | 60 | public void setMaxId(long maxId) { 61 | this.maxId = maxId; 62 | } 63 | 64 | public void setThreadNo(int threadNo) { 65 | this.threadNo = threadNo; 66 | } 67 | 68 | public void setFullPath(String fullPath) { 69 | this.fullPath = fullPath; 70 | } 71 | 72 | public void setDataService(DataService dataService) { 73 | this.dataService = dataService; 74 | } 75 | 76 | public void setDealOneTime(int dealOneTime) { 77 | this.dealOneTime = dealOneTime; 78 | } 79 | 80 | public void setRedisNoKey(String redisNoKey) { 81 | this.redisNoKey = redisNoKey; 82 | } 83 | 84 | public void setHasPriority(boolean hasPriority) { 85 | this.hasPriority = hasPriority; 86 | } 87 | 88 | @Override 89 | public void run() throws EpiphanyException { 90 | Startup.threadNumber.incrementAndGet(); 91 | String pathWithDate = EpiphanyFileUtil.getPath(fullPath); 92 | String path = new StringBuilder(pathWithDate).append(threadNo).toString(); 93 | long endThisTime = redisTemplate.opsForValue().increment(redisNoKey, dealOneTime); 94 | long curId = minId+endThisTime-dealOneTime; 95 | String prioritySetKey = new StringBuilder("ps").append(redisNoKey).toString(); 96 | while (curId <= maxId) { 97 | StopWatch stopWatch = new Slf4JStopWatch(fullPath); 98 | if(hasPriority) { 99 | List ids = dataService.getIdsByBeginEnd(curId, minId+endThisTime); 100 | List dealIds = new ArrayList(ids.size()); 101 | for(Long id : ids) { 102 | if(!redisTemplate.opsForSet().isMember(prioritySetKey, String.valueOf(id))) { 103 | dealIds.add(id); 104 | } 105 | } 106 | dataService.dealDataByIds(dealIds, path); 107 | } else { 108 | dataService.dealDataByBeginEnd(curId, minId+endThisTime, path); 109 | } 110 | stopWatch.stop(); 111 | endThisTime = redisTemplate.opsForValue().increment(redisNoKey, dealOneTime); 112 | curId = endThisTime-dealOneTime; 113 | } 114 | 115 | GzCompressUtil.compressFile(path);//压缩 116 | Startup.threadNumber.decrementAndGet(); 117 | if(Startup.threadNumber.get()==0) { 118 | LOGGER.info("fullExecute generate success"); 119 | String division = fullPath.substring(fullPath.lastIndexOf("/")+1, fullPath.length()); 120 | EpiphanyFileUtil.writeToFile(new StringBuilder(pathWithDate).append(division).append("success").toString(), EMPTY); 121 | RedisUtils.clearRedis(redisTemplate,redisNoKey); 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/main/java/com/brmayi/epiphany/business/FullStartupTask.java: -------------------------------------------------------------------------------- 1 | package com.brmayi.epiphany.business; 2 | 3 | import java.io.File; 4 | import java.text.ParseException; 5 | import java.text.SimpleDateFormat; 6 | import java.util.Calendar; 7 | import java.util.Date; 8 | import java.util.List; 9 | import java.util.TimerTask; 10 | import java.util.concurrent.ExecutorService; 11 | import java.util.concurrent.Executors; 12 | 13 | import javax.annotation.Resource; 14 | 15 | import org.apache.commons.lang3.math.NumberUtils; 16 | import org.slf4j.Logger; 17 | import org.slf4j.LoggerFactory; 18 | import org.springframework.data.redis.core.RedisTemplate; 19 | import org.springframework.data.redis.core.ValueOperations; 20 | 21 | import com.brmayi.epiphany.business.common.RedisUtils; 22 | import com.brmayi.epiphany.common.Startup; 23 | import com.brmayi.epiphany.service.DataService; 24 | import com.brmayi.epiphany.util.EpiphanyFileUtil; 25 | 26 | public class FullStartupTask extends TimerTask { 27 | private final static Logger LOGGER = LoggerFactory.getLogger(FullStartupTask.class); 28 | public int threadTotal = 23; 29 | public ExecutorService service = Executors.newFixedThreadPool(threadTotal); 30 | 31 | @Resource 32 | private RedisTemplate redisTemplate; 33 | private String fullPath="/data/epiphany"; 34 | private DataService dataService=null; 35 | private int dealOneTime = 200; 36 | private String redisNoKey = "epiphanyNo"; 37 | 38 | public void setFullPath(String fullPath) { 39 | this.fullPath = fullPath; 40 | } 41 | 42 | public void setDataService(DataService dataService) { 43 | this.dataService = dataService; 44 | } 45 | 46 | public void setDealOneTime(int dealOneTime) { 47 | this.dealOneTime = dealOneTime; 48 | } 49 | 50 | public void setRedisNoKey(String redisNoKey) { 51 | this.redisNoKey = redisNoKey; 52 | } 53 | 54 | public void setThreadTotal(int threadTotal) { 55 | this.threadTotal = threadTotal; 56 | service = Executors.newFixedThreadPool(threadTotal); 57 | } 58 | 59 | @Override 60 | public void run() { 61 | RedisUtils.clearRedis(redisTemplate,redisNoKey); 62 | redisTemplate.opsForValue().set(redisNoKey, "0"); 63 | clearData(); 64 | EpiphanyFileUtil.createPath(fullPath); 65 | ValueOperations valueOperations = redisTemplate.opsForValue(); 66 | String maxKey = new StringBuilder("max").append(redisNoKey).toString(); 67 | String maxId = valueOperations.get(maxKey); 68 | if(maxId==null) { 69 | maxId = String.valueOf(dataService.getMaxId()); 70 | valueOperations.set(maxKey, maxId); 71 | } 72 | String minKey = new StringBuilder("min").append(redisNoKey).toString(); 73 | String minId = valueOperations.get(minKey); 74 | if(minId==null) { 75 | minId = String.valueOf(dataService.getMinId()); 76 | valueOperations.set(minKey, minId); 77 | } 78 | List niceQueue = dataService.getNiceQueue(); 79 | boolean hasPriority = false; 80 | if(niceQueue!=null && !niceQueue.isEmpty()) { 81 | String numKey = new StringBuilder("n").append(redisNoKey).toString(); 82 | redisTemplate.opsForValue().set(numKey, "0"); 83 | String reverseListKey = new StringBuilder("r").append(redisNoKey).toString(); 84 | redisTemplate.delete(reverseListKey); 85 | String prioritySetKey = new StringBuilder("ps").append(redisNoKey).toString(); 86 | redisTemplate.delete(prioritySetKey); 87 | for(int i=1; i<=niceQueue.size(); i++) { 88 | String idstr = String.valueOf(niceQueue.get(i-1)); 89 | redisTemplate.opsForHash().put(reverseListKey, String.valueOf(i), idstr); 90 | redisTemplate.opsForSet().add(prioritySetKey, idstr); 91 | } 92 | for(int i=0; i2*24*3600*1000) { 133 | deleteDir(new File(new StringBuffer(fullPath).append("/").append(dateDirs[j]).toString())); 134 | } 135 | } 136 | } 137 | } 138 | } 139 | } 140 | 141 | /** 142 | * 递归删除目录下的所有文件及子目录下所有文件 143 | * @param dir 将要删除的文件目录 144 | * @return boolean Returns "true" if all deletions were successful. 145 | * If a deletion fails, the method stops attempting to 146 | * delete and returns "false". 147 | */ 148 | private static boolean deleteDir(File dir) { 149 | if (dir.isDirectory()) { 150 | String[] children = dir.list(); 151 | //递归删除目录中的子目录下 152 | for (int i=0; i redisTemplate; 43 | 44 | private DataService dataService; 45 | 46 | private String timeCacheKey="timeCacheKey"; 47 | 48 | private String fullIncModel = "yield"; 49 | 50 | /** 51 | * 缓存当前增量已执行过数据的时间戳key 52 | * @param timeCacheKey 53 | */ 54 | public void setTimeCacheKey(String timeCacheKey) { 55 | this.timeCacheKey = timeCacheKey; 56 | } 57 | 58 | public void setDataService(DataService dataService) { 59 | this.dataService = dataService; 60 | } 61 | 62 | /** 63 | * 全量和增量的运行模式: 64 | * both 共同执行模式 65 | * yield 在执行全量时停止增量的运行,在全量执行完后接断点继续执行 66 | * @param fullIncModel 全量和增量的运行模式:both 共同执行模式, yield 在执行全量时停止增量的运行,在全量执行完后接断点继续执行,默认yield 67 | */ 68 | public void setFullIncModel(String fullIncModel) { 69 | this.fullIncModel = fullIncModel; 70 | } 71 | 72 | @Override 73 | public void run() throws EpiphanyException{ 74 | if("yield".equals(fullIncModel) && Startup.threadNumber.get()>0) { 75 | return; 76 | } 77 | try { 78 | String lastTime = redisTemplate.opsForValue().get(timeCacheKey); 79 | if(StringUtils.isEmpty(lastTime)) { 80 | lastTime = getNewTime(Calendar.SECOND,-2*RUN_INTERVAL+RUN_END_TIME); 81 | } else { 82 | logger.info("lastTime{}", lastTime); 83 | } 84 | String endTime = getNewTime(Calendar.SECOND, RUN_END_TIME); //当前时间 85 | redisTemplate.opsForValue().set(timeCacheKey, endTime); 86 | List ids = dataService.getIds(lastTime, endTime); 87 | dataService.dealDataByIds(ids, null); 88 | ids = null; 89 | //更新时间戳 90 | lastTime = endTime; 91 | } catch(Exception e) { 92 | throw new EpiphanyException(e); 93 | } 94 | } 95 | 96 | /** 97 | * 取当前时间 98 | * @return 当前时间 99 | */ 100 | private static String getNewTime(Integer timeUnit, int interval) { 101 | SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); 102 | Calendar date = Calendar.getInstance(); 103 | if(timeUnit!=null) { 104 | date.set(timeUnit, date.get(timeUnit)+interval); 105 | } 106 | String newTime = sdf.format(date.getTime()); 107 | return newTime; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/com/brmayi/epiphany/business/NiceQueueTask.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.brmayi.epiphany.business; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import javax.annotation.Resource; 10 | 11 | import org.apache.commons.lang3.math.NumberUtils; 12 | import org.perf4j.StopWatch; 13 | import org.perf4j.slf4j.Slf4JStopWatch; 14 | import org.slf4j.Logger; 15 | import org.slf4j.LoggerFactory; 16 | import org.springframework.data.redis.core.RedisTemplate; 17 | 18 | import com.brmayi.epiphany.common.Startup; 19 | import com.brmayi.epiphany.exception.EpiphanyException; 20 | import com.brmayi.epiphany.service.DataService; 21 | import com.brmayi.epiphany.util.EpiphanyFileUtil; 22 | import com.brmayi.epiphany.util.GzCompressUtil; 23 | 24 | /** 25 | * 26 | * 27 | * .==. .==. 28 | * //'^\\ //^'\\ 29 | * // ^^\(\__/)/^ ^^\\ 30 | * //^ ^^ ^/6 6\ ^^^ \\ 31 | * //^ ^^ ^/( .. )\^ ^^ \\ 32 | * // ^^ ^/\|v""v|/\^^ ^ \\ 33 | * // ^^/\/ / '~~' \ \/\^ ^\\ 34 | * ---------------------------------------- 35 | * HERE BE DRAGONS WHICH CAN CREATE MIRACLE 36 | * 37 | * @author 静儿(987489055@qq.com) 38 | * 39 | */ 40 | public class NiceQueueTask implements Runnable { 41 | private final static Logger LOGGER = LoggerFactory.getLogger(NiceQueueTask.class); 42 | 43 | private static final String EMPTY = ""; 44 | 45 | private int threadNo=0; 46 | private String fullPath="/data/epiphany"; 47 | @Resource 48 | private RedisTemplate redisTemplate; 49 | private DataService dataService=null; 50 | private String redisNoKey = "epiphanyNo"; 51 | 52 | public void setThreadNo(int threadNo) { 53 | this.threadNo = threadNo; 54 | } 55 | 56 | public void setFullPath(String fullPath) { 57 | this.fullPath = fullPath; 58 | } 59 | 60 | public void setDataService(DataService dataService) { 61 | this.dataService = dataService; 62 | } 63 | 64 | public void setRedisNoKey(String redisNoKey) { 65 | this.redisNoKey = redisNoKey; 66 | } 67 | 68 | @Override 69 | public void run() throws EpiphanyException { 70 | Startup.threadNumber.incrementAndGet(); 71 | String pathWithDate = EpiphanyFileUtil.getPath(fullPath); 72 | String path = new StringBuilder(pathWithDate).append(threadNo).toString(); 73 | String numKey = new StringBuilder("n").append(redisNoKey).toString(); 74 | String reverseListKey = new StringBuilder("r").append(redisNoKey).toString(); 75 | while(true) { 76 | long endThisTime = redisTemplate.opsForValue().increment(numKey, 1); 77 | StopWatch stopWatch = new Slf4JStopWatch(fullPath); 78 | Object id = redisTemplate.opsForHash().get(reverseListKey, String.valueOf(endThisTime)); 79 | if(id==null) { 80 | break; 81 | } 82 | List ids = new ArrayList(); 83 | ids.add(NumberUtils.toLong((String) id)); 84 | dataService.dealDataByIds(ids, path); 85 | stopWatch.stop(); 86 | } 87 | GzCompressUtil.compressFile(path);//压缩 88 | Startup.threadNumber.decrementAndGet(); 89 | if(Startup.threadNumber.get()==0) { 90 | LOGGER.info("fullExecute generate success"); 91 | String division = fullPath.substring(fullPath.lastIndexOf("/")+1, fullPath.length()); 92 | EpiphanyFileUtil.writeToFile(new StringBuilder(pathWithDate).append(division).append("success").toString(), EMPTY); 93 | redisTemplate.delete(numKey); 94 | redisTemplate.delete(reverseListKey); 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/com/brmayi/epiphany/business/common/RedisUtils.java: -------------------------------------------------------------------------------- 1 | package com.brmayi.epiphany.business.common; 2 | 3 | import org.springframework.data.redis.core.RedisTemplate; 4 | 5 | public class RedisUtils { 6 | 7 | public static void clearRedis(RedisTemplate redisTemplate, String redisNoKey){ 8 | String maxKey = new StringBuilder("max").append(redisNoKey).toString(); 9 | String minKey = new StringBuilder("min").append(redisNoKey).toString(); 10 | String numKey = new StringBuilder("n").append(redisNoKey).toString(); 11 | String queueListKey = new StringBuilder("ps").append(redisNoKey).toString(); 12 | redisTemplate.delete(maxKey); 13 | redisTemplate.delete(minKey); 14 | redisTemplate.delete(numKey); 15 | redisTemplate.delete(queueListKey); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/brmayi/epiphany/business/socket/ManuallyHttpServer.java: -------------------------------------------------------------------------------- 1 | package com.brmayi.epiphany.business.socket; 2 | 3 | import static io.netty.buffer.Unpooled.copiedBuffer; 4 | import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_LENGTH; 5 | import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE; 6 | import io.netty.bootstrap.ServerBootstrap; 7 | import io.netty.buffer.ByteBuf; 8 | import io.netty.channel.Channel; 9 | import io.netty.channel.ChannelHandler.Sharable; 10 | import io.netty.channel.ChannelHandlerContext; 11 | import io.netty.channel.ChannelInitializer; 12 | import io.netty.channel.ChannelPipeline; 13 | import io.netty.channel.EventLoopGroup; 14 | import io.netty.channel.SimpleChannelInboundHandler; 15 | import io.netty.channel.nio.NioEventLoopGroup; 16 | import io.netty.channel.socket.SocketChannel; 17 | import io.netty.channel.socket.nio.NioServerSocketChannel; 18 | import io.netty.handler.codec.http.DefaultFullHttpResponse; 19 | import io.netty.handler.codec.http.FullHttpResponse; 20 | import io.netty.handler.codec.http.HttpContentCompressor; 21 | import io.netty.handler.codec.http.HttpObject; 22 | import io.netty.handler.codec.http.HttpRequest; 23 | import io.netty.handler.codec.http.HttpRequestDecoder; 24 | import io.netty.handler.codec.http.HttpResponseEncoder; 25 | import io.netty.handler.codec.http.HttpResponseStatus; 26 | import io.netty.handler.codec.http.HttpVersion; 27 | import io.netty.util.CharsetUtil; 28 | 29 | import java.net.URI; 30 | import java.util.ArrayList; 31 | import java.util.List; 32 | 33 | import org.apache.commons.lang3.math.NumberUtils; 34 | 35 | import com.brmayi.epiphany.service.DataService; 36 | 37 | public class ManuallyHttpServer implements Runnable { 38 | 39 | private ManuallyHttpServerInitializer manuallyHttpServerInitializer = new ManuallyHttpServerInitializer(); 40 | 41 | private ManuallyHttpServerHandler manuallyHttpServerHandler = new ManuallyHttpServerHandler(); 42 | 43 | private DataService dataService; 44 | 45 | private int port = 0; 46 | 47 | public void setServer(int port) { 48 | this.port = port; 49 | } 50 | 51 | public void setDataService(DataService dataService) { 52 | this.dataService = dataService; 53 | } 54 | 55 | @Override 56 | public void run() { 57 | EventLoopGroup bossGroup = new NioEventLoopGroup(1); 58 | EventLoopGroup workerGroup = new NioEventLoopGroup(); 59 | try { 60 | ServerBootstrap b = new ServerBootstrap(); 61 | b.group(bossGroup, workerGroup) 62 | .channel(NioServerSocketChannel.class) 63 | .childHandler(manuallyHttpServerInitializer); 64 | 65 | Channel ch = b.bind(port).sync().channel(); 66 | ch.closeFuture().sync(); 67 | } catch(Exception e) { 68 | 69 | }finally { 70 | bossGroup.shutdownGracefully(); 71 | workerGroup.shutdownGracefully(); 72 | } 73 | } 74 | 75 | 76 | private class ManuallyHttpServerInitializer extends ChannelInitializer { 77 | @Override 78 | public void initChannel(SocketChannel ch) throws Exception { 79 | // Create a default pipeline implementation. 80 | ChannelPipeline pipeline = ch.pipeline(); 81 | 82 | /** 83 | * http-request解码器 84 | * http服务器端对request解码 85 | */ 86 | pipeline.addLast("decoder", new HttpRequestDecoder()); 87 | /** 88 | * http-response解码器 89 | * http服务器端对response编码 90 | */ 91 | pipeline.addLast("encoder", new HttpResponseEncoder()); 92 | 93 | /** 94 | * 压缩 95 | * Compresses an HttpMessage and an HttpContent in gzip or deflate encoding 96 | * while respecting the "Accept-Encoding" header. 97 | * If there is no matching encoding, no compression is done. 98 | */ 99 | pipeline.addLast("deflater", new HttpContentCompressor()); 100 | 101 | pipeline.addLast("handler", manuallyHttpServerHandler); 102 | } 103 | } 104 | 105 | @Sharable 106 | private class ManuallyHttpServerHandler extends SimpleChannelInboundHandler { 107 | @Override 108 | public void channelInactive(ChannelHandlerContext ctx) throws Exception { 109 | 110 | } 111 | 112 | public void messageReceived(ChannelHandlerContext ctx, HttpObject msg) throws Exception { 113 | /** 114 | * msg的类型 115 | * {@link DefaultHttpRequest} 116 | * {@link LastHttpContent} 117 | */ 118 | if (msg instanceof HttpRequest) { 119 | HttpRequest request = (HttpRequest) msg; 120 | URI uri = new URI(request.getUri()); 121 | String data = uri.getQuery(); 122 | data = data.replace("ids=", ""); 123 | String[] sids = data.split(","); 124 | List ids = new ArrayList(); 125 | for(String sid : sids) { 126 | ids.add(NumberUtils.toLong(sid)); 127 | } 128 | dataService.dealDataByIds(ids, null); 129 | String advice="重发了"+ids.toString(); 130 | ByteBuf buf = copiedBuffer(advice, CharsetUtil.UTF_8); 131 | // Build the response object. 132 | FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buf); 133 | 134 | response.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8"); 135 | response.headers().set(CONTENT_LENGTH, buf.readableBytes()); 136 | 137 | // Write the response. 138 | ctx.channel().writeAndFlush(response); 139 | } 140 | } 141 | 142 | @Override 143 | public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { 144 | ctx.channel().close(); 145 | } 146 | 147 | @Override 148 | protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception { 149 | messageReceived(ctx, msg); 150 | } 151 | } 152 | } -------------------------------------------------------------------------------- /src/main/java/com/brmayi/epiphany/common/Startup.java: -------------------------------------------------------------------------------- 1 | package com.brmayi.epiphany.common; 2 | 3 | import java.util.concurrent.atomic.AtomicInteger; 4 | 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.context.support.ClassPathXmlApplicationContext; 7 | /** 8 | * 包含各种启动选项:包括加载spring上下文,是客户端需要直接调用的一个类 9 | * 10 | * 11 | * .==. .==. 12 | * //'^\\ //^'\\ 13 | * // ^^\(\__/)/^ ^^\\ 14 | * //^ ^^ ^/6 6\ ^^^ \\ 15 | * //^ ^^ ^/( .. )\^ ^^ \\ 16 | * // ^^ ^/\|v""v|/\^^ ^ \\ 17 | * // ^^/\/ / '~~' \ \/\^ ^\\ 18 | * ---------------------------------------- 19 | * HERE BE DRAGONS WHICH CAN CREATE MIRACLE 20 | * 21 | * @author 静儿(987489055@qq.com) 22 | * 23 | */ 24 | public class Startup { 25 | /** 26 | * spring 上下文:路径请放于classpath的spring文件夹下 27 | */ 28 | public static ApplicationContext context = new ClassPathXmlApplicationContext("spring/applicationContext.xml");//加载spring task 29 | /** 30 | * 当前运行中的全量线程计数器 31 | */ 32 | public static final AtomicInteger threadNumber = new AtomicInteger(0); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/brmayi/epiphany/exception/EpiphanyException.java: -------------------------------------------------------------------------------- 1 | package com.brmayi.epiphany.exception; 2 | /** 3 | * 4 | * 5 | * 6 | * .==. .==. 7 | * //'^\\ //^'\\ 8 | * // ^^\(\__/)/^ ^^\\ 9 | * //^ ^^ ^/6 6\ ^^^ \\ 10 | * //^ ^^ ^/( .. )\^ ^^ \\ 11 | * // ^^ ^/\|v""v|/\^^ ^ \\ 12 | * // ^^/\/ / '~~' \ \/\^ ^\\ 13 | * ---------------------------------------- 14 | * HERE BE DRAGONS WHICH CAN CREATE MIRACLE 15 | * 16 | * @author 静儿(987489055@qq.com) 17 | * 定义一个此功能抛出的业务异常 18 | */ 19 | public class EpiphanyException extends RuntimeException { 20 | static final long serialVersionUID = 1L; 21 | 22 | /** Constructs a new runtime exception with {@code null} as its 23 | * detail message. The cause is not initialized, and may subsequently be 24 | * initialized by a call to {@link #initCause}. 25 | */ 26 | public EpiphanyException() { 27 | super(); 28 | } 29 | 30 | /** Constructs a new runtime exception with the specified detail message. 31 | * The cause is not initialized, and may subsequently be initialized by a 32 | * call to {@link #initCause}. 33 | * 34 | * @param message the detail message. The detail message is saved for 35 | * later retrieval by the {@link #getMessage()} method. 36 | */ 37 | public EpiphanyException(String message) { 38 | super(message); 39 | } 40 | 41 | /** 42 | * Constructs a new runtime exception with the specified detail message and 43 | * cause.

Note that the detail message associated with 44 | * {@code cause} is not automatically incorporated in 45 | * this runtime exception's detail message. 46 | * 47 | * @param message the detail message (which is saved for later retrieval 48 | * by the {@link #getMessage()} method). 49 | * @param cause the cause (which is saved for later retrieval by the 50 | * {@link #getCause()} method). (A null value is 51 | * permitted, and indicates that the cause is nonexistent or 52 | * unknown.) 53 | * @since 1.4 54 | */ 55 | public EpiphanyException(String message, Throwable cause) { 56 | super(message, cause); 57 | } 58 | 59 | /** Constructs a new runtime exception with the specified cause and a 60 | * detail message of (cause==null ? null : cause.toString()) 61 | * (which typically contains the class and detail message of 62 | * cause). This constructor is useful for runtime exceptions 63 | * that are little more than wrappers for other throwables. 64 | * 65 | * @param cause the cause (which is saved for later retrieval by the 66 | * {@link #getCause()} method). (A null value is 67 | * permitted, and indicates that the cause is nonexistent or 68 | * unknown.) 69 | * @since 1.4 70 | */ 71 | public EpiphanyException(Throwable cause) { 72 | super(cause); 73 | } 74 | 75 | /** 76 | * Constructs a new runtime exception with the specified detail 77 | * message, cause, suppression enabled or disabled, and writable 78 | * stack trace enabled or disabled. 79 | * 80 | * @param message the detail message. 81 | * @param cause the cause. (A {@code null} value is permitted, 82 | * and indicates that the cause is nonexistent or unknown.) 83 | * @param enableSuppression whether or not suppression is enabled 84 | * or disabled 85 | * @param writableStackTrace whether or not the stack trace should 86 | * be writable 87 | * 88 | * @since 1.7 89 | */ 90 | protected EpiphanyException(String message, Throwable cause, 91 | boolean enableSuppression, 92 | boolean writableStackTrace) { 93 | super(message, cause, enableSuppression, writableStackTrace); 94 | } 95 | 96 | /** 97 | * Fills in the execution stack trace. This method records within this 98 | * {@code Throwable} object information about the current state of 99 | * the stack frames for the current thread. 100 | * 101 | *

If the stack trace of this {@code Throwable} {@linkplain 102 | * Throwable#Throwable(String, Throwable, boolean, boolean) is not 103 | * writable}, calling this method has no effect. 104 | * 105 | * @return a reference to this {@code Throwable} instance. 106 | * @see java.lang.Throwable#printStackTrace() 107 | */ 108 | @Override 109 | public Throwable fillInStackTrace() { 110 | return this; 111 | } 112 | } -------------------------------------------------------------------------------- /src/main/java/com/brmayi/epiphany/model/KeyValue.java: -------------------------------------------------------------------------------- 1 | package com.brmayi.epiphany.model; 2 | 3 | public class KeyValue { 4 | private String key; 5 | private String value; 6 | public String getKey() { 7 | return key; 8 | } 9 | public void setKey(String key) { 10 | this.key = key; 11 | } 12 | public String getValue() { 13 | return value; 14 | } 15 | public void setValue(String value) { 16 | this.value = value; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/brmayi/epiphany/pool/LimitedKeyedPoolableObjectFactory.java: -------------------------------------------------------------------------------- 1 | package com.brmayi.epiphany.pool; 2 | 3 | import org.apache.commons.pool.BaseKeyedPoolableObjectFactory; 4 | import org.apache.commons.pool.KeyedObjectPool; 5 | import org.apache.commons.pool.KeyedObjectPoolFactory; 6 | import org.apache.commons.pool.KeyedPoolableObjectFactory; 7 | import org.apache.commons.pool.impl.StackKeyedObjectPoolFactory; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.brmayi.epiphany.exception.EpiphanyException; 12 | 13 | /** 14 | * 15 | * 16 | * 17 | * .==. .==. 18 | * //'^\\ //^'\\ 19 | * // ^^\(\__/)/^ ^^\\ 20 | * //^ ^^ ^/6 6\ ^^^ \\ 21 | * //^ ^^ ^/( .. )\^ ^^ \\ 22 | * // ^^ ^/\|v""v|/\^^ ^ \\ 23 | * // ^^/\/ / '~~' \ \/\^ ^\\ 24 | * ---------------------------------------- 25 | * HERE BE DRAGONS WHICH CAN CREATE MIRACLE 26 | * 27 | * @author 静儿(987489055@qq.com) 28 | * 29 | */ 30 | public class LimitedKeyedPoolableObjectFactory extends BaseKeyedPoolableObjectFactory { 31 | private static final Logger logger = LoggerFactory.getLogger(LimitedKeyedPoolableObjectFactory.class); 32 | 33 | private static final int MAX_NUM_ACTIVE = 100; 34 | 35 | private static final KeyedPoolableObjectFactory limitedFactory = new LimitedKeyedPoolableObjectFactory(); 36 | 37 | private static final KeyedObjectPoolFactory limitedPoolFactory = new StackKeyedObjectPoolFactory(limitedFactory); 38 | 39 | public static KeyedObjectPool objectPool = limitedPoolFactory.createPool(); 40 | 41 | @Override 42 | public Runnable makeObject(String paramK) throws EpiphanyException { 43 | try { 44 | if(objectPool.getNumActive()>=MAX_NUM_ACTIVE) { 45 | logger.error("limitedObjectPool active exceeded!"); 46 | objectPool.clear(); 47 | return null; 48 | } 49 | @SuppressWarnings("unchecked") 50 | Class cls = (Class) Class.forName(paramK); 51 | Runnable obj = cls.newInstance(); 52 | logger.info("create class:{}", paramK); 53 | return obj; 54 | } catch(Exception e) { 55 | logger.error("limitedObjectPool exception", e); 56 | throw new EpiphanyException(e); 57 | } 58 | } 59 | 60 | @Override 61 | public void destroyObject(String key, Runnable obj){ 62 | obj = null; 63 | } 64 | } -------------------------------------------------------------------------------- /src/main/java/com/brmayi/epiphany/pool/UnlimitedKeyedPoolableObjectFactory.java: -------------------------------------------------------------------------------- 1 | package com.brmayi.epiphany.pool; 2 | 3 | import org.apache.commons.pool.BaseKeyedPoolableObjectFactory; 4 | import org.apache.commons.pool.KeyedObjectPool; 5 | import org.apache.commons.pool.KeyedObjectPoolFactory; 6 | import org.apache.commons.pool.KeyedPoolableObjectFactory; 7 | import org.apache.commons.pool.impl.StackKeyedObjectPoolFactory; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.brmayi.epiphany.exception.EpiphanyException; 12 | 13 | /** 14 | * 15 | * 16 | * 17 | * .==. .==. 18 | * //'^\\ //^'\\ 19 | * // ^^\(\__/)/^ ^^\\ 20 | * //^ ^^ ^/6 6\ ^^^ \\ 21 | * //^ ^^ ^/( .. )\^ ^^ \\ 22 | * // ^^ ^/\|v""v|/\^^ ^ \\ 23 | * // ^^/\/ / '~~' \ \/\^ ^\\ 24 | * ---------------------------------------- 25 | * HERE BE DRAGONS WHICH CAN CREATE MIRACLE 26 | * 27 | * @author 静儿(987489055@qq.com) 28 | * 29 | */ 30 | public class UnlimitedKeyedPoolableObjectFactory extends BaseKeyedPoolableObjectFactory { 31 | private static final Logger logger = LoggerFactory.getLogger(UnlimitedKeyedPoolableObjectFactory.class); 32 | 33 | private static final KeyedPoolableObjectFactory unlimitedFactory = new UnlimitedKeyedPoolableObjectFactory(); 34 | 35 | private static final KeyedObjectPoolFactory unlimitedPoolFactory = new StackKeyedObjectPoolFactory(unlimitedFactory); 36 | 37 | public static KeyedObjectPool objectPool = unlimitedPoolFactory.createPool(); 38 | 39 | @Override 40 | public Runnable makeObject(String paramK) throws EpiphanyException { 41 | try { 42 | @SuppressWarnings("unchecked") 43 | Class cls = (Class) Class.forName(paramK); 44 | Runnable obj = cls.newInstance(); 45 | logger.info("create class:{}", paramK); 46 | return obj; 47 | } catch(Exception e) { 48 | logger.error("unlimitedObjectPool exception", e); 49 | throw new EpiphanyException(e); 50 | } 51 | } 52 | 53 | @Override 54 | public void destroyObject(String key, Runnable obj) throws Exception { 55 | obj = null; 56 | } 57 | } -------------------------------------------------------------------------------- /src/main/java/com/brmayi/epiphany/serializer/ObjectRedisSerializer.java: -------------------------------------------------------------------------------- 1 | package com.brmayi.epiphany.serializer; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.ObjectInputStream; 6 | import java.io.ObjectOutputStream; 7 | import java.nio.charset.Charset; 8 | 9 | import org.springframework.data.redis.serializer.RedisSerializer; 10 | import org.springframework.data.redis.serializer.SerializationException; 11 | 12 | import com.brmayi.epiphany.exception.EpiphanyException; 13 | import com.brmayi.epiphany.util.GzCompressUtil; 14 | /** 15 | * 序列化工具 16 | * 17 | * 18 | * .==. .==. 19 | * //'^\\ //^'\\ 20 | * // ^^\(\__/)/^ ^^\\ 21 | * //^ ^^ ^/6 6\ ^^^ \\ 22 | * //^ ^^ ^/( .. )\^ ^^ \\ 23 | * // ^^ ^/\|v""v|/\^^ ^ \\ 24 | * // ^^/\/ / '~~' \ \/\^ ^\\ 25 | * ---------------------------------------- 26 | * HERE BE DRAGONS WHICH CAN CREATE MIRACLE 27 | * 28 | * @author 静儿(987489055@qq.com) 29 | * 30 | */ 31 | public class ObjectRedisSerializer implements RedisSerializer { 32 | /** 33 | * 对象序列化为字符串 34 | * @param obj jvm对象 35 | * @return 序列化后的字符串 36 | * @throws EpiphanyException 非检查异常 37 | */ 38 | @Override 39 | public byte[] serialize(Object obj) throws SerializationException { 40 | if(obj==null) { 41 | return null; 42 | } 43 | try ( ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 44 | ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); ){ 45 | objectOutputStream.writeObject(obj); 46 | return GzCompressUtil.compress(byteArrayOutputStream.toByteArray()); 47 | } catch (Exception e) { 48 | throw new EpiphanyException(e); 49 | } 50 | } 51 | 52 | 53 | /** 54 | * 字符串反序列化为对象 55 | * @param redisData 序列化的字符串 56 | * @return jvm对象 57 | * @throws EpiphanyException 非检查异常 58 | */ 59 | @Override 60 | public Object deserialize(byte[] redisData) throws SerializationException { 61 | if(redisData==null) { 62 | return null; 63 | } 64 | Object newObj = null; 65 | redisData = GzCompressUtil.decompress(redisData); 66 | try ( ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(redisData); 67 | ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream); ){ 68 | newObj = objectInputStream.readObject(); 69 | } catch (Exception e) { 70 | throw new EpiphanyException(e); 71 | } 72 | return newObj; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/brmayi/epiphany/service/DataService.java: -------------------------------------------------------------------------------- 1 | package com.brmayi.epiphany.service; 2 | 3 | import java.util.List; 4 | 5 | import com.brmayi.epiphany.exception.EpiphanyException; 6 | /** 7 | * 8 | * 通用文件处理类:这是业务代码的核心类 9 | * 10 | * .==. .==. 11 | * //'^\\ //^'\\ 12 | * // ^^\(\__/)/^ ^^\\ 13 | * //^ ^^ ^/6 6\ ^^^ \\ 14 | * //^ ^^ ^/( .. )\^ ^^ \\ 15 | * // ^^ ^/\|v""v|/\^^ ^ \\ 16 | * // ^^/\/ / '~~' \ \/\^ ^\\ 17 | * ---------------------------------------- 18 | * HERE BE DRAGONS WHICH CAN CREATE MIRACLE 19 | * 20 | * @author 静儿(987489055@qq.com) 21 | * 22 | */ 23 | public interface DataService { 24 | /** 25 | * 根据ID进行业务数据处理,因为增量和全量复用此接口,可以在实现类中做判断,如果path为null为增量,否则为全量 26 | * @param dealIds 处理ID 27 | * @param path 要保存到的磁盘路径,不需要保存磁盘,可以为null 28 | * @throws EpiphanyException 抛出通用异常 29 | */ 30 | public void dealDataByIds(List dealIds, String path) throws EpiphanyException; 31 | 32 | /** 33 | * 根据时间区间获取id列表 34 | * @param beginTime 开始时间 35 | * @param endTime 结束时间 36 | * @return id列表 37 | * @throws EpiphanyException 抛出通用异常 38 | */ 39 | public List getIds(String beginTime, String endTime) throws EpiphanyException; 40 | 41 | /** 42 | * 根据id区间获取id列表 43 | * @param beginId 开始ID 44 | * @param endId 结束ID 45 | * @return id列表 46 | * @throws EpiphanyException 抛出通用异常 47 | */ 48 | public List getIdsByBeginEnd(long beginId, long endId) throws EpiphanyException; 49 | 50 | /** 51 | * 根据开始结束ID处理数据 52 | * @param beginId 开始ID 53 | * @param endId 结束ID 54 | * @param path 要保存到的磁盘路径,不需要保存磁盘,可以为null 55 | * @throws EpiphanyException 抛出通用异常 56 | */ 57 | public void dealDataByBeginEnd(long beginId, long endId, String path) throws EpiphanyException; 58 | 59 | /** 60 | * 取得最大ID 61 | * @return 最大ID 62 | * @throws EpiphanyException 抛出通用异常 63 | */ 64 | public long getMaxId() throws EpiphanyException; 65 | 66 | 67 | /** 68 | * 取得最小ID 69 | * @return 最小ID 70 | * @throws EpiphanyException 抛出通用异常 71 | */ 72 | public long getMinId() throws EpiphanyException; 73 | 74 | /** 75 | * 取得优先运行的数据 76 | * @return 数据ID队列 77 | * @throws EpiphanyException 抛出通用异常 78 | */ 79 | public List getNiceQueue() throws EpiphanyException; 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/brmayi/epiphany/util/EpiphanyFileUtil.java: -------------------------------------------------------------------------------- 1 | package com.brmayi.epiphany.util; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.RandomAccessFile; 6 | import java.text.SimpleDateFormat; 7 | import java.util.Calendar; 8 | 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import com.brmayi.epiphany.exception.EpiphanyException; 13 | 14 | /** 15 | * 文件处理工具类 16 | * 17 | * 18 | * .==. .==. 19 | * //'^\\ //^'\\ 20 | * // ^^\(\__/)/^ ^^\\ 21 | * //^ ^^ ^/6 6\ ^^^ \\ 22 | * //^ ^^ ^/( .. )\^ ^^ \\ 23 | * // ^^ ^/\|v""v|/\^^ ^ \\ 24 | * // ^^/\/ / '~~' \ \/\^ ^\\ 25 | * ---------------------------------------- 26 | * HERE BE DRAGONS WHICH CAN CREATE MIRACLE 27 | * 28 | * @author 静儿(987489055@qq.com) 29 | * 30 | */ 31 | public class EpiphanyFileUtil { 32 | private final static Logger LOGGER = LoggerFactory.getLogger(EpiphanyFileUtil.class); 33 | 34 | /** 35 | * 或缺文件路径 36 | * @param filePath 文件根路径 37 | * @return 加上当前时间目录的路径 38 | */ 39 | public static String getPath(String filePath) { 40 | SimpleDateFormat sdfForDir = new SimpleDateFormat("yyyyMMdd"); 41 | Calendar date = Calendar.getInstance(); 42 | String dateFormat = sdfForDir.format(date.getTime()); 43 | return new StringBuilder(filePath).append("/").append(dateFormat).append("/").toString(); 44 | } 45 | 46 | /** 47 | * 创建磁盘目录 48 | * @param filePath 文件根路径 49 | * @return 加上当前时间目录的路径 50 | */ 51 | public static String createPath(String filePath) { 52 | SimpleDateFormat sdfForDir = new SimpleDateFormat("yyyyMMdd"); 53 | Calendar date = Calendar.getInstance(); 54 | String dateFormat = sdfForDir.format(date.getTime()); 55 | StringBuffer path = new StringBuffer(filePath).append("/").append(dateFormat); 56 | File f = new File(path.toString()); 57 | if(f.exists()) { 58 | String[] children = f.list(); 59 | for(String c : children) { 60 | new File(f, c).delete(); 61 | } 62 | } else { 63 | f.mkdirs(); 64 | } 65 | return path.append("/").toString(); 66 | } 67 | 68 | 69 | /** 70 | * 将json数据写入磁盘文件,分批写释放内存 71 | * @param path 文件全路径 72 | * @param content 写入内容 73 | */ 74 | public static void writeToFile(String path, String content) throws EpiphanyException{ 75 | try (RandomAccessFile randomFile = new RandomAccessFile(path, "rw");){// 打开一个随机访问文件流,按读写方式 76 | // 文件长度,字节数 77 | long fileLength = randomFile.length(); 78 | //将写文件指针移到文件尾。 79 | randomFile.seek(fileLength); 80 | randomFile.write(content.getBytes("UTF8")); 81 | } catch (IOException e) { 82 | LOGGER.error("写入全量专辑文件失败", e); 83 | throw new EpiphanyException(e); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/com/brmayi/epiphany/util/GzCompressUtil.java: -------------------------------------------------------------------------------- 1 | package com.brmayi.epiphany.util; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.FileInputStream; 6 | import java.io.FileNotFoundException; 7 | import java.io.FileOutputStream; 8 | import java.io.IOException; 9 | import java.util.concurrent.ExecutorService; 10 | import java.util.concurrent.Executors; 11 | import java.util.zip.Deflater; 12 | import java.util.zip.GZIPOutputStream; 13 | import java.util.zip.Inflater; 14 | 15 | import org.slf4j.Logger; 16 | import org.slf4j.LoggerFactory; 17 | 18 | import com.brmayi.epiphany.exception.EpiphanyException; 19 | import com.brmayi.epiphany.pool.UnlimitedKeyedPoolableObjectFactory; 20 | import com.brmayi.epiphany.util.sub.GzCompress; 21 | 22 | /** 23 | * 24 | * 25 | * 26 | * .==. .==. 27 | * //'^\\ //^'\\ 28 | * // ^^\(\__/)/^ ^^\\ 29 | * //^ ^^ ^/6 6\ ^^^ \\ 30 | * //^ ^^ ^/( .. )\^ ^^ \\ 31 | * // ^^ ^/\|v""v|/\^^ ^ \\ 32 | * // ^^/\/ / '~~' \ \/\^ ^\\ 33 | * ---------------------------------------- 34 | * HERE BE DRAGONS WHICH CAN CREATE MIRACLE 35 | * 36 | * 这里单独将压缩提出来是因为压缩计算量特别大,非常占用CPU,所以需要限制线程数 37 | * 建议将大文件写入磁盘,这时候速度和压缩比,后者更重要,所以采用gzip而没有支持deflate实现 38 | * @author 静儿(987489055@qq.com) 39 | * 40 | */ 41 | public class GzCompressUtil { 42 | private final static Logger LOGGER = LoggerFactory.getLogger(GzCompressUtil.class); 43 | private static final ExecutorService fixedThreadPoolForGz = Executors.newFixedThreadPool(6); 44 | 45 | 46 | /** 47 | * 压缩 48 | * 49 | * @param data 50 | * 待压缩数据 51 | * @return byte[] 压缩后的数据 52 | */ 53 | public static byte[] compress(byte[] data) { 54 | byte[] output = new byte[0]; 55 | 56 | Deflater compresser = new Deflater(); 57 | compresser.reset(); 58 | compresser.setInput(data); 59 | compresser.finish(); 60 | try (ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length)){ 61 | byte[] buf = new byte[data.length]; 62 | while (!compresser.finished()) { 63 | int i = compresser.deflate(buf); 64 | bos.write(buf, 0, i); 65 | } 66 | output = bos.toByteArray(); 67 | } catch (Exception e) { 68 | output = data; 69 | LOGGER.error("队列消息压缩错误", e); 70 | } 71 | compresser.end(); 72 | return output; 73 | } 74 | 75 | /** 76 | * 解压缩 77 | * 78 | * @param data 待压缩的数据 79 | * @return byte[] 解压缩后的数据 80 | */ 81 | public static byte[] decompress(byte[] data) { 82 | byte[] output = new byte[0]; 83 | 84 | Inflater decompresser = new Inflater(); 85 | decompresser.reset(); 86 | decompresser.setInput(data); 87 | 88 | try (ByteArrayOutputStream o = new ByteArrayOutputStream(data.length);){ 89 | byte[] buf = new byte[1024]; 90 | while (!decompresser.finished()) { 91 | int i = decompresser.inflate(buf); 92 | o.write(buf, 0, i); 93 | } 94 | output = o.toByteArray(); 95 | } catch (Exception e) { 96 | output = data; 97 | e.printStackTrace(); 98 | } 99 | decompresser.end(); 100 | return output; 101 | } 102 | /** 103 | * 执行gz压缩 104 | * @param path 文件路径 105 | * @throws EpiphanyException 抛出压缩异常 106 | */ 107 | @Deprecated 108 | public static void gzCompress(String path) throws EpiphanyException { 109 | try { 110 | GzCompress gzCompressTask = (GzCompress) UnlimitedKeyedPoolableObjectFactory.objectPool.borrowObject(GzCompress.class.getName()); 111 | gzCompressTask.setPath(path); 112 | fixedThreadPoolForGz.execute(gzCompressTask);//压缩 113 | } catch(Exception e) { 114 | LOGGER.error("gzcompress exception", e); 115 | throw new EpiphanyException(e); 116 | } 117 | } 118 | 119 | /** 120 | * 同步压缩,为了好计算是否终止状态,将来真正有需求可以支持同步和异步两种模式 121 | * @param path 文件路径 122 | * @throws EpiphanyException 抛出压缩异常 123 | */ 124 | public static void compressFile(String path) throws EpiphanyException { 125 | try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(path)); 126 | GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(path+".gz"));){ 127 | byte[] array = new byte[1024]; 128 | int number = -1; 129 | while((number = in.read(array, 0, array.length)) != -1) { 130 | out.write(array, 0, number); 131 | } 132 | } catch (FileNotFoundException e) { 133 | LOGGER.error("压缩错误", e); 134 | throw new EpiphanyException(e); 135 | } catch (IOException e) { 136 | LOGGER.error("压缩错误", e); 137 | throw new EpiphanyException(e); 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/main/java/com/brmayi/epiphany/util/TimerUtil.java: -------------------------------------------------------------------------------- 1 | package com.brmayi.epiphany.util; 2 | 3 | import java.util.Calendar; 4 | import java.util.Date; 5 | import java.util.Timer; 6 | import java.util.TimerTask; 7 | /** 8 | * 9 | * 10 | * 11 | * .==. .==. 12 | * //'^\\ //^'\\ 13 | * // ^^\(\__/)/^ ^^\\ 14 | * //^ ^^ ^/6 6\ ^^^ \\ 15 | * //^ ^^ ^/( .. )\^ ^^ \\ 16 | * // ^^ ^/\|v""v|/\^^ ^ \\ 17 | * // ^^/\/ / '~~' \ \/\^ ^\\ 18 | * ---------------------------------------- 19 | * HERE BE DRAGONS WHICH CAN CREATE MIRACLE 20 | * 21 | * @author 静儿(987489055@qq.com) 22 | * 23 | */ 24 | public class TimerUtil { 25 | private static final long PERIOD_DAY = 24 * 60 * 60 * 1000; 26 | private static final Timer timer = new Timer(); 27 | 28 | /** 29 | * 每天执行一次的定时器 30 | * @param task 要执行的定时任务 31 | * @param hour 几点执行 32 | * @param minute 几分执行 33 | * @param second 几秒执行 34 | */ 35 | public static void runEveryday(TimerTask task, int hour, int minute, int second) { 36 | Calendar calendar = Calendar.getInstance(); 37 | calendar.set(Calendar.HOUR_OF_DAY, hour); 38 | calendar.set(Calendar.MINUTE, minute); 39 | calendar.set(Calendar.SECOND, second); 40 | Date date=calendar.getTime(); //第一次执行定时任务的时间 41 | if (date.before(new Date())) { 42 | date = addDay(date, 1); 43 | } 44 | timer.schedule(task,date,PERIOD_DAY); 45 | } 46 | 47 | // 增加或减少天数 48 | private static Date addDay(Date date, int num) { 49 | Calendar startDT = Calendar.getInstance(); 50 | startDT.setTime(date); 51 | startDT.add(Calendar.DAY_OF_MONTH, num); 52 | return startDT.getTime(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/brmayi/epiphany/util/sub/GzCompress.java: -------------------------------------------------------------------------------- 1 | package com.brmayi.epiphany.util.sub; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.FileInputStream; 5 | import java.io.FileNotFoundException; 6 | import java.io.FileOutputStream; 7 | import java.io.IOException; 8 | import java.util.zip.GZIPOutputStream; 9 | 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | 13 | import com.brmayi.epiphany.util.GzCompressUtil; 14 | /** 15 | * 16 | * 17 | * 18 | * .==. .==. 19 | * //'^\\ //^'\\ 20 | * // ^^\(\__/)/^ ^^\\ 21 | * //^ ^^ ^/6 6\ ^^^ \\ 22 | * //^ ^^ ^/( .. )\^ ^^ \\ 23 | * // ^^ ^/\|v""v|/\^^ ^ \\ 24 | * // ^^/\/ / '~~' \ \/\^ ^\\ 25 | * ---------------------------------------- 26 | * HERE BE DRAGONS WHICH CAN CREATE MIRACLE 27 | * 28 | * @author 静儿(987489055@qq.com) 29 | * 30 | */ 31 | public class GzCompress implements Runnable { 32 | private String path; 33 | private final static Logger LOGGER = LoggerFactory.getLogger(GzCompressUtil.class); 34 | /** 35 | * hadoop支持gz格式自解压,gz可以压缩到原文本文件的1/7 36 | * 37 | * @param path 压缩的文件路径 38 | */ 39 | public void setPath(String path) { 40 | this.path = path; 41 | } 42 | 43 | /** 44 | * hadoop支持gz格式自解压,gz可以压缩到原文本文件的1/7 45 | * 46 | */ 47 | @Override 48 | public void run() { 49 | try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(path)); 50 | GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(path+".gz"));){ 51 | byte[] array = new byte[1024]; 52 | int number = -1; 53 | while((number = in.read(array, 0, array.length)) != -1) { 54 | out.write(array, 0, number); 55 | } 56 | } catch (FileNotFoundException e) { 57 | LOGGER.error("压缩错误", e); 58 | } catch (IOException e) { 59 | LOGGER.error("压缩错误", e); 60 | } 61 | } 62 | } --------------------------------------------------------------------------------