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/07/30 22:35:41 UTC
git commit: adding rx to master
Repository: incubator-usergrid
Updated Branches:
refs/heads/add-metrics 8e4465d64 -> b1efc555a
adding rx to master
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/b1efc555
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/b1efc555
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/b1efc555
Branch: refs/heads/add-metrics
Commit: b1efc555a38c86e9d716e53f329d21e36cc17304
Parents: 8e4465d
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Jul 30 14:35:13 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Jul 30 14:35:13 2014 -0600
----------------------------------------------------------------------
stack/core/pom.xml | 11 +++
.../persistence/ObservableIterator.java | 82 ++++++++++++++++++++
stack/pom.xml | 1 +
3 files changed, 94 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b1efc555/stack/core/pom.xml
----------------------------------------------------------------------
diff --git a/stack/core/pom.xml b/stack/core/pom.xml
index c6748aa..d9bc308 100644
--- a/stack/core/pom.xml
+++ b/stack/core/pom.xml
@@ -570,5 +570,16 @@
<artifactId>metrics-graphite</artifactId>
<version>${metrics.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>com.netflix.rxjava</groupId>
+ <artifactId>rxjava-core</artifactId>
+ <version>${rx.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.netflix.rxjava</groupId>
+ <artifactId>rxjava-math</artifactId>
+ <version>${rx.version}</version>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b1efc555/stack/core/src/main/java/org/apache/usergrid/persistence/ObservableIterator.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/ObservableIterator.java b/stack/core/src/main/java/org/apache/usergrid/persistence/ObservableIterator.java
new file mode 100644
index 0000000..b91bd22
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/ObservableIterator.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ */
+package org.apache.usergrid.persistence;
+
+import com.google.common.base.Preconditions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import rx.Observable;
+import rx.Subscriber;
+
+import java.util.Iterator;
+
+
+/**
+ * Converts an iterator to an observable. Subclasses need to only implement getting the iterator from the data source.
+ * This is used in favor of "Observable.just" when the initial fetch of the iterator will require I/O. This allows us
+ * to wrap the iterator in a deferred invocation to avoid the blocking on construction.
+ */
+public abstract class ObservableIterator<T> implements Observable.OnSubscribe<T> {
+
+ private static final Logger log = LoggerFactory.getLogger(ObservableIterator.class);
+
+ private final String name;
+
+
+ /**
+ * @param name The simple name of the iterator, used for debugging
+ */
+ protected ObservableIterator( final String name ) {this.name = name;}
+
+
+ @Override
+ public void call( final Subscriber<? super T> subscriber ) {
+
+
+ try {
+ //get our iterator and push data to the observer
+ final Iterator<T> itr = getIterator();
+
+ Preconditions.checkNotNull(itr,
+ "The observable must return an iterator. Null was returned for iterator " + name);
+
+
+ //while we have items to emit and our subscriber is subscribed, we want to keep emitting items
+ while ( itr.hasNext() && !subscriber.isUnsubscribed() ) {
+ final T next = itr.next();
+
+ log.trace( "Iterator '{}' emitting item '{}'", name, next );
+
+ subscriber.onNext( next );
+ }
+
+
+ subscriber.onCompleted();
+ }
+
+ //if any error occurs, we need to notify the observer so it can perform it's own error handling
+ catch ( Throwable t ) {
+ subscriber.onError( t );
+ }
+ }
+
+
+ /**
+ * Return the iterator to feed data to
+ */
+ protected abstract Iterator<T> getIterator();
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b1efc555/stack/pom.xml
----------------------------------------------------------------------
diff --git a/stack/pom.xml b/stack/pom.xml
index b58eafb..e16d470 100644
--- a/stack/pom.xml
+++ b/stack/pom.xml
@@ -114,6 +114,7 @@
<antlr.version>3.4</antlr.version>
<tika.version>1.4</tika.version>
<metrics.version>3.0.0</metrics.version>
+ <rx.version>0.19.6</rx.version>
</properties>
<licenses>