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

nstream.reflect.MetaWarpUplink Maven / Gradle / Ivy

There is a newer version: 4.13.21
Show newest version
// Copyright 2015-2024 Nstream, inc.
//
// Licensed under the Redis Source Available License 2.0 (RSALv2) Agreement;
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://redis.com/legal/rsalv2-agreement/
//
// 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 nstream.reflect;

import nstream.reflect.agent.MetaWarpUplinkAgent;
import nstream.reflect.model.LinkStats;
import nstream.reflect.model.LogEntry;
import swim.system.NodeBinding;
import swim.system.Push;
import swim.system.WarpBinding;
import swim.system.WarpProxy;
import swim.uri.UriPath;
import swim.warp.Envelope;

public class MetaWarpUplink extends WarpProxy implements MetaLink {
  final MetaLane parent;
  final MetaWarpUplinkAgent agent;

  public MetaWarpUplink(MetaLane parent, WarpBinding linkBinding) {
    super(linkBinding);
    this.parent = parent;
    this.agent = new MetaWarpUplinkAgent(this);
  }

  @Override
  public MetaLane metaParent() {
    return this.parent;
  }

  @Override
  public MetaWarpUplinkAgent metaAgent() {
    return this.agent;
  }

  @Override
  public LinkStats linkStats() {
    return this.agent.linkStats();
  }

  @Override
  public void pushDown(Push push) {
    super.pushDown(push);
    final Object message = push.message();
    if (message instanceof Envelope) {
      this.agent.didPushDown((Envelope) message);
    }
  }

  @Override
  public void pushUp(Push push) {
    super.pushUp(push);
    final Object message = push.message();
    if (message instanceof Envelope) {
      this.agent.didPushUp((Envelope) message);
    }
  }

  @Override
  public void traceDown(Object message) {
    this.agent.didLogTrace(LogEntry.trace(nodeUri(), laneUri(), message));
  }

  @Override
  public void debugDown(Object message) {
    this.agent.didLogDebug(LogEntry.debug(nodeUri(), laneUri(), message));
  }

  @Override
  public void infoDown(Object message) {
    this.agent.didLogInfo(LogEntry.info(nodeUri(), laneUri(), message));
  }

  @Override
  public void warnDown(Object message) {
    this.agent.didLogWarn(LogEntry.warn(nodeUri(), laneUri(), message));
  }

  @Override
  public void errorDown(Object message) {
    this.agent.didLogError(LogEntry.error(nodeUri(), laneUri(), message));
  }

  @Override
  public void traceUp(Object message) {
    this.agent.didLogTrace(LogEntry.trace(nodeUri(), laneUri(), message));
  }

  @Override
  public void debugUp(Object message) {
    this.agent.didLogDebug(LogEntry.debug(nodeUri(), laneUri(), message));
  }

  @Override
  public void infoUp(Object message) {
    this.agent.didLogInfo(LogEntry.info(nodeUri(), laneUri(), message));
  }

  @Override
  public void warnUp(Object message) {
    this.agent.didLogWarn(LogEntry.warn(nodeUri(), laneUri(), message));
  }

  @Override
  public void errorUp(Object message) {
    this.agent.didLogError(LogEntry.error(nodeUri(), laneUri(), message));
  }

  @Override
  public void didFail(Throwable error) {
    try {
      this.agent.didLogFail(LogEntry.fail(nodeUri(), laneUri(), error));
    } finally {
      super.didFail(error);
    }
  }

  @Override
  public void didOpenDown() {
    super.didOpenDown();
    didOpen();
  }

  protected void didOpen() {
    this.agent.didOpenUplink(this);
  }

  @Override
  public void didCloseDown() {
    didClose();
    super.didCloseDown();
  }

  @Override
  public void didCloseUp() {
    didClose();
    super.didCloseUp();
  }

  protected void didClose() {
    this.agent.didCloseUplink(linkKey());
    this.agent.close();
  }

  public NodeBinding resolveMetaUplink(UriPath nodePath) {
    if (nodePath.isEmpty()) {
      return this.agent;
    }
    return null;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy