You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2013/12/04 04:45:19 UTC
[5/5] git commit: Major refactor complete. Need to work on scheduling
of futures.
Major refactor complete. Need to work on scheduling of futures.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/cb9ec94e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/cb9ec94e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/cb9ec94e
Branch: refs/heads/two-dot-o
Commit: cb9ec94e31df24e191f2fa4010c020e2ce16c36e
Parents: 271b26c
Author: Todd Nine <to...@apache.org>
Authored: Tue Dec 3 11:12:57 2013 -0700
Committer: Todd Nine <to...@apache.org>
Committed: Tue Dec 3 20:44:14 2013 -0700
----------------------------------------------------------------------
stack/corepersistence/collection/pom.xml | 42 +-
.../collection/CollectionContextImpl.java | 93 ----
.../collection/CollectionManager.java | 4 +-
.../CollectionManagerFactoryImpl.java | 16 -
.../collection/CollectionManagerImpl.java | 81 ----
.../persistence/collection/TimeService.java | 12 -
.../exception/CollectionRuntimeException.java | 29 ++
.../collection/guice/CollectionModule.java | 74 +---
.../collection/impl/CollectionContextImpl.java | 95 ++++
.../impl/CollectionManagerFactoryImpl.java | 21 +
.../collection/impl/CollectionManagerImpl.java | 77 ++++
.../collection/mvcc/entity/MvccEntity.java | 4 -
.../collection/mvcc/entity/MvccEntityImpl.java | 110 -----
.../collection/mvcc/entity/MvccLogEntry.java | 5 -
.../mvcc/entity/MvccLogEntryImpl.java | 113 -----
.../mvcc/entity/impl/MvccEntityImpl.java | 98 +++++
.../mvcc/entity/impl/MvccLogEntryImpl.java | 100 +++++
.../mvcc/event/PostProcessListener.java | 6 +-
.../collection/mvcc/stage/MvccStrategy.java | 42 --
.../collection/mvcc/stage/StagePipeline.java | 27 +-
.../collection/mvcc/stage/WriteContext.java | 46 +-
.../mvcc/stage/WriteContextFactory.java | 30 ++
.../collection/mvcc/stage/WriteStage.java | 7 +-
.../stage/impl/CollectionPipelineModule.java | 38 +-
.../collection/mvcc/stage/impl/Commit.java | 24 -
.../mvcc/stage/impl/MvccEntityCommit.java | 28 ++
.../mvcc/stage/impl/MvccEntityNew.java | 116 +++++
.../mvcc/stage/impl/MvccEntityWrite.java | 25 ++
.../mvcc/stage/impl/StagePipelineImpl.java | 45 +-
.../collection/mvcc/stage/impl/Start.java | 67 ---
.../mvcc/stage/impl/UpdatePipeline.java | 20 -
.../collection/mvcc/stage/impl/Write.java | 27 --
.../mvcc/stage/impl/WriteContextCallback.java | 42 +-
.../stage/impl/WriteContextFactoryImpl.java | 47 ++
.../mvcc/stage/impl/WriteContextImpl.java | 111 +++++
.../MvccEntitySerializationStrategy.java | 7 +-
.../MvccEntitySerializationStrategyImpl.java | 227 ----------
.../MvccLogEntrySerializationStrategy.java | 2 +-
.../MvccLogEntrySerializationStrategyImpl.java | 238 ----------
.../MvccEntitySerializationStrategyImpl.java | 238 ++++++++++
.../MvccLogEntrySerializationStrategyImpl.java | 239 ++++++++++
.../serialization/impl/SerializationModule.java | 45 ++
.../collection/service/TimeService.java | 12 +
.../collection/service/UUIDService.java | 15 +
.../collection/service/impl/ServiceModule.java | 34 ++
.../service/impl/TimeServiceImpl.java | 14 +
.../service/impl/UUIDServiceImpl.java | 17 +
.../collection/CollectionContextImplTest.java | 1 +
.../collection/guice/TestCollectionModule.java | 3 +-
.../mvcc/entity/MvccEntityImplTest.java | 132 ------
.../mvcc/entity/MvccLogEntryImplTest.java | 104 -----
.../collection/mvcc/entity/StageTest.java | 91 ----
.../mvcc/entity/impl/MvccEntityImplTest.java | 107 +++++
.../mvcc/entity/impl/MvccLogEntryImplTest.java | 95 ++++
.../collection/mvcc/entity/impl/StageTest.java | 93 ++++
.../collection/mvcc/stage/StartTest.java | 51 ---
.../mvcc/stage/impl/MvccEntityNewTest.java | 136 ++++++
...MvccEntitySerializationStrategyImplTest.java | 430 ------------------
...ccLogEntrySerializationStrategyImplTest.java | 311 -------------
.../serialization/SerializationComparison.java | 182 --------
...MvccEntitySerializationStrategyImplTest.java | 438 +++++++++++++++++++
...ccLogEntrySerializationStrategyImplTest.java | 319 ++++++++++++++
.../impl/SerializationComparison.java | 182 ++++++++
.../persistence/index/stage/Complete.java | 7 +-
.../usergrid/persistence/index/stage/Start.java | 6 +-
.../usergrid/persistence/index/stage/Write.java | 11 +-
66 files changed, 2989 insertions(+), 2520 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/pom.xml b/stack/corepersistence/collection/pom.xml
index 1a0f358..0f4eb6d 100644
--- a/stack/corepersistence/collection/pom.xml
+++ b/stack/corepersistence/collection/pom.xml
@@ -43,32 +43,31 @@
<version>${astynax.version}</version>
</dependency>
- <!-- bean utils for setting uuids etc -->
+ <!-- lang utils for setting uuids etc -->
<dependency>
- <groupId>commons-beanutils</groupId>
- <artifactId>commons-beanutils-core</artifactId>
- <version>1.8.3</version>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.1</version>
</dependency>
-
<!-- Serialization libraries -->
<dependency>
- <groupId>org.codehaus.jackson</groupId>
- <artifactId>jackson-smile</artifactId>
- <version>1.9.13</version>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-smile</artifactId>
+ <version>1.9.13</version>
</dependency>
<dependency>
- <groupId>com.esotericsoftware.kryo</groupId>
- <artifactId>kryo</artifactId>
- <version>2.22</version>
+ <groupId>com.esotericsoftware.kryo</groupId>
+ <artifactId>kryo</artifactId>
+ <version>2.22</version>
</dependency>
<!-- helper serializers for kryo -->
<dependency>
- <groupId>de.javakaffee</groupId>
- <artifactId>kryo-serializers</artifactId>
- <version>0.26</version>
+ <groupId>de.javakaffee</groupId>
+ <artifactId>kryo-serializers</artifactId>
+ <version>0.26</version>
</dependency>
<!-- Google Guice -->
@@ -91,7 +90,11 @@
<version>${guice.version}</version>
</dependency>
-
+ <dependency>
+ <groupId>com.google.inject.extensions</groupId>
+ <artifactId>guice-assistedinject</artifactId>
+ <version>${guice.version}</version>
+ </dependency>
<!-- Google Guice Integration Test Injectors -->
@@ -102,7 +105,6 @@
<scope>test</scope>
</dependency>
-
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>testutils</artifactId>
@@ -111,10 +113,10 @@
</dependency>
<dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
- <version>1.9.5</version>
- <scope>test</scope>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.9.5</version>
+ <scope>test</scope>
</dependency>
</dependencies>
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/CollectionContextImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/CollectionContextImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/CollectionContextImpl.java
deleted file mode 100644
index 1aef1d3..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/CollectionContextImpl.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package org.apache.usergrid.persistence.collection;
-
-
-import java.util.UUID;
-
-import com.google.common.base.Preconditions;
-
-
-/**
- * Simple impl of hte collection context
- * @author tnine
- */
-public class CollectionContextImpl implements CollectionContext {
-
- private final UUID applicationId;
- private final UUID ownerId;
- private final String name;
-
-
- public CollectionContextImpl( final UUID applicationId, final UUID ownerId, final String name ) {
- Preconditions.checkNotNull( applicationId , "applicationId is required");
- Preconditions.checkNotNull( ownerId , "ownerId is required");
- Preconditions.checkNotNull( name , "name is required");
- Preconditions.checkArgument( name.length() > 0, "name must have a length" );
-
-
- this.applicationId = applicationId;
- this.ownerId = ownerId;
- this.name = name;
- }
-
-
- @Override
- public UUID getApplication() {
- return applicationId;
- }
-
-
- @Override
- public UUID getOwner() {
- return ownerId;
- }
-
-
- @Override
- public String getName() {
- return name;
- }
-
-
- @Override
- public boolean equals( final Object o ) {
- if ( this == o ) {
- return true;
- }
- if ( o == null || getClass() != o.getClass() ) {
- return false;
- }
-
- final CollectionContextImpl that = ( CollectionContextImpl ) o;
-
- if ( !applicationId.equals( that.applicationId ) ) {
- return false;
- }
- if ( !name.equals( that.name ) ) {
- return false;
- }
- if ( !ownerId.equals( that.ownerId ) ) {
- return false;
- }
-
- return true;
- }
-
-
- @Override
- public int hashCode() {
- int result = applicationId.hashCode();
- result = 31 * result + ownerId.hashCode();
- result = 31 * result + name.hashCode();
- return result;
- }
-
-
- @Override
- public String toString() {
- return "CollectionContextImpl{" +
- "applicationId=" + applicationId +
- ", ownerId=" + ownerId +
- ", name='" + name + '\'' +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/CollectionManager.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/CollectionManager.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/CollectionManager.java
index 570a1e4..53c14d6 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/CollectionManager.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/CollectionManager.java
@@ -20,14 +20,14 @@ public interface CollectionManager
*
* @param entity The entity to update
*/
- public void create( Entity entity );
+ public Entity create( Entity entity );
/**
* Update the entity with the given fields.
*
* @param entity The entity properties to update
*/
- public void update( Entity entity );
+ public Entity update( Entity entity );
/** Delete the entity and remove it's indexes with the given entity id */
public void delete( UUID entityId );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/CollectionManagerFactoryImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/CollectionManagerFactoryImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/CollectionManagerFactoryImpl.java
deleted file mode 100644
index 3ce0e7b..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/CollectionManagerFactoryImpl.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package org.apache.usergrid.persistence.collection;
-
-
-/**
- * Basic Imple
- * @author tnine
- */
-public class CollectionManagerFactoryImpl implements CollectionManagerFactory {
-
-
- @Override
- public CollectionManager createCollectionManager( final CollectionContext context ) {
-// return new CollectionManagerImpl( context );
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/CollectionManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/CollectionManagerImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/CollectionManagerImpl.java
deleted file mode 100644
index b5f0afb..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/CollectionManagerImpl.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package org.apache.usergrid.persistence.collection;
-
-
-import java.util.UUID;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.commons.beanutils.BeanUtils;
-
-import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntityImpl;
-import org.apache.usergrid.persistence.model.entity.Entity;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-
-
-/**
- * Simple implementation. Should perform
- * @author tnine
- */
-public class CollectionManagerImpl implements CollectionManager {
-
- private static final Logger logger = LoggerFactory.getLogger(CollectionManagerImpl.class);
-
- private final CollectionContext context;
- private final TimeService timeService;
-
-
-
- public CollectionManagerImpl( final CollectionContext context, final TimeService timeService ) {
- this.context = context;
- this.timeService = timeService;
- }
-
-
- @Override
- public void create( final Entity entity ) {
-
- final UUID entityId = UUIDGenerator.newTimeUUID();
- final UUID version = entityId;
- final long created = timeService.getTime();
-
-
- try {
- BeanUtils.setProperty(entity, "uuid", entityId);
- }
- catch ( Throwable t ) {
- logger.error( "Unable to set uuid. See nested exception", t );
- throw new RuntimeException( "Unable to set uuid. See nested exception", t );
- }
-
- entity.setVersion( version );
- entity.setCreated( created );
- entity.setUpdated( created );
-
- MvccEntityImpl mvccEntity = new MvccEntityImpl(context, entityId, version, entity );
-
-
-
- }
-
-
- @Override
- public void update( final Entity entity ) {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
-
- @Override
- public void delete( final UUID entityId ) {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
-
- @Override
- public Entity load( final UUID entityId ) {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/TimeService.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/TimeService.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/TimeService.java
deleted file mode 100644
index eea1e36..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/TimeService.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package org.apache.usergrid.persistence.collection;
-
-
-/** @author tnine */
-public interface TimeService {
-
- /**
- * Get the current time in milliseconds since epoch
- * @return
- */
- long getTime();
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/exception/CollectionRuntimeException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/exception/CollectionRuntimeException.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/exception/CollectionRuntimeException.java
new file mode 100644
index 0000000..9696bc1
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/exception/CollectionRuntimeException.java
@@ -0,0 +1,29 @@
+package org.apache.usergrid.persistence.collection.exception;
+
+
+/** @author tnine */
+public class CollectionRuntimeException extends RuntimeException {
+ public CollectionRuntimeException() {
+ }
+
+
+ public CollectionRuntimeException( final String message ) {
+ super( message );
+ }
+
+
+ public CollectionRuntimeException( final String message, final Throwable cause ) {
+ super( message, cause );
+ }
+
+
+ public CollectionRuntimeException( final Throwable cause ) {
+ super( cause );
+ }
+
+
+ public CollectionRuntimeException( final String message, final Throwable cause, final boolean enableSuppression,
+ final boolean writableStackTrace ) {
+ super( message, cause, enableSuppression, writableStackTrace );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
index 5f5d544..80f48d7 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/guice/CollectionModule.java
@@ -1,24 +1,15 @@
package org.apache.usergrid.persistence.collection.guice;
+import java.util.Properties;
+
import org.apache.usergrid.persistence.collection.astynax.AstynaxKeyspaceProvider;
-import org.apache.usergrid.persistence.collection.migration.Migration;
-import org.apache.usergrid.persistence.collection.migration.MigrationManager;
-import org.apache.usergrid.persistence.collection.migration.MigrationManagerImpl;
-import org.apache.usergrid.persistence.collection.mvcc.stage.StagePipeline;
-import org.apache.usergrid.persistence.collection.mvcc.stage.impl.CreatePipeline;
-import org.apache.usergrid.persistence.collection.mvcc.stage.impl.DeletePipeline;
-import org.apache.usergrid.persistence.collection.mvcc.stage.impl.UpdatePipeline;
-import org.apache.usergrid.persistence.collection.serialization.MvccEntitySerializationStrategy;
-import org.apache.usergrid.persistence.collection.serialization.MvccEntitySerializationStrategyImpl;
-import org.apache.usergrid.persistence.collection.serialization.MvccLogEntrySerializationStrategy;
-import org.apache.usergrid.persistence.collection.serialization.MvccLogEntrySerializationStrategyImpl;
+import org.apache.usergrid.persistence.collection.mvcc.stage.impl.CollectionPipelineModule;
+import org.apache.usergrid.persistence.collection.serialization.impl.SerializationModule;
+import org.apache.usergrid.persistence.collection.service.impl.ServiceModule;
import com.google.inject.AbstractModule;
-import com.google.inject.Provides;
-import com.google.inject.multibindings.Multibinder;
import com.google.inject.name.Names;
-import com.netflix.astyanax.Keyspace;
/**
@@ -35,56 +26,33 @@ public class CollectionModule extends AbstractModule {
@Override
protected void configure() {
+ /**
+ * Load our properties for the entire colleciton module
+ *
+ */
//bind our cassandra properties
- Names.bindProperties( binder(), PropertyUtils.loadFromClassPath( CASS_PROPS ) );
+
+ Properties props = PropertyUtils.loadFromClassPath( CASS_PROPS );
+
+ Names.bindProperties( binder(), props );
//Load the cassandra url if set on the system properties
Names.bindProperties( binder(),
PropertyUtils.loadSystemProperties( AstynaxKeyspaceProvider.getRuntimeOptions() ) );
- //bind our keyspace to the AstynaxKeyspaceProvider
- bind( Keyspace.class ).toProvider( AstynaxKeyspaceProvider.class );
-
- //bind our migration manager
- bind( MigrationManager.class ).to( MigrationManagerImpl.class );
-
-
- //bind the serialization strategies
-
- bind( MvccEntitySerializationStrategy.class ).to( MvccEntitySerializationStrategyImpl.class );
-
- bind( MvccLogEntrySerializationStrategy.class ).to( MvccLogEntrySerializationStrategyImpl.class );
+ //TODO allow override of all properties in the file by the system
- //do multibindings for migrations
- Multibinder<Migration> uriBinder = Multibinder.newSetBinder( binder(), Migration.class );
-
- uriBinder.addBinding().to( MvccEntitySerializationStrategyImpl.class );
- uriBinder.addBinding().to( MvccLogEntrySerializationStrategyImpl.class );
- }
-
-
- /** Wire the pipeline of operations for create. This should create a new
- * instance every time, since StagePipeline objects are mutable */
- @Provides
- @CreatePipeline
- public StagePipeline createWritePipeline() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
-
-
- @Provides
- @DeletePipeline
- public StagePipeline deletePipeline() {
- return null; //To change body of created methods use File | Settings | File Templates.
- }
+ /**
+ * Install the write pipeline configuration
+ */
+ install( new CollectionPipelineModule() );
+ //Install serialization modules
+ install( new SerializationModule());
- @Provides
- @UpdatePipeline
- public StagePipeline updatePipeline() {
- return null; //To change body of created methods use File | Settings | File Templates.
+ install (new ServiceModule());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/CollectionContextImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/CollectionContextImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/CollectionContextImpl.java
new file mode 100644
index 0000000..5f2d334
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/CollectionContextImpl.java
@@ -0,0 +1,95 @@
+package org.apache.usergrid.persistence.collection.impl;
+
+
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.collection.CollectionContext;
+
+import com.google.common.base.Preconditions;
+
+
+/**
+ * Simple impl of hte collection context
+ * @author tnine
+ */
+public class CollectionContextImpl implements CollectionContext {
+
+ private final UUID applicationId;
+ private final UUID ownerId;
+ private final String name;
+
+
+ public CollectionContextImpl( final UUID applicationId, final UUID ownerId, final String name ) {
+ Preconditions.checkNotNull( applicationId , "applicationId is required");
+ Preconditions.checkNotNull( ownerId , "ownerId is required");
+ Preconditions.checkNotNull( name , "name is required");
+ Preconditions.checkArgument( name.length() > 0, "name must have a length" );
+
+
+ this.applicationId = applicationId;
+ this.ownerId = ownerId;
+ this.name = name;
+ }
+
+
+ @Override
+ public UUID getApplication() {
+ return applicationId;
+ }
+
+
+ @Override
+ public UUID getOwner() {
+ return ownerId;
+ }
+
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+
+ @Override
+ public boolean equals( final Object o ) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+
+ final CollectionContextImpl that = ( CollectionContextImpl ) o;
+
+ if ( !applicationId.equals( that.applicationId ) ) {
+ return false;
+ }
+ if ( !name.equals( that.name ) ) {
+ return false;
+ }
+ if ( !ownerId.equals( that.ownerId ) ) {
+ return false;
+ }
+
+ return true;
+ }
+
+
+ @Override
+ public int hashCode() {
+ int result = applicationId.hashCode();
+ result = 31 * result + ownerId.hashCode();
+ result = 31 * result + name.hashCode();
+ return result;
+ }
+
+
+ @Override
+ public String toString() {
+ return "CollectionContextImpl{" +
+ "applicationId=" + applicationId +
+ ", ownerId=" + ownerId +
+ ", name='" + name + '\'' +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/CollectionManagerFactoryImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/CollectionManagerFactoryImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/CollectionManagerFactoryImpl.java
new file mode 100644
index 0000000..2ab0761
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/CollectionManagerFactoryImpl.java
@@ -0,0 +1,21 @@
+package org.apache.usergrid.persistence.collection.impl;
+
+
+import org.apache.usergrid.persistence.collection.CollectionContext;
+import org.apache.usergrid.persistence.collection.CollectionManager;
+import org.apache.usergrid.persistence.collection.CollectionManagerFactory;
+
+
+/**
+ * Basic Imple
+ * @author tnine
+ */
+public class CollectionManagerFactoryImpl implements CollectionManagerFactory {
+
+
+ @Override
+ public CollectionManager createCollectionManager( final CollectionContext context ) {
+// return new CollectionManagerImpl( context );
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/CollectionManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/CollectionManagerImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/CollectionManagerImpl.java
new file mode 100644
index 0000000..72ed6ce
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/CollectionManagerImpl.java
@@ -0,0 +1,77 @@
+package org.apache.usergrid.persistence.collection.impl;
+
+
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.usergrid.persistence.collection.CollectionContext;
+import org.apache.usergrid.persistence.collection.CollectionManager;
+import org.apache.usergrid.persistence.collection.service.TimeService;
+import org.apache.usergrid.persistence.collection.mvcc.stage.WriteContext;
+import org.apache.usergrid.persistence.collection.mvcc.stage.WriteContextFactory;
+import org.apache.usergrid.persistence.model.entity.Entity;
+
+import com.google.inject.Inject;
+import com.google.inject.assistedinject.Assisted;
+
+
+/**
+ * Simple implementation. Should perform
+ *
+ * @author tnine
+ */
+public class CollectionManagerImpl implements CollectionManager {
+
+ private static final Logger logger = LoggerFactory.getLogger( CollectionManagerImpl.class );
+
+ private final CollectionContext context;
+ private final TimeService timeService;
+ private final WriteContextFactory factory;
+
+
+ @Inject
+ public CollectionManagerImpl( final TimeService timeService, final WriteContextFactory factory,
+ @Assisted final CollectionContext context ) {
+ this.context = context;
+ this.timeService = timeService;
+ this.factory = factory;
+ }
+
+
+ @Override
+ public Entity create( final Entity entity ) {
+ // Create a new context for the write
+ WriteContext writeContext = factory.newCreateContext( context );
+
+ //perform the write
+ writeContext.performWrite( entity );
+
+ //TODO this shouldn't block, give a callback
+ return writeContext.getMessage( Entity.class );
+
+ }
+
+
+ @Override
+ public Entity update( final Entity entity ) {
+ return null;
+ }
+
+
+ @Override
+ public void delete( final UUID entityId ) {
+ WriteContext deleteContext = factory.newDeleteContext(context);
+
+ deleteContext.performWrite( entityId );
+
+ deleteContext.getMessage(Void.class);
+ }
+
+
+ @Override
+ public Entity load( final UUID entityId ) {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccEntity.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccEntity.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccEntity.java
index 3e544ad..cc212c8 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccEntity.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccEntity.java
@@ -31,8 +31,4 @@ public interface MvccEntity {
*/
UUID getUuid();
- /**
- * Get the collection context this entity belongs i
- */
- CollectionContext getContext();
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccEntityImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccEntityImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccEntityImpl.java
deleted file mode 100644
index b85b314..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccEntityImpl.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package org.apache.usergrid.persistence.collection.mvcc.entity;
-
-
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.collection.CollectionContext;
-import org.apache.usergrid.persistence.model.entity.Entity;
-
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-
-
-/** @author tnine */
-public class MvccEntityImpl implements MvccEntity {
-
- private final CollectionContext context;
- private final UUID entityId;
- private final UUID version;
- private final Optional<Entity> entity;
-
-
- public MvccEntityImpl( final CollectionContext context, final UUID entityId, final UUID version,
- final Entity entity ) {
- this( context, entityId, version, Optional.of( entity ) );
- }
-
-
- public MvccEntityImpl( final CollectionContext context, final UUID entityId, final UUID version,
- final Optional<Entity> entity ) {
- Preconditions.checkNotNull( context, "context is required" );
- Preconditions.checkNotNull( entityId, "entity id is required" );
- Preconditions.checkNotNull( version, "version id is required" );
- Preconditions.checkNotNull( entity, "entity is required" );
-
- this.context = context;
- this.entityId = entityId;
- this.version = version;
- this.entity = entity;
- }
-
-
- @Override
- public Optional<Entity> getEntity() {
- return entity;
- }
-
-
- @Override
- public UUID getVersion() {
- return version;
- }
-
-
- @Override
- public UUID getUuid() {
- return entityId;
- }
-
-
- @Override
- public CollectionContext getContext() {
- return context;
- }
-
-
- @Override
- public boolean equals( final Object o ) {
- if ( this == o ) {
- return true;
- }
- if ( o == null || getClass() != o.getClass() ) {
- return false;
- }
-
- final MvccEntityImpl that = ( MvccEntityImpl ) o;
-
- if ( !context.equals( that.context ) ) {
- return false;
- }
- if ( !getUuid().equals( that.getUuid() ) ) {
- return false;
- }
-
- if ( !getVersion().equals( that.getVersion() ) ) {
- return false;
- }
-
- return true;
- }
-
-
- @Override
- public int hashCode() {
- int result = context.hashCode();
- result = 31 * result + getUuid().hashCode();
- result = 31 * result + getVersion().hashCode();
- return result;
- }
-
-
- @Override
- public String toString() {
- return "MvccEntityImpl{" +
- "context=" + context +
- ", entityId=" + entityId +
- ", version=" + version +
- ", entity=" + entity +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccLogEntry.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccLogEntry.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccLogEntry.java
index 40ff498..c6886d1 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccLogEntry.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccLogEntry.java
@@ -29,10 +29,5 @@ public interface MvccLogEntry {
*/
UUID getVersion();
- /**
- * Get the context of the entity
- * @return
- */
- CollectionContext getContext();
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccLogEntryImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccLogEntryImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccLogEntryImpl.java
deleted file mode 100644
index 91e68ef..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/MvccLogEntryImpl.java
+++ /dev/null
@@ -1,113 +0,0 @@
-package org.apache.usergrid.persistence.collection.mvcc.entity;
-
-
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.collection.CollectionContext;
-
-import com.google.common.base.Preconditions;
-
-
-/**
- * The simple implementation of a log entry
- *
- * @author tnine
- */
-public class MvccLogEntryImpl implements MvccLogEntry {
-
- private final CollectionContext context;
- private final UUID entityId;
- private final UUID version;
- private final Stage stage;
-
-
- public MvccLogEntryImpl( final CollectionContext context, final UUID entityId, final UUID version,
- final Stage stage ) {
-
- Preconditions.checkNotNull( context, "context is required" );
- Preconditions.checkNotNull( entityId, "entity id is required" );
- Preconditions.checkNotNull( version, "version id is required" );
- Preconditions.checkNotNull( stage, "entity is required" );
-
-
- this.context = context;
- this.entityId = entityId;
- this.version = version;
- this.stage = stage;
- }
-
-
- @Override
- public Stage getStage() {
- return stage;
- }
-
-
- @Override
- public UUID getEntityId() {
- return entityId;
- }
-
-
- @Override
- public UUID getVersion() {
- return version;
- }
-
-
- @Override
- public CollectionContext getContext() {
- return context;
- }
-
-
- @Override
- public boolean equals( final Object o ) {
- if ( this == o ) {
- return true;
- }
- if ( o == null || getClass() != o.getClass() ) {
- return false;
- }
-
- final MvccLogEntryImpl that = ( MvccLogEntryImpl ) o;
-
- if ( !context.equals( that.context ) ) {
- return false;
- }
- if ( !entityId.equals( that.entityId ) ) {
- return false;
- }
- if ( !version.equals( that.version ) ) {
- return false;
- }
-
- if ( stage != that.stage ) {
- return false;
- }
-
-
- return true;
- }
-
-
- @Override
- public int hashCode() {
- int result = context.hashCode();
- result = 31 * result + entityId.hashCode();
- result = 31 * result + version.hashCode();
- result = 31 * result + stage.hashCode();
- return result;
- }
-
-
- @Override
- public String toString() {
- return "MvccLogEntryImpl{" +
- "context=" + context +
- ", entityId=" + entityId +
- ", version=" + version +
- ", stage=" + stage +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
new file mode 100644
index 0000000..1179dad
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
@@ -0,0 +1,98 @@
+package org.apache.usergrid.persistence.collection.mvcc.entity.impl;
+
+
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.collection.CollectionContext;
+import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
+import org.apache.usergrid.persistence.model.entity.Entity;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+
+
+/** @author tnine */
+public class MvccEntityImpl implements MvccEntity {
+
+ private final UUID entityId;
+ private final UUID version;
+ private final Optional<Entity> entity;
+
+
+ public MvccEntityImpl( final UUID entityId, final UUID version,
+ final Entity entity ) {
+ this( entityId, version, Optional.of( entity ) );
+ }
+
+
+ public MvccEntityImpl( final UUID entityId, final UUID version,
+ final Optional<Entity> entity ) {
+ Preconditions.checkNotNull( entityId, "entity id is required" );
+ Preconditions.checkNotNull( version, "version id is required" );
+ Preconditions.checkNotNull( entity, "entity is required" );
+
+ this.entityId = entityId;
+ this.version = version;
+ this.entity = entity;
+ }
+
+
+ @Override
+ public Optional<Entity> getEntity() {
+ return entity;
+ }
+
+
+ @Override
+ public UUID getVersion() {
+ return version;
+ }
+
+
+ @Override
+ public UUID getUuid() {
+ return entityId;
+ }
+
+
+
+ @Override
+ public boolean equals( final Object o ) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+
+ final MvccEntityImpl that = ( MvccEntityImpl ) o;
+
+ if ( !getUuid().equals( that.getUuid() ) ) {
+ return false;
+ }
+
+ if ( !getVersion().equals( that.getVersion() ) ) {
+ return false;
+ }
+
+ return true;
+ }
+
+
+ @Override
+ public int hashCode() {
+ int result = 31 * getUuid().hashCode();
+ result = 31 * result + getVersion().hashCode();
+ return result;
+ }
+
+
+ @Override
+ public String toString() {
+ return "MvccEntityImpl{" +
+ ", entityId=" + entityId +
+ ", version=" + version +
+ ", entity=" + entity +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccLogEntryImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccLogEntryImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccLogEntryImpl.java
new file mode 100644
index 0000000..2f0b4d7
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccLogEntryImpl.java
@@ -0,0 +1,100 @@
+package org.apache.usergrid.persistence.collection.mvcc.entity.impl;
+
+
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.collection.CollectionContext;
+import org.apache.usergrid.persistence.collection.mvcc.entity.MvccLogEntry;
+import org.apache.usergrid.persistence.collection.mvcc.entity.Stage;
+
+import com.google.common.base.Preconditions;
+
+
+/**
+ * The simple implementation of a log entry
+ *
+ * @author tnine
+ */
+public class MvccLogEntryImpl implements MvccLogEntry {
+
+ private final UUID entityId;
+ private final UUID version;
+ private final Stage stage;
+
+
+ public MvccLogEntryImpl( final UUID entityId, final UUID version,
+ final Stage stage ) {
+ Preconditions.checkNotNull( entityId, "entity id is required" );
+ Preconditions.checkNotNull( version, "version id is required" );
+ Preconditions.checkNotNull( stage, "entity is required" );
+
+
+ this.entityId = entityId;
+ this.version = version;
+ this.stage = stage;
+ }
+
+
+ @Override
+ public Stage getStage() {
+ return stage;
+ }
+
+
+ @Override
+ public UUID getEntityId() {
+ return entityId;
+ }
+
+
+ @Override
+ public UUID getVersion() {
+ return version;
+ }
+
+
+ @Override
+ public boolean equals( final Object o ) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+
+ final MvccLogEntryImpl that = ( MvccLogEntryImpl ) o;
+
+ if ( !entityId.equals( that.entityId ) ) {
+ return false;
+ }
+ if ( !version.equals( that.version ) ) {
+ return false;
+ }
+
+ if ( stage != that.stage ) {
+ return false;
+ }
+
+
+ return true;
+ }
+
+
+ @Override
+ public int hashCode() {
+ int result = 31 * entityId.hashCode();
+ result = 31 * result + version.hashCode();
+ result = 31 * result + stage.hashCode();
+ return result;
+ }
+
+
+ @Override
+ public String toString() {
+ return "MvccLogEntryImpl{" +
+ ", entityId=" + entityId +
+ ", version=" + version +
+ ", stage=" + stage +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/event/PostProcessListener.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/event/PostProcessListener.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/event/PostProcessListener.java
index 47ad997..29e6515 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/event/PostProcessListener.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/event/PostProcessListener.java
@@ -9,16 +9,16 @@ import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
* @author: tnine
*
*/
-public interface PostProcessListener<T extends MvccEntity>
+public interface PostProcessListener<T>
{
/**
* The entity was rejected by the MVCC system and will be removed
*
- * @param mvccEntity The mvcc entity to perform post processing on
+ * @param data The data used in the write pipeline
* @return the MvccEntity to use during this stage
*/
- public MvccEntity doPostProcessing(MvccEntity mvccEntity );
+ public T doPostProcessing(T data );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/MvccStrategy.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/MvccStrategy.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/MvccStrategy.java
deleted file mode 100644
index c11f420..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/MvccStrategy.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package org.apache.usergrid.persistence.collection.mvcc.stage;
-
-
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.collection.CollectionContext;
-import org.apache.usergrid.persistence.model.entity.Entity;
-
-
-/**
- * Interface to define mvcc operations
- *
- * TODO: Not sure we need this any more
- */
-public interface MvccStrategy {
-
- /**
- * Start progress through states for this entity
- *
- * @param context The context this entity belongs in
- * @param entityId The entity id to assign to this entity
- * @param entity The entity values to write
- */
- public WriteStage beingWrite( CollectionContext context, UUID entityId, Entity entity );
-
-
- /**
- * Get the current stage of the entity in the context at the current version. Should be used for write verification
- * on resume
- *
- * @param context The context this entity belongs in
- * @param entityId The entity Id to search for in the context
- * @param version The version of the entityId to review
- */
- public WriteStage getCurrentState( CollectionContext context, UUID entityId, UUID version );
-
-
- /**
- * Get the write stage of the entity in the context with a version <= the current version and a stage of Comitted
- */
- public WriteStage getCurrentStateOfEntity( CollectionContext context, UUID entityId, UUID maxVersion );
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/StagePipeline.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/StagePipeline.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/StagePipeline.java
index 562d852..7e88915 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/StagePipeline.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/StagePipeline.java
@@ -11,9 +11,9 @@ public interface StagePipeline {
/**
- * Get the next stage in this pipeline. Will return null if there are no more stages to execute
+ * Get the first stage in this pipeline. Will return null if there are no more stages to execute
*/
- public WriteStage next();
+ WriteStage first();
/**
@@ -22,15 +22,34 @@ public interface StagePipeline {
*
* @param stage
*/
- public void insert(WriteStage stage);
+ void insert(WriteStage stage);
/**
* Add a new stage to the end of the pipline
* @param stage
*/
- public void addLast(WriteStage stage);
+ void addLast(WriteStage stage);
+ /**
+ * get the next stage after this one
+ * @param stage
+ */
+ WriteStage nextStage(WriteStage stage);
+
+
+ /**
+ * Get the last stage in this pipeline
+ * @return
+ */
+ WriteStage last();
+
+ /**
+ * Get the current stage in the pipeline
+ * @return
+ */
+ WriteStage current();
+
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/WriteContext.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/WriteContext.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/WriteContext.java
index 42cb6ab..4f5d82a 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/WriteContext.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/WriteContext.java
@@ -1,7 +1,12 @@
package org.apache.usergrid.persistence.collection.mvcc.stage;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.usergrid.persistence.collection.CollectionContext;
import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
+import org.apache.usergrid.persistence.collection.mvcc.event.PostProcessListener;
/** @author tnine */
@@ -16,9 +21,46 @@ public interface WriteContext {
/**
* Perform the write in the context with the specified entity
- * @param entity
+ * @param inputData The data to use to being the write
+ */
+ void performWrite(Object inputData);
+
+
+ /**
+ * Get the current message. If the message is not the right type at runtime, an assertion exception will be thrown
+ * @return
+ */
+ <T> T getMessage(Class<T> clazz);
+
+ /**
+ * Set the message into the write context
+ * @return
+ */
+ Object setMessage(Object object);
+
+
+ /**
+ * Signal that the next stage in the write should proceed
+ */
+ void proceed();
+
+ /**
+ * Signal we should stop processing
+ */
+ void stop();
+
+
+ /**
+ * Add a post process listener to this write context
+ * @return A list of all post proces
+ */
+ Collection<PostProcessListener> getPostProcessors();
+
+ /**
+ * Return the current collection context
+ * @return
*/
- void nextStage(MvccEntity entity);
+ CollectionContext getCollectionContext();
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/WriteContextFactory.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/WriteContextFactory.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/WriteContextFactory.java
new file mode 100644
index 0000000..99da0fb
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/WriteContextFactory.java
@@ -0,0 +1,30 @@
+package org.apache.usergrid.persistence.collection.mvcc.stage;
+
+
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.collection.CollectionContext;
+import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
+import org.apache.usergrid.persistence.model.entity.Entity;
+
+
+/** @author tnine */
+public interface WriteContextFactory {
+
+ /**
+ * Return a new write context for the given stage pipeline
+ * @param
+ * @return A write context that can be used for creating entities. Returns the new entity to use after
+ * the write has completed
+ */
+ WriteContext newCreateContext(CollectionContext context);
+
+ /**
+ * Create a write context that cna be used for deleting entitie
+ * @return
+ */
+ WriteContext newDeleteContext(CollectionContext context);
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/WriteStage.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/WriteStage.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/WriteStage.java
index a45df6b..3f80348 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/WriteStage.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/WriteStage.java
@@ -9,17 +9,18 @@ import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
/**
* The possible stages in our write flow.
*/
-public interface WriteStage {
+public interface WriteStage{
/**
* Run this stage. This will return the MvccEntity that should be returned or passed to the next stage
*
*
* @param context The context of the current write operation
- * @param entity The entity to use in this stage
*
* @return The asynchronous listener to signal success
*
*/
- public void performStage( WriteContext context, MvccEntity entity ) throws ConnectionException;
+ public void performStage( WriteContext context);
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/CollectionPipelineModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/CollectionPipelineModule.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/CollectionPipelineModule.java
index 809d92f..16735ca 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/CollectionPipelineModule.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/CollectionPipelineModule.java
@@ -1,13 +1,20 @@
package org.apache.usergrid.persistence.collection.mvcc.stage.impl;
+import org.apache.usergrid.persistence.collection.migration.Migration;
+import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
import org.apache.usergrid.persistence.collection.mvcc.stage.StagePipeline;
+import org.apache.usergrid.persistence.collection.mvcc.stage.WriteStage;
import org.apache.usergrid.persistence.collection.serialization.MvccEntitySerializationStrategy;
import org.apache.usergrid.persistence.collection.serialization.MvccLogEntrySerializationStrategy;
+import org.apache.usergrid.persistence.collection.serialization.impl.MvccEntitySerializationStrategyImpl;
+import org.apache.usergrid.persistence.collection.serialization.impl.MvccLogEntrySerializationStrategyImpl;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Provides;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
+import com.google.inject.multibindings.Multibinder;
/**
@@ -17,38 +24,37 @@ import com.google.inject.Provides;
*/
public class CollectionPipelineModule extends AbstractModule {
- @Inject
- private MvccLogEntrySerializationStrategy mvccLogEntrySerializationStrategy;
-
- @Inject
- private MvccEntitySerializationStrategy mvccEntitySerializationStrategy;
-
/** Wire the pipeline of operations for create. This should create a new
* instance every time, since StagePipeline objects are mutable */
@Provides
@CreatePipeline
- public StagePipeline createWritePipeline() {
- return StagePipelineImpl.fromStages( new Start( mvccLogEntrySerializationStrategy ), new Write(), new Commit() );
+ @Inject
+ public StagePipeline createWritePipeline(MvccEntityNew start, MvccEntityWrite write, MvccEntityCommit commit) {
+ return StagePipelineImpl.fromStages(start, write, commit );
}
@Provides
@DeletePipeline
public StagePipeline deletePipeline() {
- return null; //To change body of created methods use File | Settings | File Templates.
+ return StagePipelineImpl.fromStages( );
}
- @Provides
- @UpdatePipeline
- public StagePipeline updatePipeline() {
- return createWritePipeline();
- }
-
@Override
protected void configure() {
- //no op, we get our values from the provides above
+
+ /**
+ * Configure all stages here
+ */
+ Multibinder<WriteStage> stageBinder = Multibinder.newSetBinder( binder(), WriteStage.class );
+
+ stageBinder.addBinding().to( MvccEntityNew.class );
+ stageBinder.addBinding().to( MvccEntityWrite.class );
+ stageBinder.addBinding().to( MvccEntityCommit.class );
+
+
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/Commit.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/Commit.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/Commit.java
deleted file mode 100644
index 378e649..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/Commit.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package org.apache.usergrid.persistence.collection.mvcc.stage.impl;
-
-
-import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
-import org.apache.usergrid.persistence.collection.mvcc.stage.WriteContext;
-import org.apache.usergrid.persistence.collection.mvcc.stage.WriteStage;
-
-import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
-
-
-/**
- * This phase should invoke any finalization, and mark the entity as committed in the data store before returning
- */
-public class Commit implements WriteStage {
-
- public Commit(){
-
- }
-
- @Override
- public void performStage( final WriteContext context, final MvccEntity entity ) throws ConnectionException {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/MvccEntityCommit.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/MvccEntityCommit.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/MvccEntityCommit.java
new file mode 100644
index 0000000..88bfca6
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/MvccEntityCommit.java
@@ -0,0 +1,28 @@
+package org.apache.usergrid.persistence.collection.mvcc.stage.impl;
+
+
+import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
+import org.apache.usergrid.persistence.collection.mvcc.stage.WriteContext;
+import org.apache.usergrid.persistence.collection.mvcc.stage.WriteStage;
+
+import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+
+
+/**
+ * This phase should invoke any finalization, and mark the entity as committed in the data store before returning
+ */
+public class MvccEntityCommit implements WriteStage {
+
+ public MvccEntityCommit(){
+
+ }
+
+
+ @Override
+ public void performStage( final WriteContext context ) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/MvccEntityNew.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/MvccEntityNew.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/MvccEntityNew.java
new file mode 100644
index 0000000..576394a
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/MvccEntityNew.java
@@ -0,0 +1,116 @@
+package org.apache.usergrid.persistence.collection.mvcc.stage.impl;
+
+
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.commons.lang3.reflect.FieldUtils;
+
+import org.apache.usergrid.persistence.collection.CollectionContext;
+import org.apache.usergrid.persistence.collection.service.TimeService;
+import org.apache.usergrid.persistence.collection.exception.CollectionRuntimeException;
+import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
+import org.apache.usergrid.persistence.collection.mvcc.entity.MvccLogEntry;
+import org.apache.usergrid.persistence.collection.mvcc.entity.Stage;
+import org.apache.usergrid.persistence.collection.mvcc.entity.impl.MvccEntityImpl;
+import org.apache.usergrid.persistence.collection.mvcc.entity.impl.MvccLogEntryImpl;
+import org.apache.usergrid.persistence.collection.mvcc.stage.WriteContext;
+import org.apache.usergrid.persistence.collection.mvcc.stage.WriteStage;
+import org.apache.usergrid.persistence.collection.serialization.MvccLogEntrySerializationStrategy;
+import org.apache.usergrid.persistence.collection.service.UUIDService;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.inject.Inject;
+import com.netflix.astyanax.MutationBatch;
+import com.netflix.astyanax.connectionpool.OperationResult;
+import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+
+
+/**
+ * This is the first stage and should be invoked immediately when a write is started. It should persist the start of a
+ * new write in the data store for a checkpoint and recovery
+ */
+public class MvccEntityNew implements WriteStage {
+
+ private static final Logger LOG = LoggerFactory.getLogger( MvccEntityNew.class );
+
+ private final MvccLogEntrySerializationStrategy logStrategy;
+ private final TimeService timeService;
+ private final UUIDService uuidService;
+
+
+
+ /** Create a new stage with the current context */
+ @Inject
+ public MvccEntityNew( final MvccLogEntrySerializationStrategy logStrategy, final TimeService timeService,
+ final UUIDService uuidService ) {
+ this.logStrategy = logStrategy;
+ this.timeService = timeService;
+ this.uuidService = uuidService;
+ }
+
+
+ /**
+ * Create the entity Id and inject it, as well as set the timestamp versions
+ * @param writeContext The context of the current write operation
+ */
+ @Override
+ public void performStage( final WriteContext writeContext) {
+
+ final Entity entity = writeContext.getMessage(Entity.class);
+
+ Preconditions.checkNotNull( entity, "Entity is required in the new stage of the mvcc write" );
+
+
+ final UUID entityId = uuidService.newTimeUUID();
+ final UUID version = entityId;
+ final long created = timeService.getTime();
+
+
+ try {
+ FieldUtils.writeDeclaredField( entity, "uuid", entityId );
+ }
+ catch ( Throwable t ) {
+ LOG.error( "Unable to set uuid. See nested exception", t );
+ throw new CollectionRuntimeException( "Unable to set uuid. See nested exception", t );
+ }
+
+ entity.setVersion( version );
+ entity.setCreated( created );
+ entity.setUpdated( created );
+
+ final CollectionContext collectionContext = writeContext.getCollectionContext();
+
+
+ final MvccLogEntry startEntry = new MvccLogEntryImpl( entityId, version, Stage.ACTIVE );
+
+ MutationBatch write = logStrategy.write(collectionContext, startEntry );
+
+ ListenableFuture<OperationResult<Void>> future;
+
+ try {
+ future = write.executeAsync();
+ }
+ catch ( ConnectionException e ) {
+ LOG.error( "Failed to execute write asynchronously ", e );
+ throw new CollectionRuntimeException( "Failed to execute write asynchronously ", e );
+ }
+
+ //create the mvcc entity for the next stage
+ MvccEntityImpl nextStage = new MvccEntityImpl( entityId, version, entity );
+
+ writeContext.setMessage( nextStage );
+
+
+ //set the next stage to invoke on return
+ WriteContextCallback.createCallback( future, writeContext );
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/MvccEntityWrite.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/MvccEntityWrite.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/MvccEntityWrite.java
new file mode 100644
index 0000000..0e795db
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/MvccEntityWrite.java
@@ -0,0 +1,25 @@
+package org.apache.usergrid.persistence.collection.mvcc.stage.impl;
+
+
+import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
+import org.apache.usergrid.persistence.collection.mvcc.stage.WriteContext;
+import org.apache.usergrid.persistence.collection.mvcc.stage.WriteStage;
+
+
+/**
+ * This phase should execute the serialization to the data store.
+ */
+public class MvccEntityWrite implements WriteStage {
+
+ /**
+ * Create a new stage with the current context
+ */
+ public MvccEntityWrite( ){
+ }
+
+
+ @Override
+ public void performStage( final WriteContext context ) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/StagePipelineImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/StagePipelineImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/StagePipelineImpl.java
index b63769b..811b6eb 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/StagePipelineImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/StagePipelineImpl.java
@@ -5,35 +5,50 @@ import java.util.Arrays;
import java.util.List;
import org.apache.usergrid.persistence.collection.mvcc.stage.StagePipeline;
+import org.apache.usergrid.persistence.collection.mvcc.stage.WriteContext;
import org.apache.usergrid.persistence.collection.mvcc.stage.WriteStage;
/** @author tnine */
public class StagePipelineImpl implements StagePipeline {
- private int currentIndex = 0;
private final List<WriteStage> stages;
+ private WriteStage current;
protected StagePipelineImpl(WriteStage[] stages){
this.stages = Arrays.asList(stages);
}
@Override
- public WriteStage next() {
+ public WriteStage first() {
- if(currentIndex < stages.size()){
+ if(stages.size() == 0){
+ return null;
+ }
+
+ return stages.get( 0 );
+ }
- //get our current stage and increment
- return stages.get( currentIndex ++);
+
+ @Override
+ public WriteStage last() {
+ if(stages.size() == 0){
+ return null;
}
- return null;
+ return stages.get( stages.size()-1 );
+ }
+
+
+ @Override
+ public WriteStage current() {
+ return current;
}
@Override
public void insert( final WriteStage stage ) {
- throw new UnsupportedOperationException("This needs written");
+ throw new UnsupportedOperationException("This needs implemented");
}
@@ -44,6 +59,22 @@ public class StagePipelineImpl implements StagePipeline {
}
+ @Override
+ public WriteStage nextStage( final WriteStage stage ) {
+ int index = stages.indexOf( stage );
+
+ //we're done, do nothing
+ if(index == stages.size()){
+ return null;
+ }
+
+ current = stages.get( index+1 );
+
+ return current;
+ }
+
+
+
/**
* Factory to create a new instance.
* @param stages
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/Start.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/Start.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/Start.java
deleted file mode 100644
index d86276d..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/Start.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package org.apache.usergrid.persistence.collection.mvcc.stage.impl;
-
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
-import org.apache.usergrid.persistence.collection.mvcc.entity.MvccLogEntry;
-import org.apache.usergrid.persistence.collection.mvcc.entity.MvccLogEntryImpl;
-import org.apache.usergrid.persistence.collection.mvcc.entity.Stage;
-import org.apache.usergrid.persistence.collection.mvcc.stage.WriteContext;
-import org.apache.usergrid.persistence.collection.mvcc.stage.WriteStage;
-import org.apache.usergrid.persistence.collection.serialization.MvccLogEntrySerializationStrategy;
-
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import com.netflix.astyanax.MutationBatch;
-import com.netflix.astyanax.connectionpool.OperationResult;
-import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
-
-
-
-/**
- * This is the first stage and should be invoked immediately when a write is started. It should persist the start of a
- * new write in the data store for a checkpoint and recovery
- */
-@Singleton
-public class Start implements WriteStage {
-
- private static final Logger LOG = LoggerFactory.getLogger( Start.class );
-
- private final MvccLogEntrySerializationStrategy logStrategy;
- /**
- * Create a new stage with the current context
- * @param logStrategy
- */
- @Inject
- public Start( final MvccLogEntrySerializationStrategy logStrategy ){
- this.logStrategy = logStrategy;
- }
-
-
- @Override
- public void performStage(final WriteContext context, final MvccEntity entity ) {
- final MvccLogEntry startEntry = new MvccLogEntryImpl(entity.getContext(), entity.getUuid(), entity.getVersion(),Stage.ACTIVE);
-
- MutationBatch write = logStrategy.write( startEntry );
-
- ListenableFuture<OperationResult<Void>> future;
-
- try {
- future = write.executeAsync();
- }
- catch ( ConnectionException e ) {
- LOG.error( "Failed to execute write asynchronously ", e );
- throw new RuntimeException( "Failed to execute write asynchronously ", e );
- }
-
- //set the next stage to invoke on return
- Futures.addCallback(future, new WriteContextCallback(context, entity));
-
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/UpdatePipeline.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/UpdatePipeline.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/UpdatePipeline.java
deleted file mode 100644
index 556e92c..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/UpdatePipeline.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.apache.usergrid.persistence.collection.mvcc.stage.impl;
-
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import com.google.inject.BindingAnnotation;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-
-/**
- * Marks the update pipeline
- * @author tnine */
-@BindingAnnotation
-@Target({ FIELD, PARAMETER, METHOD }) @Retention(RUNTIME)
-public @interface UpdatePipeline {}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/Write.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/Write.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/Write.java
deleted file mode 100644
index b45ccd5..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/Write.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package org.apache.usergrid.persistence.collection.mvcc.stage.impl;
-
-
-import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
-import org.apache.usergrid.persistence.collection.mvcc.stage.WriteContext;
-import org.apache.usergrid.persistence.collection.mvcc.stage.WriteStage;
-
-
-/**
- * This phase should execute the serialization to the data store.
- */
-public class Write implements WriteStage {
-
- /**
- * Create a new stage with the current context
- */
- public Write( ){
- }
-
-
- @Override
- public void performStage(WriteContext context, final MvccEntity entity ) {
-
-
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/WriteContextCallback.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/WriteContextCallback.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/WriteContextCallback.java
index 0fa408a..e5ca9bd 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/WriteContextCallback.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/WriteContextCallback.java
@@ -1,34 +1,62 @@
package org.apache.usergrid.persistence.collection.mvcc.stage.impl;
+import org.apache.usergrid.persistence.collection.exception.CollectionRuntimeException;
import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
import org.apache.usergrid.persistence.collection.mvcc.stage.WriteContext;
+import org.apache.usergrid.persistence.collection.mvcc.stage.WriteStage;
import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
import com.netflix.astyanax.connectionpool.OperationResult;
-/** @author tnine */
+/**
+ * Helper class to cause the async execution to continue
+ * @author tnine */
public class WriteContextCallback implements FutureCallback<OperationResult<Void>> {
private final WriteContext context;
- private final MvccEntity entity;
- public WriteContextCallback( final WriteContext context, final MvccEntity entity ) {
+ /**
+ * Create a new callback. The data will be passed to the next stage
+ * @param context
+ */
+ private WriteContextCallback( final WriteContext context ) {
this.context = context;
- this.entity = entity;
}
public void onSuccess( final OperationResult<Void> result ) {
- //proceed to the next stage
- context.nextStage( entity );
+
+ /**
+ * Proceed to the next stage
+ */
+ context.proceed();
}
@Override
public void onFailure( final Throwable t ) {
- throw new RuntimeException( "Failed to execute write", t );
+ context.stop();
+ throw new CollectionRuntimeException( "Failed to execute write", t );
+ }
+
+
+ /**
+ * This encapsulated type of Void in the listenable future is intentional. If you're not returning
+ * void in your future, you shouldn't be using this callback, you should be using a callback
+ * that will set the Response value into the next stage and invoke it
+ *
+ * @param future The listenable future returned by the Astyanax async op
+ * @param context The context to signal to continue in the callback
+ */
+ public static void createCallback( final ListenableFuture<OperationResult<Void>> future,
+ final WriteContext context ) {
+
+ Futures.addCallback(future, new WriteContextCallback( context ));
+
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/WriteContextFactoryImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/WriteContextFactoryImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/WriteContextFactoryImpl.java
new file mode 100644
index 0000000..f9b627f
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/WriteContextFactoryImpl.java
@@ -0,0 +1,47 @@
+package org.apache.usergrid.persistence.collection.mvcc.stage.impl;
+
+
+import java.util.Collection;
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.collection.CollectionContext;
+import org.apache.usergrid.persistence.collection.mvcc.event.PostProcessListener;
+import org.apache.usergrid.persistence.collection.mvcc.stage.StagePipeline;
+import org.apache.usergrid.persistence.collection.mvcc.stage.WriteContext;
+import org.apache.usergrid.persistence.collection.mvcc.stage.WriteContextFactory;
+import org.apache.usergrid.persistence.model.entity.Entity;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+
+/** @author tnine */
+@Singleton
+public class WriteContextFactoryImpl implements WriteContextFactory {
+
+ private final StagePipeline writeStage;
+ private final StagePipeline deleteStage;
+ private final Collection<PostProcessListener> postProcessListener;
+
+
+ @Inject
+ public WriteContextFactoryImpl( @CreatePipeline final StagePipeline writeStage,
+ @DeletePipeline final StagePipeline deleteStage,
+ final Collection<PostProcessListener> postProcessListener ) {
+ this.writeStage = writeStage;
+ this.deleteStage = deleteStage;
+ this.postProcessListener = postProcessListener;
+ }
+
+
+ @Override
+ public WriteContext newCreateContext(CollectionContext context) {
+ return new WriteContextImpl( postProcessListener, writeStage, context );
+ }
+
+
+ @Override
+ public WriteContext newDeleteContext(CollectionContext context) {
+ return new WriteContextImpl( postProcessListener, deleteStage, context );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb9ec94e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/WriteContextImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/WriteContextImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/WriteContextImpl.java
new file mode 100644
index 0000000..cbddcd1
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/impl/WriteContextImpl.java
@@ -0,0 +1,111 @@
+package org.apache.usergrid.persistence.collection.mvcc.stage.impl;
+
+
+import java.util.Collection;
+
+import org.apache.usergrid.persistence.collection.CollectionContext;
+import org.apache.usergrid.persistence.collection.mvcc.event.PostProcessListener;
+import org.apache.usergrid.persistence.collection.mvcc.stage.StagePipeline;
+import org.apache.usergrid.persistence.collection.mvcc.stage.WriteContext;
+import org.apache.usergrid.persistence.collection.mvcc.stage.WriteStage;
+
+import com.google.common.base.Preconditions;
+import com.google.inject.Inject;
+
+
+/** @author tnine */
+public class WriteContextImpl implements WriteContext {
+
+ private final Collection<PostProcessListener> listeners;
+ private final StagePipeline pipeline;
+ private final CollectionContext context;
+
+ private Object message;
+ private WriteStage current;
+
+
+ @Inject
+ public WriteContextImpl( final Collection<PostProcessListener> listeners, final StagePipeline pipeline,
+ final CollectionContext context ) {
+ this.listeners = listeners;
+ this.pipeline = pipeline;
+ this.context = context;
+ }
+
+
+ @Override
+ public StagePipeline getStagePipeline() {
+ return this.pipeline;
+ }
+
+
+ @Override
+ public void performWrite( Object input ) {
+
+ current = this.pipeline.first();
+
+ current.performStage( this );
+ }
+
+
+ @Override
+ public <T> T getMessage( final Class<T> clazz ) {
+ Preconditions.checkNotNull( clazz, "Class must be specified" );
+
+ if ( message == null ) {
+ return null;
+ }
+
+ if ( !clazz.isInstance( message ) ) {
+ throw new ClassCastException(
+ "Message must be an instance of class " + clazz + ". However it was of type '" + message.getClass()
+ + "'" );
+ }
+
+
+ return ( T ) message;
+ }
+
+
+ @Override
+ public Object setMessage( final Object object ) {
+ Object original = message;
+
+ this.message = object;
+
+ return original;
+ }
+
+
+ @Override
+ public void proceed() {
+ WriteStage next = this.pipeline.nextStage( current );
+
+ //Nothing to do
+ if ( next == null ) {
+ return;
+ }
+
+ current = next;
+ current.performStage( this );
+ }
+
+
+ @Override
+ public void stop() {
+ //No op ATM
+ current = null;
+ }
+
+
+ @Override
+ public Collection<PostProcessListener> getPostProcessors() {
+ return listeners;
+ }
+
+
+ @Override
+ public CollectionContext getCollectionContext() {
+ return this.context;
+ }
+}