Optional<String> behaviorOptional = instance.getBehavior(); if (behaviorOptional.isPresent()) { behavior(behaviorOptional);
public SessionTask(Consul consul, String serviceName, String serviceId, Consumer<Throwable> fatalErrorConsumer) { serviceId = defaultIfNull(serviceId, serviceName); this.serviceId = serviceId; this.serviceName = requireNonNull(serviceName); this.consul = requireNonNull(consul); this.fatalErrorConsumer = requireNonNull(fatalErrorConsumer); try { final List<String> tags = singletonList("couchbase-elasticsearch-connector");// emptyList(); final Map<String, String> meta = singletonMap("uuid", serviceUuid); // todo catch exception, retry with backoff (wait for consul agent to start) final int sessionTtlSeconds = HEALTH_CHECK_INTERVAL_SECONDS * 2; consul.agentClient().register(0, sessionTtlSeconds, this.serviceName, this.serviceId, tags, meta); passHealthCheck(); this.sessionId = consul.sessionClient().createSession(ImmutableSession.builder() .name("couchbase:cbes:" + this.serviceId) .behavior("delete") .lockDelay("15s") .addChecks("service:" + this.serviceId) // consul client library names the health check "service:<serviceId>" .build() ).getId(); } catch (Throwable t) { fatalErrorConsumer.accept(t); // todo need to send to fatalErrorConsumer? throw t; } }
.behavior("delete") .lockDelay("15s") .addChecks("service:" + this.serviceId)
/** * @param json A JSON-bindable data structure * @return An immutable value type * @deprecated Do not use this method directly, it exists only for the <em>Jackson</em>-binding infrastructure */ @Deprecated @JsonCreator static ImmutableSession fromJson(Json json) { ImmutableSession.Builder builder = ImmutableSession.builder(); if (json.lockDelay != null) { builder.lockDelay(json.lockDelay); } if (json.name != null) { builder.name(json.name); } if (json.node != null) { builder.node(json.node); } if (json.checks != null) { builder.addAllChecks(json.checks); } if (json.behavior != null) { builder.behavior(json.behavior); } if (json.ttl != null) { builder.ttl(json.ttl); } return builder.build(); }