mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-05-16 05:20:42 +08:00
v1.4.0 GA
This commit is contained in:
@@ -1,74 +1,67 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.maxkey.cache;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* AbstractCache .
|
||||
* @author Crystal
|
||||
* @version 1.0
|
||||
* @Date 2015/11/12
|
||||
* @Date 2015/11/12
|
||||
*/
|
||||
public abstract class AbstractCache extends Thread {
|
||||
public abstract class AbstractCache extends Thread {
|
||||
|
||||
protected final static Logger _logger = LoggerFactory.getLogger(AbstractCache.class);
|
||||
|
||||
private int interval = 30000/1000;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public AbstractCache() {
|
||||
protected static final Logger _logger = LoggerFactory.getLogger(AbstractCache.class);
|
||||
|
||||
}
|
||||
private int interval = 30000 / 1000;
|
||||
|
||||
public abstract void business();
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(true){
|
||||
_logger.debug("Cache Thread Start run "+getName());
|
||||
_logger.info("Cache Thread Start run "+this.getClass());
|
||||
try {
|
||||
|
||||
business();
|
||||
|
||||
_logger.debug("Cache Thread "+getName()+" Finished . ");
|
||||
_logger.info("Cache Thread "+this.getClass()+" Finished . ");
|
||||
|
||||
_logger.debug("Cache Thread sleep "+(interval * 1000)+" minute . ");
|
||||
sleep(interval * 1000);
|
||||
} catch (InterruptedException e) {
|
||||
_logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(){
|
||||
this.run();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public AbstractCache(String name) {
|
||||
super(name);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
public AbstractCache() {
|
||||
|
||||
}
|
||||
|
||||
public int getInterval() {
|
||||
return interval;
|
||||
}
|
||||
public abstract void business();
|
||||
|
||||
public void setInterval(int interval) {
|
||||
this.interval = interval;
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
_logger.debug("Cache Thread Start run " + getName());
|
||||
_logger.info("Cache Thread Start run " + this.getClass());
|
||||
try {
|
||||
|
||||
business();
|
||||
|
||||
_logger.debug("Cache Thread " + getName() + " Finished . ");
|
||||
_logger.info("Cache Thread " + this.getClass() + " Finished . ");
|
||||
|
||||
_logger.debug("Cache Thread sleep " + (interval * 1000) + " minute . ");
|
||||
sleep(interval * 1000);
|
||||
} catch (InterruptedException e) {
|
||||
_logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
this.run();
|
||||
}
|
||||
|
||||
/**
|
||||
* constructor.
|
||||
* @param name String
|
||||
*/
|
||||
public AbstractCache(String name) {
|
||||
super(name);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public int getInterval() {
|
||||
return interval;
|
||||
}
|
||||
|
||||
public void setInterval(int interval) {
|
||||
this.interval = interval;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,49 +1,46 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.maxkey.cache;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* CacheFactory.
|
||||
* @author Crystal.Sea
|
||||
*
|
||||
*/
|
||||
public class CacheFactory {
|
||||
|
||||
protected final static Logger _logger = LoggerFactory.getLogger(CacheFactory.class);
|
||||
|
||||
private ArrayList<AbstractCache> cache;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public CacheFactory() {
|
||||
|
||||
}
|
||||
|
||||
public void start(){
|
||||
|
||||
for (AbstractCache cacheable :cache){
|
||||
_logger.info("Cache "+cacheable.getClass());
|
||||
new Thread(cacheable).start();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
protected static final Logger _logger = LoggerFactory.getLogger(CacheFactory.class);
|
||||
|
||||
public ArrayList<AbstractCache> getCache() {
|
||||
return cache;
|
||||
}
|
||||
private ArrayList<AbstractCache> cache;
|
||||
|
||||
public void setCache(ArrayList<AbstractCache> cache) {
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* CacheFactory.
|
||||
*/
|
||||
public CacheFactory() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* start Cache.
|
||||
*/
|
||||
public void start() {
|
||||
|
||||
for (AbstractCache cacheable : cache) {
|
||||
_logger.info("Cache " + cacheable.getClass());
|
||||
new Thread(cacheable).start();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<AbstractCache> getCache() {
|
||||
return cache;
|
||||
}
|
||||
|
||||
public void setCache(ArrayList<AbstractCache> cache) {
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
package org.maxkey.domain;
|
||||
|
||||
import org.apache.mybatis.jpa.persistence.JpaBaseDomain;
|
||||
|
||||
public class IpAddrFilter extends JpaBaseDomain {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2308650344165845812L;
|
||||
|
||||
|
||||
public static class FILTER{
|
||||
public static int WHITELIST=1;
|
||||
public static int BLACKLIST=2;
|
||||
|
||||
}
|
||||
|
||||
String id;
|
||||
private String ipAddr;
|
||||
|
||||
private int filter;
|
||||
private String description;
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getIpAddr() {
|
||||
return ipAddr;
|
||||
}
|
||||
public void setIpAddr(String ipAddr) {
|
||||
this.ipAddr = ipAddr;
|
||||
}
|
||||
public int getFilter() {
|
||||
return filter;
|
||||
}
|
||||
public void setFilter(int filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
/**
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
/**
|
||||
* @param description the description to set
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "IpAddrFilter [ipAddr=" + ipAddr + ", filter=" + filter + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user