swim.runtime.lane.ValueLaneView Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swim-runtime Show documentation
Show all versions of swim-runtime Show documentation
Uploads all artifacts belonging to configuration ':swim-runtime:archives'
// 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.lane;
import java.util.AbstractMap;
import java.util.Iterator;
import java.util.Map;
import swim.api.Link;
import swim.api.SwimContext;
import swim.api.agent.AgentContext;
import swim.api.http.function.DecodeRequestHttp;
import swim.api.http.function.DidRequestHttp;
import swim.api.http.function.DidRespondHttp;
import swim.api.http.function.DoRespondHttp;
import swim.api.http.function.WillRequestHttp;
import swim.api.http.function.WillRespondHttp;
import swim.api.lane.Lane;
import swim.api.lane.ValueLane;
import swim.api.lane.function.DidCommand;
import swim.api.lane.function.DidEnter;
import swim.api.lane.function.DidLeave;
import swim.api.lane.function.DidUplink;
import swim.api.lane.function.WillCommand;
import swim.api.lane.function.WillEnter;
import swim.api.lane.function.WillLeave;
import swim.api.lane.function.WillUplink;
import swim.concurrent.Conts;
import swim.observable.function.DidSet;
import swim.observable.function.WillSet;
import swim.streamlet.Inlet;
import swim.streamlet.Outlet;
import swim.structure.Form;
import swim.util.Cursor;
public class ValueLaneView extends LaneView implements ValueLane {
protected final AgentContext agentContext;
protected Form valueForm;
protected int flags;
protected ValueLaneModel laneBinding;
protected Outlet extends V> input;
protected Inlet super V>[] outputs; // TODO: unify with observers
protected int version;
ValueLaneView(AgentContext agentContext, Form valueForm, int flags, Object observers) {
super(observers);
this.agentContext = agentContext;
this.valueForm = valueForm;
this.flags = flags;
this.input = null;
this.outputs = null;
this.version = -1;
}
public ValueLaneView(AgentContext agentContext, Form valueForm) {
this(agentContext, valueForm, RESIDENT, null);
}
@Override
public AgentContext agentContext() {
return this.agentContext;
}
@Override
public ValueLaneModel getLaneBinding() {
return this.laneBinding;
}
void setLaneBinding(ValueLaneModel laneBinding) {
this.laneBinding = laneBinding;
}
@Override
public ValueLaneModel createLaneBinding() {
return new ValueLaneModel(this.flags);
}
@Override
public final Form valueForm() {
return this.valueForm;
}
@Override
public ValueLaneView valueForm(Form valueForm) {
return new ValueLaneView(this.agentContext, valueForm, this.flags,
typesafeObservers(this.observers));
}
@Override
public ValueLaneView valueClass(Class valueClass) {
return valueForm(Form.forClass(valueClass));
}
public void setValueForm(Form valueForm) {
this.valueForm = valueForm;
}
protected Object typesafeObservers(Object observers) {
// TODO: filter out WillSet, DidSet
return observers;
}
@Override
public final boolean isResident() {
return (this.flags & RESIDENT) != 0;
}
@Override
public ValueLaneView isResident(boolean isResident) {
didSetResident(isResident);
// note: marked final given access of concurrently accessed volatile objects
final ValueLaneModel laneBinding = this.laneBinding;
if (laneBinding != null) {
laneBinding.isResident(isResident);
}
return this;
}
void didSetResident(boolean isResident) {
if (isResident) {
this.flags |= RESIDENT;
} else {
this.flags &= ~RESIDENT;
}
}
@Override
public final boolean isTransient() {
return (this.flags & TRANSIENT) != 0;
}
@Override
public ValueLaneView isTransient(boolean isTransient) {
didSetTransient(isTransient);
// note: marked final given access of concurrently accessed volatile objects
final ValueLaneModel laneBinding = this.laneBinding;
if (laneBinding != null) {
laneBinding.isTransient(isTransient);
}
return this;
}
void didSetTransient(boolean isTransient) {
if (isTransient) {
this.flags |= TRANSIENT;
} else {
this.flags &= ~TRANSIENT;
}
}
@Override
public final boolean isSigned() {
return (this.flags & SIGNED) != 0;
}
@Override
public ValueLaneView isSigned(boolean isSigned) {
didSetSigned(isSigned);
// note: marked final given access of concurrently accessed volatile objects
final ValueLaneModel laneBinding = this.laneBinding;
if (laneBinding != null) {
laneBinding.isSigned(isSigned);
}
return this;
}
void didSetSigned(boolean isSigned) {
if (isSigned) {
this.flags |= SIGNED;
} else {
this.flags &= ~SIGNED;
}
}
@Override
public void close() {
this.laneBinding.closeLaneView(this);
}
@SuppressWarnings("unchecked")
@Override
public ValueLaneView observe(Object observer) {
return (ValueLaneView) super.observe(observer);
}
@SuppressWarnings("unchecked")
@Override
public ValueLaneView unobserve(Object observer) {
return (ValueLaneView) super.unobserve(observer);
}
@Override
public ValueLaneView willSet(WillSet willSet) {
return observe(willSet);
}
@Override
public ValueLaneView didSet(DidSet didSet) {
return observe(didSet);
}
@Override
public ValueLaneView willCommand(WillCommand willCommand) {
return observe(willCommand);
}
@Override
public ValueLaneView didCommand(DidCommand didCommand) {
return observe(didCommand);
}
@Override
public ValueLaneView willUplink(WillUplink willUplink) {
return observe(willUplink);
}
@Override
public ValueLaneView didUplink(DidUplink didUplink) {
return observe(didUplink);
}
@Override
public ValueLaneView willEnter(WillEnter willEnter) {
return observe(willEnter);
}
@Override
public ValueLaneView didEnter(DidEnter didEnter) {
return observe(didEnter);
}
@Override
public ValueLaneView willLeave(WillLeave willLeave) {
return observe(willLeave);
}
@Override
public ValueLaneView didLeave(DidLeave didLeave) {
return observe(didLeave);
}
@Override
public ValueLaneView decodeRequest(DecodeRequestHttp
© 2015 - 2025 Weber Informatics LLC | Privacy Policy