com.vmware.xenon.common.Utils.mergeWithState()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(107)

本文整理了Java中com.vmware.xenon.common.Utils.mergeWithState()方法的一些代码示例,展示了Utils.mergeWithState()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.mergeWithState()方法的具体详情如下:
包路径:com.vmware.xenon.common.Utils
类名称:Utils
方法名:mergeWithState

Utils.mergeWithState介绍

[英]Update the state of collections that are part of the service state
[中]更新属于服务状态的集合的状态

代码示例

代码示例来源:origin: vmware/xenon

/**
 * This updates the state of the task. Note that we are merging information from the PATCH into
 * the current task. Because we are merging into the current task (it's the same object), we do
 * not need to explicitly save the state: that will happen when we call patch.complete()
 */
protected void updateState(T currentTask, T patchBody) {
  Utils.mergeWithState(getStateDescription(), currentTask, patchBody);
  // NOTE: If patchBody provides a new expiration, Utils.mergeWithState will take care of it
}

代码示例来源:origin: vmware/xenon

private State applyPatch(State patchState, State currentState) {
  Utils.mergeWithState(getStateDescription(), currentState, patchState);
  currentState.latestSourceUpdateTimeMicros = Math.max(
      Optional.ofNullable(currentState.latestSourceUpdateTimeMicros).orElse(0L),
      Optional.ofNullable(patchState.latestSourceUpdateTimeMicros).orElse(0L));
  return currentState;
}

代码示例来源:origin: vmware/admiral

/**
 * Performs automatic task state merge based on state annotations.
 */
protected void autoMergeState(Operation patch, T patchBody, T currentState) {
  // use default merging for AUTO_MERGE_IF_NOT_NULL fields
  Utils.mergeWithState(getStateDescription(), currentState, patchBody);
}

代码示例来源:origin: vmware/xenon

@Override
  public void handlePatch(Operation patch) {
    LocalFileServiceState currentTask = getState(patch);
    LocalFileServiceState patchBody = getBody(patch);
    Utils.mergeWithState(getStateDescription(), currentTask, patchBody);
    patch.complete();
  }
}

代码示例来源:origin: vmware/xenon

@Override
  public void handlePatch(Operation patch) {
    Employee state = getState(patch);
    Employee patchBody = getBody(patch);

    Utils.mergeWithState(getStateDescription(), state, patchBody);
    patch.setBody(state);
    patch.complete();
  }
}

代码示例来源:origin: vmware/xenon

@Override
  public void handlePatch(Operation patch) {
    Employee state = getState(patch);
    Employee patchBody = getBody(patch);

    Utils.mergeWithState(getStateDescription(), state, patchBody);
    patch.setBody(state);
    patch.complete();

    logInfo("Successfully patched %s. New body is:%s", state.documentSelfLink, state);
  }
}

代码示例来源:origin: vmware/xenon

@Override
  public void handlePatch(Operation patch) {
    Employee state = getState(patch);
    Employee patchBody = getBody(patch);

    Utils.mergeWithState(getStateDescription(), state, patchBody);
    patch.setBody(state);
    patch.complete();

    // Added for 'add-logging' project.
    logInfo("Successfully patched %s. New body is:%s", state.documentSelfLink, state);
  }
}

代码示例来源:origin: vmware/xenon

protected ExampleServiceState updateState(Operation update) {
  // A DCP service handler is state-less: Everything it needs is provided as part of the
  // of the operation. The body and latest state associated with the service are retrieved
  // below.
  ExampleServiceState body = getBody(update);
  ExampleServiceState currentState = getState(update);
  // use helper that will merge automatically current state, with state supplied in body.
  // Note the usage option PropertyUsageOption.AUTO_MERGE_IF_NOT_NULL has been set on the
  // "name" field.
  boolean hasStateChanged = Utils.mergeWithState(getStateDescription(),
      currentState, body);
  updateCounter(body, currentState, hasStateChanged);
  if (body.documentExpirationTimeMicros != currentState.documentExpirationTimeMicros) {
    currentState.documentExpirationTimeMicros = body.documentExpirationTimeMicros;
  }
  // response has latest, updated state
  update.setBody(currentState);
  return currentState;
}

