blob: 550bfbeb972551e0c5f06289661617bd3cd5dbbf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/*******************************************************************************
* Copyright (c) 2010-2019, Tamas Szabo, Istvan Rath and Daniel Varro
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-v20.html.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package tools.refinery.viatra.runtime.rete.network.communication.timely;
import tools.refinery.viatra.runtime.matchers.tuple.Tuple;
import tools.refinery.viatra.runtime.matchers.util.Direction;
import tools.refinery.viatra.runtime.matchers.util.Preconditions;
import tools.refinery.viatra.runtime.rete.network.Receiver;
import tools.refinery.viatra.runtime.rete.network.communication.CommunicationGroup;
import tools.refinery.viatra.runtime.rete.network.communication.MessageSelector;
import tools.refinery.viatra.runtime.rete.network.communication.Timestamp;
import tools.refinery.viatra.runtime.rete.network.mailbox.Mailbox;
/**
* A timely proxy for another {@link Mailbox}, which performs some preprocessing
* on the differential timestamps before passing it on to the real recipient.
*
* @author Tamas Szabo
* @since 2.3
*/
public class TimelyMailboxProxy implements Mailbox {
protected final TimestampTransformation preprocessor;
protected final Mailbox wrapped;
public TimelyMailboxProxy(final Mailbox wrapped, final TimestampTransformation preprocessor) {
Preconditions.checkArgument(!(wrapped instanceof TimelyMailboxProxy), "Proxy in a proxy is not allowed!");
this.wrapped = wrapped;
this.preprocessor = preprocessor;
}
public Mailbox getWrappedMailbox() {
return wrapped;
}
@Override
public void postMessage(final Direction direction, final Tuple update, final Timestamp timestamp) {
this.wrapped.postMessage(direction, update, preprocessor.process(timestamp));
}
@Override
public String toString() {
return this.preprocessor.toString() + "_PROXY -> " + this.wrapped.toString();
}
@Override
public void clear() {
this.wrapped.clear();
}
@Override
public void deliverAll(final MessageSelector selector) {
this.wrapped.deliverAll(selector);
}
@Override
public CommunicationGroup getCurrentGroup() {
return this.wrapped.getCurrentGroup();
}
@Override
public void setCurrentGroup(final CommunicationGroup group) {
this.wrapped.setCurrentGroup(group);
}
@Override
public Receiver getReceiver() {
return this.wrapped.getReceiver();
}
@Override
public boolean isEmpty() {
return this.wrapped.isEmpty();
}
@Override
public boolean equals(final Object obj) {
if (obj == null || obj.getClass() != this.getClass()) {
return false;
} else if (obj == this) {
return true;
} else {
final TimelyMailboxProxy that = (TimelyMailboxProxy) obj;
return this.wrapped.equals(that.wrapped) && this.preprocessor == that.preprocessor;
}
}
@Override
public int hashCode() {
int hash = 1;
hash = hash * 17 + this.wrapped.hashCode();
hash = hash * 31 + this.preprocessor.hashCode();
return hash;
}
}
|