[
https://issues.apache.org/jira/browse/DROIDS-48?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12722486#action_12722486
]
Mingfai Ma edited comment on DROIDS-48 at 6/21/09 9:50 PM:
-----------------------------------------------------------
just come up with a even better design for weight.
Weighted interface
{code}
public interface Weighted {
public int getWeight();
}
{code}
The Link/LinkTask, assume extends HashMap
{code}
public class WeightedLink extends Link implements Weighted { //or LinkTask
public int getWeight() {
return Integer.parseInt(String.valueOf(this.get("weight")));
}
}
{code}
WeightComparator :
{code}
public class WeightComparator implements Comparator {
public int compare(Object link1, Object link2) {
int weight1 = link1 instanceof Weighted ? ((Weighted)
link1).getWeight() : 0;
int weight2 = link2 instanceof Weighted ? ((Weighted)
link2).getWeight() : 0;
return weight2 - weight1;
}
}
{code}
Task Queue
{code}
Queue queue = new PriorityBlockingQueue(10, new WeightComparator())
{code}
so, weighted becomes optional. if user want to support weight, then, they
implement Weighted and let the user decide how to weight.
was (Author: mingfai):
just come up with a event better design for weight.
Weighted interface
{code}
public interface Weighted {
public int getWeight();
}
{code}
The Link/LinkTask, assume extends HashMap
{code}
public class WeightedLink extends Link implements Weighted { //or LinkTask
public int getWeight() {
return Integer.parseInt(String.valueOf(this.get("weight")));
}
}
{code}
WeightComparator :
{code}
public class WeightComparator implements Comparator {
public int compare(Object link1, Object link2) {
int weight1 = link1 instanceof Weighted ? ((Weighted)
link1).getWeight() : 0;
int weight2 = link2 instanceof Weighted ? ((Weighted)
link2).getWeight() : 0;
return weight2 - weight1;
}
}
{code}
Task Queue
{code}
Queue queue = new PriorityBlockingQueue(10, new WeightComparator())
{code}
so, weighted becomes optional. if user want to support weight, then, they
implement Weighted and let the user decide how to weight.
> Support prioritizing in the TaskQueue
> -------------------------------------
>
> Key: DROIDS-48
> URL: https://issues.apache.org/jira/browse/DROIDS-48
> Project: Droids
> Issue Type: New Feature
> Components: core
> Affects Versions: 0.01
> Reporter: Mingfai Ma
> Attachments: DROIDS-48d.patch, DROIDS-48d2.patch
>
>
> Use case:
> - when looping a directory, (imagine someone is too stupid and dunno the
> dmoz database can be downloaded and try to crawl it with Droids) we got
> collect a lot of links that will be handled later. assume the requirement is
> to fetch dmoz directory +1 link outside dmoz.org, In the original mechanism,
> it will keep adding new links to the TaskQueue. Ideally, there should be a
> mechanism to give a higher priority to the non-dmoz.org links, so when
> non-dmoz links are added, they are processed first, and be removed from the
> TaskQueue asap.
> with the patch in DROIDS-47, a constructor is added to the SimpleTaskQueue to
> support a custom Queue. This issue suggests to change the SimpleTaskQueue to
> use a PriorityBlockingQueue by default, and add a getWeight to the Task
> interface
> I'm also thinking about a more complex TaskQueue. to be discussed in the mail
> list later.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.