Skip to content

Commit

Permalink
add RxJava support
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmcclean committed Apr 20, 2016
1 parent 1e27f9e commit a57d719
Show file tree
Hide file tree
Showing 14 changed files with 620 additions and 20 deletions.
7 changes: 1 addition & 6 deletions cyclops-reactor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ dependencies {
compile 'io.projectreactor:reactor-core:'+reactorVersion
compile group: 'com.aol.simplereact', name:'cyclops-react', version:cyclopsReactVersion
provided group: 'org.projectlombok', name: 'lombok', version:lombokVersion
compile 'io.javaslang:javaslang:'+javaslangVersion
provided "org.functionaljava:functionaljava:"+functionalJavaVersion
provided "org.functionaljava:functionaljava-java8:"+functionalJavaVersion
provided 'com.google.guava:guava:'+guavaVersion
provided "org.functionaljava:functionaljava:4.5"
provided "org.functionaljava:functionaljava-java8:4.5"

testCompile 'commons-io:commons-io:2.4'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'junit', name: 'junit', version: '4.12'
Expand Down
13 changes: 3 additions & 10 deletions cyclops-reactor/src/main/java/com/aol/cyclops/reactor/Reactor.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public static <T> AnyMSeq<T> flux(Flux<T> flux){
return AnyM.ofSeq(flux);
}
public static <T> StreamTSeq<T> fluxT(Publisher<Flux<T>> nested){
return StreamT.fromPublisher(flux(Flux.from(nested).map(f->ReactiveSeq.fromPublisher(f))));
return StreamT.fromPublisher(Flux.from(nested).map(f->ReactiveSeq.fromPublisher(f)));
}

public static <T> AnyMValue<T> mono(Mono<T> mono){
return AnyM.ofValue(mono);
}
public static <T> FutureWTSeq<T> monoT(Publisher<Mono<T>> nested){
return FutureWT.fromPublisher(flux(Flux.from(nested).map(f->FutureW.of(f.toCompletableFuture()))));
return FutureWT.fromPublisher(Flux.from(nested).map(f->FutureW.of(f.toCompletableFuture())));
}
public interface ForFlux {

Expand Down Expand Up @@ -181,13 +181,6 @@ static <T, R1, R> Mono<R> each2(Mono<? extends T> value1, Function<? super T, ?
}
}

public static void main(String[] args){
Flux<Integer> flux = Flux.just(1,2,3,4).map(i->i+2);
Flux<String> string = flux.map(s->"hello"+s);
System.out.println(flux.toList().get());
System.out.println(flux.toList().get());
System.out.println(string.toList().get());
System.out.println(string.toList().get());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ public Object resolveForCrossTypeFlatMap(Comprehender comp,Flux apply){

return comp.fromIterator(apply.toIterable().iterator());
}
public static <T> T unwrapOtherMonadTypes(Comprehender<T> comp,Object apply){

public static Flux unwrapOtherMonadTypes(Comprehender<Flux> comp,Object apply){
if(apply instanceof Flux)
return (Flux)apply;
if(apply instanceof Iterable){
return (T)Flux.fromIterable((Iterable)apply);
return Flux.fromIterable((Iterable)apply);

}
if(apply instanceof BaseStream){
return (T)Flux.fromStream(StreamSupport.stream(Spliterators.spliteratorUnknownSize(((BaseStream)apply).iterator(), Spliterator.ORDERED),
return Flux.fromStream(StreamSupport.stream(Spliterators.spliteratorUnknownSize(((BaseStream)apply).iterator(), Spliterator.ORDERED),
false));
}
return Comprehender.unwrapOtherMonadTypes(comp,apply);
Expand Down
104 changes: 104 additions & 0 deletions cyclops-rx/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'com.bmuschko.nexus'
apply plugin: 'maven-publish'

buildscript {
repositories {
jcenter()
}

dependencies {
classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1'

}
}

sourceCompatibility = 1.8

jar {
manifest {
attributes 'Implementation-Title': 'Cyclops Rx', 'Implementation-Version': version
}
}

repositories {
mavenCentral()

}
configurations {
provided
}
dependencies {
compile 'io.reactivex:rxjava:'+rxJavaVersion
compile group: 'com.aol.simplereact', name:'cyclops-react', version:cyclopsReactVersion
compile 'io.reactivex:rxjava-reactive-streams:1.0.1'
provided group: 'org.projectlombok', name: 'lombok', version:lombokVersion


testCompile 'commons-io:commons-io:2.4'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version:'1.3'
testCompile group: 'org.mockito', name: 'mockito-all', version:'1.9.5'
testCompile 'org.reactivestreams:reactive-streams-tck:1.0.0'
testCompile 'org.assertj:assertj-core:3.2.0'
}
sourceSets {
main.compileClasspath += [configurations.provided]
test.compileClasspath += [configurations.provided]
test.runtimeClasspath += [configurations.provided]
}
eclipse.classpath.plusConfigurations += [configurations.provided] // Eclipse users only
test {
systemProperties 'property': 'value'
}



modifyPom {
project {
name 'cyclops-rx'
description 'Converters and Comprehenders for RxJava'
url 'https://github.com/aol/cyclops'
inceptionYear '2016'

groupId 'com.aol.cyclops'
artifactId 'cyclops-rx'
version "$version"

scm {
url 'ssh://[email protected]:aol/cyclops.git'
connection 'ssh://[email protected]:aol/cyclops.git'
developerConnection 'ssh://[email protected]:aol/cyclops.git'
}

licenses {
license {
name 'The MIT License (MIT)'
url 'https://github.com/aol/cyclops/blob/master/licence.txt'
distribution 'repo'
}
}

developers {
developer {
id 'johnmcclean-aol'
name 'John McClean'
email '[email protected]'
}
}
}
}

extraArchive {
sources = true
tests = true
javadoc = true
}

nexus {
sign = true
repositoryUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
snapshotRepositoryUrl = 'https://oss.sonatype.org/content/repositories/snapshots'
}
6 changes: 6 additions & 0 deletions cyclops-rx/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Wed Apr 20 15:55:33 IST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-bin.zip
160 changes: 160 additions & 0 deletions cyclops-rx/gradlew
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#!/usr/bin/env bash

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
echo "$*"
}

die ( ) {
echo
echo "$*"
echo
exit 1
}

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option

if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
Loading

0 comments on commit a57d719

Please sign in to comment.