|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | +package com.microsoft.durabletask; |
| 4 | + |
| 5 | +import java.util.Objects; |
| 6 | +import javax.annotation.Nonnull; |
| 7 | + |
| 8 | +/** |
| 9 | + * Represents the parent orchestration of a sub-orchestration. |
| 10 | + * This is available via {@link TaskOrchestrationContext#getParentInstance()} when the |
| 11 | + * current orchestration was started as a sub-orchestration. |
| 12 | + */ |
| 13 | +public final class ParentOrchestrationInstance { |
| 14 | + private final String name; |
| 15 | + private final String instanceId; |
| 16 | + |
| 17 | + /** |
| 18 | + * Creates a new ParentOrchestrationInstance. |
| 19 | + * |
| 20 | + * @param name the name of the parent orchestration |
| 21 | + * @param instanceId the instance ID of the parent orchestration |
| 22 | + */ |
| 23 | + public ParentOrchestrationInstance(@Nonnull String name, @Nonnull String instanceId) { |
| 24 | + this.name = Objects.requireNonNull(name, "name"); |
| 25 | + this.instanceId = Objects.requireNonNull(instanceId, "instanceId"); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Gets the name of the parent orchestration. |
| 30 | + * |
| 31 | + * @return the parent orchestration name |
| 32 | + */ |
| 33 | + @Nonnull |
| 34 | + public String getName() { |
| 35 | + return this.name; |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Gets the instance ID of the parent orchestration. |
| 40 | + * |
| 41 | + * @return the parent orchestration instance ID |
| 42 | + */ |
| 43 | + @Nonnull |
| 44 | + public String getInstanceId() { |
| 45 | + return this.instanceId; |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public String toString() { |
| 50 | + return String.format("ParentOrchestrationInstance{name='%s', instanceId='%s'}", name, instanceId); |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public boolean equals(Object o) { |
| 55 | + if (this == o) return true; |
| 56 | + if (!(o instanceof ParentOrchestrationInstance)) return false; |
| 57 | + ParentOrchestrationInstance that = (ParentOrchestrationInstance) o; |
| 58 | + return Objects.equals(name, that.name) && Objects.equals(instanceId, that.instanceId); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public int hashCode() { |
| 63 | + return Objects.hash(name, instanceId); |
| 64 | + } |
| 65 | +} |
0 commit comments