jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.workflow.api; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 20 | /** |
| 21 | * WorkflowContext for system workflow. |
| 22 | */ |
| 23 | public class SystemWorkflowContext extends DefaultWorkflowContext { |
| 24 | |
| 25 | /** |
| 26 | * Timestamp when this system workflow context was created. |
| 27 | */ |
| 28 | private final long timestamp; |
| 29 | |
| 30 | /** |
| 31 | * Distributor string for designating which onos node executes this workflow context with work partition. |
| 32 | */ |
| 33 | private String distributor; |
| 34 | |
| 35 | /** |
| 36 | * The constructor of SystemWorkflowContext. |
jaegonkim | e0f45b5 | 2018-10-09 20:23:26 +0900 | [diff] [blame] | 37 | * @param builder builder of SystemWorkflowContext |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 38 | */ |
jaegonkim | e0f45b5 | 2018-10-09 20:23:26 +0900 | [diff] [blame] | 39 | public SystemWorkflowContext(Builder builder) { |
| 40 | super(builder); |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 41 | timestamp = System.currentTimeMillis(); |
| 42 | //initial distributor(It can be changed) |
| 43 | distributor = name(); |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public String distributor() { |
| 48 | return distributor; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Sets distributor string of this workflow context. |
| 53 | * @param distributor distributor string |
| 54 | */ |
| 55 | public void setDistributor(String distributor) { |
| 56 | this.distributor = distributor; |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public String name() { |
| 61 | return workflowId().toString() |
| 62 | + ":" + timestamp |
| 63 | + "@" + workplaceName(); |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public String toString() { |
| 68 | return MoreObjects.toStringHelper(getClass()) |
| 69 | .add("name", name()) |
| 70 | .add("triggernext", triggerNext()) |
| 71 | .add("data", data()) |
| 72 | .add("current", current()) |
| 73 | .add("state", state()) |
| 74 | .add("cause", cause()) |
| 75 | .toString(); |
| 76 | } |
jaegonkim | e0f45b5 | 2018-10-09 20:23:26 +0900 | [diff] [blame] | 77 | |
| 78 | /** |
| 79 | * Gets systemBuilder instance. |
| 80 | * @return systemBuilder instance |
| 81 | */ |
| 82 | public static final Builder systemBuilder() { |
| 83 | return new Builder(); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Builder for system workflow context. |
| 88 | */ |
| 89 | public static class Builder extends DefaultWorkflowContext.Builder { |
| 90 | |
| 91 | /** |
| 92 | * Builds system workflow context. |
| 93 | * @return instance of default workflow context. |
| 94 | */ |
| 95 | public SystemWorkflowContext build() { |
| 96 | return new SystemWorkflowContext(this); |
| 97 | } |
| 98 | } |
| 99 | |
jaegonkim | 6a7b524 | 2018-09-12 23:09:42 +0900 | [diff] [blame] | 100 | } |