This commit is contained in:
Jan Bartel 2017-02-08 09:23:32 +11:00
parent e01636d109
commit 7bc0ae57ca
3 changed files with 41 additions and 31 deletions

View File

@ -422,9 +422,9 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
if (!_dsProvided)
{
if (!StringUtil.isBlank(getNamespace()))
_datastore = DatastoreOptions.builder().namespace(getNamespace()).build().service();
_datastore = DatastoreOptions.newBuilder().setNamespace(getNamespace()).build().getService();
else
_datastore = DatastoreOptions.defaultInstance().service();
_datastore = DatastoreOptions.getDefaultInstance().getService();
}
if (_model == null)
@ -433,7 +433,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
addBean(_model,true);
}
_keyFactory = _datastore.newKeyFactory().kind(_model.getKind());
_keyFactory = _datastore.newKeyFactory().setKind(_model.getKind());
_indexesPresent = checkIndexes();
if (!_indexesPresent)
@ -566,9 +566,9 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
{
try
{
Query<Key> q = Query.keyQueryBuilder()
.kind(_model.getKind())
.filter(PropertyFilter.eq(_model.getId(), s))
Query<Key> q = Query.newKeyQueryBuilder()
.setKind(_model.getKind())
.setFilter(PropertyFilter.eq(_model.getId(), s))
.build();
QueryResults<Key> res = _datastore.run(q);
if (!res.hasNext())
@ -604,10 +604,10 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
Set<ExpiryInfo> info = new HashSet<>();
//get up to maxResult number of sessions that have expired
Query<Entity> query = Query.entityQueryBuilder()
.kind(_model.getKind())
.filter(CompositeFilter.and(PropertyFilter.gt(_model.getExpiry(), 0), PropertyFilter.le(_model.getExpiry(), System.currentTimeMillis())))
.limit(_maxResults)
Query<Entity> query = Query.newEntityQueryBuilder()
.setKind(_model.getKind())
.setFilter(CompositeFilter.and(PropertyFilter.gt(_model.getExpiry(), 0), PropertyFilter.le(_model.getExpiry(), System.currentTimeMillis())))
.setLimit(_maxResults)
.build();
QueryResults<Entity> results;
@ -637,11 +637,11 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
protected Set<ExpiryInfo> queryExpiryByIndex () throws Exception
{
Set<ExpiryInfo> info = new HashSet<>();
Query<ProjectionEntity> query = Query.projectionEntityQueryBuilder()
.kind(_model.getKind())
.projection(_model.getId(), _model.getLastNode(), _model.getExpiry())
.filter(CompositeFilter.and(PropertyFilter.gt(_model.getExpiry(), 0), PropertyFilter.le(_model.getExpiry(), System.currentTimeMillis())))
.limit(_maxResults)
Query<ProjectionEntity> query = Query.newProjectionEntityQueryBuilder()
.setKind(_model.getKind())
.setProjection(_model.getId(), _model.getLastNode(), _model.getExpiry())
.setFilter(CompositeFilter.and(PropertyFilter.gt(_model.getExpiry(), 0), PropertyFilter.le(_model.getExpiry(), System.currentTimeMillis())))
.setLimit(_maxResults)
.build();
QueryResults<ProjectionEntity> presults;
@ -674,10 +674,10 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
{
if (_indexesPresent)
{
Query<ProjectionEntity> query = Query.projectionEntityQueryBuilder()
.kind(_model.getKind())
.projection(_model.getExpiry())
.filter(PropertyFilter.eq(_model.getId(), id))
Query<ProjectionEntity> query = Query.newProjectionEntityQueryBuilder()
.setKind(_model.getKind())
.setProjection(_model.getExpiry())
.setFilter(PropertyFilter.eq(_model.getId(), id))
.build();
QueryResults<ProjectionEntity> presults;
@ -700,9 +700,9 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
}
else
{
Query<Entity> query = Query.entityQueryBuilder()
.kind(_model.getKind())
.filter(PropertyFilter.eq(_model.getId(), id))
Query<Entity> query = Query.newEntityQueryBuilder()
.setKind(_model.getKind())
.setFilter(PropertyFilter.eq(_model.getId(), id))
.build();
QueryResults<Entity> results;
@ -761,7 +761,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
}
catch (DatastoreException e)
{
if (e.retryable())
if (e.isRetryable())
{
if (LOG.isDebugEnabled()) LOG.debug("Datastore put retry {} waiting {}ms", attempts, backoff);
@ -814,18 +814,26 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
*/
protected boolean checkIndexes ()
{
long start =0;
try
{
Query<ProjectionEntity> query = Query.projectionEntityQueryBuilder()
.kind(_model.getKind())
.projection(_model.getExpiry())
.filter(PropertyFilter.eq(_model.getId(), "-"))
Query<ProjectionEntity> query = Query.newProjectionEntityQueryBuilder()
.setKind(_model.getKind())
.setProjection(_model.getExpiry())
.setFilter(PropertyFilter.eq(_model.getId(), "-"))
.build();
start = System.currentTimeMillis();
System.err.println("Checking indexes at "+start);
_datastore.run(query);
long end = System.currentTimeMillis();
System.err.println("Done checking, elapsed "+(end-start));
return true;
}
catch (DatastoreException e)
{
long end = System.currentTimeMillis();
System.err.println("Done checking, no indexes, elapsed="+(end-start));
//need to assume that the problem is the index doesn't exist, because there
//is no specific code for that
if (LOG.isDebugEnabled())
@ -855,7 +863,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
oos.flush();
//turn a session into an entity
entity = Entity.builder(key)
entity = Entity.newBuilder(key)
.set(_model.getId(), session.getId())
.set(_model.getContextPath(), session.getContextPath())
.set(_model.getVhost(), session.getVhost())
@ -866,7 +874,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
.set(_model.getLastNode(),session.getLastNode())
.set(_model.getExpiry(), session.getExpiry())
.set(_model.getMaxInactive(), session.getMaxInactiveMs())
.set(_model.getAttributes(), BlobValue.builder(Blob.copyFrom(baos.toByteArray())).excludeFromIndexes(true).build()).build();
.set(_model.getAttributes(), BlobValue.newBuilder(Blob.copyFrom(baos.toByteArray())).setExcludeFromIndexes(true).build()).build();
return entity;

View File

@ -13,7 +13,7 @@
<name>Jetty :: GCloud</name>
<properties>
<gcloud.version>0.7.0</gcloud.version>
<gcloud.version>0.8.2-beta</gcloud.version>
</properties>
<modules>

View File

@ -27,6 +27,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.joda.time.Duration;
import com.google.cloud.datastore.Datastore;
import com.google.cloud.datastore.DatastoreOptions;
import com.google.cloud.datastore.Entity;
@ -73,7 +75,7 @@ public class GCloudSessionTestSupport
public void tearDown()
throws Exception
{
_helper.stop();
_helper.stop(Duration.millis(5)); //wait up to 5ms for shutdown
}