@Test public void createSession() { final Consul consul = new Consul(System.getProperty(EP_PROPERTY)); assertTrue(consul.isValid()); final ConsulSession session = consul.createSession(getSessionName(), 10, 0); assertThat(session, is(notNullValue())); assertThat(session.getId(), is(not(""))); session.close(); }
public ConsulSession createSession(final String name, final int ttlMs, final int lockDelay) { final ConsulSession newSession = new ConsulSession(this.endpoint, "id", name, ttlMs, lockDelay); final String sessionString = newSession.toJson(); final Entity<String> entity = Entity.entity(sessionString, MediaType.APPLICATION_JSON); final Response response = httpClient .target(endpoint) .path("/v1/session/create") .request() .accept(MediaType.APPLICATION_JSON) .put(entity); if (response.getStatus() != Response.Status.OK.getStatusCode()) { LOG.log(Level.WARNING, "Expected 200 when creating session " + sessionString + " but got " + response.getStatus() + ". Consul Agent" + " responded with " + response.readEntity(String.class)); return null; } final ConsulSession session = ConsulSession.fromJsonResponse(newSession, response.readEntity(String.class)); if (session != null) { session.startKeepAlive(); } return session; }
Consul { public ConsulSession createSession(final String name, final int ttlMs, final int lockDelay) { final ConsulSession newSession = new ConsulSession(this.endpoint, "id", name, ttlMs, lockDelay); final String sessionString = newSession.toJson(); final Entity<String> entity = Entity.entity(sessionString, MediaType.APPLICATION_JSON); final Response response = httpClient .target(endpoint) .path("/v1/session/create") .request() .accept(MediaType.APPLICATION_JSON) .put(entity); if (response.getStatus() != Response.Status.OK.getStatusCode()) { LOG.log(Level.WARNING, "Expected 200 when creating session " + sessionString + " but got " + response.getStatus() + ". Consul Agent" + " responded with " + response.readEntity(String.class)); return null; } final ConsulSession session = ConsulSession.fromJsonResponse(newSession, response.readEntity(String.class)); if (session != null) { session.startKeepAlive(); } return session; } }
Consul { public ConsulSession createSession(final String name, final int ttlMs, final int lockDelay) { final ConsulSession newSession = new ConsulSession(this.endpoint, "id", name, ttlMs, lockDelay); final String sessionString = newSession.toJson(); final Entity<String> entity = Entity.entity(sessionString, MediaType.APPLICATION_JSON); final Response response = httpClient .target(endpoint) .path("/v1/session/create") .request() .accept(MediaType.APPLICATION_JSON) .put(entity); if (response.getStatus() != Response.Status.OK.getStatusCode()) { LOG.log(Level.WARNING, "Expected 200 when creating session " + sessionString + " but got " + response.getStatus() + ". Consul Agent" + " responded with " + response.readEntity(String.class)); return null; } final ConsulSession session = ConsulSession.fromJsonResponse(newSession, response.readEntity(String.class)); if (session != null) { session.startKeepAlive(); } return session; } Consul(final String endpoint); }
Consul { public ConsulSession createSession(final String name, final int ttlMs, final int lockDelay) { final ConsulSession newSession = new ConsulSession(this.endpoint, "id", name, ttlMs, lockDelay); final String sessionString = newSession.toJson(); final Entity<String> entity = Entity.entity(sessionString, MediaType.APPLICATION_JSON); final Response response = httpClient .target(endpoint) .path("/v1/session/create") .request() .accept(MediaType.APPLICATION_JSON) .put(entity); if (response.getStatus() != Response.Status.OK.getStatusCode()) { LOG.log(Level.WARNING, "Expected 200 when creating session " + sessionString + " but got " + response.getStatus() + ". Consul Agent" + " responded with " + response.readEntity(String.class)); return null; } final ConsulSession session = ConsulSession.fromJsonResponse(newSession, response.readEntity(String.class)); if (session != null) { session.startKeepAlive(); } return session; } Consul(final String endpoint); boolean isValid(); ConsulSession createSession(final String name, final int ttlMs, final int lockDelay); boolean writeSessionData(final String name, final String data, final String sessionId); boolean createPermanentData(final String name, final String data); boolean writePermanentData(
            final String name, final String data); boolean removePermanentData(final String name); String readData(final String name); ConsulWatch createWatch(final String pathToWatch); }
Consul { public ConsulSession createSession(final String name, final int ttlMs, final int lockDelay) { final ConsulSession newSession = new ConsulSession(this.endpoint, "id", name, ttlMs, lockDelay); final String sessionString = newSession.toJson(); final Entity<String> entity = Entity.entity(sessionString, MediaType.APPLICATION_JSON); final Response response = httpClient .target(endpoint) .path("/v1/session/create") .request() .accept(MediaType.APPLICATION_JSON) .put(entity); if (response.getStatus() != Response.Status.OK.getStatusCode()) { LOG.log(Level.WARNING, "Expected 200 when creating session " + sessionString + " but got " + response.getStatus() + ". Consul Agent" + " responded with " + response.readEntity(String.class)); return null; } final ConsulSession session = ConsulSession.fromJsonResponse(newSession, response.readEntity(String.class)); if (session != null) { session.startKeepAlive(); } return session; } Consul(final String endpoint); boolean isValid(); ConsulSession createSession(final String name, final int ttlMs, final int lockDelay); boolean writeSessionData(final String name, final String data, final String sessionId); boolean createPermanentData(final String name, final String data); boolean writePermanentData(
            final String name, final String data); boolean removePermanentData(final String name); String readData(final String name); ConsulWatch createWatch(final String pathToWatch); static final int DEFAULT_LOCK_DELAY; }