-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(*): make modules loose coupled
- Loading branch information
Showing
11 changed files
with
265 additions
and
282 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
2 changes: 1 addition & 1 deletion
2
.../me/wuqq/util/BadCredentialException.java → .../me/wuqq/core/BadCredentialException.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,4 +1,4 @@ | ||
package me.wuqq.util; | ||
package me.wuqq.core; | ||
|
||
/** | ||
* Created by wuqq on 2016/10/2. | ||
|
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,8 @@ | ||
package me.wuqq.core; | ||
|
||
/** | ||
* Created by wuqq on 16-10-8. | ||
*/ | ||
public interface Driver { | ||
void fetch() throws BadCredentialException; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package me.wuqq.impl; | ||
|
||
import lombok.val; | ||
import me.wuqq.core.*; | ||
import me.wuqq.domain.QZoneMeta; | ||
import me.wuqq.domain.Record; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by wuqq on 16-10-8. | ||
*/ | ||
@Component | ||
public final class DriverImpl implements Driver { | ||
@Autowired Archiver mArchiver; | ||
@Autowired Progressor mProgressor; | ||
@Autowired Extractor mExtractor; | ||
@Autowired Fetcher mFetcher; | ||
|
||
QZoneMeta mMetaInfo; | ||
|
||
@Override | ||
public void fetch() throws BadCredentialException { | ||
this.initComponents(); | ||
this.doFetch(); | ||
} | ||
|
||
private void initComponents() throws BadCredentialException { | ||
mMetaInfo = this.fetchMeta(); | ||
|
||
mArchiver.init(mMetaInfo); | ||
mProgressor.init(mMetaInfo.getRecordCount()); | ||
} | ||
|
||
private void doFetch() throws BadCredentialException { | ||
val recordCount = mMetaInfo.getRecordCount(); | ||
val recordPageSize = mFetcher.getPageSize(); | ||
|
||
for (int offset = 0; offset < recordCount; offset += recordPageSize) { | ||
val records = this.fetchRecordsFromOffset(offset); | ||
|
||
mProgressor.advance(records.size()); | ||
mArchiver.save(records); | ||
} | ||
} | ||
|
||
private QZoneMeta fetchMeta() throws BadCredentialException { | ||
val data = mFetcher.fetchMessagesFromOffset(0); | ||
|
||
val recordCount = mExtractor.extractRecordCount(data); | ||
val username = mExtractor.extractUsername(data); | ||
|
||
return new QZoneMeta(recordCount, username, mFetcher.getTargetQQ()); | ||
} | ||
|
||
private List<Record> fetchRecordsFromOffset(final int offset) throws BadCredentialException { | ||
val rawData = mFetcher.fetchMessagesFromOffset(offset); | ||
|
||
return mExtractor.extractRecords(rawData); | ||
} | ||
} |
Oops, something went wrong.