public void run() {
if (getStatus() != JKadStatus.CONNECTED) return;
SharingManager sharing_manager = SharingManagerSingleton
.getInstance();
Publisher publisher = Publisher.getInstance();
ConfigurationManager config_manager = ConfigurationManagerSingleton
.getInstance();
Iterable<SharedFile> shared_files = sharing_manager
.getSharedFiles();
long filesToPublish = 0;
for (SharedFile file : shared_files) {
if (publisher.getPublishKeywordCount() > JKadConstants.MAX_CONCURRENT_PUBLISH_FILES) {
break;
}
if (publishedFiles.contains(file.getFileHash()))
continue;
if (filesToPublish > JKadConstants.ITERATION_MAX_PUBLISH_FILES)
break;
if (file instanceof PartialFile) {
PartialFile p_file = (PartialFile) file;
if (p_file.getAvailablePartCount()==0) continue;
}
publishedFiles.add(file.getFileHash());
byte[] hash = file.getFileHash().getHash().clone();
Convert.updateSearchID(hash);
Int128 id = new Int128(hash);
if (!publisher.isPublishingSource(id)) {
filesToPublish++;
List<Tag> tagList = new LinkedList<Tag>();
tagList.add(new StringTag(TAG_FILENAME, file
.getSharingName()));
tagList.add(new IntTag(TAG_FILESIZE, (int) file
.length()));
tagList
.add(new IntTag(TAG_SOURCEIP,
org.jmule.core.utils.Convert
.byteToInt(getIPAddress()
.getAddress())));
try {
tagList.add(new IntTag(TAG_SOURCEPORT,
config_manager.getTCP()));
} catch (ConfigurationManagerException e) {
e.printStackTrace();
}
publisher.publishSource(id, tagList);
}
if (!publisher.isPublishingKeyword(id)) {
filesToPublish++;
List<Tag> tagList = new LinkedList<Tag>();
tagList.add(new StringTag(TAG_FILENAME, file
.getSharingName()));
tagList.add(new IntTag(TAG_FILESIZE, (int) file
.length()));
publisher.publishKeyword(id, tagList);
}
if (file.getTagList().hasTag(TAG_FILERATING))
if (!publisher.isPublishingNote(id)) {
filesToPublish++;
List<Tag> tagList = new LinkedList<Tag>();
tagList.add(new StringTag(TAG_FILENAME, file
.getSharingName()));
tagList.add(new IntTag(TAG_FILESIZE, (int) file
.length()));
tagList.add(new IntTag(TAG_FILERATING, file
.getFileQuality().getAsInt()));
publisher.publishNote(id, tagList);
}
}
}
};