本文整理了Java中com.vmware.xenon.common.Utils.clone()
方法的一些代码示例,展示了Utils.clone()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.clone()
方法的具体详情如下:
包路径:com.vmware.xenon.common.Utils
类名称:Utils
方法名:clone
暂无
代码示例来源:origin: vmware/xenon
/**
* Retrieves rate limit configuration for the supplied key
*/
public RequestRateInfo getRequestRateLimit(String key) {
RequestRateInfo ri = this.state.requestRateLimits.get(key);
if (ri == null) {
return null;
}
return Utils.clone(ri);
}
代码示例来源:origin: vmware/xenon
public Query getResourceQuery(Action action) {
if (this.resourceQueryMap == null) {
return null;
}
return Utils.clone(this.resourceQueryMap.get(action));
}
代码示例来源:origin: vmware/xenon
public SystemHostInfo getSystemInfo() {
if (!this.info.properties.isEmpty() && !this.info.ipAddresses.isEmpty()) {
return Utils.clone(this.info);
}
return updateSystemInfo(true);
}
代码示例来源:origin: vmware/xenon
public ServiceHostState getState() {
ServiceHostState s = Utils.clone(this.state);
s.systemInfo = getSystemInfo();
return s;
}
代码示例来源:origin: vmware/xenon
public Operation setBody(Object body) {
if (body != null) {
if (hasOption(OperationOption.CLONING_DISABLED)) {
this.body = body;
} else {
this.body = Utils.clone(body);
}
} else {
this.body = null;
}
return this;
}
代码示例来源:origin: vmware/xenon
private ReliableSubscriptionService(Operation subscribeOp, ServiceSubscriber sr,
Consumer<Operation> notificationConsumer) {
// cache the subscribe operation since we will clone and re-use if we need to
// re-subscribe. It contains the appropriate authorization context
this.subscribeOp = subscribeOp.clone();
// cache the request details
this.subscribeRequest = Utils.clone(sr);
this.consumer = notificationConsumer;
}
代码示例来源:origin: vmware/xenon
/**
* See {@link #setRequestRateLimit(String, double)}
*/
public ServiceHost setRequestRateLimit(String key, RequestRateInfo ri) {
if (ri.limit <= 0.0) {
throw new IllegalArgumentException("limit must be a non zero positive number");
}
ri = Utils.clone(ri);
if (ri.timeSeries == null) {
ri.timeSeries = new TimeSeriesStats(
60,
TimeUnit.SECONDS.toMillis(1),
EnumSet.of(AggregationType.SUM));
} else if (!ri.timeSeries.aggregationType.contains(AggregationType.SUM)) {
throw new IllegalArgumentException(
"time series must be of type " + AggregationType.SUM);
}
if (ri.options == null || ri.options.isEmpty()) {
ri.options = EnumSet.of(Option.FAIL);
}
// overwrite any existing limit
this.state.requestRateLimits.put(key, ri);
return this;
}
代码示例来源:origin: vmware/admiral
private Operation createCloneOperation(String resourceType, ServiceDocument component,
String projectLink) {
if (component instanceof ResourceState) {
String factoryLink = CompositeComponentRegistry
.descriptionFactoryLinkByDescriptionLink(component.documentSelfLink);
if (factoryLink == null) {
throw new LocalizableValidationException(
"Cannot clone unsupported type " + resourceType,
"compute.clone.unsupported.type", resourceType);
}
ResourceState cloned = Utils.clone((ResourceState) component);
if (cloned.customProperties == null) {
cloned.customProperties = new HashMap<>();
}
cloned.customProperties.put(CloneableResource.PARENT_RESOURCE_LINK_PROPERTY_NAME,
cloned.documentSelfLink);
cloned.documentSelfLink = null;
Operation post = Operation.createPost(this, factoryLink)
.setBody(cloned);
if (projectLink != null && projectLink.isEmpty()) {
post.addRequestHeader(OperationUtil.PROJECT_ADMIRAL_HEADER, projectLink);
}
return post;
}
throw new LocalizableValidationException("Cannot clone unsupported type " + resourceType,
"compute.clone.unsupported.type", resourceType);
}
代码示例来源:origin: vmware/xenon
body = Utils.clone(body);
body.associatedOp = op;
代码示例来源:origin: vmware/xenon
/**
* Invoke the service setInitialState method and ensures the state has proper self link and
* kind. If the service is not marked with {@link ServiceOption#IMMUTABLE}, the state
* is serialized to JSON to verify serialization is possible, and cloned
*/
void normalizeInitialServiceState(Service s, Operation post, Long finalVersion) {
if (!post.hasBody()) {
return;
}
// We force serialize to JSON to clone
// and prove the state *is* convertible to JSON. It also forces type
// to the service state type through type coercion
Object body = post.getBodyRaw();
if (!body.getClass().equals(s.getStateType())) {
body = Utils.toJson(body);
}
ServiceDocument initialState = s.setInitialState(
body,
finalVersion);
initialState.documentSelfLink = s.getSelfLink();
initialState.documentKind = Utils.buildKind(initialState.getClass());
initialState.documentAuthPrincipalLink = (post.getAuthorizationContext() != null) ? post
.getAuthorizationContext().getClaims().getSubject() : null;
if (!isServiceImmutable(s)) {
initialState = Utils.clone(initialState);
}
post.setBodyNoCloning(initialState);
}
代码示例来源:origin: vmware/xenon
@Override
public void handleStart(Operation startPost) {
NodeGroupState initState = null;
if (startPost.hasBody()) {
initState = startPost.getBody(NodeGroupState.class);
} else {
initState = new NodeGroupState();
}
initState.documentOwner = getHost().getId();
if (initState.config == null) {
initState.config = new NodeGroupConfig();
}
NodeState self = initState.nodes.get(getHost().getId());
self = buildLocalNodeState(self);
if (!validateNodeOptions(startPost, self.options)) {
return;
}
initState.nodes.put(self.id, self);
this.cachedState = Utils.clone(initState);
startPost.setBody(this.cachedState).complete();
}
代码示例来源:origin: com.vmware.xenon/xenon-common
@Test
public void testSerializeClassesWithoutDefaultConstructor() {
Range range = new Range(0, 100);
// clone uses kryo serialization
Range clone = Utils.clone(range);
assertEquals(range.from, clone.from);
assertEquals(range.to, clone.to);
}
代码示例来源:origin: vmware/xenon
@Test
public void testSerializeClassesWithoutDefaultConstructor() {
Range range = new Range(0, 100);
// clone uses kryo serialization
Range clone = Utils.clone(range);
assertEquals(range.from, clone.from);
assertEquals(range.to, clone.to);
}
代码示例来源:origin: com.vmware.xenon/xenon-common
private void doExampleServicePatch(Map<String, ExampleServiceState> states,
URI hostUri) throws Throwable {
this.host.log("Starting PATCH to %d example services", states.size());
TestContext ctx = this.host
.testCreate(this.updateCount * states.size());
this.setOperationTimeoutMicros(TimeUnit.SECONDS.toMicros(this.host.getTimeoutSeconds()));
for (int i = 0; i < this.updateCount; i++) {
for (Entry<String, ExampleServiceState> e : states.entrySet()) {
ExampleServiceState st = Utils.clone(e.getValue());
st.counter = (long) i;
Operation patch = Operation
.createPatch(UriUtils.buildUri(hostUri, e.getKey()))
.setCompletion(ctx.getCompletion())
.setBody(st);
this.host.send(patch);
}
}
this.host.testWait(ctx);
this.host.log("Done with PATCH to %d example services", states.size());
}
代码示例来源:origin: vmware/xenon
private void doExampleServicePatch(Map<String, ExampleServiceState> states,
URI hostUri) throws Throwable {
this.host.log("Starting PATCH to %d example services", states.size());
TestContext ctx = this.host
.testCreate(this.updateCount * states.size());
this.setOperationTimeoutMicros(TimeUnit.SECONDS.toMicros(this.host.getTimeoutSeconds()));
for (int i = 0; i < this.updateCount; i++) {
for (Entry<String, ExampleServiceState> e : states.entrySet()) {
ExampleServiceState st = Utils.clone(e.getValue());
st.counter = (long) i;
Operation patch = Operation
.createPatch(UriUtils.buildUri(hostUri, e.getKey()))
.setCompletion(ctx.getCompletion())
.setBody(st);
this.host.send(patch);
}
}
this.host.testWait(ctx);
this.host.log("Done with PATCH to %d example services", states.size());
}
代码示例来源:origin: vmware/admiral
private void queryComputesToUnassign(EpzComputeEnumerationTaskState state) {
Query mustBeOut = Utils.clone(state.resourcePoolQuery)
.setOccurance(Occurance.MUST_NOT_OCCUR);
Query areIn = Query.Builder.create()
.addKindFieldClause(ComputeState.class)
.addCompositeFieldClause(ResourceState.FIELD_NAME_CUSTOM_PROPERTIES,
EPZ_CUSTOM_PROP_NAME_PREFIX + extractRpId(state), EPZ_CUSTOM_PROP_VALUE)
.build();
Query combinedQuery = Query.Builder.create().addClauses(mustBeOut, areIn).build();
queryComputes(state, combinedQuery,
EpzComputeEnumerationTaskState.SubStage.UNASSIGN_COMPUTES,
EpzComputeEnumerationTaskState.SubStage.QUERY_COMPUTES_TO_ASSIGN);
}
代码示例来源:origin: vmware/admiral
private void queryComputesToAssign(EpzComputeEnumerationTaskState state) {
Query mustBeIn = Utils.clone(state.resourcePoolQuery);
Query areOut = Query.Builder.create()
.addKindFieldClause(ComputeState.class)
.addFieldClause(
QuerySpecification.buildCompositeFieldName(
ResourceState.FIELD_NAME_CUSTOM_PROPERTIES,
EPZ_CUSTOM_PROP_NAME_PREFIX + extractRpId(state)),
EPZ_CUSTOM_PROP_VALUE,
MatchType.TERM,
Occurance.MUST_NOT_OCCUR)
.build();
Query combinedQuery = Query.Builder.create().addClauses(mustBeIn, areOut).build();
queryComputes(state, combinedQuery, EpzComputeEnumerationTaskState.SubStage.ASSIGN_COMPUTES,
EpzComputeEnumerationTaskState.SubStage.COMPLETED);
}
代码示例来源:origin: vmware/xenon
private void subscribeToService(URI uri, ServiceSubscriber sr) {
if (sr.usePublicUri) {
sr = Utils.clone(sr);
sr.reference = UriUtils.buildPublicUri(this.host, sr.reference.getPath());
}
URI subUri = UriUtils.buildSubscriptionUri(uri);
this.host.send(Operation.createPost(subUri)
.setCompletion(this.host.getCompletion())
.setReferer(this.host.getReferer())
.setBody(sr)
.addPragmaDirective(Operation.PRAGMA_DIRECTIVE_QUEUE_FOR_SERVICE_AVAILABILITY));
}
代码示例来源:origin: com.vmware.xenon/xenon-common
private void subscribeToService(URI uri, ServiceSubscriber sr) {
if (sr.usePublicUri) {
sr = Utils.clone(sr);
sr.reference = UriUtils.buildPublicUri(this.host, sr.reference.getPath());
}
URI subUri = UriUtils.buildSubscriptionUri(uri);
this.host.send(Operation.createPost(subUri)
.setCompletion(this.host.getCompletion())
.setReferer(this.host.getReferer())
.setBody(sr)
.addPragmaDirective(Operation.PRAGMA_DIRECTIVE_QUEUE_FOR_SERVICE_AVAILABILITY));
}
代码示例来源:origin: vmware/admiral
@Test
public void ensureSerializationAndCloning() throws Throwable {
TestTaskServiceDocument task = new TestTaskServiceDocument();
task.taskSubStage = DefaultSubStage.PROCESSING;
task.taskInfo = new TaskState();
task.taskInfo.stage = TaskStage.CREATED;
task = Utils.clone(task);
assertEquals(DefaultSubStage.PROCESSING, task.taskSubStage);
assertEquals(TaskStage.CREATED, task.taskInfo.stage);
String jsonTask = Utils.toJson(task);
task = Utils.fromJson(jsonTask, TestTaskServiceDocument.class);
assertEquals(DefaultSubStage.PROCESSING, task.taskSubStage);
assertEquals(TaskStage.CREATED, task.taskInfo.stage);
}
内容来源于网络,如有侵权,请联系作者删除!