diff options
Diffstat (limited to 'subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/remote/Address.java')
-rw-r--r-- | subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/remote/Address.java | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/remote/Address.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/remote/Address.java new file mode 100644 index 00000000..2fed3225 --- /dev/null +++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/remote/Address.java | |||
@@ -0,0 +1,125 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2004-2008 Gabor Bergmann and Daniel Varro | ||
3 | * This program and the accompanying materials are made available under the | ||
4 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
5 | * http://www.eclipse.org/legal/epl-v20.html. | ||
6 | * | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | |||
10 | package tools.refinery.viatra.runtime.rete.remote; | ||
11 | |||
12 | import tools.refinery.viatra.runtime.rete.network.Node; | ||
13 | import tools.refinery.viatra.runtime.rete.network.ReteContainer; | ||
14 | |||
15 | /** | ||
16 | * Remote identifier of a node of type T. | ||
17 | * | ||
18 | * @author Gabor Bergmann | ||
19 | * | ||
20 | */ | ||
21 | public class Address<T extends Node> { | ||
22 | ReteContainer container; | ||
23 | Long nodeId; | ||
24 | /** | ||
25 | * Feel free to leave null e.g. if node is in a separate JVM. | ||
26 | */ | ||
27 | T nodeCache; | ||
28 | |||
29 | /** | ||
30 | * Address of local node (use only for containers in the same VM!) | ||
31 | */ | ||
32 | public static <N extends Node> Address<N> of(N node) { | ||
33 | return new Address<N>(node); | ||
34 | } | ||
35 | |||
36 | /** | ||
37 | * General constructor. | ||
38 | * | ||
39 | * @param container | ||
40 | * @param nodeId | ||
41 | */ | ||
42 | public Address(ReteContainer container, Long nodeId) { | ||
43 | super(); | ||
44 | this.container = container; | ||
45 | this.nodeId = nodeId; | ||
46 | } | ||
47 | |||
48 | /** | ||
49 | * Local-only constructor. (use only for containers in the same VM!) | ||
50 | * | ||
51 | * @param node | ||
52 | * the node to address | ||
53 | */ | ||
54 | public Address(T node) { | ||
55 | super(); | ||
56 | this.nodeCache = node; | ||
57 | this.container = node.getContainer(); | ||
58 | this.nodeId = node.getNodeId(); | ||
59 | } | ||
60 | |||
61 | @Override | ||
62 | public int hashCode() { | ||
63 | final int prime = 31; | ||
64 | int result = 1; | ||
65 | result = prime * result + ((container == null) ? 0 : container.hashCode()); | ||
66 | result = prime * result + ((nodeId == null) ? 0 : nodeId.hashCode()); | ||
67 | return result; | ||
68 | } | ||
69 | |||
70 | @Override | ||
71 | public boolean equals(Object obj) { | ||
72 | if (this == obj) | ||
73 | return true; | ||
74 | if (obj == null) | ||
75 | return false; | ||
76 | if (!(obj instanceof Address<?>)) | ||
77 | return false; | ||
78 | final Address<?> other = (Address<?>) obj; | ||
79 | if (container == null) { | ||
80 | if (other.container != null) | ||
81 | return false; | ||
82 | } else if (!container.equals(other.container)) | ||
83 | return false; | ||
84 | if (nodeId == null) { | ||
85 | if (other.nodeId != null) | ||
86 | return false; | ||
87 | } else if (!nodeId.equals(other.nodeId)) | ||
88 | return false; | ||
89 | return true; | ||
90 | } | ||
91 | |||
92 | public ReteContainer getContainer() { | ||
93 | return container; | ||
94 | } | ||
95 | |||
96 | public void setContainer(ReteContainer container) { | ||
97 | this.container = container; | ||
98 | } | ||
99 | |||
100 | public Long getNodeId() { | ||
101 | return nodeId; | ||
102 | } | ||
103 | |||
104 | public void setNodeId(Long nodeId) { | ||
105 | this.nodeId = nodeId; | ||
106 | } | ||
107 | |||
108 | public T getNodeCache() { | ||
109 | return nodeCache; | ||
110 | } | ||
111 | |||
112 | public void setNodeCache(T nodeCache) { | ||
113 | this.nodeCache = nodeCache; | ||
114 | } | ||
115 | |||
116 | @Override | ||
117 | public String toString() { | ||
118 | if (nodeCache == null) | ||
119 | return "A(" + nodeId + " @ " + container + ")"; | ||
120 | else | ||
121 | return "A(" + nodeCache + ")"; | ||
122 | |||
123 | } | ||
124 | |||
125 | } | ||