@Override public <T> void sendCopy(String channel, T event) { T copy = BeanUtils.copy(event); this.send(channel, copy); }
private ClientBuilder getClientBuilder() { if (clientBuilder == null) { clientBuilder = clientBuilder(); } return BeanUtils.copy(clientBuilder); }
private void reportStatus(String name, NodeHealthStat currentHealth) { switch (currentHealth.getStatus()) { case PASS: if (debug) logger.debug("HEALTH PASS :: {} status check and got status {} ", name, currentHealth); onCheckIn.ifPresent(checkIn -> checkIn.accept(BeanUtils.copy(currentHealth))); super.incrementCount("pass"); break; case FAIL: logger.error("HEALTH FAIL :: {} status check and got status {} ", name, currentHealth); onFail.ifPresent(checkIn -> checkIn.accept(BeanUtils.copy(currentHealth))); super.incrementCount("fail"); break; case WARN: logger.warn("HEALTH WARNING :: {} status check and got status {} ", name, currentHealth); onWarn.ifPresent(checkIn -> checkIn.accept(BeanUtils.copy(currentHealth))); super.incrementCount("warn"); break; default: onCheckIn.ifPresent(checkIn -> checkIn.accept(BeanUtils.copy(currentHealth))); } }
@Override public void warnWithReason(final String name, final HealthFailReason reason) { logger.warn("HealthService::warn() {}", name); super.incrementCount("warn"); final NodeHealthStat nodeHealthStat = getServiceHealthStat(name); nodeHealthStat.setStatus(HealthStatus.WARN); nodeHealthStat.setReason(reason); nodeHealthStat.setLastCheckIn(super.time); onWarn.ifPresent(checkIn -> checkIn.accept(BeanUtils.copy(nodeHealthStat))); }
/** * Check in the service. * * @param name name */ @Override public void checkInOk(final String name) { if (debug) logger.debug("HealthService::checkInOk() {} ", name); final NodeHealthStat nodeHealthStat = getServiceHealthStat(name); nodeHealthStat.setLastCheckIn(super.time); nodeHealthStat.setReason(null); nodeHealthStat.setStatus(HealthStatus.PASS); super.incrementCount("checkin"); onCheckIn.ifPresent(checkIn -> checkIn.accept(BeanUtils.copy(nodeHealthStat))); }
/** * Check in the service with a specific status. * * @param name name * @param reason reason */ @Override public void failWithReason(final String name, final HealthFailReason reason) { logger.error("HealthService::fail() {}", name); super.incrementCount("fail"); final NodeHealthStat nodeHealthStat = getServiceHealthStat(name); nodeHealthStat.setStatus(HealthStatus.FAIL); nodeHealthStat.setReason(reason); nodeHealthStat.setLastCheckIn(super.time); onFail.ifPresent(checkIn -> checkIn.accept(BeanUtils.copy(nodeHealthStat))); }
@Override public void warnWithError(final String name, final Throwable error) { logger.warn("HealthService::warn() {}", name); super.incrementCount("warn"); final NodeHealthStat nodeHealthStat = getServiceHealthStat(name); nodeHealthStat.setStatus(HealthStatus.WARN); nodeHealthStat.setReason(HealthFailReason.ERROR); nodeHealthStat.setLastCheckIn(super.time); nodeHealthStat.setError(error); onWarn.ifPresent(checkIn -> checkIn.accept(BeanUtils.copy(nodeHealthStat))); }
/** * Fail the node for the service with a specific status. * * @param name name * @param error error */ @Override public void failWithError(final String name, final Throwable error) { logger.error("HealthService::fail() {}", name); super.incrementCount("fail"); final NodeHealthStat nodeHealthStat = getServiceHealthStat(name); nodeHealthStat.setStatus(HealthStatus.FAIL); nodeHealthStat.setReason(HealthFailReason.ERROR); nodeHealthStat.setLastCheckIn(super.time); nodeHealthStat.setError(error); onFail.ifPresent(checkIn -> checkIn.accept(BeanUtils.copy(nodeHealthStat))); }
private void checkTTL(final NodeHealthStat nodeHealthStat) { if (debug) logger.debug("HealthService::checkTTL() {}", nodeHealthStat.getName()); if (!nodeHealthStat.isOk()) { return; } if (nodeHealthStat.isForever()) { return; } final long duration = super.time - nodeHealthStat.getLastCheckIn(); /* If the duration is greater than the ttl interval, then mark it as failed. */ if (duration > nodeHealthStat.getTtlInMS()) { logger.error("HealthService::checkTTL() {} FAILED TTL check, duration {}", nodeHealthStat.getName(), duration); nodeHealthStat.setReason(HealthFailReason.FAILED_TTL); nodeHealthStat.setStatus(HealthStatus.FAIL); onFail.ifPresent(checkIn -> checkIn.accept(BeanUtils.copy(nodeHealthStat))); } }
public HttpServerVertx(final boolean startedVertx, final Vertx vertx, final String endpointName, final HttpServerOptions options, final QBitSystemManager systemManager, final ServiceDiscovery serviceDiscovery, final HealthServiceAsync healthServiceAsync, final int serviceDiscoveryTtl, final TimeUnit serviceDiscoveryTtlTimeUnit, final CopyOnWriteArrayList<HttpResponseDecorator> decorators, final HttpResponseCreator httpResponseCreator, final RequestContinuePredicate requestBodyContinuePredicate) { this.startedVertx = startedVertx; this.simpleHttpServer = new SimpleHttpServer(endpointName, systemManager, options.getFlushInterval(), options.getHost(), options.getPort(), serviceDiscovery, healthServiceAsync, serviceDiscoveryTtl, serviceDiscoveryTtlTimeUnit, decorators, httpResponseCreator, requestBodyContinuePredicate); this.vertx = vertx; this.systemManager = systemManager; this.port = options.getPort(); this.host = options.getHost(); this.options = BeanUtils.copy(options); this.setWebSocketIdleConsume(aVoid -> { }); this.setHttpRequestsIdleConsumer(aVoid -> { }); }
public static <V> Set<V> deepCopy( Collection<V> collection ) { Set<V> newSet = new LinkedHashSet<>(collection.size()); for (V v : collection) { newSet.add(BeanUtils.copy(v)); } return newSet; }
public static <V> List<V> deepCopy( Collection<V> collection ) { List<V> list = new ArrayList<>(collection.size()); for (V v : collection) { list.add( BeanUtils.copy(v)); } return list; }
.setInvokeDynamic(invokeDynamic) .setSystemManager(systemManager) .setRequestQueueBuilder(BeanUtils.copy(this.requestQueueBuilder)) .setRequestQueueBuilder(requestQueueBuilder) .setHandleCallbacks(false)
public static <V> Set<V> deepCopy( Collection<V> collection ) { Set<V> newSet = new LinkedHashSet<>(collection.size()); for (V v : collection) { newSet.add(BeanUtils.copy(v)); } return newSet; }
@Override public <T> void sendCopy(String channel, T event) { T copy = BeanUtils.copy(event); this.send(channel, copy); }
@Test public void test() { ok |= webSocketMessage.body().equals("foo") || die(); ok |= webSocketMessage.isSingleton() || die(); ok |= webSocketMessage.address().equals("/foo") || die(); ok |= webSocketMessage.getUri().equals("/foo") || die(); ok |= webSocketMessage.returnAddress().equals("/blah") || die(); ok |= !webSocketMessage.isHandled() || die(); webSocketMessage.getSender().sendText("hello mom"); webSocketMessage.handled(); ok |= webSocketMessage.isHandled() || die(); ok |= called || die(); ok |= lastMessage.equals("hello mom") || die(); System.out.println(webSocketMessage); ok |= webSocketMessage.equals(BeanUtils.copy(webSocketMessage)) || die(); ok |= webSocketMessage.hashCode() == BeanUtils.copy(webSocketMessage).hashCode() || die(); ok |= webSocketMessage.timestamp() > 0 || die(); ok |= webSocketMessage.id() >= 0 || die(); ok |= !webSocketMessage.hasParams() && webSocketMessage.params().size() == 0 || die(); ok |= !webSocketMessage.hasHeaders() && webSocketMessage.headers().size() == 0 || die(); final WebSocketMessageBuilder webSocketMessageBuilder = new WebSocketMessageBuilder(); webSocketMessageBuilder.getMessage(); webSocketMessageBuilder.getRemoteAddress(); webSocketMessageBuilder.getSender(); webSocketMessageBuilder.getUri(); }
@Override public void warnWithReason(final String name, final HealthFailReason reason) { logger.warn("HealthService::warn() {}", name); super.incrementCount("warn"); final NodeHealthStat nodeHealthStat = getServiceHealthStat(name); nodeHealthStat.setStatus(HealthStatus.WARN); nodeHealthStat.setReason(reason); nodeHealthStat.setLastCheckIn(super.time); onWarn.ifPresent(checkIn -> checkIn.accept(BeanUtils.copy(nodeHealthStat))); }
@Override public void warnWithReason(final String name, final HealthFailReason reason) { logger.warn("HealthService::warn() {}", name); super.incrementCount("warn"); final NodeHealthStat nodeHealthStat = getServiceHealthStat(name); nodeHealthStat.setStatus(HealthStatus.WARN); nodeHealthStat.setReason(reason); nodeHealthStat.setLastCheckIn(super.time); onWarn.ifPresent(checkIn -> checkIn.accept(BeanUtils.copy(nodeHealthStat))); }
@Override public void warnWithError(final String name, final Throwable error) { logger.warn("HealthService::warn() {}", name); super.incrementCount("warn"); final NodeHealthStat nodeHealthStat = getServiceHealthStat(name); nodeHealthStat.setStatus(HealthStatus.WARN); nodeHealthStat.setReason(HealthFailReason.ERROR); nodeHealthStat.setLastCheckIn(super.time); nodeHealthStat.setError(error); onWarn.ifPresent(checkIn -> checkIn.accept(BeanUtils.copy(nodeHealthStat))); }