src/com/vehiclerental/presentationLayer/headOffice/StaffHeadOfficeController.java
/**
     * Broadcasts the shutdown request to all the branches and then shut down the head office server
     *
     * @param request the request parameters
     * @return the result response
     */
Broadcasts the shutdown request to all the branches and then shut down the head office server
@param request the request parameters
@return the result response
Broadcasts the shutdown request to all the branches and then shut down the head office server @param request the request parameters @return the result response
public static HeadOfficeResponseMessage HandleShutdownSystem(HeadOfficeRequestMessage request) {
        try {
            User user = doAuthentication(request.getAuthEmail(), request.getAuthPassword(), true);
            Collection<Branch> branches = NodeConfiguration.Current.branches.values();
            for (Branch branch : branches) {
                ForwardRequestToBranch(branch, request.OperationCode, null, null, user);
            }
            NodeConfiguration.Current.systemAvailable = false;
            /*
                It's actually not possible to finalize only the branches, MPI_Finalize requires all the processes to call
                MPI_Finalize before finalizing the cluster
             */
            NodeConfiguration.Current.headOfficeManager.stopAfterCurrentRequest();
            return generateSuccessfulResponse(request.OperationCode, null);
        } catch (ClusterCommunicatorException e) {
            return generateError(request.OperationCode, 500, "Server error");
        } catch (NotAuthorizedException e) {
            return generateError(request.OperationCode, 401, "Unauthorized");
        }
    }
public static HeadOfficeResponseMessage HandleShutdownSystem ( HeadOfficeRequestMessage request ) { try { User user = doAuthentication ( request . getAuthEmail ( ) , request . getAuthPassword ( ) , true ) ; Collection < Branch > branches = NodeConfiguration . Current . branches . values ( ) ; for ( Branch branch : branches ) { ForwardRequestToBranch ( branch , request . OperationCode , null , null , user ) ; } NodeConfiguration . Current . systemAvailable = false ; /*
                It's actually not possible to finalize only the branches, MPI_Finalize requires all the processes to call
                MPI_Finalize before finalizing the cluster
             */ NodeConfiguration . Current . headOfficeManager . stopAfterCurrentRequest ( ) ; return generateSuccessfulResponse ( request . OperationCode , null ) ; } catch ( ClusterCommunicatorException e ) { return generateError ( request . OperationCode , 500 , "Server error" ) ; } catch ( NotAuthorizedException e ) { return generateError ( request . OperationCode , 401 , "Unauthorized" ) ; } }
Broadcasts the shutdown request to all the branches and then shut down the head office server
 @param request the request parameters
 @return the result response
Broadcasts the shutdown request to all the branches and then shut down the head office server @param request the request parameters @return the result response
//We do not handle errors because the single thread nature of the system makes it very unlikely to fail on shutdown //Everything will go down after this request //Form socket response