java.lang.Comparable<java.util.concurrent.Delayed>
, java.util.concurrent.Delayed
public final class WorkbenchEntry
extends java.lang.Object
implements java.util.concurrent.Delayed
Workbench
.
A workbench entry is associated with a single IP address (actually, to a 64-bit hash of an
IP address, to accommodate for IPv6), and contains a queue of all
visit states associated with that address, prioritized by VisitState.nextFetch
. The queue can
be modified using the synchronized methods add(VisitState)
, remove()
, size()
and isEmpty()
.
A nonempty workbench entry is a Delayed
object whose priority is
given by the maximum between its nextFetch
and the VisitState.nextFetch
of the top
of the queue. The delay, if any, is given by the priority minus
System.currentTimeMillis()
. This setup makes it possible to just take
a WorkbenchEntry
from the Workbench
and remove its top VisitState
, with the guarantee that
it is ready to be visited. Moreover, if there at least one VisitState
that is ready to be visited,
the method will not block.
A workbench entry is either acquired
or not. If it not acquired, it is on the
workbench if and only if it is nonempty.
Modifier and Type | Field | Description |
---|---|---|
protected boolean |
acquired |
Whether this entry has been acquired.
|
byte[] |
ipAddress |
The IP address of this workbench entry, computed by
DnsResolver.resolve(String) . |
protected long |
nextFetch |
The minimum time at which visit states in this entry can be accessed because of IP-based politeness.
|
Constructor | Description |
---|---|
WorkbenchEntry(byte[] ipAddress,
java.util.concurrent.atomic.AtomicLong brokenVisitStates) |
Creates a workbench entry for a given IP address.
|
Modifier and Type | Method | Description |
---|---|---|
void |
add(VisitState visitState) |
Adds the given visit state to the visit-state queue.
|
void |
add(VisitState visitState,
Workbench workbench) |
Adds the given visit state to the visit-state queue, and adds this entry to the workbench if it was empty
and not acquired.
|
int |
compareTo(java.util.concurrent.Delayed o) |
|
long |
getDelay(java.util.concurrent.TimeUnit unit) |
|
boolean |
isEmpty() |
Returns true if the visit-state queue is not empty.
|
boolean |
isEntirelyBroken() |
Returns true if this entry is nonempty and all its visit states are broken (i.e.,
VisitState.lastExceptionClass ≠ null ) |
long |
nextFetch() |
Returns the minimum time at which some URL in some
VisitState of the visit-state queue
of this workbench entry can be accessed. |
void |
putOnWorkbenchIfNotEmpty(Workbench workbench) |
Puts this entry on the workbench, if not empty.
|
VisitState |
remove() |
Removes the top element from the visit-state queue.
|
int |
size() |
Returns the number of visit states currently in the visit-state queue.
|
java.lang.String |
toString() |
|
VisitState[] |
visitStates() |
Returns the visit states currently in the queue.
|
public final byte[] ipAddress
DnsResolver.resolve(String)
.protected boolean acquired
protected volatile long nextFetch
public WorkbenchEntry(byte[] ipAddress, java.util.concurrent.atomic.AtomicLong brokenVisitStates)
ipAddress
- the IP address.brokenVisitStates
- a reference to Frontier.brokenVisitStates
.public boolean isEntirelyBroken()
VisitState.lastExceptionClass
≠ null
)public void add(VisitState visitState)
This method is used for deserialization only.
visitState
- the visit state that must be added to the visit-state queue.PriorityQueue.add(Object)
public VisitState remove()
AbstractQueue.remove()
public void putOnWorkbenchIfNotEmpty(Workbench workbench)
workbench
- the workbench.public void add(VisitState visitState, Workbench workbench)
visitState
- the nonempty visit state that must be added to the visit-state queue.workbench
- the workbench.PriorityQueue.add(Object)
public int size()
public VisitState[] visitStates()
This method is mainly useful to compute statistics The returned array is created with the current queue content, and it will not reflect changes of the queue. In particular, some visit states might have an empty URL queue because of concurrent modifications.
PriorityQueue.toArray()
public boolean isEmpty()
public long nextFetch()
VisitState
of the visit-state queue
of this workbench entry can be accessed.
It is computed by maximizing nextFetch
with VisitState.nextFetch
of the
top element of the visit-state queue.
Note that this method will access blindly the top element, which might cause a NullPointerException
if the visit-state queue is empty. Thus, great care must be exercised in placing on the workbench
entries with a nonempty visit-state queue only.
VisitState
of this entry can be accessed.public long getDelay(java.util.concurrent.TimeUnit unit)
getDelay
in interface java.util.concurrent.Delayed
public int compareTo(java.util.concurrent.Delayed o)
compareTo
in interface java.lang.Comparable<java.util.concurrent.Delayed>
public java.lang.String toString()
toString
in class java.lang.Object