代码示例来源:origin: vmware/xenon

@Override
public void handlePatch(Operation patch) {
  if (!patch.hasBody()) {
    patch.fail(new IllegalArgumentException("body is required"));
    return;
  }
  AuthCredentialsServiceState currentState = getState(patch);
  try {
    if (!Utils.mergeWithState(currentState, patch)) {
      AuthCredentialsServiceState patchBody = patch.getBody(AuthCredentialsServiceState.class);
      updateState(patchBody, currentState);
    }
  } catch (NoSuchFieldException | IllegalAccessException e) {
    patch.fail(e);
    return;
  }
  patch.setBody(currentState).complete();
}

代码示例来源:origin: vmware/admiral

@Override
public void handlePatch(Operation patch) {
  ResourceOperationSpec currentState = getState(patch);
  ResourceOperationSpec body = patch.getBody(ResourceOperationSpec.class);
  validate(body, patch.getRefererAsString());
  boolean merged = Utils.mergeWithState(getStateDescription(), currentState, body);
  if (merged) {
    logFine("%s updated.", currentState);
  } else {
    patch.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED);
  }
  patch.complete();
}

代码示例来源:origin: vmware/admiral

@Override
public void handlePatch(Operation patch) {
  TestState body = getBody(patch);
  TestState state = getState(patch);
  Utils.mergeWithState(getStateDescription(), state, body);
  if (body.intValue != null) {
    state.intValues.add(body.intValue);
  }
  if (body.documentExpirationTimeMicros > 0) {
    state.documentExpirationTimeMicros = body.documentExpirationTimeMicros;
  }
  patch.setBodyNoCloning(state).complete();
}

代码示例来源:origin: com.vmware.xenon/xenon-common

@Override
public void handlePatch(Operation op) {
  ExampleService.ExampleServiceState state = getState(op);
  ExampleService.ExampleServiceState body = getBody(op);
  Utils.mergeWithState(getStateDescription(), state, body);
  state.keyValues = body.keyValues;
  op.complete();
}

代码示例来源:origin: vmware/xenon

@Override
public void handlePatch(Operation op) {
  ExampleService.ExampleServiceState state = getState(op);
  ExampleService.ExampleServiceState body = getBody(op);
  Utils.mergeWithState(getStateDescription(), state, body);
  state.keyValues = body.keyValues;
  op.complete();
}

代码示例来源:origin: vmware/admiral

@Override
public void handlePatch(Operation patch) {
  // logInfo("handlePatch called");
  TestPeriodicState body = getBody(patch);
  TestPeriodicState state = getState(patch);
  Utils.mergeWithState(getStateDescription(), state, body);
  state.calls += body.calls;
  if (body.documentExpirationTimeMicros > 0) {
    state.documentExpirationTimeMicros = body.documentExpirationTimeMicros;
  }
  if (body.intValue != null) {
    state.intValues.add(body.intValue);
  }
  patch.setBodyNoCloning(state).complete();
}

代码示例来源:origin: vmware/admiral

@Override
public void handlePatch(Operation patch) {
  try {
    ScheduledTaskState patchBody = getBody(patch);
    Utils.validateState(getStateDescription(), patchBody);
    ScheduledTaskState currentState = getState(patch);
    boolean hasStateChanged = Utils.mergeWithState(getStateDescription(),
        currentState, patchBody);
    if (!hasStateChanged) {
      patch.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED);
    } else {
      patch.setBody(currentState);
    }
    patch.complete();
  } catch (Throwable e) {
    patch.fail(e);
  }
}

代码示例来源:origin: vmware/xenon

/**
 * Test merging in an empty patch.
 */
@Test
public void testEmptyPatch() {
  MergeTest source = new MergeTest();
  source.s = SOME_STRING_VALUE;
  source.x = SOME_INT_VALUE;
  source.ignore = SOME_IGNORE_VALUE;
  MergeTest patch = new MergeTest();
  ServiceDocumentDescription d = ServiceDocumentDescription.Builder.create()
      .buildDescription(MergeTest.class);
  Assert.assertFalse("There should be no changes", Utils.mergeWithState(d, source, patch));
  Assert.assertEquals("Annotated s field", source.s, SOME_STRING_VALUE);
  Assert.assertEquals("Annotated x field", source.x, SOME_INT_VALUE);
  Assert.assertEquals("Non-annotated ignore field", source.ignore, SOME_IGNORE_VALUE);
}

