/** * Creates a new Builder that inherits this origin's properties. * * @return a new Builder that inherits this origin's properties */ public Builder newBuilder() { return newOriginBuilder(this); }
private static String makeAResponse(Origin origin) { return format("Response From %s - %s", origin.hostAndPortString(), randomUUID().toString()); }
private ConnectionsPool() { String prefix = format("origins.%s.%s.connectionspool", origin.applicationId(), origin.id()); SortedMap<String, Gauge> gauges = metrics.getGauges(); availableGauge = gauges.get(prefix + ".available-connections"); busyGauge = gauges.get(prefix + ".busy-connections"); pendingGauge = gauges.get(prefix + ".pending-connections"); }
private static HttpServer createHttpServer(Origin origin) { LOG.info("creating server for {}", origin.hostAndPortString()); return new NettyServerBuilder() .name(origin.hostAndPortString()) .setServerEventLoopFactory(serverEventLoopFactory) .setHttpConnector(new WebServerConnectorFactory().create(new HttpConnectorConfig(origin.port()))) .httpHandler(new StandardHttpRouter().add("/*", new AppHandler(origin))) .build(); }
public Meter meter(Origin origin, MetricRegistry metricRegistry) { String name = format(format, origin.applicationId()); return metricRegistry.meter(name); } }
/** * Builds a new Origin with the properties set in this builder. * * @return a new Origin */ public Origin build() { return new Origin(this); } }
private Origin(com.hotels.styx.api.extension.Origin origin) { this.origin = origin; connectionsPool = new ConnectionsPool(); String prefix = format("origins.%s.%s.requests.response.status", origin.applicationId(), origin.id()); this.responsesSupplier = new ResponseCodeSupplier(metrics, METER, prefix, true); this.requests = new Requests(format("origins.%s.%s", origin.applicationId(), origin.id())); }
/** * Gets a naming scope for metrics pertaining to the given origin. * * @param origin an origin * @return naming scope */ public static String originMetricsScope(Origin origin) { return name(OriginMetrics.PREFIX, origin.applicationId().toString(), originName(origin)); }
private static Set<Origin> withAppId(Collection<Origin> origins, String appId) { return origins.stream().map(origin -> newOriginBuilder(origin) .applicationId(appId) .build()) .collect(toSet()); }
private void removeMonitoredEndpoint(Id originId) { MonitoredOrigin host = this.origins.get(originId); host.close(); LOG.info("Existing origin has been removed. Origin={}:{}", appId, host.origin.id()); metricRegistry.deregister(host.gaugeName); }
private static String hosts(Iterable<RemoteHost> origins) { return stream(origins.spliterator(), false) .map(host -> host.origin().hostAndPortString()) .collect(joining(", ")); } }
/** * Create a new OriginMetrics. * * @param origin an origin * @param metricRegistry a metrics registry * @return a new OriginMetrics */ public static OriginMetrics create(Origin origin, MetricRegistry metricRegistry) { MetricRegistry originsRootRegistry = metricRegistry.scope(OriginMetrics.PREFIX); ApplicationMetrics appMetrics = new ApplicationMetrics(origin.applicationId(), originsRootRegistry); return new OriginMetrics(appMetrics, origin); }
/** * Creates a new {@link Origin} porting to a specified host and port. * * @param host host * @param port port * @return origin */ public static Origin origin(String host, int port) { return newOriginBuilder(host, port) .applicationId(randomUUID().toString()) .id(randomUUID().toString()) .build(); } }
private static String originName(Origin origin) { return name(origin.id().toString()); }
@Override public String toString() { return toStringHelper(this) .add("host", this.origin.hostAndPortString()) .add("channel", toString(channel)) .toString(); }
private static Iterable<Origin> originsWithApplicationId(BackendService backendService) { return backendService.origins().stream().map(origin -> newOriginBuilder(origin) .applicationId(backendService.id()) .build()) .collect(toList()); }
private void onEvent(Origin origin, Object event) { onEvent(origin.id(), event); }
private io.netty.handler.codec.http.HttpRequest makeRequest(LiveHttpRequest request) { DefaultHttpRequest nettyRequest = toNettyRequest(request); Optional<String> host = request.header(HOST); if (!host.isPresent()) { nettyRequest.headers().set(HOST, nettyConnection.getOrigin().hostAndPortString()); } return nettyRequest; } }