use of com.google.spanner.v1.CreateSessionRequest in project swiftmq-client by iitsoftware.
the class TopicConnectionImpl method createTopicSession.
public TopicSession createTopicSession(boolean transacted, int acknowledgeMode) throws JMSException {
verifyState();
SessionImpl topicSession = null;
CreateSessionReply reply = null;
try {
reply = (CreateSessionReply) requestRegistry.request(new CreateSessionRequest(0, transacted, acknowledgeMode, CreateSessionRequest.TOPIC_SESSION));
} catch (Exception e) {
throw ExceptionConverter.convert(e);
}
if (reply.isOk()) {
int dispatchId = reply.getSessionDispatchId();
String cid = clientID != null ? clientID : internalCID;
topicSession = new SessionImpl(SessionImpl.TYPE_TOPIC_SESSION, this, transacted, acknowledgeMode, dispatchId, requestRegistry, myHostname, cid);
topicSession.setUserName(userName);
topicSession.setMyDispatchId(addRequestService(topicSession));
addSession(topicSession);
} else {
throw ExceptionConverter.convert(reply.getException());
}
return (topicSession);
}
use of com.google.spanner.v1.CreateSessionRequest in project java-spanner by googleapis.
the class GapicSpannerRpc method createSession.
@Override
public Session createSession(String databaseName, @Nullable Map<String, String> labels, @Nullable Map<Option, ?> options) throws SpannerException {
CreateSessionRequest.Builder requestBuilder = CreateSessionRequest.newBuilder().setDatabase(databaseName);
if (labels != null && !labels.isEmpty()) {
Session.Builder session = Session.newBuilder().putAllLabels(labels);
requestBuilder.setSession(session);
}
CreateSessionRequest request = requestBuilder.build();
GrpcCallContext context = newCallContext(options, databaseName, request, SpannerGrpc.getCreateSessionMethod());
return get(spannerStub.createSessionCallable().futureCall(request, context));
}
use of com.google.spanner.v1.CreateSessionRequest in project java-spanner by googleapis.
the class MockSpannerServiceImpl method createSession.
@Override
public void createSession(CreateSessionRequest request, StreamObserver<Session> responseObserver) {
requests.add(request);
Preconditions.checkNotNull(request.getDatabase());
String name = generateSessionName(request.getDatabase());
try {
createSessionExecutionTime.simulateExecutionTime(exceptions, stickyGlobalExceptions, freezeLock);
Timestamp now = getCurrentGoogleTimestamp();
Session session = Session.newBuilder().setCreateTime(now).setName(name).setApproximateLastUseTime(now).build();
Session prev = sessions.putIfAbsent(name, session);
if (prev == null) {
sessionLastUsed.put(name, Instant.now());
numSessionsCreated.incrementAndGet();
responseObserver.onNext(session);
responseObserver.onCompleted();
} else {
// Someone else tried to create a session with the same id. This should not be possible
responseObserver.onError(Status.ALREADY_EXISTS.asRuntimeException());
}
} catch (StatusRuntimeException e) {
sessions.remove(name);
responseObserver.onError(e);
} catch (Throwable e) {
sessions.remove(name);
responseObserver.onError(Status.INTERNAL.withDescription("Create session failed: " + e.getMessage()).asRuntimeException());
}
}
use of com.google.spanner.v1.CreateSessionRequest in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerIntegrationTest method testCreateAndGetSessionBlocking.
@Test
public void testCreateAndGetSessionBlocking() throws Exception {
SpannerBlockingStub stub = getSpannerBlockingStub();
CreateSessionRequest req = CreateSessionRequest.newBuilder().setDatabase(DATABASE_PATH).build();
// The first MAX_CHANNEL requests (without affinity) should be distributed 1 per channel.
List<Session> sessions = new ArrayList<>();
for (int i = 0; i < MAX_CHANNEL; i++) {
Session session = stub.createSession(req);
assertThat(session).isNotEqualTo(null);
sessions.add(session);
Session responseGet = stub.getSession(GetSessionRequest.newBuilder().setName(session.getName()).build());
assertEquals(responseGet.getName(), session.getName());
}
checkChannelRefs(MAX_CHANNEL, 0, 1);
for (Session session : sessions) {
deleteSession(stub, session);
}
checkChannelRefs(MAX_CHANNEL, 0, 0);
}
use of com.google.spanner.v1.CreateSessionRequest in project grpc-gcp-java by GoogleCloudPlatform.
the class SpannerIntegrationTest method testBoundAfterUnbind.
@Test
public void testBoundAfterUnbind() {
SpannerBlockingStub stub = getSpannerBlockingStub();
CreateSessionRequest req = CreateSessionRequest.newBuilder().setDatabase(DATABASE_PATH).build();
Session session = stub.createSession(req);
stub.deleteSession(DeleteSessionRequest.newBuilder().setName(session.getName()).build());
expectedEx.expect(StatusRuntimeException.class);
expectedEx.expectMessage("NOT_FOUND: Session not found: " + session.getName());
stub.getSession(GetSessionRequest.newBuilder().setName(session.getName()).build());
}
Aggregations