代码示例来源:origin: com.vmware.xenon/xenon-common

/**
 * Test merging in an empty patch.
 */
@Test
public void testEmptyPatch() {
  MergeTest source = new MergeTest();
  source.s = SOME_STRING_VALUE;
  source.x = SOME_INT_VALUE;
  source.ignore = SOME_IGNORE_VALUE;
  MergeTest patch = new MergeTest();
  ServiceDocumentDescription d = ServiceDocumentDescription.Builder.create()
      .buildDescription(MergeTest.class);
  Assert.assertFalse("There should be no changes", Utils.mergeWithState(d, source, patch));
  Assert.assertEquals("Annotated s field", source.s, SOME_STRING_VALUE);
  Assert.assertEquals("Annotated x field", source.x, SOME_INT_VALUE);
  Assert.assertEquals("Non-annotated ignore field", source.ignore, SOME_IGNORE_VALUE);
}

代码示例来源:origin: com.vmware.xenon/xenon-common

/**
 * Test merging patch with same values as existing value.
 */
@Test
public void testEqualsMerge() {
  MergeTest source = new MergeTest();
  source.s = SOME_STRING_VALUE;
  source.x = SOME_INT_VALUE;
  source.ignore = SOME_IGNORE_VALUE;
  MergeTest patch = new MergeTest();
  patch.s = source.s;
  patch.x = source.x;
  patch.ignore = source.ignore;
  ServiceDocumentDescription d = ServiceDocumentDescription.Builder.create()
      .buildDescription(MergeTest.class);
  Assert.assertFalse("There should be no changes", Utils.mergeWithState(d, source, patch));
  Assert.assertEquals("Annotated s field", source.s, SOME_STRING_VALUE);
  Assert.assertEquals("Annotated x field", source.x, SOME_INT_VALUE);
  Assert.assertEquals("Non-annotated ignore field", source.ignore, SOME_IGNORE_VALUE);
}

代码示例来源:origin: vmware/xenon

/**
 * Test merging partially defined patch object.
 */
@Test
public void testPartialMerge() {
  MergeTest source = new MergeTest();
  source.s = SOME_STRING_VALUE;
  source.x = SOME_INT_VALUE;
  source.ignore = SOME_IGNORE_VALUE;
  MergeTest patch = new MergeTest();
  patch.x = SOME_OTHER_INT_VALUE;
  ServiceDocumentDescription d = ServiceDocumentDescription.Builder.create()
      .buildDescription(MergeTest.class);
  Assert.assertTrue("There should be changes", Utils.mergeWithState(d, source, patch));
  Assert.assertEquals("Annotated s field", source.s, SOME_STRING_VALUE);
  Assert.assertEquals("Annotated x field", source.x, SOME_OTHER_INT_VALUE);
  Assert.assertEquals("Non-annotated ignore field", source.ignore, SOME_IGNORE_VALUE);
}

代码示例来源:origin: com.vmware.xenon/xenon-common

/**
 * Test merging partially defined patch object.
 */
@Test
public void testPartialMerge() {
  MergeTest source = new MergeTest();
  source.s = SOME_STRING_VALUE;
  source.x = SOME_INT_VALUE;
  source.ignore = SOME_IGNORE_VALUE;
  MergeTest patch = new MergeTest();
  patch.x = SOME_OTHER_INT_VALUE;
  ServiceDocumentDescription d = ServiceDocumentDescription.Builder.create()
      .buildDescription(MergeTest.class);
  Assert.assertTrue("There should be changes", Utils.mergeWithState(d, source, patch));
  Assert.assertEquals("Annotated s field", source.s, SOME_STRING_VALUE);
  Assert.assertEquals("Annotated x field", source.x, SOME_OTHER_INT_VALUE);
  Assert.assertEquals("Non-annotated ignore field", source.ignore, SOME_IGNORE_VALUE);
}

相关文章