nstream.reflect.agent.MetaNodeAgent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nstream-reflect Show documentation
Show all versions of nstream-reflect Show documentation
Web Agent introspection runtime
The 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.agent;
import java.util.Iterator;
import nstream.reflect.MetaNode;
import nstream.reflect.model.DataStats;
import nstream.reflect.model.LaneInfo;
import nstream.reflect.model.LaneStats;
import swim.api.lane.DemandMapLane;
import swim.api.lane.function.OnCueKey;
import swim.api.lane.function.OnSyncKeys;
import swim.api.warp.WarpUplink;
import swim.system.LaneBinding;
import swim.uri.Uri;
public class MetaNodeAgent extends MetaRouterAgent {
final MetaNode meta;
volatile DemandMapLane lanes;
public MetaNodeAgent(MetaNode meta) {
this.meta = meta;
}
@Override
public MetaNode meta() {
return this.meta;
}
@Override
protected void openLanes() {
super.openLanes();
final DemandMapLane lanes = demandMapLane()
.keyForm(Uri.form())
.valueForm(LaneInfo.form())
.observe(new MetaNodeLanesController(this));
openLane(LANES_URI, lanes);
this.lanes = lanes;
}
public void didOpenNode() {
// FIXME: this.routerTotal.didOpenNode(this.meta.agentKey());
// FIXME: this.routerDelta.didOpenNode(this.meta.agentKey());
didUpdateStats();
}
public void didCloseNode() {
// FIXME: this.routerTotal.didCloseNode(this.meta.agentKey());
// FIXME: this.routerDelta.didCloseNode(this.meta.agentKey());
didUpdateStats();
}
public void accumulateLaneStats(LaneStats stats) {
this.linkTotal.accumulate(stats.linkStats);
this.linkDelta.accumulate(stats.linkStats);
// FIXME: this.routerTotal.accumulate(this.meta.agentKey(), stats);
// FIXME: this.routerDelta.accumulate(this.meta.agentKey(), stats);
didUpdateStats();
}
@Override
protected void bubbleDataStats() {
final DataStats stats = this.meta.dataStats();
stats.supersedeLocal(this.dataTotal, this.dataDelta);
super.bubbleDataStats();
}
@Override
protected void bubbleStoreStats() {
// prevent bubble
}
static final Uri LANES_URI = Uri.parse("lanes");
}
class MetaNodeLanesController implements OnCueKey, OnSyncKeys {
final MetaNodeAgent agent;
MetaNodeLanesController(MetaNodeAgent agent) {
this.agent = agent;
}
@Override
public LaneInfo onCue(Uri laneUri, WarpUplink uplink) {
final LaneBinding laneBinding = this.agent.meta.getLane(laneUri);
if (laneBinding == null) {
return null;
}
return LaneInfo.from(laneBinding);
}
@Override
public Iterator onSync(WarpUplink uplink) {
return this.agent.meta.lanes().keyIterator();
}
}