@Override public void handlePut(Operation put) { final LoaderServiceState newState = put.getBody(LoaderServiceState.class); if (newState.loaderType == null) { newState.loaderType = LoaderType.FILESYSTEM; } setState(put, newState); put.setBody(newState).complete(); }
@Override public void handleStart(Operation op) { if (op.hasBody()) { LoaderServiceState s = op.getBody(LoaderServiceState.class); if (s.loaderType == null) { s.loaderType = LoaderType.FILESYSTEM; } logFine("Initial path is %s", s.path); } super.setMaintenanceIntervalMicros(MAINTENANCE_INTERVAL_MICROS); op.complete(); }
private void loadServices(LoaderServiceState localState) { Map<String, LoaderServiceInfo> discoveredPackages = null; switch (localState.loaderType) { case FILESYSTEM: try { discoveredPackages = loadFromFileSystem(localState); } catch (Exception e) { logWarning( "Failed to load packages from path %s, %s.", localState.path, Utils.toString(e)); } break; default: logWarning("Unknown loader type: %s", localState.loaderType); } if (discoveredPackages != null) { LoaderServiceState newState = new LoaderServiceState(); newState.servicePackages = discoveredPackages; final Operation patch = Operation.createPatch(getUri()).setBody(newState); sendRequest(patch); } }
@Override public void handlePatch(Operation patch) { // Get the current state. final LoaderServiceState currentState = getState(patch); final LoaderServiceState patchBody = patch.getBody(LoaderServiceState.class); if (patchBody.path != null) { currentState.path = patchBody.path; } if (patchBody.loaderType != null) { currentState.loaderType = patchBody.loaderType; } else { currentState.loaderType = LoaderType.FILESYSTEM; } if (patchBody.servicePackages != null) { currentState.servicePackages = patchBody.servicePackages; } // Update the state. patch.setBody(currentState).complete(); }