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-2024 Nstream, 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.system.downlink;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import swim.concurrent.Cont;
import swim.concurrent.Stage;
import swim.structure.Form;
import swim.structure.Value;
import swim.system.DownlinkModel;
import swim.system.DownlinkRelay;
import swim.system.DownlinkView;
import swim.system.Push;
import swim.system.warp.DemandDownlinkModem;
import swim.uri.Uri;
import swim.warp.CommandMessage;
import swim.warp.EventMessage;
public class ValueDownlinkModel extends DemandDownlinkModem> {
protected volatile Value state;
protected int flags;
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.state = Value.absent();
this.flags = 0;
}
public final boolean isStateful() {
return (this.flags & ValueDownlinkModel.STATEFUL) != 0;
}
public ValueDownlinkModel isStateful(boolean isStateful) {
if (isStateful) {
this.flags |= ValueDownlinkModel.STATEFUL;
} else {
this.flags &= ~ValueDownlinkModel.STATEFUL;
}
final Object views = DownlinkModel.VIEWS.get(this);
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(Push push) {
final EventMessage message = push.message();
final Value value = message.body();
new ValueDownlinkRelaySet(this, message, push.cont(), value).run();
}
@Override
protected Push nextUpCue() {
final Uri hostUri = hostUri();
final Uri nodeUri = nodeUri();
final Uri laneUri = laneUri();
final float prio = prio();
final Value body = ValueDownlinkModel.STATE.get(this);
final CommandMessage message = new CommandMessage(nodeUri, laneUri, body);
return new Push(Uri.empty(), hostUri, nodeUri, laneUri,
prio, null, message, null);
}
@Override
protected void didAddDownlink(ValueDownlinkView> view) {
super.didAddDownlink(view);
if (DownlinkModel.VIEWS.get(this) instanceof DownlinkView) {
this.isStateful(((ValueDownlinkView>) view).isStateful());
}
}
public Value get() {
return ValueDownlinkModel.STATE.get(this);
}
@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, view.stage(), newValue);
relay.valueForm = (Form