[virtualcommons-svn] SF.net SVN: virtualcommons:[399] foraging/branches/deepak-branch-fall-09/ src/
Status: Beta
Brought to you by:
alllee
From: <al...@us...> - 2009-12-04 06:54:31
|
Revision: 399 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=399&view=rev Author: alllee Date: 2009-12-04 06:54:23 +0000 (Fri, 04 Dec 2009) Log Message: ----------- starting refactoring on client side, server-side is nearly complete. Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ForagingRole.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/RegulationData.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round5.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round6.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round7.xml Added Paths: ----------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/MonitorTaxEvent.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationSubmissionUpdateEvent.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationUpdateEvent.java Removed Paths: ------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/NewClientRole.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationEvent.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientRole.java Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-04 06:54:23 UTC (rev 399) @@ -40,15 +40,8 @@ // FIXME: can obtain tokensConsumed from the clientDataMap now. private int currentTokens; - private int role; - private Identifier monitorId; - private static final int MONITOR = 0; - private static final int HARVEST = 1; - private static final int SANCTION = 2; - private static final int HARVESTANDSANCTION = 3; - // these are the subjects whom we have sanctioned private Map<Identifier, Duration> sanctioned = new HashMap<Identifier, Duration>(); @@ -62,23 +55,13 @@ public ClientDataModel(ForagingClient client) { super(client.getEventChannel()); this.client = client; - this.role = HARVEST; } public void toggleExplicitCollectionMode() { explicitCollectionMode = !explicitCollectionMode; - client.transmit(new ExplicitCollectionModeRequest(client.getId(), - explicitCollectionMode)); + client.transmit(new ExplicitCollectionModeRequest(client.getId(), explicitCollectionMode)); } - public void setMyRole(int role){ - this.role = role; - } - - public int getMyRole() { - return this.role; - } - public void setMonitorId (Identifier moniterId) { this.monitorId = moniterId; } @@ -91,42 +74,18 @@ } - public boolean isSanctioningAllowed(){ - System.out.println("My Role : "+getMyRole()); - /* - boolean result = false; - switch(getMyRole()) { - case MONITER: - case SANCTION: - case HARVESTANDSANCTION: - result = true; - break; - } - return result;*/ - - if(getMyRole() == MONITOR || getMyRole() == SANCTION || getMyRole() == HARVESTANDSANCTION)return true; - else return false; - + public boolean isSanctioningAllowed() { + return getClientData().isSanctioningAllowed(); } - public boolean isHarvestingAllowed(){ - if(getMyRole() == HARVEST || getMyRole() == HARVESTANDSANCTION)return true; - else return false; + public boolean isHarvestingAllowed() { + return getClientData().isHarvestingAllowed(); } public boolean isMonitor() { - return role == MONITOR; + return getClientData().getForagingRole().isMonitor(); } - - public boolean canHarvest() { - return role == HARVEST || role == HARVESTANDSANCTION; - } - - public boolean canSanction() { - return role == SANCTION || role == HARVESTANDSANCTION || role == MONITOR; - - } - + /* * public Map<Identifier, Duration> getSanctioned() { return sanctioned; } */ Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-04 06:54:23 UTC (rev 399) @@ -26,17 +26,15 @@ import edu.asu.commons.foraging.event.EndRoundEvent; import edu.asu.commons.foraging.event.EnforcementMechanismUpdateEvent; import edu.asu.commons.foraging.event.LockResourceEvent; -import edu.asu.commons.foraging.event.NewClientRole; import edu.asu.commons.foraging.event.PostRoundSanctionRequest; import edu.asu.commons.foraging.event.PostRoundSanctionUpdateEvent; import edu.asu.commons.foraging.event.RealTimeSanctionRequest; -import edu.asu.commons.foraging.event.RegulationEvent; +import edu.asu.commons.foraging.event.RegulationSubmissionUpdateEvent; import edu.asu.commons.foraging.event.ResetTokenDistributionRequest; import edu.asu.commons.foraging.event.RoundStartedEvent; import edu.asu.commons.foraging.event.ShowInstructionsRequest; import edu.asu.commons.foraging.event.SynchronizeClientEvent; import edu.asu.commons.foraging.model.EnforcementData; -import edu.asu.commons.net.Identifier; import edu.asu.commons.util.Duration; import edu.asu.commons.util.Utils; @@ -70,15 +68,10 @@ private ClientDataModel dataModel; - private int regulationID; - - private int enforcementID; - - private int token; - private MessageQueue messageQueue; - private JPanel panel = new JPanel(); + private JPanel clientPanel = new JPanel(); + public ForagingClient(ServerConfiguration configuration) { this(configuration, new Dimension(800, 600)); } @@ -89,12 +82,11 @@ if (configuration.shouldInitialize2D()) { gameWindow2D = new GameWindow2D(this, screenSize); } - if (configuration.shouldInitialize3D()) { + else if (configuration.shouldInitialize3D()) { gameWindow3D = new GameWindow3D(this); } - panel.setLayout(new BorderLayout()); - panel.add(configuration.getCurrentParameters().is2dExperiment() - ? gameWindow2D : gameWindow3D.getPanel(), + clientPanel.setLayout(new BorderLayout()); + clientPanel.add(configuration.getCurrentParameters().is2dExperiment() ? gameWindow2D : gameWindow3D.getPanel(), BorderLayout.CENTER); } @@ -120,18 +112,7 @@ return gameWindow3D; } } - public void setRegulationID(int ID){this.regulationID = ID;} - - public int getRegulationID(){return this.regulationID;} - - public void setEnforcementID(int ID){this.enforcementID = ID;} - - public int getEnforcementID(){return this.enforcementID;} - - public void setToken(int token){this.token = token;} - - public int getToken(){return this.token;} - + public void sendAvatarInfo(boolean male, Color hairColor, Color skinColor, Color shirtColor, Color trouserColor, Color shoesColor) { transmit(new AgentInfoRequest(getId(), male, hairColor, skinColor, shirtColor, trouserColor, shoesColor)); gameWindow3D.removeAgentDesigner(); @@ -151,19 +132,19 @@ dataModel.setRoundConfiguration(configuration); SwingUtilities.invokeLater(new Runnable() { public void run() { - panel.removeAll(); - panel.invalidate(); + clientPanel.removeAll(); + clientPanel.invalidate(); if (dataModel.is2dExperiment()) { - panel.add(gameWindow2D, BorderLayout.CENTER); + clientPanel.add(gameWindow2D, BorderLayout.CENTER); if (gameWindow3D != null) { gameWindow3D.dispose(); } } else { - panel.add(gameWindow3D.getPanel(), BorderLayout.CENTER); + clientPanel.add(gameWindow3D.getPanel(), BorderLayout.CENTER); } - panel.validate(); - panel.repaint(); + clientPanel.validate(); + clientPanel.repaint(); getGameWindow().init(); } }); @@ -187,23 +168,23 @@ } }); - addEventProcessor(new EventTypeProcessor<NewClientRole>(NewClientRole.class) { - public void handle(NewClientRole event) { - Identifier receivedClientId = event.getRoleObj().getClientId(); - //System.out.println("Broadcast ID : "+receivedClientId); - if(dataModel.getId().equals(receivedClientId)) { - int[] roles = event.getRoleObj().getClientRoles(); - //System.out.println("Setting my role"); - dataModel.setMyRole(roles[event.getRoleObj().getRoleNo()]); - dataModel.setMonitorId(event.getRoleObj().getMoniterId()); - //System.out.println("New role for the client : "+dataModel.getMyRole()); - gameWindow2D.displayErrorMessage(GameWindow2D.roleDescription[getDataModel().getMyRole()],1); +// addEventProcessor(new EventTypeProcessor<NewClientRole>(NewClientRole.class) { +// public void handle(NewClientRole event) { +// Identifier receivedClientId = event.getRoleObj().getClientId(); +// //System.out.println("Broadcast ID : "+receivedClientId); +// if(dataModel.getId().equals(receivedClientId)) { +// int[] roles = event.getRoleObj().getClientRoles(); +// //System.out.println("Setting my role"); +// dataModel.setMyRole(roles[event.getRoleObj().getRoleNo()]); +// dataModel.setMonitorId(event.getRoleObj().getMoniterId()); +// //System.out.println("New role for the client : "+dataModel.getMyRole()); +// gameWindow2D.displayErrorMessage(GameWindow2D.roleDescription[getDataModel().getMyRole()],1); +// +// // Utils.notify(GameWindow2D.clientRoleSignal); +// } +// } +// }); - // Utils.notify(GameWindow2D.clientRoleSignal); - } - } - }); - addEventProcessor(new EventTypeProcessor<EndRoundEvent>(EndRoundEvent.class) { public void handle(final EndRoundEvent event) { if (state == ClientState.RUNNING) { @@ -280,8 +261,8 @@ gameWindow2D.displayVotedEnforcement(); } }); - addEventProcessor(new EventTypeProcessor<RegulationEvent>(RegulationEvent.class) { - public void handle(final RegulationEvent regulationEvent) { + addEventProcessor(new EventTypeProcessor<RegulationSubmissionUpdateEvent>(RegulationSubmissionUpdateEvent.class) { + public void handle(final RegulationSubmissionUpdateEvent regulationEvent) { dataModel.setRegulation(regulationEvent.getMessage()); } }); @@ -470,7 +451,7 @@ client.connect(); frame.setTitle("Client Window: " + client.getId()); frame.setSize(defaultDimension); - frame.add(client.panel); + frame.add(client.clientPanel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-04 06:54:23 UTC (rev 399) @@ -747,12 +747,6 @@ // by the server no new clients can connect because the round // has begun. update(configuration.getRoundDuration().getTimeLeft()); - - //if(configuration.isChatEnabled()){ - if(configuration.isSanctioningEnabled()){ - displayErrorMessage(roleDescription[client.getDataModel().getMyRole()], 1); - - } add(messagePanel, BorderLayout.SOUTH); addCenterComponent(subjectWindow); @@ -894,14 +888,9 @@ } public void displayVotedEnforcement(){ - //new code - // System.out.println("*****Inside display voting enforcement"); + // TODO: reimplement SwingUtilities.invokeLater(new Runnable() { public void run() { - instructionsEditorPane.setText("Below enforcement has been voted from the voting conducting earlier<br><br>" + - "<b>"+getEnforcementPanel().getVotedEnforcementOptions(votedEnforcement.getResultIndex())+ - "</b><br><br>This is your role for the next round <br><br><b>"+roleDescription[client.getDataModel().getMyRole()]+"</b>"); - remove(enforcementPanel); addCenterComponent(instructionsScrollPane); startEnforcementDisplayTimer(); } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-04 06:54:23 UTC (rev 399) @@ -185,11 +185,6 @@ return getSanctionCost() * getSanctionMultiplier(); } - public int getSanctionPenalty(int option) { - if (option == 1) return getSanctionCost() * getSanctionMultiplier(); - else return (getSanctionCost() * 1); - } - public SanctionType getSanctionType() { return SanctionType.find(getProperty("sanction-type", "none")); } Added: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/MonitorTaxEvent.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/MonitorTaxEvent.java (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/MonitorTaxEvent.java 2009-12-04 06:54:23 UTC (rev 399) @@ -0,0 +1,29 @@ +package edu.asu.commons.foraging.event; + +import java.util.Map; + +import edu.asu.commons.event.AbstractPersistableEvent; +import edu.asu.commons.net.Identifier; + +public class MonitorTaxEvent extends AbstractPersistableEvent { + + private static final long serialVersionUID = -3191310440517697158L; + + private Map<Identifier, Integer> monitorTaxes; + private int totalMonitorTax; + + public MonitorTaxEvent(Identifier id, Map<Identifier, Integer> monitorTaxes, int totalMonitorTax) { + super(id); + this.monitorTaxes = monitorTaxes; + this.totalMonitorTax = totalMonitorTax; + } + + public Map<Identifier, Integer> getMonitorTaxes() { + return monitorTaxes; + } + + public int getTotalMonitorTax() { + return totalMonitorTax; + } + +} Deleted: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/NewClientRole.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/NewClientRole.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/NewClientRole.java 2009-12-04 06:54:23 UTC (rev 399) @@ -1,35 +0,0 @@ -//package edu.asu.commons.event; -package edu.asu.commons.foraging.event; - -import edu.asu.commons.event.AbstractEvent; -import edu.asu.commons.foraging.model.ClientRole; -import edu.asu.commons.net.Identifier; - - -/** - * $Id: VoteEvent.java 49 2008-09-04 16:57:40Z dbarge $ - * - * Sent from the server to all clients about the - * updated vote stats - * @author <a href='db...@as...'>Deepak Barge</a> - * @version $Revision: 49 $ - */ - -public class NewClientRole extends AbstractEvent { - - private static final long serialVersionUID = 475300882222383637L; - - private ClientRole clientRole; - - public NewClientRole(Identifier id) { - super(id); - } - - public void setRoleObj(ClientRole clientRole) { - this.clientRole = clientRole; - } - - public ClientRole getRoleObj() { - return this.clientRole; - } -} Deleted: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationEvent.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationEvent.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationEvent.java 2009-12-04 06:54:23 UTC (rev 399) @@ -1,28 +0,0 @@ -//package edu.asu.commons.event; -package edu.asu.commons.foraging.event; - -import edu.asu.commons.event.AbstractEvent; -import edu.asu.commons.foraging.model.RegulationData; -import edu.asu.commons.net.Identifier; - - -/** - * $Id: VoteEvent.java 49 2008-09-04 16:57:40Z dbarge $ - * - * Sent from the server to all clients about the updated vote stats. - * - * @author <a href='db...@as...'>Deepak Barge</a> - * @version $Revision: 49 $ - */ - -public class RegulationEvent extends AbstractEvent { - - private static final long serialVersionUID = 475300882222383637L; - - public RegulationEvent(Identifier id, RegulationData[] regulations) { - super(id); - - } - - -} Copied: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationSubmissionUpdateEvent.java (from rev 398, foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationEvent.java) =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationSubmissionUpdateEvent.java (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationSubmissionUpdateEvent.java 2009-12-04 06:54:23 UTC (rev 399) @@ -0,0 +1,35 @@ +//package edu.asu.commons.event; +package edu.asu.commons.foraging.event; + +import java.util.List; + +import edu.asu.commons.event.AbstractEvent; +import edu.asu.commons.foraging.model.RegulationData; +import edu.asu.commons.net.Identifier; + + +/** + * $Id: VoteEvent.java 49 2008-09-04 16:57:40Z dbarge $ + * + * Sent from the server to all clients about the updated vote stats. + * + * @author <a href='db...@as...'>Deepak Barge</a> + * @version $Revision: 49 $ + */ + +public class RegulationSubmissionUpdateEvent extends AbstractEvent { + + private static final long serialVersionUID = 475300882222383637L; + + private List<RegulationData> submittedRegulations; + + public RegulationSubmissionUpdateEvent(Identifier id, List<RegulationData> submittedRegulations) { + super(id); + this.submittedRegulations = submittedRegulations; + } + + public List<RegulationData> getSubmittedRegulations() { + return submittedRegulations; + } + +} Added: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationUpdateEvent.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationUpdateEvent.java (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationUpdateEvent.java 2009-12-04 06:54:23 UTC (rev 399) @@ -0,0 +1,33 @@ +//package edu.asu.commons.event; +package edu.asu.commons.foraging.event; + +import edu.asu.commons.event.AbstractEvent; +import edu.asu.commons.foraging.model.RegulationData; +import edu.asu.commons.net.Identifier; + + +/** + * $Id: VoteEvent.java 49 2008-09-04 16:57:40Z dbarge $ + * + * Sent from the server to all clients about the selected regulation data. + * + * @author <a href='db...@as...'>Deepak Barge</a> + * @version $Revision: 49 $ + */ + +public class RegulationUpdateEvent extends AbstractEvent { + + private static final long serialVersionUID = 475300882222383637L; + + private RegulationData regulationData; + + public RegulationUpdateEvent(Identifier id, RegulationData regulationData) { + super(id); + this.regulationData = regulationData; + } + + public RegulationData getRegulationData() { + return regulationData; + } + +} Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.java 2009-12-04 06:54:23 UTC (rev 399) @@ -37,8 +37,6 @@ private ForagingRole foragingRole = ForagingRole.HARVEST; - private ClientRole clientRole; - private double totalIncome; private int totalTokens; private int currentTokens; @@ -60,7 +58,11 @@ private double viewSubjectsRadius; private double viewTokensRadius; - // this is only used in the Rotating Monitor enforcement mechanism. + // only needed if this client has already received a tax. + private boolean taxReceived = false; + + + // this is only used in the Rotating Monitor enforcement mechanism. private int tokensCollectedDuringInterval = 0; public ClientData(Identifier id) { @@ -116,6 +118,14 @@ } } + public boolean isSanctioningAllowed() { + return foragingRole != null && foragingRole.isSanctioningAllowed(); + } + + public boolean isHarvestingAllowed() { + return foragingRole != null && foragingRole.isHarvestingAllowed(); + } + public boolean isSubjectInFieldOfVision(Point subjectPosition) { Circle circle = getSubjectsFieldOfVision(); if (circle == null) { @@ -179,24 +189,10 @@ subtractTokens(sanctionPenalty); } else if (sanctionAction.equals("freeze")) { - freeze( roundConfiguration.getSanctionPenalty(1) ); + freeze( roundConfiguration.getSanctionPenalty() ); } } - public void sanctionPenalty(int option) { - RoundConfiguration roundConfiguration = getGroupDataModel().getRoundConfiguration(); - String sanctionAction = roundConfiguration.getSanctionAction(); - if (sanctionAction.equals("fine")) { - final int sanctionPenalty = roundConfiguration.getSanctionPenalty(option); - sanctionPenalties += sanctionPenalty; - subtractTokens(sanctionPenalty); - } - else if (sanctionAction.equals("freeze")) { - freeze( roundConfiguration.getSanctionPenalty(option) ); - } - - } - /** * If this ClientData is already frozen, this method returns false and does nothing. * If not, sets or resets the freeze duration for this ClientData and returns true. @@ -290,6 +286,8 @@ public void reset() { resetCurrentTokens(); resetLatestSanctions(); + foragingRole = ForagingRole.HARVEST; + taxReceived = false; } public void resetLatestSanctions() { @@ -348,14 +346,6 @@ this.enforcementData = enforcementData; } - public void setClientRole(ClientRole clientRole){ - this.clientRole = clientRole; - } - - public ClientRole getClientRole(){ - return clientRole; - } - // FIXME: generalize for arbitrary clients per group. public Point3D generate3DPosition() { // float x = assignedNumber * getGroupDataModel().getCurrentConfiguration().getWorldWidth() / getGroupDataModel().getNumberOfClients() + 1; @@ -563,4 +553,13 @@ public void setEnforcementRankings(int[] enforcementRankings) { this.enforcementRankings = enforcementRankings; } + + public boolean isTaxReceived() { + return taxReceived; + } + + public void setTaxReceived() { + this.taxReceived = true; + } + } Deleted: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientRole.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientRole.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientRole.java 2009-12-04 06:54:23 UTC (rev 399) @@ -1,63 +0,0 @@ -package edu.asu.commons.foraging.model; - -import java.io.Serializable; - -import edu.asu.commons.net.Identifier; - -/** - * - * $Id: RegulationData.java 117 2009-04-21 17:26:20Z dbarge $ - * - * - * @author <a href='mailto:db...@as...'>dbarge</a> - * @version $Revision: 117 $ - */ - -public class ClientRole implements Serializable { - - private static final long serialVersionUID = 5281922601551921005L; - - private int roles[]; - - private Identifier id; - - private Identifier moniterId; - - private int roleNo; - - public ClientRole() {} - - public int[] getClientRoles(){ - return roles; - } - - public void setClientRoles(int roles[]){ - this.roles = roles; - } - - public Identifier getClientId(){ - return id; - } - - public void setClientId(Identifier id){ - this.id = id; - } - - public Identifier getMoniterId(){ - return moniterId; - } - - public void setMoniterId(Identifier moniterId){ - this.moniterId = moniterId; - } - - - public int getRoleNo(){ - return roleNo; - } - - public void setRoleNo(int roleNo){ - this.roleNo = roleNo; - } - -} Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ForagingRole.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ForagingRole.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ForagingRole.java 2009-12-04 06:54:23 UTC (rev 399) @@ -24,8 +24,12 @@ return this == MONITOR; } - public boolean canSanction() { + public boolean isSanctioningAllowed() { return this != HARVEST; } + + public boolean isHarvestingAllowed() { + return this != MONITOR; + } } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java 2009-12-04 06:54:23 UTC (rev 399) @@ -19,6 +19,7 @@ import edu.asu.commons.foraging.event.ClientPositionUpdateEvent; import edu.asu.commons.foraging.event.EnforcementRankingRequest; import edu.asu.commons.foraging.event.LockResourceRequest; +import edu.asu.commons.foraging.event.MonitorTaxEvent; import edu.asu.commons.foraging.event.PostRoundSanctionRequest; import edu.asu.commons.foraging.event.RegulationRankingRequest; import edu.asu.commons.foraging.event.SubmitRegulationRequest; @@ -64,9 +65,12 @@ private volatile int receivedRegulationRankings = 0; private EnforcementMechanism activeEnforcementMechanism = EnforcementMechanism.NONE; + private RegulationData activeRegulation; private List<ClientData> waitingMonitors; + private ClientData activeMonitor; + private int tokensCollectedDuringInterval = 0; private ArrayList<RegulationData> submittedRegulations = new ArrayList<RegulationData>(); @@ -118,18 +122,44 @@ return clients.size(); } - public void rotateMonitor() { + public boolean rotateMonitorIfNecessary() { if (activeEnforcementMechanism.isRotatingMonitor() && ! waitingMonitors.isEmpty()) { - for (ClientData clientData: clients.values()) { - if (clientData.isMonitor()) { - // this is the active monitor, give them 25% of the take. - } - clientData.setForagingRole(ForagingRole.HARVEST); - } - ClientData nextMonitor = waitingMonitors.remove(0); - nextMonitor.setForagingRole(ForagingRole.MONITOR); + applyMonitorTax(); + // set active monitor back to harvest + activeMonitor.setForagingRole(ForagingRole.HARVEST); + if (waitingMonitors.isEmpty()) { + logger.warning("no waiting monitors left but still trying to rotate: " + activeMonitor); + return false; + } + else { + activeMonitor = waitingMonitors.remove(0); + activeMonitor.setForagingRole(ForagingRole.MONITOR); + return true; + } } + return false; } + + public RegulationData generateRegulationRankings() { + resetRegulationRankingCount(); + double[] regulationVotingTally = new double[submittedRegulations.size()]; + Arrays.fill(regulationVotingTally, 0.0d); + int maxRankingIndex = 0; + double maxRankingValue = 0.0d; + for (ClientData clientData : clients.values()) { + int[] regulationRankings = clientData.getRegulationRankings(); + for (int index = 0; index < regulationRankings.length; index++) { + regulationVotingTally[index] += rankToValue(regulationRankings[index]); + if (regulationVotingTally[index] > maxRankingValue) { + maxRankingValue = regulationVotingTally[index]; + maxRankingIndex = index; + } + } + } + activeRegulation = submittedRegulations.get(maxRankingIndex); + logger.info("active regulation: " + activeRegulation.getText()); + return activeRegulation; + } public EnforcementMechanism generateEnforcementRankings() { resetEnforcementRankingCount(); @@ -156,8 +186,8 @@ ArrayList<ClientData> clientDataList = new ArrayList<ClientData>(clients.values()); Collections.shuffle(clientDataList); // pick the first client from the shuffled list and set their role to MONITOR - ClientData monitor = clientDataList.remove(0); - monitor.setForagingRole(ForagingRole.MONITOR); + activeMonitor = clientDataList.remove(0); + activeMonitor.setForagingRole(ForagingRole.MONITOR); // set the rest of the clients to the HARVEST role for (ClientData clientData : clientDataList) { clientData.setForagingRole(ForagingRole.HARVEST); @@ -178,6 +208,10 @@ receivedEnforcementRankings = 0; } + private void resetRegulationRankingCount() { + receivedRegulationRankings = 0; + } + public boolean hasReceivedAllEnforcementRankings() { return receivedEnforcementRankings >= clients.size(); } @@ -215,6 +249,7 @@ tokensCollectedDuringInterval = 0; activeEnforcementMechanism = EnforcementMechanism.NONE; submittedRegulations.clear(); + activeMonitor = null; } public void clearResourceDistribution() { @@ -579,6 +614,7 @@ public String toString() { return "Group #" + groupId; } + @Override public int compareTo(GroupDataModel other) { return Long.valueOf(groupId).compareTo(other.groupId); @@ -595,8 +631,13 @@ } public void submitRegulationRanking(RegulationRankingRequest request) { - + clients.get(request.getId()).setRegulationRankings(request.getRankings()); + receivedRegulationRankings++; } + + public boolean isRotatingMonitor() { + return activeEnforcementMechanism != null && activeEnforcementMechanism.isRotatingMonitor(); + } public boolean hasReceivedAllRegulationRankings() { return receivedRegulationRankings >= clients.size(); @@ -605,5 +646,30 @@ public List<RegulationData> getSubmittedRegulations() { return submittedRegulations; } + + public void applyMonitorTax() { + if (activeMonitor == null) { + logger.severe("Trying to apply monitor tax for null monitor."); + return; + } + if (activeMonitor.isTaxReceived()) { + logger.severe("active monitor: " + activeMonitor + " already received tax."); + return; + } + ArrayList<ClientData> clientDataList = new ArrayList<ClientData>(clients.values()); + clientDataList.remove(activeMonitor); + Map<Identifier, Integer> monitorTaxes = new HashMap<Identifier, Integer>(); + int totalTax = 0; + for (ClientData clientData : clientDataList) { + int monitorTax = clientData.applyMonitorTax(); + totalTax += monitorTax; + activeMonitor.addTokens(monitorTax); + monitorTaxes.put(clientData.getId(), monitorTax); + } + logger.info("active monitor: " + activeMonitor + " received tax: " + totalTax); + activeMonitor.setTaxReceived(); + // persist monitor tax + serverDataModel.getEventChannel().handle(new MonitorTaxEvent(activeMonitor.getId(), monitorTaxes, totalTax)); + } } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/RegulationData.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/RegulationData.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/RegulationData.java 2009-12-04 06:54:23 UTC (rev 399) @@ -70,6 +70,10 @@ return text.hashCode() ^ id.hashCode() * (rank + 34); } + public String toString() { + return text; + } + public int compareTo(RegulationData regulationData) { int comparison = Integer.valueOf(rank).compareTo(regulationData.rank); if (comparison == 0) { Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java 2009-12-04 06:54:23 UTC (rev 399) @@ -42,12 +42,13 @@ import edu.asu.commons.foraging.event.HarvestResourceRequest; import edu.asu.commons.foraging.event.LockResourceEvent; import edu.asu.commons.foraging.event.LockResourceRequest; -import edu.asu.commons.foraging.event.NewClientRole; import edu.asu.commons.foraging.event.PostRoundSanctionRequest; import edu.asu.commons.foraging.event.PostRoundSanctionUpdateEvent; import edu.asu.commons.foraging.event.QuizCompletedEvent; import edu.asu.commons.foraging.event.RealTimeSanctionRequest; import edu.asu.commons.foraging.event.RegulationRankingRequest; +import edu.asu.commons.foraging.event.RegulationSubmissionUpdateEvent; +import edu.asu.commons.foraging.event.RegulationUpdateEvent; import edu.asu.commons.foraging.event.ResetTokenDistributionRequest; import edu.asu.commons.foraging.event.RoundStartedEvent; import edu.asu.commons.foraging.event.ShowInstructionsRequest; @@ -55,10 +56,10 @@ import edu.asu.commons.foraging.event.SynchronizeClientEvent; import edu.asu.commons.foraging.event.UnlockResourceRequest; import edu.asu.commons.foraging.model.ClientData; -import edu.asu.commons.foraging.model.ClientRole; import edu.asu.commons.foraging.model.Direction; import edu.asu.commons.foraging.model.EnforcementMechanism; import edu.asu.commons.foraging.model.GroupDataModel; +import edu.asu.commons.foraging.model.RegulationData; import edu.asu.commons.foraging.model.ResourceDispenser; import edu.asu.commons.foraging.model.ServerDataModel; import edu.asu.commons.foraging.util.ForagingSaveFileConverter; @@ -116,7 +117,8 @@ private volatile int numberOfCompletedQuizzes; private volatile int numberOfCompletedSanctions; private volatile int numberOfCompletedAgentDesigns; - private volatile int clientToken; + + private int monitorRotationInterval; private Duration currentRoundDuration; // private Duration chatDuration; @@ -295,6 +297,7 @@ } } }); + addEventProcessor(new EventTypeProcessor<SubmitRegulationRequest>(SubmitRegulationRequest.class) { public void handle(final SubmitRegulationRequest request) { GroupDataModel group = serverDataModel.getGroup(request.getId()); @@ -389,9 +392,6 @@ addEventProcessor(new EventTypeProcessor<RealTimeSanctionRequest>(RealTimeSanctionRequest.class) { @Override public void handleInExperimentThread(final RealTimeSanctionRequest request) { - System.out.println("received sanctioning request"); - ClientData targetClient = clients.get(request.getTarget()); - ClientData sourceClient = clients.get(request.getSource()); // validate request // a user can sanction iff the following hold: // 1. sanctioning is enabled or they are the monitor @@ -444,13 +444,16 @@ } private void sendRegulationUpdate(GroupDataModel group) { - // TODO: implement me + for (Identifier id: group.getClientIdentifiers()) { + transmit(new RegulationSubmissionUpdateEvent(id, group.getSubmittedRegulations())); + } } + private void sendRegulationRankingUpdate(GroupDataModel group) { - EnforcementMechanism enforcementMechanism = group.generateEnforcementRankings(); + RegulationData regulationData = group.generateRegulationRankings(); for (Identifier id: group.getClientIdentifiers()) { - transmit(new EnforcementMechanismUpdateEvent(id, enforcementMechanism)); + transmit(new RegulationUpdateEvent(id, regulationData)); } } @@ -464,84 +467,115 @@ private void handleEnforcementSanctionRequest(RealTimeSanctionRequest request) { ClientData sourceClient = clients.get(request.getSource()); ClientData targetClient = clients.get(request.getTarget()); - if (sourceClient.isMonitor()) { - // monitor can always sanction regardless of if they have enough tokens. - if (targetClient.getCurrentTokens() == 0) { - // nothing to take, so sanctioning has no effect. - transmit(new ClientMessageEvent(sourceClient.getId(), - String.format("Ignoring token reduction request: # %d does not have any tokens to reduce.", targetClient.getAssignedNumber()))); - return; + + GroupDataModel group = sourceClient.getGroupDataModel(); + if (! group.equals(targetClient.getGroupDataModel())) { + logger.severe("source client and target client groups are different: " + sourceClient + targetClient); + return; + } + EnforcementMechanism enforcementMechanism = group.getActiveEnforcementMechanism(); + switch (enforcementMechanism) { + case EVERYONE_CAN_SANCTION: + handleRealTimeSanctionRequest(request); + break; + case RANDOM_MONITOR: + case ROTATING_MONITOR: + if (sourceClient.isMonitor()) { + // monitor can always sanction regardless of if they have enough tokens. + if (targetClient.getCurrentTokens() == 0) { + // nothing to take, so sanctioning has no effect. + transmit(new ClientMessageEvent(sourceClient.getId(), + String.format("Ignoring token reduction request: # %d does not have any tokens to reduce.", targetClient.getAssignedNumber()))); + return; + } + // monitors don't get any sanction costs. + targetClient.sanctionPenalty(); + // add sanction request to the target client so they can figure out who just sanctioned them + targetClient.getLatestSanctions().add(request); + transmit(new ClientMessageEvent(sourceClient.getId(), + String.format("Subtracting %d tokens from # %d at the cost of 0 to yourself." , + getCurrentRoundConfiguration().getSanctionPenalty(), + targetClient.getAssignedNumber()))); + transmit(new ClientMessageEvent(targetClient.getId(), + String.format("# %d subtracted %d tokens from you.", sourceClient.getAssignedNumber(), getCurrentRoundConfiguration().getSanctionPenalty()))); } - + break; + case NONE: + default: + logger.severe("tried to sanction with EnforcementMechanism.NONE"); } - int srcEnforcementType = sourceClient.getEnforcementData().getResultIndex(); - int tgtEnforcementType = targetClient.getEnforcementData().getResultIndex(); - if(srcEnforcementType == tgtEnforcementType) { - System.out.println("This condition should be always true"); - switch(srcEnforcementType) { - /* - * No sanctioning just harvest - */ case NO_SANCTIONS: - System.out.println("This code should never be reached"); - - break; - - /* - * Harvest and sanction - * Reduce other by 2 but also own by 1 - */ - case HARVEST_WITH_SANCTION: - sourceClient.sanctionCost(); - targetClient.sanctionPenalty(1); - // add sanction request to the target client so they can figure out who just sanctioned them - targetClient.getLatestSanctions().add(request); - transmit(new ClientMessageEvent(sourceClient.getId(), - String.format("Subtracting %d tokens from # %d at the cost of %d to yourself." , - getCurrentRoundConfiguration().getSanctionPenalty(1), - targetClient.getAssignedNumber(), - getCurrentRoundConfiguration().getSanctionCost()))); - transmit(new ClientMessageEvent(targetClient.getId(), - String.format("# %d subtracted %d tokens from you.", sourceClient.getAssignedNumber(), getCurrentRoundConfiguration().getSanctionPenalty(1)))); - break; - - - /* - * One participant is a moniter who sanctions but cannot harvest - * Moniter can give penalty by subtract 1 from sanctionee - * Nothing taken from Moniter but receives 25% tokens from each - */ case RANDOM_SANCTIONER: - //sourceClient.sanctionCost(); - targetClient.sanctionPenalty(0); - // add sanction request to the target client so they can figure out who just sanctioned them - targetClient.getLatestSanctions().add(request); - transmit(new ClientMessageEvent(sourceClient.getId(), - String.format("Subtracting %d tokens from # %d at the cost of 0 to yourself." , - getCurrentRoundConfiguration().getSanctionPenalty(0), - targetClient.getAssignedNumber()))); - transmit(new ClientMessageEvent(targetClient.getId(), - String.format("# %d subtracted %d tokens from you.", sourceClient.getAssignedNumber(), getCurrentRoundConfiguration().getSanctionPenalty(0)))); - break; - - /* - * Harvest and sanction for 48 secs in sequence - * One participant is a moniter who sanctions but cannot harvest - * Moniter can give penalty by subtract 1 from sanctionee - * Nothing taken from Moniter but receives 25% tokens from each - */ case CIRCULAR_MONITERING: - //sourceClient.sanctionCost(); - targetClient.sanctionPenalty(0); - // add sanction request to the target client so they can figure out who just sanctioned them - targetClient.getLatestSanctions().add(request); - transmit(new ClientMessageEvent(sourceClient.getId(), - String.format("Subtracting %d tokens from # %d at the cost of 0 to yourself." , - getCurrentRoundConfiguration().getSanctionPenalty(0), - targetClient.getAssignedNumber()))); - transmit(new ClientMessageEvent(targetClient.getId(), - String.format("# %d subtracted %d tokens from you.", sourceClient.getAssignedNumber(), getCurrentRoundConfiguration().getSanctionPenalty(0)))); - break; - } - } + // TODO: reimplement +// +// +// int srcEnforcementType = sourceClient.getEnforcementData().getResultIndex(); +// int tgtEnforcementType = targetClient.getEnforcementData().getResultIndex(); +// +// if(srcEnforcementType == tgtEnforcementType) { +// System.out.println("This condition should be always true"); +// switch(srcEnforcementType) { +// /* +// * No sanctioning just harvest +// */ case NO_SANCTIONS: +// System.out.println("This code should never be reached"); +// +// break; +// +// /* +// * Harvest and sanction +// * Reduce other by 2 but also own by 1 +// */ +// case HARVEST_WITH_SANCTION: +// sourceClient.sanctionCost(); +// targetClient.monitorSanctionPenalty(1); +// // add sanction request to the target client so they can figure out who just sanctioned them +// targetClient.getLatestSanctions().add(request); +// transmit(new ClientMessageEvent(sourceClient.getId(), +// String.format("Subtracting %d tokens from # %d at the cost of %d to yourself." , +// getCurrentRoundConfiguration().getSanctionPenalty(1), +// targetClient.getAssignedNumber(), +// getCurrentRoundConfiguration().getSanctionCost()))); +// transmit(new ClientMessageEvent(targetClient.getId(), +// String.format("# %d subtracted %d tokens from you.", sourceClient.getAssignedNumber(), getCurrentRoundConfiguration().getSanctionPenalty(1)))); +// break; +// +// +// /* +// * One participant is a moniter who sanctions but cannot harvest +// * Moniter can give penalty by subtract 1 from sanctionee +// * Nothing taken from Moniter but receives 25% tokens from each +// */ case RANDOM_SANCTIONER: +// //sourceClient.sanctionCost(); +// targetClient.monitorSanctionPenalty(0); +// // add sanction request to the target client so they can figure out who just sanctioned them +// targetClient.getLatestSanctions().add(request); +// transmit(new ClientMessageEvent(sourceClient.getId(), +// String.format("Subtracting %d tokens from # %d at the cost of 0 to yourself." , +// getCurrentRoundConfiguration().getSanctionPenalty(0), +// targetClient.getAssignedNumber()))); +// transmit(new ClientMessageEvent(targetClient.getId(), +// String.format("# %d subtracted %d tokens from you.", sourceClient.getAssignedNumber(), getCurrentRoundConfiguration().getSanctionPenalty(0)))); +// break; +// +// /* +// * Harvest and sanction for 48 secs in sequence +// * One participant is a moniter who sanctions but cannot harvest +// * Moniter can give penalty by subtract 1 from sanctionee +// * Nothing taken from Moniter but receives 25% tokens from each +// */ case CIRCULAR_MONITERING: +// //sourceClient.sanctionCost(); +// targetClient.monitorSanctionPenalty(0); +// // add sanction request to the target client so they can figure out who just sanctioned them +// targetClient.getLatestSanctions().add(request); +// transmit(new ClientMessageEvent(sourceClient.getId(), +// String.format("Subtracting %d tokens from # %d at the cost of 0 to yourself." , +// getCurrentRoundConfiguration().getSanctionPenalty(), +// targetClient.getAssignedNumber()))); +// transmit(new ClientMessageEvent(targetClient.getId(), +// String.format("# %d subtracted %d tokens from you.", sourceClient.getAssignedNumber(), getCurrentRoundConfiguration().getSanctionPenalty()))); +// break; +// } +// } } private void handleRealTimeSanctionRequest(RealTimeSanctionRequest request) { @@ -653,50 +687,49 @@ // FIXME: handle reconfiguration requests from facilitator } - private double getRank(int rankNo) { - double actualRank = 0; - if (rankNo == 0) actualRank=1; - if (rankNo == 1) actualRank=0.5; - if (rankNo == 2) actualRank=0.33; - if (rankNo == 3) actualRank=0.25; - if (rankNo == 4) actualRank=0.2; - return actualRank; - } +// private double getRank(int rankNo) { +// double actualRank = 0; +// if (rankNo == 0) actualRank=1; +// if (rankNo == 1) actualRank=0.5; +// if (rankNo == 2) actualRank=0.33; +// if (rankNo == 3) actualRank=0.25; +// if (rankNo == 4) actualRank=0.2; +// return actualRank; +// } +// +// private int findMax(double voteArray[], int loopCount) +// { +// double max = voteArray[0]; +// int i=0; +// int index=0; +// for(i=0 ; i < loopCount ; i++) +// { +// if(voteArray[i] > max) +// { +// index = i; +// max = voteArray[i]; +// } +// } +// return index; +// } - private int findMax(double voteArray[], int loopCount) - { - double max = voteArray[0]; - int i=0; - int index=0; - for(i=0 ; i < loopCount ; i++) - { - if(voteArray[i] > max) - { - index = i; - max = voteArray[i]; - } - } - return index; - } +// private void sendNewRolesToClients(Identifier id, int roles[]) { +// ClientRole clientRole = new ClientRole(); +// clientRole.setClientRoles(roles); +// int i = 0; +// for (Identifier targetId : clients.get(id).getGroupDataModel().getClientIdentifiers()) { +// NewClientRole newClientRole = new NewClientRole(targetId); +// clientRole.setClientId(targetId); +// clientRole.setRoleNo(i); +// if(roles[i] == MONITER)clientRole.setMoniterId(targetId); +// clients.get(targetId).setClientRole(clientRole); +// newClientRole.setRoleObj(clientRole); +// transmit(newClientRole); +// getLogger().info("transmitted timesliced client roles"); +// i++; +// } +// } - // FIXME: refactor later - private void sendNewRolesToClients(Identifier id, int roles[]) { - ClientRole clientRole = new ClientRole(); - clientRole.setClientRoles(roles); - int i = 0; - for (Identifier targetId : clients.get(id).getGroupDataModel().getClientIdentifiers()) { - NewClientRole newClientRole = new NewClientRole(targetId); - clientRole.setClientId(targetId); - clientRole.setRoleNo(i); - if(roles[i] == MONITER)clientRole.setMoniterId(targetId); - clients.get(targetId).setClientRole(clientRole); - newClientRole.setRoleObj(clientRole); - transmit(newClientRole); - getLogger().info("transmitted timesliced client roles"); - i++; - } - } - // private int [] findClientRoles(GroupDataModel group, int index) { // int roles [] = new int [MAX_CLIENTS_PER_GROUP]; // int i; @@ -824,7 +857,7 @@ // perform token adjustment if needed. for (GroupDataModel group: serverDataModel.getGroups()) { if (group.getActiveEnforcementMechanism().hasMonitor()) { - // check for monitor status + group.applyMonitorTax(); } } stopRound(); @@ -916,10 +949,22 @@ } serverDataModel.clearDiffLists(); } - + private void processRound2d() { boolean secondHasPassed = secondTick.hasExpired(); if (secondHasPassed) { + if (currentRoundDuration.getElapsedTimeInSeconds() % monitorRotationInterval == 0) { + for (GroupDataModel group: serverDataModel.getGroups()) { + boolean rotated = group.rotateMonitorIfNecessary(); + if (rotated) { + // send new roles to all clients + for (ClientData clientData : group.getClientDataMap().values()) { + transmit(new SynchronizeClientEvent(clientData, currentRoundDuration.getTimeLeft())); + } + } + + } + } resourceDispenser.generateResources(); secondTick.restart(); } @@ -928,9 +973,6 @@ // ask each client if it wants to grab a token, wherever it is. clientData.collectToken(); } - if (getCurrentRoundConfiguration().isVotingAndRegulationEnabled() && group.getActiveEnforcementMechanism().isRotatingMonitor()) { - - } } for (ClientData clientData : clients.values()) { @@ -1089,6 +1131,10 @@ // start timers currentRoundDuration = roundConfiguration.getRoundDuration(); + if (roundConfiguration.isVotingAndRegulationEnabled()) { + monitorRotationInterval = currentRoundDuration.getElapsedTimeInSeconds() / roundConfiguration.getClientsPerGroup(); + logger.info("monitor rotation interval: " + monitorRotationInterval); + } currentRoundDuration.start(); transmit(new FacilitatorUpdateEvent(facilitatorId, serverDataModel, currentRoundDuration.getTimeLeft())); ... [truncated message content] |