1 | package geniusweb.progress;
|
---|
2 |
|
---|
3 | import java.util.Date;
|
---|
4 |
|
---|
5 | import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
---|
6 | import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
---|
7 | import com.fasterxml.jackson.annotation.JsonSubTypes;
|
---|
8 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
---|
9 | import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
|
---|
10 |
|
---|
11 | import geniusweb.deadline.Deadline;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Progress is similar to {@link Deadline} but contains absolute values. It
|
---|
15 | * always contains a hard termination moment at which the party should be
|
---|
16 | * killed. This is used to free up the run server. The protocol should always
|
---|
17 | * check its own clock, as parties may be ignoring or cheating with the
|
---|
18 | * deadline.
|
---|
19 | * <p>
|
---|
20 | * immutable.
|
---|
21 | */
|
---|
22 | @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = As.WRAPPER_OBJECT)
|
---|
23 | @JsonSubTypes({ @JsonSubTypes.Type(value = ProgressTime.class),
|
---|
24 | @JsonSubTypes.Type(value = ProgressRounds.class) })
|
---|
25 | @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE)
|
---|
26 | public interface Progress {
|
---|
27 | /**
|
---|
28 | * @param currentTimeMs the current time in ms since 1970 as from
|
---|
29 | * {@link System#currentTimeMillis()}.
|
---|
30 | * @return the current time as a fraction of the total amount of time/rounds
|
---|
31 | * available. So at start this returns 0, and when (and after) the
|
---|
32 | * deadline is reached this returns 1. Notice that when the progress
|
---|
33 | * is about the number of rounds, the party may also want to keep an
|
---|
34 | * eye on {@link #getTerminationTime()}.
|
---|
35 | */
|
---|
36 | Double get(long currentTimeMs);
|
---|
37 |
|
---|
38 | /**
|
---|
39 | *
|
---|
40 | * @return the unix time (UTC, ms since 1970) at which the party will be
|
---|
41 | * terminated. At this time the server can remove the party and free
|
---|
42 | * up its resources. Notice that server and party implementations
|
---|
43 | * are free to ignore this, the protocol should always check on
|
---|
44 | * whether a party is out of time.
|
---|
45 | */
|
---|
46 | Date getTerminationTime();
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * @param currentTimeMs the current time in ms since 1970 as from
|
---|
50 | * {@link System#currentTimeMillis()}.
|
---|
51 | * @return true iff the progress has passed the deadline.
|
---|
52 | */
|
---|
53 | boolean isPastDeadline(long currentTimeMs);
|
---|
54 | }
|
---|