Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// Copyright 2015-2019 SWIM.AI inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package swim.runtime.downlink;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import swim.structure.Form;
import swim.structure.Value;
import swim.uri.Uri;
import swim.warp.EventMessage;
public class ValueDownlinkModel extends DemandDownlinkModem> {
protected int flags;
protected volatile Value state;
public ValueDownlinkModel(Uri meshUri, Uri hostUri, Uri nodeUri, Uri laneUri,
float prio, float rate, Value body) {
super(meshUri, hostUri, nodeUri, laneUri, prio, rate, body);
this.flags = 0;
}
public final boolean isStateful() {
return (this.flags & STATEFUL) != 0;
}
public ValueDownlinkModel isStateful(boolean isStateful) {
if (isStateful) {
this.flags |= STATEFUL;
} else {
this.flags &= ~STATEFUL;
}
final Object views = this.views;
if (views instanceof DownlinkView) {
((ValueDownlinkView>) views).didSetStateful(isStateful);
} else if (views instanceof DownlinkView[]) {
final DownlinkView[] viewArray = (DownlinkView[]) views;
for (int i = 0, n = viewArray.length; i < n; i += 1) {
((ValueDownlinkView>) viewArray[i]).didSetStateful(isStateful);
}
}
return this;
}
@Override
protected void pushDownEvent(EventMessage message) {
new ValueDownlinkRelaySet(this, message, message.body()).run();
}
@Override
protected Value nextUpCue() {
return this.state;
}
@Override
protected void didAddDownlink(ValueDownlinkView> view) {
if (this.views instanceof DownlinkView) {
isStateful(((ValueDownlinkView>) view).isStateful());
}
}
public Value get() {
return this.state;
}
@SuppressWarnings("unchecked")
public V set(ValueDownlinkView view, V newObject) {
final Form valueForm = view.valueForm;
final Value newValue = valueForm.mold(newObject).toValue();
final ValueDownlinkRelaySet relay = new ValueDownlinkRelaySet(this, newValue);
relay.valueForm = (Form