Adding the SubscriptionHub interface and making the SubcriptionMessageHub implement it

This commit is contained in:
Nelson R. Perez 2017-01-31 19:53:29 -05:00
parent aec4e55953
commit 09974a66f6
3 changed files with 42 additions and 3 deletions

3
.gitignore vendored
View file

@ -78,4 +78,5 @@ atlassian-ide-plugin.xml
src/main/java/com/luminiasoft/bitshares/mycelium/*
bts_bilthon_20161218.bin
# Ignore bin backups
*.bin

View file

@ -11,6 +11,7 @@ import de.bitsharesmunich.graphenej.AssetAmount;
import de.bitsharesmunich.graphenej.RPC;
import de.bitsharesmunich.graphenej.Transaction;
import de.bitsharesmunich.graphenej.TransferOperation;
import de.bitsharesmunich.graphenej.interfaces.SubscriptionHub;
import de.bitsharesmunich.graphenej.interfaces.SubscriptionListener;
import de.bitsharesmunich.graphenej.models.ApiCall;
import de.bitsharesmunich.graphenej.models.BaseResponse;
@ -28,7 +29,7 @@ import java.util.Map;
*
* Created by nelson on 1/26/17.
*/
public class SubscriptionMessagesHub extends WebSocketAdapter {
public class SubscriptionMessagesHub extends WebSocketAdapter implements SubscriptionHub {
// Sequence of message ids
private final static int LOGIN_ID = 1;
private final static int GET_DATABASE_ID = 2;
@ -56,12 +57,19 @@ public class SubscriptionMessagesHub extends WebSocketAdapter {
this.gson = builder.create();
}
@Override
public void addSubscriptionListener(SubscriptionListener listener){
this.mSubscriptionDeserializer.addSubscriptionListener(listener);
}
@Override
public void removeSubscriptionListener(SubscriptionListener listener){
this.removeSubscriptionListener(listener);
this.mSubscriptionDeserializer.removeSubscriptionListener(listener);
}
@Override
public List<SubscriptionListener> getSubscriptionListeners() {
return this.mSubscriptionDeserializer.getSubscriptionListeners();
}
@Override

View file

@ -0,0 +1,30 @@
package de.bitsharesmunich.graphenej.interfaces;
import java.util.List;
/**
* Interface to be implemented by any class that hosts a SubscriptionResponseDeserializer and wants to
* expose an interface for its management of its listeners.
*
* Created by nelson on 1/30/17.
*/
public interface SubscriptionHub {
/**
* Adds a given listener to the list of subscription listeners.
* @param listener: The SubscriptionListener to add.
*/
void addSubscriptionListener(SubscriptionListener listener);
/**
* Removes a given listener from the list.
* @param listener: The SubscriptionListener to remove.
*/
void removeSubscriptionListener(SubscriptionListener listener);
/**
* Retrieves a list of all subscription listeners.
* @return
*/
List<SubscriptionListener> getSubscriptionListeners();
}