@Override public UpdateRigStatusResponse updateRigStatus(UpdateRigStatus request) { /* Request parameters. */ UpdateRigType upRig = request.getUpdateRigStatus(); StatusType status = upRig.getStatus(); this.logger.debug( "Received " + this.getClass().getSimpleName() + "#updateRigStatus with parameters: name=" + upRig.getName() + ", isOnline=" + status.getIsOnline() + ", offlineReason=" + status.getOfflineReason() + '.'); /* Response parameters. */ UpdateRigStatusResponse response = new UpdateRigStatusResponse(); ProviderResponse providerResp = new ProviderResponse(); response.setUpdateRigStatusResponse(providerResp); UpdateLocalRigStatus updater = new UpdateLocalRigStatus(); if (updater.updateStatus(upRig.getName(), status.getIsOnline(), status.getOfflineReason())) { providerResp.setSuccessful(true); providerResp.setIdentityToken( IdentityTokenRegister.getInstance().getOrGenerateIdentityToken(upRig.getName())); } else { providerResp.setSuccessful(false); providerResp.setErrorReason(updater.getFailedReason()); } updater.getSession().close(); return response; }
@Override public RegisterRigResponse registerRig(RegisterRig request) { RegisterLocalRig register = null; try { /* Request parameters. */ RegisterRigType rig = request.getRegisterRig(); StatusType status = rig.getStatus(); this.logger.debug( "Received " + this.getClass().getSimpleName() + "#registerRig with parameters: name=" + rig.getName() + ", type=" + rig.getType() + ", capabilities=" + rig.getCapabilities() + ", contact URL=" + rig.getContactUrl().toString() + ", isOnline=" + status.getIsOnline() + ", offlineReason=" + status.getOfflineReason() + "."); /* Response parameters. */ RegisterRigResponse response = new RegisterRigResponse(); ProviderResponse providerResp = new ProviderResponse(); response.setRegisterRigResponse(providerResp); register = new RegisterLocalRig(); if (register.registerRig( rig.getName(), rig.getType(), rig.getCapabilities(), rig.getContactUrl().toString())) { Rig registeredRig = register.getRegisteredRig(); /* Rig register so update its status. */ UpdateLocalRigStatus updater = new UpdateLocalRigStatus(register.getSession()); if (updater.updateStatus( registeredRig.getName(), status.getIsOnline(), status.getOfflineReason())) { providerResp.setSuccessful(true); providerResp.setIdentityToken( IdentityTokenRegister.getInstance().getIdentityToken(registeredRig.getName())); } else { providerResp.setSuccessful(false); providerResp.setErrorReason(updater.getFailedReason()); } } else { providerResp.setSuccessful(false); providerResp.setErrorReason(register.getFailedReason()); } return response; } finally { if (register != null) register.getSession().close(); } }