-
Notifications
You must be signed in to change notification settings - Fork 7
SubmitCarbonEmissionReportHandler
farhanrahman edited this page Jun 22, 2012
·
2 revisions
ActionHandler that handles the SubmitCarbonEmissionReport action that can be invoked by any Participant.
CarbonReportingService: Depends on this service to update the shared state of the participant that invoked the action.
In the Simulation.java file, this class is registered as a valid action handler. In order to specify that it specifically handles the SubmitCarbonEmissionReport the canHandle()
function of the super class ActionHandler needs to be overridden as follow:
@Override
public boolean canHandle(Action action) {
return action instanceof SubmitCarbonEmissionReport;
}
The handle()
function is overridden such that it first typecasts the action to a SubmitCarbonEmissionReport action with handling the ActionHandlingException. The overridden function is as follows:
@Override
public Input handle(Action action, UUID actor)
throws ActionHandlingException {
if(action instanceof SubmitCarbonEmissionReport){
SubmitCarbonEmissionReport reportAction = (SubmitCarbonEmissionReport) action;
synchronized(crs){
this.crs.updateReport(actor, reportAction.getCarbonEmission(), reportAction.getSimTime());
}
return null;
}
throw new ActionHandlingException("Action not recognized (From SubmitCarbonEmissionReportHandler");
}