Skip to content

Commit

Permalink
update resty-server to scan classes
Browse files Browse the repository at this point in the history
Dreampie committed Sep 8, 2016
1 parent 09a7546 commit 47ba2c6
Showing 5 changed files with 15 additions and 12 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ maven使用方式:
<dependency>
<groupId>cn.dreampie</groupId>
<artifactId>resty-route</artifactId>
<version>1.0</version>
<version>1.3.0-SNAPSHOT</version>
</dependency>
```

@@ -56,6 +56,8 @@ maven使用方式:

重大更新:

1.3.0更新内容: 使用jetty作为嵌入式热加载默认实现(只要java文件进行编译就会重新加载),resty-captcha验证码功能...

1.2.0更新内容:使用header来控制api版本,基于数据源的读写分离,更简单的tableSetting.[详情查看](http://www.oschina.net/news/68791/resty-1-2-0-snapshot)

1.1.0版本重大更新:快速接入spring,缓存,加密,header,XForwardedSupports等,[详情查看](http://www.oschina.net/news/67001/resty-1-1-0-snapshot)
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@
public class ExampleApplication {

public static void main(String[] args) throws Exception {
System.out.println("xxxxxx");
new JettyServerProvider().build().start();
}
}
Original file line number Diff line number Diff line change
@@ -15,25 +15,23 @@ public class ReloadRunnable extends Observable implements Runnable {

public static final int SCAN_INTERVAL_DEFAULT = 1000;
public static final int RELOAD_INTERVAL_DEFAULT = 1000;
private String rootPath;
private int scanInterval;
private int restartInterval;
private Set<File> files;
private Map<String, Long> fileModifieds = new HashMap<String, Long>();
private long lastErrorModified = 0;
private RestyServer server;

public ReloadRunnable(String rootPath, RestyServer server) {
this(SCAN_INTERVAL_DEFAULT, RELOAD_INTERVAL_DEFAULT, rootPath, server);
public ReloadRunnable(RestyServer server) {
this(SCAN_INTERVAL_DEFAULT, RELOAD_INTERVAL_DEFAULT, server);
}

public ReloadRunnable(int scanInterval, int restartInterval, String rootPath, RestyServer server) {
public ReloadRunnable(int scanInterval, int restartInterval, RestyServer server) {
this.scanInterval = scanInterval;
this.restartInterval = restartInterval;
this.server = server;
this.rootPath = rootPath;

this.files = FileScaner.of().isAbsolutePath(true).include(server.classLoader.getResource(".").getPath(), rootPath + "pom.xml").scanToFile();
this.files = FileScaner.of().isAbsolutePath(true).include(server.classPath, server.webXmlPath, server.rootPath + "pom.xml").scanToFile();
for (File file : files) {
fileModifieds.put(file.getAbsolutePath(), file.lastModified());
}
@@ -60,7 +58,7 @@ public void run() {
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
while (!Thread.currentThread().isInterrupted()) {
Thread.sleep(scanInterval);
this.files = FileScaner.of().isAbsolutePath(true).include(server.classLoader.getResource(".").getPath(), rootPath + "pom.xml").scanToFile();
this.files = FileScaner.of().isAbsolutePath(true).include(server.classPath, server.webXmlPath, server.rootPath + "pom.xml").scanToFile();

Iterator<File> fileIterator = files.iterator();
while (fileIterator.hasNext()) {
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@ public abstract class RestyServer {

protected boolean useHttpSession = false;
protected String rootPath;
protected String classPath;
protected String webXmlPath;

protected ReloadRunnable reloadRunnable;
protected ReloadObserver reloadObserver;
Original file line number Diff line number Diff line change
@@ -43,14 +43,16 @@ protected void init() throws Exception {
webAppContext.setParentLoaderPriority(true);
webAppContext.setThrowUnavailableOnStartupException(true);

rootPath = new File(classLoader.getResource(".").toURI()).getParentFile().getParentFile().getCanonicalFile().getAbsolutePath() + "/";
classPath = classLoader.getResource(".").getPath();
rootPath = new File(classPath).getParentFile().getParentFile().getCanonicalFile().getAbsolutePath() + "/";

File webappDir = new File(rootPath + resourceBase);
if (!webappDir.exists() || !webappDir.isDirectory()) {
throw new IllegalArgumentException("Could not found webapp directory or it is not directory.");
}
String webappUrl = webappDir.getAbsolutePath();
webAppContext.setDescriptor(webappUrl + "/WEB-INF/web.xml");
webXmlPath = webappUrl + "/WEB-INF/web.xml";
webAppContext.setDescriptor(webXmlPath);
webAppContext.setContextPath(contextPath);
webAppContext.setResourceBase(webappUrl);

@@ -85,7 +87,7 @@ public void start() throws Exception {
}

if (Constant.devEnable) {
reloadRunnable = new ReloadRunnable(rootPath, this);
reloadRunnable = new ReloadRunnable(this);
reloadObserver = new ReloadObserver(reloadRunnable, this);
reloadRunnable.addObserver(reloadObserver);

0 comments on commit 47ba2c6

Please sign in to comment.