private void startQueuesWorkers() {
try {
//Phone Calls Worker
phoneCallsWorker = new MessageConsumerWorker("IncomingCallCoreServer", new MessageConsumerWorkerHandler<IncomingCallMessage>() {
@Override
public void handleMessage(IncomingCallMessage incomingCallMessage) {
GenericEmergencyProcedureImpl.getInstance().newPhoneCall(incomingCallMessage.getCall());
}
});
//Procedure Ended Worker
procedureEndedWorker = new MessageConsumerWorker("ProcedureEndedCoreServer", new MessageConsumerWorkerHandler<ProcedureCompletedMessage>() {
@Override
public void handleMessage(ProcedureCompletedMessage procedureEndsMessage) {
GenericEmergencyProcedureImpl.getInstance().procedureCompletedNotification(procedureEndsMessage.getEmergencyId(), procedureEndsMessage.getProcedureId());
}
});
//All Procedures Ended Worker
allProceduresEndedWorker = new MessageConsumerWorker("AllProceduresEndedCoreServer", new MessageConsumerWorkerHandler<AllProceduresEndedMessage>() {
@Override
public void handleMessage(AllProceduresEndedMessage allProceduresEndedMessage) {
GenericEmergencyProcedureImpl.getInstance().allProceduresEnededNotification(new AllProceduresEndedEvent(allProceduresEndedMessage.getEmergencyId(), allProceduresEndedMessage.getEndedProcedures()));
}
});
//Procedure Selected Worker
//@TODO: Delete because now the generic procedure use the Start Procedure work item to do this
selectedProcedureWorker = new MessageConsumerWorker("selectedProcedureCoreServer", new MessageConsumerWorkerHandler<SelectedProcedureMessage>() {
@Override
public void handleMessage(SelectedProcedureMessage selectedProcedureMessage) {
try {
ProceduresMGMTService.getInstance().newRequestedProcedure(selectedProcedureMessage.getEmergencyId(),
selectedProcedureMessage.getProcedureName(),
selectedProcedureMessage.getParameters());
} catch (IOException ex) {
Logger.getLogger(CoreServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
//Emergency Details Persistence Selected Worker
emergencyDetailsPersistenceWorker = new MessageConsumerWorker("emergencyDetailsCoreServer", new MessageConsumerWorkerHandler<EmergencyDetailsMessage>() {
@Override
public void handleMessage(EmergencyDetailsMessage emergencyDetailsMessage) {
//update the emergency
persistenceService.storeEmergency(emergencyDetailsMessage.getEmergency());
//attachs it to the call
trackingService.attachEmergency(emergencyDetailsMessage.getEmergency().getCall().getId(), emergencyDetailsMessage.getEmergency().getId());
}
});
//Vehicle Hits an Emergency Selected Worker
vehicleHitsEmergencyWorker = new MessageConsumerWorker("vehicleHitsEmergencyCoreServer", new MessageConsumerWorkerHandler<VehicleHitsEmergencyMessage>() {
@Override
public void handleMessage(VehicleHitsEmergencyMessage vehicleHitsEmergencyMessage) {
EmergencyEvent event = MessageToEventConverter.convertMessageToEvent(vehicleHitsEmergencyMessage);
vehicleHitEmergency.put(vehicleHitsEmergencyMessage.getVehicleId(), Boolean.TRUE);
ProceduresMGMTService.getInstance().notifyProcedures(event);
}
});
//Vehicle Hits an Hospital Selected Worker
vehicleHitsHospitalWorker = new MessageConsumerWorker("vehicleHitsHospitalCoreServer", new MessageConsumerWorkerHandler<VehicleHitsHospitalMessage>() {
@Override
public void handleMessage(VehicleHitsHospitalMessage vehicleHitsHospitalMessage) {
EmergencyEvent event = MessageToEventConverter.convertMessageToEvent(vehicleHitsHospitalMessage);
vehicleHitHospital.put(vehicleHitsHospitalMessage.getVehicleId(), Boolean.TRUE);
ProceduresMGMTService.getInstance().notifyProcedures(event);
//Notify VehicleMGMTService
VehiclesMGMTService.getInstance().vehicleRemoved(vehicleHitsHospitalMessage.getVehicleId());
}
});
//Vehicle Hits a Fire Department Selected Worker
vehicleHitsFireDepartmentWorker = new MessageConsumerWorker("vehicleHitsFireDepartmentWorkerCoreServer", new MessageConsumerWorkerHandler<VehicleHitsFireDepartmentMessage>() {
@Override
public void handleMessage(VehicleHitsFireDepartmentMessage vehicleHitsFireDepartmentMessage) {
EmergencyEvent event = MessageToEventConverter.convertMessageToEvent(vehicleHitsFireDepartmentMessage);
ProceduresMGMTService.getInstance().notifyProcedures(event);
VehiclesMGMTService.getInstance().processEvent((EmergencyVehicleEvent)event);
}
});
//Vehicle Dispatched
vehicleDispatchedWorker = new MessageConsumerWorker("vehicleDispatchedCoreServer", new MessageConsumerWorkerHandler<VehicleDispatchedMessage>() {
@Override
public void handleMessage(VehicleDispatchedMessage message) {
vehicleHitEmergency.put(message.getVehicleId(), Boolean.FALSE);
vehicleHitHospital.put(message.getVehicleId(), Boolean.FALSE);
VehiclesMGMTService.getInstance().newVehicleDispatched(message.getEmergencyId(), message.getVehicleId());
// try {
// Thread.sleep(3000);
// } catch (InterruptedException ex) {
// Logger.getLogger(CoreServer.class.getName()).log(Level.SEVERE, null, ex);
// }
}
});
//Heart Beat Received
heartBeatReceivedWorker = new MessageConsumerWorker("heartBeatCoreServer", new MessageConsumerWorkerHandler<HeartBeatMessage>() {
@Override
public void handleMessage(HeartBeatMessage message) {
//Only notify if the vehicle already hit the emergency
//but it doesnt hit the hospital
Boolean hitEmergency = vehicleHitEmergency.get(message.getVehicleId());
Boolean hitHospital = vehicleHitHospital.get(message.getVehicleId());
if (hitEmergency == null || hitHospital == null){
return;
}
if (hitEmergency && !hitHospital){
EmergencyEvent event = MessageToEventConverter.convertMessageToEvent(message);
VehiclesMGMTService.getInstance().processEvent((PulseEvent)event);
}
}
});
//FireTruck Water Level Decreased Received
fireTruckDecreaseWaterLevelWorker = new MessageConsumerWorker("fireTruckDecreaseWaterLevelCoreServer", new MessageConsumerWorkerHandler<FireTruckDecreaseWaterLevelMessage>() {
@Override
public void handleMessage(FireTruckDecreaseWaterLevelMessage message) {
VehiclesMGMTService.getInstance().processEvent(new FireTruckDecreaseWaterLevelEvent(message.getEmergencyId(), message.getVehicleId(), message.getTime()));
}
});
//FireTruck Out Of Water Received
fireTruckOutOfWaterWorker = new MessageConsumerWorker("fireTruckOutOfWaterCoreServer", new MessageConsumerWorkerHandler<FireTruckOutOfWaterMessage>() {
@Override
public void handleMessage(FireTruckOutOfWaterMessage message) {
EmergencyEvent event = MessageToEventConverter.convertMessageToEvent(message);
VehiclesMGMTService.getInstance().processEvent((EmergencyVehicleEvent)event);
ProceduresMGMTService.getInstance().notifyProcedures(event);
}
});
reportingWorker = new MessageConsumerWorker("reportingCoreServer", new MessageConsumerWorkerHandler<EmergencyInterchangeMessage>() {
@Override
public void handleMessage(EmergencyInterchangeMessage message) {
persistenceService.addEntryToReport(message.getEmergencyId(), message.toString());
}
});
asynchProcedureStartWorker = new MessageConsumerWorker("asyncProcedureStartCoreServer", new MessageConsumerWorkerHandler<AsyncProcedureStartMessage>() {
@Override
public void handleMessage(AsyncProcedureStartMessage message) {
System.out.println(">>>>>>>>>>>Creating a new Procedure = "+message.getProcedureName());
try {
ProceduresMGMTService.getInstance().newRequestedProcedure(message.getEmergencyId(), message.getProcedureName(), message.getParameters());
} catch (IOException ex) {
Logger.getLogger(CoreServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
fireTruckWaterRefillMonitorWorker = new MessageConsumerWorker("asynchFireMonitorCoreServer", new MessageConsumerWorkerHandler<FireTruckWaterRefilledMessage>() {
@Override
public void handleMessage(FireTruckWaterRefilledMessage message) {
VehiclesMGMTService.getInstance().processEvent((EmergencyVehicleEvent)MessageToEventConverter.convertMessageToEvent(message));