Skip to content

Commit 739eebd

Browse files
committed
第一次提交
0 parents  commit 739eebd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3492
-0
lines changed

.gitignore

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#eclipse files
2+
.classpath
3+
.project
4+
.settings
5+
# Built application files
6+
*.apk
7+
*.ap_
8+
9+
# Files for the Dalvik VM
10+
*.dex
11+
12+
# Java class files
13+
*.class
14+
15+
# Generated files
16+
/bin/
17+
/gen/
18+
/out/
19+
20+
# Gradle files
21+
.gradle/
22+
gradle/
23+
gradlew
24+
gradlew.bat
25+
build/
26+
27+
# Local configuration file (sdk path, etc)
28+
my*.properties
29+
30+
# Proguard folder generated by Eclipse
31+
proguard/
32+
33+
# Log Files
34+
*.log
35+
36+
# Android Studio Navigation editor temp files
37+
.navigation/
38+
39+
# Android Studio captures folder
40+
captures/
41+
42+
# Intellij
43+
*.iml
44+
45+
# Keystore files
46+
*.jks

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# GradleWebApp

build.gradle

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* This build file was generated by the Gradle 'init' task.
3+
*
4+
* This generated file contains a sample Java Library project to get you started.
5+
* For more details take a look at the Java Libraries chapter in the Gradle
6+
* user guide available at https://docs.gradle.org/3.4/userguide/java_library_plugin.html
7+
*/
8+
9+
// Apply the java-library plugin to add support for Java Library
10+
apply plugin: 'java'
11+
apply plugin: 'war'
12+
apply plugin: 'eclipse-wtp'
13+
sourceCompatibility=1.8
14+
targetCompatibility =1.8
15+
16+
[compileJava, javadoc, compileTestJava]*.options*.encoding = 'UTF-8'
17+
18+
// In this section you declare where to find the dependencies of your project
19+
repositories {
20+
// Use jcenter for resolving your dependencies.
21+
// You can declare any Maven/Ivy/file repository here.
22+
//jcenter()
23+
maven {
24+
url "http://192.168.2.207:8081/nexus/content/groups/public"
25+
}
26+
}
27+
28+
ext{
29+
SPRING_VERSION='4.3.5.RELEASE'
30+
31+
}
32+
33+
dependencies {
34+
// The production code uses the SLF4J logging API at compile time
35+
compile 'org.slf4j:slf4j-api:1.7.21'
36+
37+
// Declare the dependency for your favourite test framework you want to use in your tests.
38+
// TestNG is also supported by the Gradle Test task. Just change the
39+
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
40+
// 'test.useTestNG()' to your build script.
41+
testCompile 'junit:junit:4.12'
42+
43+
compileOnly group: 'javax.servlet',name: 'javax.servlet-api',version: '3.+'
44+
compile group: 'org.springframework', name: 'spring-aop', version: SPRING_VERSION
45+
compile group: 'org.springframework', name: 'spring-beans', version: SPRING_VERSION
46+
compile group: 'org.springframework', name: 'spring-context', version: SPRING_VERSION
47+
compile group: 'org.springframework', name: 'spring-context-support', version: SPRING_VERSION
48+
compile group: 'org.springframework', name: 'spring-web', version: SPRING_VERSION
49+
compile group: 'org.springframework', name: 'spring-webmvc', version: SPRING_VERSION
50+
compile group: 'org.springframework', name: 'spring-core', version: SPRING_VERSION
51+
52+
compile group: 'aopalliance', name: 'aopalliance', version: '1.0'
53+
compile group: 'org.aspectj', name: 'aspectjweaver', version: '1.8.10'
54+
55+
56+
57+
compile group: 'redis.clients', name: 'jedis', version: '2.8.+'
58+
compile group: 'net.sf.ehcache', name: 'ehcache', version: '2.8.0'
59+
//compile group: 'net.sf.ehcache', name: 'ehcache', version: '3.2.0'
60+
61+
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.+'
62+
63+
compile group: 'joda-time', name: 'joda-time', version: '2.+'
64+
65+
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.+'
66+
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.+'
67+
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.8.+'
68+
69+
compile group: 'org.apache.commons', name: 'commons-pool2', version: '2.4.2'
70+
compile group: 'commons-codec', name: 'commons-codec', version: '1.10'
71+
compile group: 'commons-io', name: 'commons-io', version: '2.5'
72+
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
73+
74+
}
75+

