Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e1bfc3b
Removing Retrolambda and adding support for Native Java 8 compilation
forresthopkinsa Aug 1, 2017
36ba99c
Update to Canary 9
forresthopkinsa Aug 1, 2017
1952ea1
Fixed Gradle expecting both OkHttp and JWS, and updated documentation
forresthopkinsa Aug 1, 2017
98e578a
Added disconnect() to interface, cleaned up some Rx methods
forresthopkinsa Aug 2, 2017
24f989f
Cleaning up, restoring JWS support
forresthopkinsa Aug 3, 2017
a5c7586
Working on StompClient. This version is not stable
forresthopkinsa Aug 4, 2017
da0be9c
Successfully replaced the old mechanism for caching pre-connect sends.
forresthopkinsa Aug 7, 2017
8a41770
Now we have Topic Unsubscribe working as intended.
forresthopkinsa Aug 8, 2017
0e82ce9
Did some cleanup, created another ConnectionProvider abstraction
forresthopkinsa Aug 8, 2017
de27e32
Preparing for release
forresthopkinsa Aug 8, 2017
14e9dd6
Nullity inference and documentation update
forresthopkinsa Aug 8, 2017
d796357
Working on reconnection
forresthopkinsa Aug 11, 2017
d719ba6
Support for RabbitMQ topic wildcards
forresthopkinsa Aug 11, 2017
9c7a46b
Finished fixing reconnect and its race conditions
forresthopkinsa Aug 15, 2017
2067dfc
Abstracted reconnect logic and implemented it for JWS
forresthopkinsa Aug 15, 2017
3880e3c
Started on heartbeats, fixed example
forresthopkinsa Sep 19, 2017
f948c53
Merge remote-tracking branch 'NaikSoftware/master' into NoJack
forresthopkinsa Sep 19, 2017
24da370
Huge cleanup, ready for release
forresthopkinsa Sep 19, 2017
cb10e8b
Fixed protocol breach with message format; removed Clojars dependency.
forresthopkinsa Sep 29, 2017
a429a3b
Updating documentation and Gradle files
forresthopkinsa Nov 22, 2017
2dce3c6
Merge remote-tracking branch 'NaikSoftware/master'
forresthopkinsa Nov 22, 2017
4695ad0
Updating JWS to new implementation (Draft 17 to 6455, RFC compliant)
forresthopkinsa Nov 27, 2017
17b9d6c
Deleting the old, non-functional example client and unit tests
forresthopkinsa Nov 27, 2017
29e6f01
Simple repair of broken resubscribe. Easy fix, but still needs testing.
forresthopkinsa Nov 27, 2017
efcb19f
Fixing stupid mistake in the last commit
forresthopkinsa Nov 28, 2017
08631fe
Unsubscribe from messages on disconnect
Nov 30, 2017
9983e9d
17.11.0 release
forresthopkinsa Dec 1, 2017
965f127
OkHttp Failures are a combination of an Error *and* a Close.
forresthopkinsa Dec 1, 2017
0f285f0
Merge branch 'master' of https://github.com/forresthopkinsa/StompProt…
NaikSoftware Apr 3, 2018
f5d191e
Change group
NaikSoftware Apr 3, 2018
0b18b86
Refactor
NaikSoftware Apr 3, 2018
0348606
Fix example
NaikSoftware Apr 3, 2018
2bf78e0
Fix def value
NaikSoftware Apr 3, 2018
5d4b938
Fix def value
NaikSoftware Apr 3, 2018
18990db
Fix send
NaikSoftware Apr 3, 2018
d67eaeb
Fix subscribing
NaikSoftware Apr 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.idea
.DS_Store
/build
/captures
/captures
11 changes: 7 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'me.tatarka:gradle-retrolambda:3.4.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -18,7 +21,7 @@ allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
maven { url "http://clojars.org/repo" }
google()
}
}

