You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2014/10/09 17:22:24 UTC

git commit: Adding factory classes

Repository: incubator-usergrid
Updated Branches:
  refs/heads/two-dot-o-events 23ff82e05 -> 5a7aa5b28


Adding factory classes


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/5a7aa5b2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/5a7aa5b2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/5a7aa5b2

Branch: refs/heads/two-dot-o-events
Commit: 5a7aa5b28cdd516e516d26cd453ca2bc74ab1797
Parents: 23ff82e
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Oct 9 09:22:11 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Oct 9 09:22:11 2014 -0600

----------------------------------------------------------------------
 .../collection/EntityDeletedFactory.java        | 34 +++++++++++++
 .../collection/EntityVersionCleanupFactory.java | 32 ++++++++++++
 .../impl/EntityCollectionManagerImpl.java       |  7 +--
 .../collection/impl/EntityDeletedTask.java      | 52 ++++++++++++++++----
 .../impl/EntityVersionCleanupFactory.java       | 31 ------------
 5 files changed, 110 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5a7aa5b2/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityDeletedFactory.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityDeletedFactory.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityDeletedFactory.java
new file mode 100644
index 0000000..13b1f1a
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityDeletedFactory.java
@@ -0,0 +1,34 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  *  contributor license agreements.  The ASF licenses this file to You
+ *  * under the Apache License, Version 2.0 (the "License"); you may not
+ *  * use this file except in compliance with the License.
+ *  * You may obtain a copy of the License at
+ *  *
+ *  *     http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing, software
+ *  * distributed under the License is distributed on an "AS IS" BASIS,
+ *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  * See the License for the specific language governing permissions and
+ *  * limitations under the License.  For additional information regarding
+ *  * copyright in this work, please see the NOTICE file in the top level
+ *  * directory of this distribution.
+ *
+ */
+
+package org.apache.usergrid.persistence.collection;
+
+import org.apache.usergrid.persistence.collection.impl.EntityDeletedTask;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+import java.util.UUID;
+
+/**
+ * Creats EntityDeletedTask instances
+ */
+public interface EntityDeletedFactory {
+    public EntityDeletedTask getTask( final Id entityId, final UUID version );
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5a7aa5b2/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityVersionCleanupFactory.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityVersionCleanupFactory.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityVersionCleanupFactory.java
new file mode 100644
index 0000000..606f394
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityVersionCleanupFactory.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.collection;
+
+
+import com.google.inject.assistedinject.Assisted;
+import org.apache.usergrid.persistence.collection.event.EntityVersionDeleted;
+import org.apache.usergrid.persistence.collection.impl.EntityVersionCleanupTask;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+import java.util.List;
+import java.util.UUID;
+
+public interface EntityVersionCleanupFactory {
+    public EntityVersionCleanupTask getTask( final Id entityId, final UUID version );
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5a7aa5b2/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
index 5f1fdc7..f255beb 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
@@ -19,16 +19,12 @@
 package org.apache.usergrid.persistence.collection.impl;
 
 
-import java.util.List;
-import java.util.UUID;
-
+import org.apache.usergrid.persistence.collection.EntityVersionCleanupFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.apache.usergrid.persistence.collection.CollectionScope;
 import org.apache.usergrid.persistence.collection.EntityCollectionManager;
-import org.apache.usergrid.persistence.collection.event.EntityVersionCreated;
-import org.apache.usergrid.persistence.collection.event.EntityVersionDeleted;
 import org.apache.usergrid.persistence.collection.guice.CollectionTaskExecutor;
 import org.apache.usergrid.persistence.collection.guice.Write;
 import org.apache.usergrid.persistence.collection.guice.WriteUpdate;
@@ -44,7 +40,6 @@ import org.apache.usergrid.persistence.collection.mvcc.stage.write.WriteOptimist
 import org.apache.usergrid.persistence.collection.mvcc.stage.write.WriteStart;
 import org.apache.usergrid.persistence.collection.mvcc.stage.write.WriteUniqueVerify;
 import org.apache.usergrid.persistence.collection.service.UUIDService;
-import org.apache.usergrid.persistence.core.task.Task;
 import org.apache.usergrid.persistence.core.task.TaskExecutor;
 import org.apache.usergrid.persistence.core.util.ValidationUtils;
 import org.apache.usergrid.persistence.model.entity.Entity;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5a7aa5b2/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityDeletedTask.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityDeletedTask.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityDeletedTask.java
index 8abb456..f113900 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityDeletedTask.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityDeletedTask.java
@@ -21,18 +21,20 @@
 package org.apache.usergrid.persistence.collection.impl;
 
 import com.google.inject.assistedinject.Assisted;
-import com.netflix.astyanax.Keyspace;
 import com.netflix.astyanax.MutationBatch;
 import org.apache.usergrid.persistence.collection.CollectionScope;
-import org.apache.usergrid.persistence.collection.event.EntityVersionDeleted;
+import org.apache.usergrid.persistence.collection.EntityVersionCleanupFactory;
+import org.apache.usergrid.persistence.collection.event.EntityDeleted;
 import org.apache.usergrid.persistence.collection.mvcc.MvccEntitySerializationStrategy;
 import org.apache.usergrid.persistence.collection.mvcc.MvccLogEntrySerializationStrategy;
-import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
-import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
 import org.apache.usergrid.persistence.core.task.Task;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import rx.Observable;
+import rx.functions.Action1;
+import rx.functions.Func1;
+import rx.schedulers.Schedulers;
 
 import java.util.List;
 import java.util.UUID;
@@ -44,24 +46,22 @@ public class EntityDeletedTask implements Task<Void> {
     private EntityVersionCleanupFactory entityVersionCleanupFactory;
     private MvccLogEntrySerializationStrategy logEntrySerializationStrategy;
     private MvccEntitySerializationStrategy entitySerializationStrategy;
+    private List<EntityDeleted> listeners;
     private CollectionScope collectionScope;
     private Id entityId;
     private UUID version;
     private static final Logger LOG =  LoggerFactory.getLogger(EntityDeletedTask.class);
 
     public EntityDeletedTask(EntityVersionCleanupFactory entityVersionCleanupFactory,
-                             final SerializationFig serializationFig,
                              final MvccLogEntrySerializationStrategy logEntrySerializationStrategy,
                              final MvccEntitySerializationStrategy entitySerializationStrategy,
-                             final UniqueValueSerializationStrategy uniqueValueSerializationStrategy,
-                             final Keyspace keyspace,
-                             final CollectionScope scope,
-                             final List<EntityVersionDeleted> listeners,
+                             final List<EntityDeleted> listeners,
                              CollectionScope collectionScope,
                              @Assisted Id entityId, @Assisted UUID version){
         this.entityVersionCleanupFactory = entityVersionCleanupFactory;
         this.logEntrySerializationStrategy = logEntrySerializationStrategy;
         this.entitySerializationStrategy = entitySerializationStrategy;
+        this.listeners = listeners;
         this.collectionScope = collectionScope;
         this.entityId = entityId;
         this.version = version;
@@ -96,5 +96,39 @@ public class EntityDeletedTask implements Task<Void> {
         return null;
     }
 
+    private void fireEvents() {
+        final int listenerSize = listeners.size();
+
+        if ( listenerSize == 0 ) {
+            return;
+        }
+
+        if ( listenerSize == 1 ) {
+            listeners.get( 0 ).deleted( collectionScope, entityId,version );
+            return;
+        }
+
+        LOG.debug( "Started firing {} listeners", listenerSize );
+
+        //if we have more than 1, run them on the rx scheduler for a max of 8 operations at a time
+        Observable.from(listeners)
+                .parallel( new Func1<Observable<EntityDeleted>, Observable<EntityDeleted>>() {
+
+                    @Override
+                    public Observable<EntityDeleted> call(
+                            final Observable<EntityDeleted> entityVersionDeletedObservable ) {
+
+                        return entityVersionDeletedObservable.doOnNext( new Action1<EntityDeleted>() {
+                            @Override
+                            public void call( final EntityDeleted listener ) {
+                                listener.deleted(collectionScope, entityId, version);
+                            }
+                        } );
+                    }
+                }, Schedulers.io() ).toBlocking().last();
+
+        LOG.debug( "Finished firing {} listeners", listenerSize );
+    }
+
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5a7aa5b2/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCleanupFactory.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCleanupFactory.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCleanupFactory.java
deleted file mode 100644
index 7d6e2a5..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityVersionCleanupFactory.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  The ASF licenses this file to You
- * under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.  For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.collection.impl;
-
-
-import com.google.inject.assistedinject.Assisted;
-import org.apache.usergrid.persistence.collection.event.EntityVersionDeleted;
-import org.apache.usergrid.persistence.model.entity.Id;
-
-import java.util.List;
-import java.util.UUID;
-
-public interface EntityVersionCleanupFactory {
-    public EntityVersionCleanupTask getTask( final Id entityId, final UUID version );
-
-}