settings.gradle

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* This settings file was generated by the Gradle 'init' task.
3+
*
4+
* The settings file is used to specify which projects to include in your build.
5+
* In a single project build this file can be empty or even removed.
6+
*
7+
* Detailed information about configuring a multi-project build in Gradle can be found
8+
* in the user guide at https://docs.gradle.org/3.4/userguide/multi_project_builds.html
9+
*/
10+
11+
/*
12+
// To declare projects as part of a multi-project build use the 'include' method
13+
include 'shared'
14+
include 'api'
15+
include 'services:webservice'
16+
*/
17+
18+
rootProject.name = 'GradleWebApp2'
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package com.api.album.controller;
2+
3+
4+
import javax.annotation.Resource;
5+
6+
import org.springframework.stereotype.Controller;
7+
import org.springframework.web.bind.annotation.PathVariable;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RequestMethod;
10+
import org.springframework.web.bind.annotation.ResponseBody;
11+
12+
import com.api.album.service.IAlbumService;
13+
import com.base.cache.CacheManager;
14+
import com.base.cache.CacheManagerTOT;
15+
import com.base.cache.album.AlbumCache;
16+
import com.base.commons.constant.KeyPrefix;
17+
import com.base.commons.constant.StatusCode;
18+
import com.base.vo.album.AlbumResult;
19+
import com.base.vo.statistic.StatisticResult;
20+
21+
@Controller
22+
@RequestMapping("/api/v1")
23+
public class AlbumController {
24+
25+
26+
// @Resource(name="cManagerTOT")
27+
// private CacheManagerTOT cache;
28+
29+
@Resource(name="cManager")
30+
private CacheManager cache;
31+
@Resource
32+
private IAlbumService albumService;
33+
34+
@RequestMapping(value = "/getAlbumCache/{albumId}", produces = { "application/json;charset=UTF-8" }, method = RequestMethod.GET)
35+
@ResponseBody
36+
public AlbumResult getAlbumCache(@PathVariable("albumId") String albumId) {
37+
AlbumResult result = new AlbumResult();
38+
AlbumCache album =(AlbumCache) cache.getLocalCache(KeyPrefix.keyPrefix+albumId);
39+
// System.out.println(KeyPrefix.keyPrefix+albumId);
40+
// System.out.println(cache.getMemoryStoreSize());
41+
// System.out.println(cache.getSize());
42+
if (album == null){
43+
result.failure(StatusCode.CACHE_ERROR);
44+
}else{
45+
result.setAlbum(album.getAlbumVO());
46+
result.setPlist(album.getProgramListVO());
47+
result.setTotal(album.getProgramListVO().size());
48+
}
49+
return result;
50+
}
51+
@RequestMapping(value = "/setAlbumCache/{albumNum}", produces = { "application/json;charset=UTF-8" }, method = RequestMethod.GET)
52+
@ResponseBody
53+
public AlbumResult setAlbumCache(@PathVariable("albumNum")Integer albumNum) {
54+
System.out.println("Controller-----"+cache);
55+
AlbumResult result = new AlbumResult();
56+
albumService.setAlbumCache(albumNum);
57+
return result;
58+
}
59+
@RequestMapping(value = "/setAlbumCacheById/{albumId}", produces = { "application/json;charset=UTF-8" }, method = RequestMethod.GET)
60+
@ResponseBody
61+
public AlbumResult setAlbumCacheById(@PathVariable("albumId")Integer albumId) {
62+
System.out.println("Controller-----"+cache);
63+
AlbumResult result = new AlbumResult();
64+
albumService.setAlbumCacheById(albumId);
65+
return result;
66+
}
67+
68+
@RequestMapping(value = "/getTotalEntries", produces = { "application/json;charset=UTF-8" }, method = RequestMethod.GET)
69+
@ResponseBody
70+
public AlbumResult getTotalEntries() {
71+
AlbumResult result = new AlbumResult();
72+
result.setTotalEntries((long) albumService.getTotalEntries());
73+
return result;
74+
}
75+
@RequestMapping(value = "/getElementSize/{albumId}", produces = { "application/json;charset=UTF-8" }, method = RequestMethod.GET)
76+
@ResponseBody
77+
public AlbumResult getElementSize(@PathVariable("albumId")Integer albumId) {
78+
AlbumResult result = new AlbumResult();
79+
result.setAlbumCacheSize(albumService.getElementSize(albumId));
80+
return result;
81+
}
82+
83+
@RequestMapping(value = "/getStatistics/{albumId}", produces = { "application/json;charset=UTF-8" }, method = RequestMethod.GET)
84+
@ResponseBody
85+
public StatisticResult getStatistics(@PathVariable("albumId")Integer albumId) {
86+
StatisticResult result = new StatisticResult();
87+
result.setLocalDiskSize(cache.getStatistics().getLocalDiskSize());
88+
result.setLocalDiskSizeInBytes(cache.getStatistics().getLocalDiskSizeInBytes());
89+
result.setLocalHeapSize(cache.getStatistics().getLocalHeapSize());
90+
result.setLocalHeapSizeInBytes(cache.getStatistics().getLocalHeapSizeInBytes());
91+
result.setLocalSize(cache.getStatistics().getSize());
92+
result.setAlbumCacheSize(albumService.getElementSize(albumId));
93+
return result;
94+
}
95+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.api.album.service;
2+
3+
public interface IAlbumService {
4+
public void setAlbumCache(int albumNum);
5+
public void setAlbumCacheById(int albumId);
6+
public int getTotalEntries();
7+
public long getElementSize(int albumId);
8+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.api.album.service.impl;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import javax.annotation.Resource;
7+
8+
import org.springframework.stereotype.Service;
9+
10+
import com.api.album.service.IAlbumService;
11+
import com.base.cache.CacheManager;
12+
import com.base.cache.CacheManagerTOT;
13+
import com.base.cache.album.AlbumCache;
14+
import com.base.vo.album.AlbumVO;
15+
import com.base.vo.program.ProgramVO;
16+
import com.base.vo.tag.TagVO;
17+
18+
@Service
19+
public class AlbumServiceImpl implements IAlbumService{
20+
private final String keyPrefix = "local_cache_album_id_";
21+
22+
// @Resource(name="cManagerTOT")
23+
// private CacheManagerTOT cManager;
24+
25+
@Resource(name="cManager")
26+
private CacheManager cManager;
27+
28+
@Override
29+
public void setAlbumCache(int albumNum) {
30+
// TODO Auto-generated method stub
31+
System.out.println("Service-----"+cManager);
32+
for (int i = 0; i < albumNum; i++) {
33+
AlbumCache c = getCache(i);
34+
cManager.setLocalCache(keyPrefix+i, c);
35+
System.out.println(keyPrefix+i+"====="+c);
36+
}
37+
}
38+
39+
@Override
40+
public void setAlbumCacheById(int albumId){
41+
System.out.println("Service-----"+cManager);
42+
AlbumCache c = getCache(albumId);
43+
cManager.setLocalCache(keyPrefix+albumId, c);
44+
System.out.println(keyPrefix+albumId+"====="+c);
45+
}
46+
47+
@Override
48+
public int getTotalEntries(){
49+
return cManager.getTotalEntries();
50+
}
51+
@Override
52+
public long getElementSize(int albumId){
53+
String key = keyPrefix+albumId;
54+
return cManager.getElementSize(key);
55+
}
56+
57+
private static AlbumCache getCache(int j) {
58+
AlbumCache c = new AlbumCache();
59+
60+
// 封装vo
61+
AlbumVO albumVo = new AlbumVO();
62+
albumVo.setAlbumId(j);
63+
albumVo.setAlbumType(1);
64+
albumVo.setAlbumName("但是风格谁的风格");
65+
albumVo.setAuthor("反跟");
66+
albumVo.setSummary("但是风格");
67+
albumVo.setPlayStatus("21");
68+
albumVo.setTags("21,15,12");
69+
List<TagVO> list = new ArrayList<>();
70+
TagVO tag = new TagVO();
71+
tag.setChannelId(51);
72+
tag.setTagId(21);
73+
tag.setTagName("谁加的,没名");
74+
list.add(tag);
75+
list.add(tag);
76+
list.add(tag);
77+
albumVo.setTagList(list);
78+
albumVo.setAlbumCover(
79+
"http://192.168.2.195/res/upload/cdn/kting_huawei_fm/cmsProgram123456/cover/album/20161229/23kf8qr9.jpg"+j);
80+
albumVo.setChannelId(52);
81+
albumVo.setRssCount(1000000L);
82+
albumVo.setProgramNum(3000);
83+
84+
// 封装programList
85+
List<ProgramVO> plist = new ArrayList<>();
86+
for (int i = 0; i < 3000; i++) {
87+
ProgramVO pro = new ProgramVO();
88+
pro.setProgramId(i);
89+
pro.setAlbumId(12L);
90+
pro.setProgramName("阿德法大赛");
91+
pro.setProgramCover(
92+
"http://192.168.2.195/res/upload/cdn/kting_huawei_fm/cmsProgram123456/cover/program/20161206/21rkif1i.jpg_"+j+"_"+i);
93+
pro.setAudioUrl("http://192.168.2.195/res/upload/cdn/kting_huawei_fm/audio/convert/20161206/21rkmfgu.mp3_"+j+"_"+i);
94+
pro.setAnchorName("阿德法大赛");
95+
pro.setPlayNum(1000000L);
96+
pro.setDuration(169700L);
97+
pro.setFileSize(1358283L);
98+
plist.add(pro);
99+
}
100+
101+
c.setAlbumVO(albumVo);
102+
c.setProgramListVO(plist);
103+
104+
return c;
105+
}
106+
}

0 commit comments

Comments
 (0)