nstream.reflect.agent.MetaMeshAgent 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
// 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 nstream.reflect.MetaMesh;
import nstream.reflect.model.MeshStats;
import swim.api.lane.DemandLane;
import swim.api.lane.function.OnCue;
import swim.api.warp.WarpUplink;
import swim.structure.Record;
import swim.structure.Value;
import swim.uri.Uri;
public class MetaMeshAgent extends MetaGlobalAgent {
final MetaMesh meta;
Value globalKey;
volatile DemandLane meshStats;
public MetaMeshAgent(MetaMesh meta) {
this.meta = meta;
}
@Override
public MetaMesh meta() {
return this.meta;
}
@Override
public Value globalKey() {
Value globalKey = this.globalKey;
if (globalKey == null) {
final Uri meshUri = this.meta.meshUri();
if (meshUri.isDefined()) {
globalKey = Record.create(1).attr("mesh", meshUri.toString());
} else {
globalKey = Record.create(1).attr("mesh");
}
this.globalKey = globalKey.commit();
}
return globalKey;
}
@Override
protected void openLanes() {
super.openLanes();
final DemandLane meshStats = demandLane()
.valueForm(MeshStats.form())
.observe(new MetaMeshStatsController(this));
openLane(MESH_STATS_URI, meshStats);
this.meshStats = meshStats;
}
public MeshStats meshStats() {
return this.meta.meshStats();
}
@Override
public void cueStats() {
super.cueStats();
cueMeshStats();
}
protected void cueMeshStats() {
final DemandLane meshStats = this.meshStats;
if (meshStats != null) {
meshStats.cue();
}
}
static final Uri MESH_STATS_URI = Uri.parse("meshStats");
}
final class MetaMeshStatsController implements OnCue {
final MetaMeshAgent agent;
MetaMeshStatsController(MetaMeshAgent agent) {
this.agent = agent;
}
@Override
public MeshStats onCue(WarpUplink uplink) {
return this.agent.meshStats();
}
}