Java Reference
In-Depth Information
package Negotiation;
public interface Negotiator {
public void intersect(Proposal own, Proposal other);
public Proposal initialProposal();
public Proposal counterProposal(Proposal received);
public void completed( boolean success);
public Proposal finalProposal();
Class Mediator executes the negotiation process. The behaviour is defined
in the method startNegotiation() that implements the negotiation process
described in Figure 20.6. The constructor receives as a parameter the
maximum number of iterations for the negotiation process.
package Negotiation;
public class Mediator {
Proposal providerProposal;
Proposal clientProposal;
int maxIterations;
public Mediator( int max) {
maxIterations # max;
// return the last client proposal
public Proposal getClient() { return clientProposal; }
// return the last provider proposal
public Proposal getProvider() { return providerProposal; }
public boolean startNegotiation(Negotiator client,
Negotiator provider) {
// ask the negotiators for their first proposal
providerProposal # provider.initialProposal();
clientProposal # client.initialProposal();
// intersect the proposals
// (only the attributes relevant for both are taken into
// consideration)
provider.intersect(providerProposal, clientProposal);
client.intersect(clientProposal, providerProposal);
// perform the negotiation repeating the loop for a
// limited number of times
for ( int i # 0; i<maxIterations; !! i){
clientProposal # client.counterProposal
if (clientProposal.equals(providerProposal)) break;
providerProposal # provider.counterProposal
if (clientProposal.equals(providerProposal)) break;
Search WWH ::

Custom Search