forked from monstercodings/websiphon-light
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5241c83
commit 48dd8e9
Showing
34 changed files
with
658 additions
and
568 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/top/codings/websiphon/light/function/ComponentCloseAware.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package top.codings.websiphon.light.function; | ||
|
||
public interface ComponentCloseAware { | ||
void close() throws Exception; | ||
} |
6 changes: 3 additions & 3 deletions
6
...function/processor/ProcessErrorAware.java → ...n/light/function/ComponentErrorAware.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
package top.codings.websiphon.light.function.processor; | ||
package top.codings.websiphon.light.function; | ||
|
||
import top.codings.websiphon.light.crawler.ICrawler; | ||
import top.codings.websiphon.light.error.StopHandlErrorException; | ||
import top.codings.websiphon.light.requester.IRequest; | ||
|
||
public interface ProcessErrorAware { | ||
void doOnError(IRequest request, Throwable throwable, ICrawler crawler) throws StopHandlErrorException; | ||
public interface ComponentErrorAware { | ||
void doOnError(Throwable throwable, IRequest request, ICrawler crawler) throws StopHandlErrorException; | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/top/codings/websiphon/light/function/ComponentInitAware.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package top.codings.websiphon.light.function; | ||
|
||
public interface ComponentInitAware<T> { | ||
void init(T t) throws Exception; | ||
} |
22 changes: 21 additions & 1 deletion
22
src/main/java/top/codings/websiphon/light/function/handler/AbstractResponseHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,32 @@ | ||
package top.codings.websiphon.light.function.handler; | ||
|
||
import top.codings.websiphon.light.config.CrawlerConfig; | ||
import top.codings.websiphon.light.crawler.ICrawler; | ||
import top.codings.websiphon.light.error.FrameworkException; | ||
import top.codings.websiphon.light.function.ComponentInitAware; | ||
import top.codings.websiphon.light.loader.anno.Shared; | ||
|
||
public abstract class AbstractResponseHandler implements IResponseHandler { | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
public abstract class AbstractResponseHandler implements IResponseHandler, ComponentInitAware<ICrawler> { | ||
private transient volatile boolean init; | ||
protected CrawlerConfig config; | ||
|
||
@Override | ||
public void setConfig(CrawlerConfig config) { | ||
this.config = config; | ||
} | ||
|
||
@Override | ||
public void init(ICrawler crawler) throws Exception { | ||
synchronized (this) { | ||
if (init && getClass().getDeclaredAnnotation(Shared.class) == null) { | ||
throw new FrameworkException(String.format( | ||
"[%s]非共享组件,如需使用单例供多个爬虫使用则需使用@Shared注解修饰该组件", | ||
getClass().getName() | ||
)); | ||
} | ||
init = true; | ||
} | ||
} | ||
} |
Oops, something went wrong.