public class GroupRequest extends java.lang.Object implements RspCollector, Command
The supported transport to send requests is currently either a RequestCorrelator or a generic Transport. One of them has to be given in the constructor. It will then be used to send a request. When a message is received by either one, the receiveResponse() of this class has to be called (this class does not actively receive requests/responses itself). Also, when a view change or suspicion is received, the methods viewChange() or suspect() of this class have to be called.
When started, an array of responses, correlating to the membership, is created. Each response
is added to the corresponding field in the array. When all fields have been set, the algorithm
terminates.
This algorithm can optionally use a suspicion service (failure detector) to detect (and
exclude from the membership) fauly members. If no suspicion service is available, timeouts
can be used instead (see execute()
). When done, a list of suspected members
can be retrieved.
Because a channel might deliver requests, and responses to different requests, the
GroupRequest
class cannot itself receive and process requests/responses from the
channel. A mechanism outside this class has to do this; it has to determine what the responses
are for the message sent by the execute()
method and call receiveResponse()
to do so.
Requirements: lossless delivery, e.g. acknowledgment-based message confirmation.
Modifier and Type | Field and Description |
---|---|
protected RequestCorrelator |
corr |
protected boolean |
done |
protected int |
expected_mbrs |
static int |
GET_ABS_MAJORITY
return majority (of all members, may block)
|
static int |
GET_ALL
return all responses
|
static int |
GET_FIRST
return only first response
|
static int |
GET_MAJORITY
return majority (of all non-faulty members)
|
static int |
GET_N
return n responses (may block)
|
static int |
GET_NONE
return no response (async call)
|
protected Message |
request_msg |
protected int |
rsp_mode |
protected long |
timeout |
protected Transport |
transport |
Constructor and Description |
---|
GroupRequest(Message m,
RequestCorrelator corr,
java.util.Vector members,
int rsp_mode) |
GroupRequest(Message m,
RequestCorrelator corr,
java.util.Vector members,
int rsp_mode,
long timeout,
int expected_mbrs) |
GroupRequest(Message m,
Transport transport,
java.util.Vector members,
int rsp_mode) |
GroupRequest(Message m,
Transport transport,
java.util.Vector members,
int rsp_mode,
long timeout,
int expected_mbrs) |
Modifier and Type | Method and Description |
---|---|
boolean |
execute() |
boolean |
execute(boolean use_anycasting)
Sends the message.
|
Address |
getCaller() |
int |
getNumSuspects() |
RspList |
getResults()
Returns the results as a RspList
|
java.util.Vector |
getSuspects() |
boolean |
isDone() |
void |
receiveResponse(java.lang.Object response_value,
Address sender)
Callback (called by RequestCorrelator or Transport).
|
void |
reset(java.util.Vector mbrs)
This method sets the
membership variable to the value of
members . |
void |
setCaller(Address caller) |
void |
suspect(Address suspected_member)
Callback (called by RequestCorrelator or Transport).
|
java.lang.String |
toString() |
void |
viewChange(View new_view)
Any member of 'membership' that is not in the new view is flagged as
SUSPECTED.
|
public static final int GET_FIRST
public static final int GET_ALL
public static final int GET_MAJORITY
public static final int GET_ABS_MAJORITY
public static final int GET_N
public static final int GET_NONE
protected Message request_msg
protected RequestCorrelator corr
protected Transport transport
protected int rsp_mode
protected boolean done
protected long timeout
protected int expected_mbrs
public GroupRequest(Message m, RequestCorrelator corr, java.util.Vector members, int rsp_mode)
m
- The message to be sentcorr
- The request correlator to be used. A request correlator sends requests tagged with
a unique ID and notifies the sender when matching responses are received. The
reason GroupRequest
uses it instead of a Transport
is
that multiple requests/responses might be sent/received concurrently.members
- The initial membership. This value reflects the membership to which the request
is sent (and from which potential responses are expected). Is reset by reset().rsp_mode
- How many responses are expected. Can be
GET_ALL
: wait for all responses from non-suspected members.
A suspicion service might warn
us when a member from which a response is outstanding has crashed, so it can
be excluded from the responses. If no suspision service is available, a
timeout can be used (a value of 0 means wait forever). If a timeout of
0 is used, no suspicion service is available and a member from which we
expect a response has crashed, this methods blocks forever !.
GET_FIRST
: wait for the first available response.
GET_MAJORITY
: wait for the majority of all responses. The
majority is re-computed when a member is suspected.
GET_ABS_MAJORITY
: wait for the majority of
all members.
This includes failed members, so it may block if no timeout is specified.
GET_N
: wait for N members.
Return if n is >= membership+suspects.
GET_NONE
: don't wait for any response. Essentially send an
asynchronous message to the group members.
public GroupRequest(Message m, RequestCorrelator corr, java.util.Vector members, int rsp_mode, long timeout, int expected_mbrs)
timeout
- Time to wait for responses (ms). A value of <= 0 means wait indefinitely
(e.g. if a suspicion service is available; timeouts are not needed).public GroupRequest(Message m, Transport transport, java.util.Vector members, int rsp_mode)
public GroupRequest(Message m, Transport transport, java.util.Vector members, int rsp_mode, long timeout, int expected_mbrs)
timeout
- Time to wait for responses (ms). A value of <= 0 means wait indefinitely
(e.g. if a suspicion service is available; timeouts are not needed).public Address getCaller()
public void setCaller(Address caller)
public boolean execute() throws java.lang.Exception
public boolean execute(boolean use_anycasting) throws java.lang.Exception
java.lang.Exception
public final void reset(java.util.Vector mbrs)
membership
variable to the value of
members
. It requires that the caller already hold the
rsp_mutex
lock.mbrs
- The new list of memberspublic void receiveResponse(java.lang.Object response_value, Address sender)
execute()
returns.receiveResponse
in interface RspCollector
public void suspect(Address suspected_member)
GroupRequest
that a member is reported as faulty (suspected).
This method would probably be called when getting a suspect message from a failure detector
(where available). It is used to exclude faulty members from the response list.suspect
in interface RspCollector
public void viewChange(View new_view)
viewChange
in interface RspCollector
public RspList getResults()
public java.lang.String toString()
toString
in class java.lang.Object
public int getNumSuspects()
public java.util.Vector getSuspects()
public boolean isDone()
Copyright ? 1998-2006 Bela Ban. All Rights Reserved.