parent
f2d2422848
commit
3ccf3ad5ab
@ -1,17 +0,0 @@
|
||||
package com.xxl.job.core.glue.cache;
|
||||
|
||||
/**
|
||||
* chche interface
|
||||
* @author xuxueli 2016-1-8 15:57:27
|
||||
*/
|
||||
public interface ICache {
|
||||
|
||||
public boolean set(String key, Object value);
|
||||
|
||||
public boolean set(String key, Object value, long timeout);
|
||||
|
||||
public Object get(String key);
|
||||
|
||||
public boolean remove(String key);
|
||||
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package com.xxl.job.core.glue.cache;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* local interface
|
||||
* @author Administrator
|
||||
*/
|
||||
public class LocalCache implements ICache{
|
||||
|
||||
private static final LocalCache instance = new LocalCache();
|
||||
public static LocalCache getInstance(){
|
||||
return instance;
|
||||
}
|
||||
|
||||
private static final ConcurrentHashMap<String, Object> cacheMap = new ConcurrentHashMap<String, Object>();
|
||||
private static final long CACHE_TIMEOUT = 5000;
|
||||
|
||||
private static String makeTimKey(String key){
|
||||
return key.concat("_tim");
|
||||
}
|
||||
private static String makeDataKey(String key){
|
||||
return key.concat("_data");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean set(String key, Object value) {
|
||||
cacheMap.put(makeTimKey(key), System.currentTimeMillis() + CACHE_TIMEOUT);
|
||||
cacheMap.put(makeDataKey(key), value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean set(String key, Object value, long timeout) {
|
||||
cacheMap.put(makeTimKey(key), System.currentTimeMillis() + timeout);
|
||||
cacheMap.put(makeDataKey(key), value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(String key) {
|
||||
Object tim = cacheMap.get(makeTimKey(key));
|
||||
if (tim != null && System.currentTimeMillis() < Long.parseLong(tim.toString())) {
|
||||
return cacheMap.get(makeDataKey(key));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(String key) {
|
||||
cacheMap.remove(makeTimKey(key));
|
||||
cacheMap.remove(makeDataKey(key));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String key = "key01";
|
||||
System.out.println(LocalCache.getInstance().get(key));
|
||||
|
||||
LocalCache.getInstance().set(key, "v1");
|
||||
System.out.println(LocalCache.getInstance().get(key));
|
||||
|
||||
LocalCache.getInstance().set(key, "v2");
|
||||
System.out.println(LocalCache.getInstance().get(key));
|
||||
|
||||
LocalCache.getInstance().remove(key);
|
||||
System.out.println(LocalCache.getInstance().get(key));
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +1,30 @@
|
||||
package com.xxl.job.core.handler.impl;
|
||||
|
||||
import com.xxl.job.core.glue.GlueFactory;
|
||||
import com.xxl.job.core.handler.IJobHandler;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* glue job handler
|
||||
* @author xuxueli 2016-5-19 21:05:45
|
||||
*/
|
||||
public class GlueJobHandler extends IJobHandler {
|
||||
private static Logger logger = LoggerFactory.getLogger(GlueJobHandler.class);
|
||||
|
||||
private int jobId;
|
||||
public GlueJobHandler(int jobId) {
|
||||
this.jobId = jobId;
|
||||
private long glueUpdatetime;
|
||||
private IJobHandler jobHandler;
|
||||
public GlueJobHandler(IJobHandler jobHandler, long glueUpdatetime) {
|
||||
this.jobHandler = jobHandler;
|
||||
this.glueUpdatetime = glueUpdatetime;
|
||||
}
|
||||
public long getGlueUpdatetime() {
|
||||
return glueUpdatetime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String... params) throws Exception {
|
||||
GlueFactory.glue(jobId, params);
|
||||
logger.info("----------- glue.version:{} -----------", glueUpdatetime);
|
||||
jobHandler.execute(params);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in new issue