Commit e580084a authored by yanzg's avatar yanzg

修改实例化关系

parent 4bf722af
package com.yanzuoguang.media;
/**
* 获取视频是否已经在处理
*
* @author 颜佐光
*/
public interface MediaCache {
/**
* 获取缓存是否正在执行
*
* @param req 需要运行的请求参数
* @param runnable 当没有运行时,需要执行的函数
* @return
*/
MediaResVo start(MediaReqVo req, Runnable runnable);
/**
* 获取缓存是否正在运行
*
* @param req
* @return
*/
MediaResVo get(MediaReqVo req);
/**
* 写入处理结果到缓存中
*
* @param res
*/
void put(MediaResVo res);
}
package com.yanzuoguang.media;
import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.thread.ThreadHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class MediaFirst {
/**
* 判断该视频是否已经实现处理
*/
@Autowired(required = false)
private MediaCache cache;
public MediaResVo start(MediaReqVo req) {
MediaResVo res = cache.start(req, new Runnable() {
@Override
public void run() {
ThreadHelper.runThread(new Runnable() {
@Override
public void run() {
handle(req);
}
});
}
});
return res;
}
private void handle(MediaReqVo req) {
do {
MediaResVo res = cache.get(req);
if (res == null) {
res = JsonHelper.to(req, MediaResVo.class);
} else if (res.getCount() < 1) {
break;
}
res.subCount();
cache.put(res);
ThreadHelper.sleep(res.getSplit());
} while (true);
}
}
package com.yanzuoguang.media;
import com.yanzuoguang.util.vo.BaseVo;
import io.swagger.annotations.ApiModelProperty;
/**
* 获取视频首页请求参数
*
* @author 颜佐光
*/
public class MediaReqVo extends BaseVo {
/**
* 汲取视频的url
*/
@ApiModelProperty(notes = "m3mu地址")
private String url;
/**
* m3mu地址截取次数
*/
@ApiModelProperty(notes = "m3mu地址截取次数")
private int count;
/**
* m3mu地址截取间隔时间
*/
@ApiModelProperty(notes = "m3mu地址截取间隔时间")
private int split;
/**
* m3mu缓存的图片地址
*/
@ApiModelProperty(notes = "m3mu缓存的图片地址")
private String imageUrl;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public int getSplit() {
return split;
}
public void setSplit(int split) {
this.split = split;
}
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
}
package com.yanzuoguang.media;
/**
* 获取视频结果
*
* @author 颜佐光
*/
public class MediaResVo extends MediaReqVo {
public void subCount() {
this.setCount(this.getCount() - 1);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment