예제 #1
0
 @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();
 }
예제 #2
0
  @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();
  }
예제 #3
0
  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);
    }
  }
예제 #4
0
  @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();
  }