@Override public DatabaseClient getDatabaseClient(DatabaseId db) { synchronized (this) { Preconditions.checkState(!spannerIsClosed, "Cloud Spanner client has been closed"); if (dbClients.containsKey(db)) { return dbClients.get(db); } else { SessionPool pool = SessionPool.createPool(getOptions(), db, SpannerImpl.this); DatabaseClientImpl dbClient = new DatabaseClientImpl(pool); dbClients.put(db, dbClient); return dbClient; } } }
/** * Create a session pool with the given options and for the given database. It will also start * eagerly creating sessions if {@link SessionPoolOptions#getMinSessions()} is greater than 0. * Return pool is immediately ready for use, though getting a session might block for sessions to * be created. */ static SessionPool createPool(SpannerOptions spannerOptions, DatabaseId db, SpannerImpl spanner) { return createPool( spannerOptions.getSessionPoolOptions(), ((GrpcTransportOptions) spannerOptions.getTransportOptions()).getExecutorFactory(), db, spanner); }
private SessionPool createPool() { return SessionPool.createPool(options, new TestExecutorFactory(), db, client); }
private SessionPool createPool(Clock clock) { return SessionPool.createPool(options, new TestExecutorFactory(), db, client, clock); }
static SessionPool createPool( SessionPoolOptions poolOptions, ExecutorFactory<ScheduledExecutorService> executorFactory, DatabaseId db, SpannerImpl spanner, Clock clock) { SessionPool pool = new SessionPool(poolOptions, executorFactory, executorFactory.get(), db, spanner, clock); pool.initPool(); return pool; }
SessionPool.createPool(builder.build(), new TestExecutorFactory(), db, mockSpanner, clock); for (int i = 0; i < concurrentThreads; i++) { new Thread(
@Before public void setUp() throws Exception { SessionPoolOptions options = SessionPoolOptions.newBuilder().setMinSessions(1).setMaxSessions(2).build(); pool = SessionPool.createPool( options, new ExecutorFactory<ScheduledExecutorService>() { @Override public void release(ScheduledExecutorService executor) { executor.shutdown(); } @Override public ScheduledExecutorService get() { return new ScheduledThreadPoolExecutor(2); } }, db.getId(), (SpannerImpl) env.getTestHelper().getClient()); }
@Override public DatabaseClient getDatabaseClient(DatabaseId db) { synchronized (this) { Preconditions.checkState(!spannerIsClosed, "Cloud Spanner client has been closed"); if (dbClients.containsKey(db)) { return dbClients.get(db); } else { SessionPool pool = SessionPool.createPool(getOptions(), db, SpannerImpl.this); DatabaseClientImpl dbClient = new DatabaseClientImpl(pool); dbClients.put(db, dbClient); return dbClient; } } }
/** * Create a session pool with the given options and for the given database. It will also start * eagerly creating sessions if {@link SessionPoolOptions#getMinSessions()} is greater than 0. * Return pool is immediately ready for use, though getting a session might block for sessions to * be created. */ static SessionPool createPool(SpannerOptions spannerOptions, DatabaseId db, SpannerImpl spanner) { return createPool( spannerOptions.getSessionPoolOptions(), ((GrpcTransportOptions) spannerOptions.getTransportOptions()).getExecutorFactory(), db, spanner); }
static SessionPool createPool( SessionPoolOptions poolOptions, ExecutorFactory<ScheduledExecutorService> executorFactory, DatabaseId db, SpannerImpl spanner, Clock clock) { SessionPool pool = new SessionPool(poolOptions, executorFactory, executorFactory.get(), db, spanner, clock); pool.initPool(); return pool; }