All Downloads are FREE. Search and download functionalities are using the official Maven repository.

swim.runtime.lane.SupplyLaneView Maven / Gradle / Ivy

// 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 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.SupplyLane;
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.structure.Form;

public class SupplyLaneView extends LaneView implements SupplyLane {
  protected final AgentContext agentContext;
  protected Form valueForm;

  protected SupplyLaneModel laneBinding;

  public SupplyLaneView(AgentContext agentContext, Form valueForm, Object observers) {
    super(observers);
    this.agentContext = agentContext;
    this.valueForm = valueForm;
  }

  public SupplyLaneView(AgentContext agentContext, Form valueForm) {
    this(agentContext, valueForm, null);
  }

  @Override
  public AgentContext agentContext() {
    return this.agentContext;
  }

  @Override
  public SupplyLaneModel getLaneBinding() {
    return this.laneBinding;
  }

  void setLaneBinding(SupplyLaneModel laneBinding) {
    this.laneBinding = laneBinding;
  }

  @Override
  public SupplyLaneModel createLaneBinding() {
    return new SupplyLaneModel();
  }

  @Override
  public final Form valueForm() {
    return this.valueForm;
  }

  @Override
  public  SupplyLaneView valueForm(Form valueForm) {
    return new SupplyLaneView(this.agentContext, valueForm, this.observers);
  }

  @Override
  public  SupplyLaneView valueClass(Class valueClass) {
    return valueForm(Form.forClass(valueClass));
  }

  public void setValueForm(Form valueForm) {
    this.valueForm = valueForm;
  }

  @Override
  public final boolean isSigned() {
    return false; // TODO
  }

  @Override
  public SupplyLaneView isSigned(boolean isSigned) {
    return this; // TODO
  }

  @Override
  public void close() {
    this.laneBinding.closeLaneView(this);
  }

  @SuppressWarnings("unchecked")
  @Override
  public SupplyLaneView observe(Object observer) {
    return (SupplyLaneView) super.observe(observer);
  }

  @SuppressWarnings("unchecked")
  @Override
  public SupplyLaneView unobserve(Object observer) {
    return (SupplyLaneView) super.unobserve(observer);
  }

  @Override
  public SupplyLaneView willCommand(WillCommand willCommand) {
    return observe(willCommand);
  }

  @Override
  public SupplyLaneView didCommand(DidCommand didCommand) {
    return observe(didCommand);
  }

  @Override
  public SupplyLaneView willUplink(WillUplink willUplink) {
    return observe(willUplink);
  }

  @Override
  public SupplyLaneView didUplink(DidUplink didUplink) {
    return observe(didUplink);
  }

  @Override
  public SupplyLaneView willEnter(WillEnter willEnter) {
    return observe(willEnter);
  }

  @Override
  public SupplyLaneView didEnter(DidEnter didEnter) {
    return observe(didEnter);
  }

  @Override
  public SupplyLaneView willLeave(WillLeave willLeave) {
    return observe(willLeave);
  }

  @Override
  public SupplyLaneView didLeave(DidLeave didLeave) {
    return observe(didLeave);
  }

  @Override
  public SupplyLaneView decodeRequest(DecodeRequestHttp decodeRequest) {
    return observe(decodeRequest);
  }

  @Override
  public SupplyLaneView willRequest(WillRequestHttp willRequest) {
    return observe(willRequest);
  }

  @Override
  public SupplyLaneView didRequest(DidRequestHttp didRequest) {
    return observe(didRequest);
  }

  @Override
  public SupplyLaneView doRespond(DoRespondHttp doRespond) {
    return observe(doRespond);
  }

  @Override
  public SupplyLaneView willRespond(WillRespondHttp willRespond) {
    return observe(willRespond);
  }

  @Override
  public SupplyLaneView didRespond(DidRespondHttp didRespond) {
    return observe(didRespond);
  }

  @Override
  public void push(V value) {
    this.laneBinding.sendDown(this.valueForm.mold(value).toValue());
  }
}