Expand Down
5 changes: 2 additions & 3 deletions example-client/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
buildToolsVersion '26.0.2'

defaultConfig {
applicationId "ua.naiksoftware.stompclientexample"
Expand All @@ -29,7 +28,7 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'org.java-websocket:java-websocket:1.3.2'
compile 'org.java-websocket:Java-WebSocket:1.3.6'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ua.naiksoftware.stompclientexample;

import io.reactivex.Completable;
import io.reactivex.Flowable;
import retrofit2.http.POST;
import retrofit2.http.Query;
Expand All @@ -10,5 +11,5 @@
public interface ExampleRepository {

@POST("hello-convert-and-send")
Flowable<Void> sendRestEcho(@Query("msg") String message);
Completable sendRestEcho(@Query("msg") String message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import org.java_websocket.WebSocket;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import io.reactivex.FlowableTransformer;
import io.reactivex.CompletableTransformer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
Expand Down Expand Up @@ -56,7 +54,7 @@ public void disconnectStomp(View view) {
}

public void connectStomp(View view) {
mStompClient = Stomp.over(WebSocket.class, "ws://" + ANDROID_EMULATOR_LOCALHOST
mStompClient = Stomp.over(Stomp.ConnectionProvider.JWS, "ws://" + ANDROID_EMULATOR_LOCALHOST
+ ":" + RestClient.SERVER_PORT + "/example-endpoint/websocket");

mStompClient.lifecycle()
Expand Down Expand Up @@ -91,7 +89,7 @@ public void connectStomp(View view) {
public void sendEchoViaStomp(View v) {
mStompClient.send("/topic/hello-msg-mapping", "Echo STOMP " + mTimeFormat.format(new Date()))
.compose(applySchedulers())
.subscribe(aVoid -> {
.subscribe(() -> {
Log.d(TAG, "STOMP echo send successfully");
}, throwable -> {
Log.e(TAG, "Error send STOMP echo", throwable);
Expand All @@ -103,7 +101,7 @@ public void sendEchoViaRest(View v) {
mRestPingDisposable = RestClient.getInstance().getExampleRepository()
.sendRestEcho("Echo REST " + mTimeFormat.format(new Date()))
.compose(applySchedulers())
.subscribe(aVoid -> {
.subscribe(() -> {
Log.d(TAG, "REST echo send successfully");
}, throwable -> {
Log.e(TAG, "Error send REST echo", throwable);
Expand All @@ -122,8 +120,8 @@ private void toast(String text) {
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
}

protected <T> FlowableTransformer<T, T> applySchedulers() {
return tFlowable -> tFlowable
protected CompletableTransformer applySchedulers() {
return upstream -> upstream
.unsubscribeOn(Schedulers.newThread())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Feb 23 17:37:13 EET 2017
#Tue Sep 05 08:26:08 MST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
12 changes: 5 additions & 7 deletions lib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
apply plugin: 'com.android.library'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.github.dcendents.android-maven'

group='com.github.NaikSoftware'

android {
compileSdkVersion 25
buildToolsVersion "25.0.1"

defaultConfig {
minSdkVersion 16
Expand All @@ -30,12 +28,12 @@ android {


dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile "io.reactivex.rxjava2:rxjava:2.1.2"
implementation "io.reactivex.rxjava2:rxjava:2.1.8"
// Supported transports
provided "org.java-websocket:java-websocket:1.3.2"
provided 'com.squareup.okhttp3:okhttp:3.8.0'
compileOnly 'org.java-websocket:Java-WebSocket:1.3.6'
compileOnly 'com.squareup.okhttp3:okhttp:3.9.1'

implementation 'com.android.support:support-annotations:27.1.0'
}

task sourcesJar(type: Jar) {
Expand Down

This file was deleted.

5 changes: 2 additions & 3 deletions lib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ua.naiksoftware.stomp">
<manifest package="com.github.forresthopkinsa">

<application/>
<application />

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package ua.naiksoftware.stomp;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;

import io.reactivex.Completable;
import io.reactivex.Observable;
import io.reactivex.subjects.PublishSubject;

/**
* Created by forresthopkinsa on 8/8/2017.
* <p>
* Created because there was a lot of shared code between JWS and OkHttp connection providers.
*/

abstract class AbstractConnectionProvider implements ConnectionProvider {

private static final String TAG = AbstractConnectionProvider.class.getSimpleName();

@NonNull
private final PublishSubject<LifecycleEvent> mLifecycleStream;
@NonNull
private final PublishSubject<String> mMessagesStream;

AbstractConnectionProvider() {
mLifecycleStream = PublishSubject.create();
mMessagesStream = PublishSubject.create();
}

@NonNull
@Override
public Observable<String> messages() {
return mMessagesStream.startWith(initSocket().toObservable());
}

/**
* Simply close socket.
* <p>
* For example:
* <pre>
* webSocket.close();
* </pre>
*/
abstract void rawDisconnect();

@Override
public Completable disconnect() {
return Completable
.fromAction(this::rawDisconnect);
}

private Completable initSocket() {
return Completable
.fromAction(this::createWebSocketConnection);
}

// Doesn't do anything at all, only here as a stub
public Completable setHeartbeat(int ms) {
return Completable.complete();
}

/**
* Most important method: connects to websocket and notifies program of messages.
* <p>
* See implementations in OkHttpConnectionProvider and WebSocketsConnectionProvider.
*/
abstract void createWebSocketConnection();

@NonNull
@Override
public Completable send(String stompMessage) {
return Completable.fromCallable(() -> {
if (getSocket() == null) {
throw new IllegalStateException("Not connected yet");
} else {
Log.d(TAG, "Send STOMP message: " + stompMessage);
rawSend(stompMessage);
return null;
}
});
}

/**
* Just a simple message send.
* <p>
* For example:
* <pre>
* webSocket.send(stompMessage);
* </pre>
*
* @param stompMessage message to send
*/
abstract void rawSend(String stompMessage);

/**
* Get socket object.
* Used for null checking; this object is expected to be null when the connection is not yet established.
* <p>
* For example:
* <pre>
* return webSocket;
* </pre>
*/
@Nullable
abstract Object getSocket();

void emitLifecycleEvent(@NonNull LifecycleEvent lifecycleEvent) {
Log.d(TAG, "Emit lifecycle event: " + lifecycleEvent.getType().name());
mLifecycleStream.onNext(lifecycleEvent);
}

void emitMessage(String stompMessage) {
Log.d(TAG, "Emit STOMP message: " + stompMessage);
mMessagesStream.onNext(stompMessage);
}

@NonNull
@Override
public Observable<LifecycleEvent> lifecycle() {
return mLifecycleStream;
}
}
16 changes: 13 additions & 3 deletions lib/src/main/java/ua/naiksoftware/stomp/ConnectionProvider.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ua.naiksoftware.stomp;

import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Observable;

/**
* Created by naik on 05.05.16.
Expand All @@ -10,17 +12,25 @@ public interface ConnectionProvider {
/**
* Subscribe this for receive stomp messages
*/
Flowable<String> messages();
Observable<String> messages();

/**
* Sending stomp messages via you ConnectionProvider.
* onError if not connected or error detected will be called, or onCompleted id sending started
* TODO: send messages with ACK
*/
Flowable<Void> send(String stompMessage);
Completable send(String stompMessage);

/**
* Subscribe this for receive #LifecycleEvent events
*/
Flowable<LifecycleEvent> getLifecycleReceiver();
Observable<LifecycleEvent> lifecycle();

/**
* Disconnects from server. This is basically a Callable.
* Automatically emits Lifecycle.CLOSE
*/
Completable disconnect();

Completable setHeartbeat(int ms);
}
Loading