Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
11c2dcd0
Commit
11c2dcd0
authored
Nov 12, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改实例化关系
parent
e580084a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
190 additions
and
29 deletions
+190
-29
MediaCache.java
...image/src/main/java/com/yanzuoguang/media/MediaCache.java
+1
-24
MediaCacheBase.java
...e/src/main/java/com/yanzuoguang/media/MediaCacheBase.java
+40
-0
MediaCacheLocal.java
.../src/main/java/com/yanzuoguang/media/MediaCacheLocal.java
+41
-0
MediaFirst.java
...image/src/main/java/com/yanzuoguang/media/MediaFirst.java
+79
-5
MediaFirstTest.java
yzg-util-image/src/test/java/helper/MediaFirstTest.java
+29
-0
No files found.
yzg-util-image/src/main/java/com/yanzuoguang/media/MediaCache.java
View file @
11c2dcd0
...
@@ -6,28 +6,5 @@ package com.yanzuoguang.media;
...
@@ -6,28 +6,5 @@ package com.yanzuoguang.media;
*
*
* @author 颜佐光
* @author 颜佐光
*/
*/
public
interface
MediaCache
{
public
interface
MediaCache
extends
MediaCacheBase
{
/**
* 获取缓存是否正在执行
*
* @param req 需要运行的请求参数
* @param runnable 当没有运行时,需要执行的函数
* @return
*/
MediaResVo
start
(
MediaReqVo
req
,
Runnable
runnable
);
/**
* 获取缓存是否正在运行
*
* @param req
* @return
*/
MediaResVo
get
(
MediaReqVo
req
);
/**
* 写入处理结果到缓存中
*
* @param res
*/
void
put
(
MediaResVo
res
);
}
}
yzg-util-image/src/main/java/com/yanzuoguang/media/MediaCacheBase.java
0 → 100644
View file @
11c2dcd0
package
com
.
yanzuoguang
.
media
;
/**
* 视频缓存处理
*
* @author 颜佐光
*/
public
interface
MediaCacheBase
{
/**
* 获取缓存是否正在执行
*
* @param req 需要运行的请求参数
* @param runnable 当没有运行时,需要执行的函数
* @return
*/
MediaResVo
start
(
MediaReqVo
req
,
Runnable
runnable
);
/**
* 获取缓存是否正在运行
*
* @param req
* @return
*/
MediaResVo
get
(
MediaReqVo
req
);
/**
* 写入处理结果到缓存中
*
* @param res
*/
void
sub
(
MediaResVo
res
);
/**
* 锁定临时文件,防止被人修改
*
* @param req
* @param runnable
*/
void
lockTempFile
(
MediaReqVo
req
,
Runnable
runnable
);
}
yzg-util-image/src/main/java/com/yanzuoguang/media/MediaCacheLocal.java
0 → 100644
View file @
11c2dcd0
package
com
.
yanzuoguang
.
media
;
/**
* 本地缓存实现
*
* @author 颜佐光
*/
public
class
MediaCacheLocal
implements
MediaCacheBase
{
/**
* 获取缓存是否正在执行
*
* @param req 需要运行的请求参数
* @param runnable 当没有运行时,需要执行的函数
* @return
*/
@Override
public
MediaResVo
start
(
MediaReqVo
req
,
Runnable
runnable
)
{
return
null
;
}
/**
* 获取缓存是否正在运行
*
* @param req
* @return
*/
@Override
public
MediaResVo
get
(
MediaReqVo
req
)
{
return
null
;
}
/**
* 写入处理结果到缓存中
*
* @param res
*/
@Override
public
void
sub
(
MediaResVo
res
)
{
}
}
yzg-util-image/src/main/java/com/yanzuoguang/media/MediaFirst.java
View file @
11c2dcd0
package
com
.
yanzuoguang
.
media
;
package
com
.
yanzuoguang
.
media
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.FileHelper
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.thread.ThreadHelper
;
import
com.yanzuoguang.util.thread.ThreadHelper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.io.File
;
@Component
@Component
public
class
MediaFirst
{
public
class
MediaFirst
{
...
@@ -14,10 +18,45 @@ public class MediaFirst {
...
@@ -14,10 +18,45 @@ public class MediaFirst {
@Autowired
(
required
=
false
)
@Autowired
(
required
=
false
)
private
MediaCache
cache
;
private
MediaCache
cache
;
private
MediaCacheBase
cacheLocal
=
new
MediaCacheLocal
();
public
MediaFirst
()
{
}
private
MediaCacheBase
getCache
()
{
if
(
cache
!=
null
)
{
return
cache
;
}
return
cacheLocal
;
}
public
MediaFirst
(
MediaCache
cache
)
{
this
.
cache
=
cache
;
}
public
MediaResVo
start
(
MediaReqVo
req
)
{
public
MediaResVo
start
(
MediaReqVo
req
)
{
MediaResVo
res
=
cache
.
start
(
req
,
new
Runnable
()
{
if
(
cache
==
null
)
{
throw
new
CodeException
(
"请通过程序编写视频缓存处理对象"
);
}
// 将临时文件移动到正式文件
cache
.
lockTempFile
(
req
,
new
Runnable
()
{
@Override
public
void
run
()
{
File
file
=
getFile
(
req
);
File
fileTemp
=
getFileTemp
(
req
);
FileHelper
.
createDirectory
(
file
.
getParentFile
());
if
(
fileTemp
.
exists
())
{
fileTemp
.
renameTo
(
file
);
}
}
});
// 通过判断,当没有开启线程运行时,则开启线程运行
MediaResVo
res
=
this
.
getCache
().
start
(
req
,
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
// 开始开启线程运行
ThreadHelper
.
runThread
(
new
Runnable
()
{
ThreadHelper
.
runThread
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
...
@@ -29,6 +68,22 @@ public class MediaFirst {
...
@@ -29,6 +68,22 @@ public class MediaFirst {
return
res
;
return
res
;
}
}
private
File
getFile
(
MediaReqVo
req
)
{
return
new
File
(
req
.
getImageUrl
());
}
private
File
getFileTemp
(
MediaReqVo
req
)
{
return
new
File
(
req
.
getImageUrl
()
+
".tmp"
);
}
private
File
getDownM3muFile
(
MediaReqVo
req
)
{
return
null
;
}
private
File
getCatTempFile
(
MediaReqVo
req
)
{
return
null
;
}
private
void
handle
(
MediaReqVo
req
)
{
private
void
handle
(
MediaReqVo
req
)
{
do
{
do
{
MediaResVo
res
=
cache
.
get
(
req
);
MediaResVo
res
=
cache
.
get
(
req
);
...
@@ -38,12 +93,31 @@ public class MediaFirst {
...
@@ -38,12 +93,31 @@ public class MediaFirst {
break
;
break
;
}
}
res
.
subCount
();
downM3mu
(
req
);
catImage
(
req
);
// 将下载临时文件移动到临时文件
cache
.
put
(
res
);
cache
.
lockTempFile
(
req
,
new
Runnable
()
{
@Override
public
void
run
()
{
File
catTemp
=
getCatTempFile
(
req
);
File
fileTemp
=
getFileTemp
(
req
);
if
(
catTemp
.
exists
())
{
catTemp
.
renameTo
(
fileTemp
);
}
}
});
// 写入缓存
cache
.
sub
(
res
);
ThreadHelper
.
sleep
(
res
.
getSplit
());
ThreadHelper
.
sleep
(
res
.
getSplit
());
}
while
(
true
);
}
while
(
true
);
}
}
private
void
downM3mu
(
MediaReqVo
req
)
{
}
private
void
catImage
(
MediaReqVo
req
)
{
}
}
}
yzg-util-image/src/test/java/helper/MediaFirstTest.java
0 → 100644
View file @
11c2dcd0
package
helper
;
import
com.yanzuoguang.media.MediaFirst
;
import
com.yanzuoguang.media.MediaReqVo
;
import
com.yanzuoguang.media.MediaResVo
;
import
com.yanzuoguang.util.thread.ThreadHelper
;
import
org.junit.Test
;
import
java.io.File
;
public
class
MediaFirstTest
{
@Test
public
void
test
()
{
MediaFirst
first
=
new
MediaFirst
();
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
MediaResVo
start
=
first
.
start
(
new
MediaReqVo
());
File
file
=
new
File
(
start
.
getImageUrl
());
if
(
file
.
exists
())
{
System
.
out
.
println
(
"文件"
+
file
.
getAbsolutePath
()
+
"已经存在"
);
}
else
{
System
.
out
.
println
(
"文件"
+
file
.
getAbsolutePath
()
+
"不存在"
);
}
ThreadHelper
.
sleep
(
5000
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment