Finishing base docs for all API handler classes

This commit is contained in:
Vinícius 2017-07-20 23:47:24 -03:00
parent 240cff9c7c
commit a824d8fc40
21 changed files with 393 additions and 226 deletions

View file

@ -12,8 +12,6 @@ import de.bitsharesmunich.graphenej.models.BaseResponse;
/** /**
* Base class that should be extended by any implementation of a specific request to the full node. * Base class that should be extended by any implementation of a specific request to the full node.
*
* Created by nelson on 1/5/17.
*/ */
public abstract class BaseGrapheneHandler extends WebSocketAdapter { public abstract class BaseGrapheneHandler extends WebSocketAdapter {
@ -32,9 +30,22 @@ public abstract class BaseGrapheneHandler extends WebSocketAdapter {
*/ */
protected long requestId; protected long requestId;
/**
* Constructor (The original constructor, should be replaced with the one that receives
* NodeErrorListener instead of WitnessResponseListener)
*
* @param listener listener to be notified in if an error occurs
*/
@Deprecated
public BaseGrapheneHandler(WitnessResponseListener listener){ public BaseGrapheneHandler(WitnessResponseListener listener){
this.mListener = listener; this.mListener = listener;
} }
/**
* Constructor
*
* @param listener listener to be notified if an error occurs
*/
public BaseGrapheneHandler(NodeErrorListener listener){ public BaseGrapheneHandler(NodeErrorListener listener){
this.mErrorListener = listener; this.mErrorListener = listener;
} }
@ -52,7 +63,14 @@ public abstract class BaseGrapheneHandler extends WebSocketAdapter {
for (StackTraceElement element : cause.getStackTrace()){ for (StackTraceElement element : cause.getStackTrace()){
System.out.println(element.getFileName()+"#"+element.getClassName()+":"+element.getLineNumber()); System.out.println(element.getFileName()+"#"+element.getClassName()+":"+element.getLineNumber());
} }
mErrorListener.onError(new BaseResponse.Error(cause.getMessage())); // Should be replaced for mErrorListener (NodeErrorListener type) only in the future
if(mErrorListener != null){
mErrorListener.onError(new BaseResponse.Error(cause.getMessage()));
}
else{
mListener.onError(new BaseResponse.Error(cause.getMessage()));
}
websocket.disconnect(); websocket.disconnect();
} }

View file

@ -23,11 +23,10 @@ import java.util.Map;
* *
* Get an accounts balances in various assets. * Get an accounts balances in various assets.
* *
* The request returns the balances of the account * The response returns the balances of the account
* *
* @see <a href="https://goo.gl/faFdey">get_account_balances API doc</a> * @see <a href="https://goo.gl/faFdey">get_account_balances API doc</a>
* *
* Created by nelson on 1/13/17.
*/ */
public class GetAccountBalances extends BaseGrapheneHandler { public class GetAccountBalances extends BaseGrapheneHandler {
@ -38,13 +37,14 @@ public class GetAccountBalances extends BaseGrapheneHandler {
/** /**
* Default Constructor * Default Constructor
* *
* @param userAccount account to get balances for * @param userAccount account to get balances for
* @param assets list of the assets to get balances of; if empty, get all assets account has a balance in * @param assets list of the assets to get balances of; if empty, get all assets account
* @param oneTime boolean value indicating if websocket must be closed (true) or not (false) * has a balance in
* after the response * @param oneTime boolean value indicating if WebSocket must be closed (true) or not
* @param listener A class implementing the WitnessResponseListener interface. This should * (false) after the response
* be implemented by the party interested in being notified about the success/failure * @param listener A class implementing the WitnessResponseListener interface. This should
* of the transaction broadcast operation. * be implemented by the party interested in being notified about the
* success/failure of the operation.
*/ */
public GetAccountBalances(UserAccount userAccount, List<Asset> assets, boolean oneTime, WitnessResponseListener listener) { public GetAccountBalances(UserAccount userAccount, List<Asset> assets, boolean oneTime, WitnessResponseListener listener) {
super(listener); super(listener);
@ -54,13 +54,14 @@ public class GetAccountBalances extends BaseGrapheneHandler {
} }
/** /**
* Using this constructor the websocket connection closes after the response. * Using this constructor the WebSocket connection closes after the response.
* *
* @param userAccount account to get balances for * @param userAccount account to get balances for
* @param assets list of the assets to get balances of; if empty, get all assets account has a balance in * @param assets list of the assets to get balances of; if empty, get all assets account
* @param listener A class implementing the WitnessResponseListener interface. This should * has a balance in
* be implemented by the party interested in being notified about the success/failure * @param listener A class implementing the WitnessResponseListener interface. This should
* of the transaction broadcast operation. * be implemented by the party interested in being notified about the
* success/failure of the operation.
*/ */
public GetAccountBalances(UserAccount userAccount, List<Asset> assets, WitnessResponseListener listener) { public GetAccountBalances(UserAccount userAccount, List<Asset> assets, WitnessResponseListener listener) {
this(userAccount, assets, true, listener); this(userAccount, assets, true, listener);

View file

@ -24,7 +24,7 @@ import de.bitsharesmunich.graphenej.models.WitnessResponse;
* *
* Get an accounts info by name. * Get an accounts info by name.
* *
* The request returns account data that refer to the name. * The response returns account data that refer to the name.
* *
* @see <a href="https://goo.gl/w75qjV">get_account_by_name API doc</a> * @see <a href="https://goo.gl/w75qjV">get_account_by_name API doc</a>
*/ */
@ -37,12 +37,12 @@ public class GetAccountByName extends BaseGrapheneHandler {
/** /**
* Default Constructor * Default Constructor
* *
* @param accountName name of the account to get info * @param accountName name of the account to get info
* @param oneTime boolean value indicating if websocket must be closed (true) or not (false) * @param oneTime boolean value indicating if WebSocket must be closed (true) or not
* after the response * (false) after the response
* @param listener A class implementing the WitnessResponseListener interface. This should * @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the success/failure * be implemented by the party interested in being notified about the
* of the transaction broadcast operation. * success/failure of the operation.
*/ */
public GetAccountByName(String accountName, boolean oneTime, WitnessResponseListener listener){ public GetAccountByName(String accountName, boolean oneTime, WitnessResponseListener listener){
super(listener); super(listener);
@ -52,12 +52,12 @@ public class GetAccountByName extends BaseGrapheneHandler {
} }
/** /**
* Using this constructor the websocket connection closes after the response. * Using this constructor the WebSocket connection closes after the response.
* *
* @param accountName name of the account to get info * @param accountName name of the account to get info
* @param listener A class implementing the WitnessResponseListener interface. This should * @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the success/failure * be implemented by the party interested in being notified about the
* of the transaction broadcast operation. * success/failure of the operation.
*/ */
public GetAccountByName(String accountName, WitnessResponseListener listener){ public GetAccountByName(String accountName, WitnessResponseListener listener){
this(accountName, true, listener); this(accountName, true, listener);

View file

@ -3,5 +3,6 @@ package de.bitsharesmunich.graphenej.api;
/** /**
* Created by nelson on 12/26/16. * Created by nelson on 12/26/16.
*/ */
//TODO: Implement if needed: http://docs.bitshares.eu/api/history.html?highlight=get_market_history#account-history-api
public class GetAccountHistory { public class GetAccountHistory {
} }

View file

@ -25,7 +25,7 @@ import de.bitsharesmunich.graphenej.models.WitnessResponse;
* *
* Get a list of accounts by ID. * Get a list of accounts by ID.
* *
* The request returns the accounts corresponding to the provided IDs. * The response returns the accounts corresponding to the provided IDs.
* *
* @see <a href="https://goo.gl/r5RqKG">get_accounts API doc</a> * @see <a href="https://goo.gl/r5RqKG">get_accounts API doc</a>
*/ */
@ -36,13 +36,14 @@ public class GetAccounts extends BaseGrapheneHandler {
private boolean mOneTime; private boolean mOneTime;
/** /**
* Default Constructor * Constructor for one account only.
* @param accountId ID of the account to retrieve *
* @param oneTime boolean value indicating if websocket must be closed (true) or not (false) * @param accountId ID of the account to retrieve
* after the response * @param oneTime boolean value indicating if WebSocket must be closed (true) or not
* @param listener A class implementing the WitnessResponseListener interface. This should * (false) after the response
* be implemented by the party interested in being notified about the success/failure * @param listener A class implementing the WitnessResponseListener interface. This should
* of the transaction broadcast operation. * be implemented by the party interested in being notified about the
* success/failure of the operation.
*/ */
public GetAccounts(String accountId, boolean oneTime, WitnessResponseListener listener){ public GetAccounts(String accountId, boolean oneTime, WitnessResponseListener listener){
super(listener); super(listener);
@ -52,13 +53,14 @@ public class GetAccounts extends BaseGrapheneHandler {
} }
/** /**
* Using this constructor the websocket connection closes after the response. * Constructor for account list.
* @param accounts list with the accounts to retrieve *
* @param oneTime boolean value indicating if websocket must be closed (true) or not (false) * @param accounts list with the accounts to retrieve
* after the response * @param oneTime boolean value indicating if WebSocket must be closed (true) or not
* @param listener A class implementing the WitnessResponseListener interface. This should * (false) after the response
* be implemented by the party interested in being notified about the success/failure * @param listener A class implementing the WitnessResponseListener interface. This should
* of the transaction broadcast operation. * be implemented by the party interested in being notified about the
* success/failure of the operation.
*/ */
public GetAccounts(List<UserAccount> accounts, boolean oneTime, WitnessResponseListener listener){ public GetAccounts(List<UserAccount> accounts, boolean oneTime, WitnessResponseListener listener){
super(listener); super(listener);
@ -68,22 +70,25 @@ public class GetAccounts extends BaseGrapheneHandler {
} }
/** /**
* Using this constructor the websocket connection closes after the response. * Using this constructor the WebSocket connection closes after the response. (Account based)
* @param accountId ID of the account to retrieve *
* @param listener A class implementing the WitnessResponseListener interface. This should * @param accountId ID of the account to retrieve
* be implemented by the party interested in being notified about the success/failure * @param listener A class implementing the WitnessResponseListener interface. This should
* of the transaction broadcast operation. * be implemented by the party interested in being notified about the
* success/failure of the operation.
*/ */
public GetAccounts(String accountId, WitnessResponseListener listener){ public GetAccounts(String accountId, WitnessResponseListener listener){
this(accountId, true, listener); this(accountId, true, listener);
} }
/** /**
* Using this constructor the websocket connection closes after the response. * Using this constructor the WebSocket connection closes after the response. (Account List
* @param accounts list with the accounts to retrieve * based)
* @param listener A class implementing the WitnessResponseListener interface. This should *
* be implemented by the party interested in being notified about the success/failure * @param accounts list with the accounts to retrieve
* of the transaction broadcast operation. * @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the
* success/failure of the operation.
*/ */
public GetAccounts(List<UserAccount> accounts, WitnessResponseListener listener){ public GetAccounts(List<UserAccount> accounts, WitnessResponseListener listener){
this(accounts, true, listener); this(accounts, true, listener);

View file

@ -20,9 +20,9 @@ import java.util.Map;
* *
* Get a list of all system assets with holders count. * Get a list of all system assets with holders count.
* *
* The request returns the list of all assets with holders count. * The response returns the list of all assets with holders count.
* *
* @see <a href="https://goo.gl/AgTSLU">get_all_asset_holders API doc</a> * @see <a href="https://goo.gl/AgTSLU">get_all_asset_holders API doc (source code ref.)</a>
*/ */
public class GetAllAssetHolders extends BaseGrapheneHandler { public class GetAllAssetHolders extends BaseGrapheneHandler {
private final static int LOGIN_ID = 1; private final static int LOGIN_ID = 1;
@ -35,12 +35,13 @@ public class GetAllAssetHolders extends BaseGrapheneHandler {
private boolean mOneTime; private boolean mOneTime;
/** /**
* Constructor * Default Constructor
* @param oneTime boolean value indicating if websocket must be closed (true) or not (false) *
* after the response * @param oneTime boolean value indicating if WebSocket must be closed (true) or not
* @param listener A class implementing the WitnessResponseListener interface. This should * (false) after the response
* be implemented by the party interested in being notified about the success/failure * @param listener A class implementing the WitnessResponseListener interface. This should
* of the transaction broadcast operation. * be implemented by the party interested in being notified about the
* success/failure of the operation.
*/ */
public GetAllAssetHolders(boolean oneTime, WitnessResponseListener listener) { public GetAllAssetHolders(boolean oneTime, WitnessResponseListener listener) {
super(listener); super(listener);
@ -48,7 +49,7 @@ public class GetAllAssetHolders extends BaseGrapheneHandler {
} }
/** /**
* Using this constructor the websocket connection closes after the response. * Using this constructor the WebSocket connection closes after the response.
* *
* @param listener A class implementing the WitnessResponseListener interface. This should * @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the success/failure * be implemented by the party interested in being notified about the success/failure

View file

@ -43,13 +43,14 @@ public class GetBlockHeader extends BaseGrapheneHandler {
private boolean mOneTime; private boolean mOneTime;
/** /**
* Constructor * Default Constructor
* @param blockNumber height of the block whose header should be returned *
* @param oneTime boolean value indicating if websocket must be closed (true) or not (false) * @param blockNumber height of the block whose header should be returned
* after the response * @param oneTime boolean value indicating if WebSocket must be closed (true) or not
* @param listener A class implementing the WitnessResponseListener interface. This should * (false) after the response
* be implemented by the party interested in being notified about the success/failure * @param listener A class implementing the WitnessResponseListener interface. This should
* of the transaction broadcast operation. * be implemented by the party interested in being notified about the
* success/failure of the operation.
*/ */
public GetBlockHeader(long blockNumber, boolean oneTime, WitnessResponseListener listener){ public GetBlockHeader(long blockNumber, boolean oneTime, WitnessResponseListener listener){
super(listener); super(listener);
@ -59,11 +60,12 @@ public class GetBlockHeader extends BaseGrapheneHandler {
} }
/** /**
* Using this constructor the websocket connection closes after the response. * Using this constructor the WebSocket connection closes after the response.
* @param blockNumber height of the block whose header should be returned *
* @param listener A class implementing the WitnessResponseListener interface. This should * @param blockNumber height of the block whose header should be returned
* be implemented by the party interested in being notified about the success/failure * @param listener A class implementing the WitnessResponseListener interface. This should
* of the transaction broadcast operation. * be implemented by the party interested in being notified about the
* success/failure of the operation.
*/ */
public GetBlockHeader(long blockNumber, WitnessResponseListener listener){ public GetBlockHeader(long blockNumber, WitnessResponseListener listener){
this(blockNumber, true, listener); this(blockNumber, true, listener);

View file

@ -37,7 +37,7 @@ public class GetKeyReferences extends BaseGrapheneHandler {
* Constructor * Constructor
* *
* @param address address to be query * @param address address to be query
* @param oneTime boolean value indicating if websocket must be closed (true) or not (false) * @param oneTime boolean value indicating if WebSocket must be closed (true) or not (false)
* after the response * after the response
* @param listener A class implementing the WitnessResponseListener interface. This should * @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the success/failure * be implemented by the party interested in being notified about the success/failure
@ -53,7 +53,7 @@ public class GetKeyReferences extends BaseGrapheneHandler {
/** /**
* *
* @param addresses list of addresses to be query * @param addresses list of addresses to be query
* @param oneTime boolean value indicating if websocket must be closed (true) or not (false) * @param oneTime boolean value indicating if WebSocket must be closed (true) or not (false)
* after the response * after the response
* @param listener A class implementing the WitnessResponseListener interface. This should * @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the success/failure * be implemented by the party interested in being notified about the success/failure

View file

@ -47,11 +47,11 @@ public class GetLimitOrders extends BaseGrapheneHandler {
* @param a id of asset being sold * @param a id of asset being sold
* @param b id of asset being purchased * @param b id of asset being purchased
* @param limit maximum number of orders to retrieve * @param limit maximum number of orders to retrieve
* @param oneTime boolean value indicating if websocket must be closed (true) or not (false) * @param oneTime boolean value indicating if WebSocket must be closed (true) or not
* after the response * (false) after the response
* @param listener A class implementing the WitnessResponseListener interface. This should * @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the success/failure * be implemented by the party interested in being notified about the
* of the transaction broadcast operation. * success/failure of the operation.
*/ */
public GetLimitOrders(String a, String b, int limit, boolean oneTime, WitnessResponseListener listener) { public GetLimitOrders(String a, String b, int limit, boolean oneTime, WitnessResponseListener listener) {
super(listener); super(listener);
@ -63,14 +63,14 @@ public class GetLimitOrders extends BaseGrapheneHandler {
} }
/** /**
* Using this constructor the websocket connection closes after the response. * Using this constructor the WebSocket connection closes after the response.
* *
* @param a id of asset being sold * @param a id of asset being sold
* @param b id of asset being purchased * @param b id of asset being purchased
* @param limit maximum number of orders to retrieve * @param limit maximum number of orders to retrieve
* @param listener A class implementing the WitnessResponseListener interface. This should * @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the success/failure * be implemented by the party interested in being notified about the
* of the transaction broadcast operation. * success/failure of the operation.
*/ */
public GetLimitOrders(String a, String b, int limit, WitnessResponseListener listener) { public GetLimitOrders(String a, String b, int limit, WitnessResponseListener listener) {
this(a, b, limit, true, listener); this(a, b, limit, true, listener);

View file

@ -25,6 +25,7 @@ import de.bitsharesmunich.graphenej.models.WitnessResponse;
/** /**
* Class that implements get_market_history request handler. * Class that implements get_market_history request handler.
* *
* Get mar
* *
* @see <a href="https://goo.gl/hfVFBW">get_market_history API doc</a> * @see <a href="https://goo.gl/hfVFBW">get_market_history API doc</a>
* *
@ -51,18 +52,23 @@ public class GetMarketHistory extends BaseGrapheneHandler {
private boolean mOneTime; private boolean mOneTime;
/** /**
* Constructor * Default Constructor
* *
* @param base * @param base asset which history is desired
* @param quote * @param quote asset which the base price asset will be compared to
* @param bucket * @param bucket the time interval (in seconds) for each point should be (analog to
* @param start * candles on a candle stick graph).
* @param end * Note: The bucket value is discrete and node dependent. The default value
* @param oneTime boolean value indicating if websocket must be closed (true) or not (false) * is 3600s. To get the available buckets of a node use
* after the response * get_all_asset_holders API call.
* @param listener a class implementing the WitnessResponseListener interface. This should * @param start datetime of of the most recent operation to retrieve (Note: The name is
* be implemented by the party interested in being notified about the success/failure * counter intuitive, but it follow the original API parameter name)
* of the transaction broadcast operation. * @param end datetime of the the earliest operation to retrieve
* @param oneTime boolean value indicating if WebSocket must be closed (true) or not
* (false) after the response
* @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the
* success/failure of the operation.
*/ */
public GetMarketHistory(Asset base, Asset quote, long bucket, Date start, Date end, boolean oneTime, WitnessResponseListener listener){ public GetMarketHistory(Asset base, Asset quote, long bucket, Date start, Date end, boolean oneTime, WitnessResponseListener listener){
super(listener); super(listener);
@ -76,15 +82,21 @@ public class GetMarketHistory extends BaseGrapheneHandler {
} }
/** /**
* Using this constructor the websocket connection closes after the response. * Using this constructor the WebSocket connection closes after the response.
* *
* @param base * @param base asset which history is desired
* @param quote * @param quote asset which the base price asset will be compared to
* @param bucket * @param bucket the time interval (in seconds) for each point should be (analog to
* @param start * candles on a candle stick graph).
* @param end * Note: The bucket value is discrete and node dependent. The default value
* @param listener a class implementing the WitnessResponseListener interface. This should * is 3600s. To get the available buckets of a node use
* be implemented by the party interested in being notified about the success/failure * get_all_asset_holders API call.
* @param start datetime of of the most recent operation to retrieve (Note: The name is
* counter intuitive, but it follow the original API parameter name)
* @param end datetime of the the earliest operation to retrieve
* @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the
* success/failure of the operation.
*/ */
public GetMarketHistory(Asset base, Asset quote, long bucket, Date start, Date end, WitnessResponseListener listener){ public GetMarketHistory(Asset base, Asset quote, long bucket, Date start, Date end, WitnessResponseListener listener){
this(base, quote, bucket, start, end, true, listener); this(base, quote, bucket, start, end, true, listener);
@ -135,7 +147,7 @@ public class GetMarketHistory extends BaseGrapheneHandler {
} }
public void disconnect(){ public void disconnect(){
if(mWebsocket != null && mWebsocket.isOpen() && mOneTime){ if(mWebsocket != null && mWebsocket.isOpen()){
mWebsocket.disconnect(); mWebsocket.disconnect();
} }
} }

View file

@ -28,19 +28,45 @@ import de.bitsharesmunich.graphenej.models.BitAssetData;
import de.bitsharesmunich.graphenej.models.WitnessResponse; import de.bitsharesmunich.graphenej.models.WitnessResponse;
/** /**
* Created by nelson on 1/8/17. *
* Class that implements get_objects request handler.
*
* Get the objects corresponding to the provided IDs.
*
* The response returns a list of objects retrieved, in the order they are mentioned in ids
*
* @see <a href="https://goo.gl/isRfeg">get_objects API doc</a>
*
*/ */
public class GetObjects extends BaseGrapheneHandler { public class GetObjects extends BaseGrapheneHandler {
private List<String> ids; private List<String> ids;
private boolean mOneTime; private boolean mOneTime;
/**
* Default Constructor
*
* @param ids list of IDs of the objects to retrieve
* @param oneTime boolean value indicating if WebSocket must be closed (true) or not
* (false) after the response
* @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the
* success/failure of the operation.
*/
public GetObjects(List<String> ids, boolean oneTime, WitnessResponseListener listener){ public GetObjects(List<String> ids, boolean oneTime, WitnessResponseListener listener){
super(listener); super(listener);
this.ids = ids; this.ids = ids;
this.mOneTime = oneTime; this.mOneTime = oneTime;
} }
/**
* Using this constructor the WebSocket connection closes after the response.
*
* @param ids list of IDs of the objects to retrieve
* @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the
* success/failure of the operation.
*/
public GetObjects(List<String> ids, WitnessResponseListener listener){ public GetObjects(List<String> ids, WitnessResponseListener listener){
this(ids, true, listener); this(ids, true, listener);
} }

View file

@ -52,12 +52,16 @@ public class GetRelativeAccountHistory extends BaseGrapheneHandler {
/** /**
* Constructor that takes all possible parameters. * Constructor that takes all possible parameters.
* @param userAccount The user account to be queried *
* @param stop Sequence number of earliest operation * @param userAccount The user account to be queried
* @param limit Maximum number of operations to retrieve (must not exceed 100) * @param stop Sequence number of earliest operation
* @param start Sequence number of the most recent operation to retrieve * @param limit Maximum number of operations to retrieve (must not exceed 100)
* @param oneTime Boolean value indicating if websocket must be closed or not after request * @param start Sequence number of the most recent operation to retrieve
* @param listener Listener to be notified with the result of this query * @param oneTime boolean value indicating if WebSocket must be closed (true) or not
* (false) after the response
* @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the
* success/failure of the operation.
*/ */
public GetRelativeAccountHistory(UserAccount userAccount, int stop, int limit, int start, boolean oneTime, WitnessResponseListener listener){ public GetRelativeAccountHistory(UserAccount userAccount, int stop, int limit, int start, boolean oneTime, WitnessResponseListener listener){
super(listener); super(listener);
@ -72,9 +76,13 @@ public class GetRelativeAccountHistory extends BaseGrapheneHandler {
/** /**
* Constructor that uses the default values, and sets the limit to its maximum possible value. * Constructor that uses the default values, and sets the limit to its maximum possible value.
* @param userAccount The user account to be queried *
* @param oneTime Boolean value indicating if websocket must be closed or not after request * @param userAccount The user account to be queried
* @param listener Listener to be notified with the result of this query * @param oneTime boolean value indicating if WebSocket must be closed (true) or not
* (false) after the response
* @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the
* success/failure of the operation.
*/ */
public GetRelativeAccountHistory(UserAccount userAccount, boolean oneTime, WitnessResponseListener listener){ public GetRelativeAccountHistory(UserAccount userAccount, boolean oneTime, WitnessResponseListener listener){
super(listener); super(listener);
@ -87,12 +95,16 @@ public class GetRelativeAccountHistory extends BaseGrapheneHandler {
} }
/** /**
* Constructor that takes all possible parameters except for oneTime (which will be always true here) * Constructor that takes all possible parameters for the query.
* @param userAccount The user account to be queried * Using this constructor the WebSocket connection closes after the response.
* @param stop Sequence number of earliest operation *
* @param limit Maximum number of operations to retrieve (must not exceed 100) * @param userAccount The user account to be queried
* @param start Sequence number of the most recent operation to retrieve * @param stop Sequence number of earliest operation
* @param listener Listener to be notified with the result of this query * @param limit Maximum number of operations to retrieve (must not exceed 100)
* @param start Sequence number of the most recent operation to retrieve
* @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the
* success/failure of the operation.
*/ */
public GetRelativeAccountHistory(UserAccount userAccount, int stop, int limit, int start, WitnessResponseListener listener){ public GetRelativeAccountHistory(UserAccount userAccount, int stop, int limit, int start, WitnessResponseListener listener){
this(userAccount, stop, limit, start, true, listener); this(userAccount, stop, limit, start, true, listener);
@ -100,9 +112,12 @@ public class GetRelativeAccountHistory extends BaseGrapheneHandler {
/** /**
* Constructor that uses the default values, and sets the limit to its maximum possible value. * Constructor that uses the default values, and sets the limit to its maximum possible value.
* oneTime is always set to true at this constructor. * Using this constructor the WebSocket connection closes after the response.
* @param userAccount The user account to be queried *
* @param listener Listener to be notified with the result of this query * @param userAccount The user account to be queried
* @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the
* success/failure of the operation.
*/ */
public GetRelativeAccountHistory(UserAccount userAccount, WitnessResponseListener listener){ public GetRelativeAccountHistory(UserAccount userAccount, WitnessResponseListener listener){
this(userAccount, true, listener); this(userAccount, true, listener);
@ -167,7 +182,8 @@ public class GetRelativeAccountHistory extends BaseGrapheneHandler {
} }
/** /**
* Updates the arguments and makes a new call to the get_relative_account_history API * Updates the arguments and makes a new call to the get_relative_account_history API.
*
* @param stop Sequence number of earliest operation * @param stop Sequence number of earliest operation
* @param limit Maximum number of operations to retrieve (must not exceed 100) * @param limit Maximum number of operations to retrieve (must not exceed 100)
* @param start Sequence number of the most recent operation to retrieve * @param start Sequence number of the most recent operation to retrieve
@ -180,7 +196,7 @@ public class GetRelativeAccountHistory extends BaseGrapheneHandler {
} }
/** /**
* Disconnects the websocket * Disconnects the WebSocket.
*/ */
public void disconnect(){ public void disconnect(){
if(mWebsocket != null && mWebsocket.isOpen() && mOneTime){ if(mWebsocket != null && mWebsocket.isOpen() && mOneTime){

View file

@ -38,15 +38,15 @@ public class GetRequiredFees extends BaseGrapheneHandler {
private boolean mOneTime; private boolean mOneTime;
/** /**
* Constructor * Default Constructor
* *
* @param operations list of operations that fee should be calculated * @param operations list of operations that fee should be calculated
* @param asset specify the asset of the operations * @param asset specify the asset of the operations
* @param oneTime boolean value indicating if websocket must be closed (true) or not (false) * @param oneTime boolean value indicating if WebSocket must be closed (true) or not
* after the response * (false) after the response
* @param listener A class implementing the WitnessResponseListener interface. This should * @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the success/failure * be implemented by the party interested in being notified about the
* of the transaction broadcast operation. * success/failure of the operation.
*/ */
public GetRequiredFees(List<BaseOperation> operations, Asset asset, boolean oneTime, WitnessResponseListener listener){ public GetRequiredFees(List<BaseOperation> operations, Asset asset, boolean oneTime, WitnessResponseListener listener){
super(listener); super(listener);
@ -57,13 +57,13 @@ public class GetRequiredFees extends BaseGrapheneHandler {
} }
/** /**
* Using this constructor the websocket connection closes after the response. * Using this constructor the WebSocket connection closes after the response.
* *
* @param operations list of operations that fee should be calculated * @param operations list of operations that fee should be calculated
* @param asset specify the asset of the operations * @param asset specify the asset of the operations
* @param listener A class implementing the WitnessResponseListener interface. This should * @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the success/failure * be implemented by the party interested in being notified about the
* of the transaction broadcast operation. * success/failure of the operation.
*/ */
public GetRequiredFees(List<BaseOperation> operations, Asset asset, WitnessResponseListener listener){ public GetRequiredFees(List<BaseOperation> operations, Asset asset, WitnessResponseListener listener){
this(operations, asset, true, listener); this(operations, asset, true, listener);

View file

@ -18,7 +18,15 @@ import de.bitsharesmunich.graphenej.models.ApiCall;
import de.bitsharesmunich.graphenej.models.WitnessResponse; import de.bitsharesmunich.graphenej.models.WitnessResponse;
/** /**
* @author henry * Class that implements get_trade_history request handler.
*
* Get recent trades for the market assetA:assetB for a time interval
* Note: Currently, timezone offsets are not supported. The time must be UTC.
*
* The request returns the all trades of the passed pair of asset at a specific time interval.
*
* @see <a href="https://goo.gl/Y1x3bE">get_trade_history API doc</a>
*
*/ */
public class GetTradeHistory extends BaseGrapheneHandler { public class GetTradeHistory extends BaseGrapheneHandler {
@ -31,19 +39,45 @@ public class GetTradeHistory extends BaseGrapheneHandler {
private boolean mOneTime; private boolean mOneTime;
public GetTradeHistory(String a, String b, String toTime, String fromTime,int limit, boolean oneTime, WitnessResponseListener mListener) { /**
super(mListener); * Constructor
*
* @param a name of the first asset
* @param b name of the second asset
* @param toTime stop time as a UNIX timestamp
* @param fromTime start time as a UNIX timestamp
* @param limit number of transactions to retrieve, capped at 100
* @param oneTime boolean value indicating if WebSocket must be closed (true) or not
* (false) after the response
* @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the
* success/failure of the operation.
*/
public GetTradeHistory(String a, String b, String toTime, String fromTime,int limit, boolean oneTime, WitnessResponseListener listener) {
super(listener);
this.a = a; this.a = a;
this.b = b; this.b = b;
this.toTime = toTime; this.toTime = toTime;
this.fromTime = fromTime; this.fromTime = fromTime;
this.limit = limit; this.limit = limit;
this.mOneTime = oneTime; this.mOneTime = oneTime;
this.mListener = mListener; this.mListener = listener;
} }
public GetTradeHistory(String a, String b, String toTime, String fromTime,int limit, WitnessResponseListener mListener) { /**
this(a, b, toTime, fromTime, limit, true, mListener); * Using this constructor the WebSocket connection closes after the response.
*
* @param a name of the first asset
* @param b name of the second asset
* @param toTime stop time as a UNIX timestamp
* @param fromTime start time as a UNIX timestamp
* @param limit number of transactions to retrieve, capped at 100
* @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the
* success/failure of the operation.
*/
public GetTradeHistory(String a, String b, String toTime, String fromTime,int limit, WitnessResponseListener listener) {
this(a, b, toTime, fromTime, limit, true, listener);
} }
@Override @Override

View file

@ -19,13 +19,12 @@ import java.util.Map;
/** /**
* WebSocketAdapter class used to send a request a 'list_assets' API call to the witness node. * WebSocketAdapter class used to send a request a 'list_assets' API call to the witness node.
* *
* @see: <a href="http://docs.bitshares.org/development/namespaces/app.html"></a>
*
* The API imposes a limit of of 100 assets per request, but if the user of this class wants * The API imposes a limit of of 100 assets per request, but if the user of this class wants
* to get a list of all assets, the LIST_ALL constant must be used as second argument in the * to get a list of all assets, the LIST_ALL constant must be used as second argument in the
* constructor. Internally we are going to perform multiple calls in order to satisfy the user's * constructor. Internally we are going to perform multiple calls in order to satisfy the user's
* request. * request.
* *
* @see: <a href="http://docs.bitshares.org/development/namespaces/app.html"></a>
*/ */
public class ListAssets extends BaseGrapheneHandler { public class ListAssets extends BaseGrapheneHandler {
/** /**
@ -49,9 +48,14 @@ public class ListAssets extends BaseGrapheneHandler {
/** /**
* Constructor * Constructor
* *
* @param lowerBoundSymbol: Lower bound of symbol names to retrieve * @param lowerBoundSymbol Lower bound of symbol names to retrieve
* @param limit: Maximum number of assets to fetch, if the constant LIST_ALL * @param limit Maximum number of assets to fetch, if the constant LIST_ALL
* is passed, all existing assets will be retrieved. * is passed, all existing assets will be retrieved.
* @param oneTime boolean value indicating if WebSocket must be closed (true) or not
* (false) after the response
* @param listener A class implementing the WitnessResponseListener interface. This
* should be implemented by the party interested in being notified
* about the success/failure of the operation.
*/ */
public ListAssets(String lowerBoundSymbol, int limit, boolean oneTime, WitnessResponseListener listener){ public ListAssets(String lowerBoundSymbol, int limit, boolean oneTime, WitnessResponseListener listener){
super(listener); super(listener);
@ -63,9 +67,14 @@ public class ListAssets extends BaseGrapheneHandler {
/** /**
* Using this constructor the WebSocket connection closes after the response. * Using this constructor the WebSocket connection closes after the response.
* *
* @param lowerBoundSymbol: Lower bound of symbol names to retrieve * @param lowerBoundSymbol Lower bound of symbol names to retrieve
* @param limit: Maximum number of assets to fetch, if the constant LIST_ALL * @param limit Maximum number of assets to fetch, if the constant LIST_ALL
* is passed, all existing assets will be retrieved. * is passed, all existing assets will be retrieved.
* @param oneTime boolean value indicating if WebSocket must be closed (true) or not
* (false) after the response
* @param listener A class implementing the WitnessResponseListener interface. This
* should be implemented by the party interested in being notified
* about the success/failure of the operation.
*/ */
public ListAssets(String lowerBoundSymbol, int limit, WitnessResponseListener listener){ public ListAssets(String lowerBoundSymbol, int limit, WitnessResponseListener listener){
this(lowerBoundSymbol, limit, true, listener); this(lowerBoundSymbol, limit, true, listener);

View file

@ -38,12 +38,12 @@ public class LookupAccounts extends BaseGrapheneHandler {
/** /**
* Constructor * Constructor
* *
* @param accountName account name used at the query * @param accountName account name used at the query
* @param oneTime boolean value indicating if websocket must be closed (true) or not (false) * @param oneTime boolean value indicating if WebSocket must be closed (true) or not
* after the response * (false) after the response
* @param listener A class implementing the WitnessResponseListener interface. This should * @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the success/failure * be implemented by the party interested in being notified about the
* of the transaction broadcast operation. * success/failure of the operation.
*/ */
public LookupAccounts(String accountName, boolean oneTime, WitnessResponseListener listener){ public LookupAccounts(String accountName, boolean oneTime, WitnessResponseListener listener){
super(listener); super(listener);
@ -56,13 +56,13 @@ public class LookupAccounts extends BaseGrapheneHandler {
/** /**
* Constructor with maxAccounts * Constructor with maxAccounts
* *
* @param accountName account name used at the query * @param accountName account name used at the query
* @param maxAccounts maximum number of results to return (must not exceed 1000) * @param maxAccounts maximum number of results to return (must not exceed 1000)
* @param oneTime boolean value indicating if websocket must be closed (true) or not (false) * @param oneTime boolean value indicating if WebSocket must be closed (true) or not
* after the response * (false) after the response
* @param listener A class implementing the WitnessResponseListener interface. This should * @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the success/failure * be implemented by the party interested in being notified about the
* of the transaction broadcast operation. * success/failure of the operation.
*/ */
public LookupAccounts(String accountName, int maxAccounts, boolean oneTime, WitnessResponseListener listener){ public LookupAccounts(String accountName, int maxAccounts, boolean oneTime, WitnessResponseListener listener){
super(listener); super(listener);
@ -75,10 +75,10 @@ public class LookupAccounts extends BaseGrapheneHandler {
/** /**
* Using this constructor the WebSocket connection closes after the response. * Using this constructor the WebSocket connection closes after the response.
* *
* @param accountName account name used at the query * @param accountName account name used at the query
* @param listener A class implementing the WitnessResponseListener interface. This should * @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the success/failure * be implemented by the party interested in being notified about the
* of the transaction broadcast operation. * success/failure of the operation.
*/ */
public LookupAccounts(String accountName, WitnessResponseListener listener){ public LookupAccounts(String accountName, WitnessResponseListener listener){
this(accountName, true, listener); this(accountName, true, listener);
@ -87,9 +87,11 @@ public class LookupAccounts extends BaseGrapheneHandler {
/** /**
* Using this constructor the WebSocket connection closes after the response. * Using this constructor the WebSocket connection closes after the response.
* *
* @param accountName account name used at the query * @param accountName account name used at the query
* @param maxAccounts maximum number of results to return (must not exceed 1000) * @param maxAccounts maximum number of results to return (must not exceed 1000)
* @param listener * @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the
* success/failure of the operation.
*/ */
public LookupAccounts(String accountName, int maxAccounts, WitnessResponseListener listener){ public LookupAccounts(String accountName, int maxAccounts, WitnessResponseListener listener){
this(accountName, maxAccounts, true, listener); this(accountName, maxAccounts, true, listener);

View file

@ -33,14 +33,14 @@ public class LookupAssetSymbols extends BaseGrapheneHandler {
private boolean mOneTime; private boolean mOneTime;
/** /**
* Constructor * Default Constructor
* *
* @param assets list of the assets to retrieve * @param assets list of the assets to retrieve
* @param oneTime boolean value indicating if websocket must be closed (true) or not (false) * @param oneTime boolean value indicating if WebSocket must be closed (true) or not
* after the response * (false) after the response
* @param listener A class implementing the WitnessResponseListener interface. This should * @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the success/failure * be implemented by the party interested in being notified about the
* of the transaction broadcast operation. * success/failure of the operation.
*/ */
public LookupAssetSymbols(List<Asset> assets, boolean oneTime, WitnessResponseListener listener){ public LookupAssetSymbols(List<Asset> assets, boolean oneTime, WitnessResponseListener listener){
super(listener); super(listener);
@ -52,10 +52,10 @@ public class LookupAssetSymbols extends BaseGrapheneHandler {
/** /**
* Using this constructor the WebSocket connection closes after the response. * Using this constructor the WebSocket connection closes after the response.
* *
* @param assets list of the assets to retrieve * @param assets list of the assets to retrieve
* @param listener A class implementing the WitnessResponseListener interface. This should * @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the success/failure * be implemented by the party interested in being notified about the
* of the transaction broadcast operation. * success/failure of the operation.
*/ */
public LookupAssetSymbols(List<Asset> assets, WitnessResponseListener listener){ public LookupAssetSymbols(List<Asset> assets, WitnessResponseListener listener){
this(assets, true, listener); this(assets, true, listener);

View file

@ -31,8 +31,6 @@ import de.bitsharesmunich.graphenej.operations.TransferOperation;
/** /**
* A WebSocket adapter prepared to be used as a basic dispatch hub for subscription messages. * A WebSocket adapter prepared to be used as a basic dispatch hub for subscription messages.
*
* Created by nelson on 1/26/17.
*/ */
public class SubscriptionMessagesHub extends BaseGrapheneHandler implements SubscriptionHub { public class SubscriptionMessagesHub extends BaseGrapheneHandler implements SubscriptionHub {
@ -73,10 +71,11 @@ public class SubscriptionMessagesHub extends BaseGrapheneHandler implements Subs
* *
* A list of ObjectTypes must be provided, otherwise we won't get any update. * A list of ObjectTypes must be provided, otherwise we won't get any update.
* *
* @param user: User name, in case the node to which we're going to connect to requires authentication * @param user User name, in case the node to which we're going to connect to requires
* @param password: Password, same as above * authentication
* @param clearFilter: Whether to automatically subscribe of not to the notification feed. * @param password Password, same as above
* @param errorListener: Callback that will be fired in case there is an error. * @param clearFilter Whether to automatically subscribe of not to the notification feed.
* @param errorListener Callback that will be fired in case there is an error.
*/ */
public SubscriptionMessagesHub(String user, String password, boolean clearFilter, NodeErrorListener errorListener){ public SubscriptionMessagesHub(String user, String password, boolean clearFilter, NodeErrorListener errorListener){
super(errorListener); super(errorListener);
@ -96,13 +95,14 @@ public class SubscriptionMessagesHub extends BaseGrapheneHandler implements Subs
} }
/** /**
* Constructor used to create a subscription message hub that will call the set_subscribe_callback * Constructor used to create a subscription message hub that will call the
* API with the clear_filter parameter set to false, meaning that it will only receive updates * set_subscribe_callback API with the clear_filter parameter set to false, meaning that it will
* from objects we register. * only receive updates from objects we register.
* *
* @param user: User name, in case the node to which we're going to connect to requires authentication * @param user User name, in case the node to which we're going to connect to requires
* @param password: Password, same as above * authentication
* @param errorListener: Callback that will be fired in case there is an error. * @param password Password, same as above
* @param errorListener Callback that will be fired in case there is an error.
*/ */
public SubscriptionMessagesHub(String user, String password, NodeErrorListener errorListener){ public SubscriptionMessagesHub(String user, String password, NodeErrorListener errorListener){
this(user, password, false, errorListener); this(user, password, false, errorListener);
@ -246,7 +246,8 @@ public class SubscriptionMessagesHub extends BaseGrapheneHandler implements Subs
/** /**
* Method used to check the current state of the connection. * Method used to check the current state of the connection.
* @return: True if the websocket is open and there is an active subscription, false otherwise. *
* @return True if the websocket is open and there is an active subscription, false otherwise.
*/ */
public boolean isSubscribed(){ public boolean isSubscribed(){
return this.mWebsocket.isOpen() && isSubscribed; return this.mWebsocket.isOpen() && isSubscribed;

View file

@ -46,12 +46,14 @@ public class TransactionBroadcastSequence extends BaseGrapheneHandler {
private boolean mOneTime; private boolean mOneTime;
/** /**
* Constructor of this class. The ids required * Default Constructor
* @param transaction: The transaction to be broadcasted. *
* @param oneTime Boolean value indicating if websocket must be closed or not after request * @param transaction transaction to be broadcasted.
* @param listener: A class implementing the WitnessResponseListener interface. This should * @param oneTime boolean value indicating if WebSocket must be closed (true) or not
* be implemented by the party interested in being notified about the success/failure * (false) after the response
* of the transaction broadcast operation. * @param listener A class implementing the WitnessResponseListener interface. This should
* be implemented by the party interested in being notified about the
* success/failure of the operation.
*/ */
public TransactionBroadcastSequence(Transaction transaction, Asset feeAsset, boolean oneTime, WitnessResponseListener listener){ public TransactionBroadcastSequence(Transaction transaction, Asset feeAsset, boolean oneTime, WitnessResponseListener listener){
super(listener); super(listener);
@ -62,11 +64,12 @@ public class TransactionBroadcastSequence extends BaseGrapheneHandler {
} }
/** /**
* Constructor of this class with oneTime=true * Using this constructor the WebSocket connection closes after the response.
* @param transaction: The transaction to be broadcasted. *
* @param listener: A class implementing the WitnessResponseListener interface. This should * @param transaction: transaction to be broadcasted.
* be implemented by the party interested in being notified about the success/failure * @param listener A class implementing the WitnessResponseListener interface. This should
* of the transaction broadcast operation. * be implemented by the party interested in being notified about the
* success/failure of the operation.
*/ */
public TransactionBroadcastSequence(Transaction transaction, Asset feeAsset, WitnessResponseListener listener){ public TransactionBroadcastSequence(Transaction transaction, Asset feeAsset, WitnessResponseListener listener){
this(transaction, feeAsset, true, listener); this(transaction, feeAsset, true, listener);

View file

@ -11,9 +11,11 @@ import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener;
import de.bitsharesmunich.graphenej.models.BaseResponse; import de.bitsharesmunich.graphenej.models.BaseResponse;
/** /**
* Created by nelson on 6/26/17. * Class used to encapsulate all connections that should be done to a node (with node hop support).
*
* This class is intended to be used as a central broker for all full node API requests. It should
* be used as a singleton under an application.
*/ */
public class NodeConnection { public class NodeConnection {
/** /**
* List of URLs of the nodes * List of URLs of the nodes
@ -35,7 +37,7 @@ public class NodeConnection {
private boolean mSubscribe; private boolean mSubscribe;
/* /*
* Ger the instance of the NodeConnection which is inteded to be used as a Singleton. * Get the instance of the NodeConnection which is intended to be used as a Singleton.
*/ */
public static NodeConnection getInstance(){ public static NodeConnection getInstance(){
if(instance == null){ if(instance == null){
@ -49,7 +51,7 @@ public class NodeConnection {
} }
/** /**
* Add a websocket URL node that will be added to the list used at node hop scheme. * Add a WebSocket URL node that will be added to the list used at node hop scheme.
* *
* @param url: URL of the node * @param url: URL of the node
*/ */
@ -59,7 +61,7 @@ public class NodeConnection {
} }
/** /**
* Add a list of websocket URL nodes that will be added to the current list and * Add a list of WebSocket URL nodes that will be added to the current list and
* be used at node hop scheme. * be used at node hop scheme.
* *
* @param urlList: List of URLs of the nodes * @param urlList: List of URLs of the nodes
@ -70,7 +72,7 @@ public class NodeConnection {
} }
/** /**
* Get the list of websocket URL nodes. * Get the list of WebSocket URL nodes.
* *
* @return List of URLs of the nodes * @return List of URLs of the nodes
*/ */
@ -79,7 +81,7 @@ public class NodeConnection {
} }
/** /**
* Clear list of websocket URL nodes. * Clear list of WebSocket URL nodes.
*/ */
public void clearNodeList(){ public void clearNodeList(){
this.mUrlList.clear(); this.mUrlList.clear();
@ -94,10 +96,22 @@ public class NodeConnection {
} }
}; };
/**
*/
/** /**
* Method that will try to connect to one of the nodes. If the connection fails * Method that will try to connect to one of the nodes. If the connection fails
* a subsequent call to this method will try to connect with the next node in the * a subsequent call to this method will try to connect with the next node in the
* list if there is one. * list if there is one.
*
* @param user user credential used for restricted requested that needed to be
* logged
* @param password password credential used for restricted requested that needed to be
* logged
* @param subscribe if the node should be subscribed to the node
* @param errorListener a class implementing the WitnessResponseListener interface. This
* should be implemented by the party interested in being notified
* about the failure of the desired broadcast operation.
*/ */
public void connect(String user, String password, boolean subscribe, WitnessResponseListener errorListener) { public void connect(String user, String password, boolean subscribe, WitnessResponseListener errorListener) {
if(this.mUrlList.size() > 0){ if(this.mUrlList.size() > 0){
@ -116,7 +130,10 @@ public class NodeConnection {
} }
/** /**
* Add the API Handler to the node. * Add the API Handler to the node.
*
* @param handler request handler to be added to the connection
* @throws RepeatedRequestIdException
*/ */
public void addRequestHandler(BaseGrapheneHandler handler) throws RepeatedRequestIdException { public void addRequestHandler(BaseGrapheneHandler handler) throws RepeatedRequestIdException {
handler.setRequestId(requestCounter); handler.setRequestId(requestCounter);

View file

@ -15,7 +15,8 @@ import de.bitsharesmunich.graphenej.models.BaseResponse;
import de.bitsharesmunich.graphenej.test.NaiveSSLContext; import de.bitsharesmunich.graphenej.test.NaiveSSLContext;
/** /**
* Created by nelson on 11/17/16. * Class used to encapsulate the thread where the WebSocket does the requests.
*
*/ */
public class WebsocketWorkerThread extends Thread { public class WebsocketWorkerThread extends Thread {
private final String TAG = this.getClass().getName(); private final String TAG = this.getClass().getName();
@ -27,6 +28,11 @@ public class WebsocketWorkerThread extends Thread {
private WebSocket mWebSocket; private WebSocket mWebSocket;
private NodeErrorListener mErrorListener; private NodeErrorListener mErrorListener;
/**
* Constructor
*
* @param url URL of the WebSocket
*/
public WebsocketWorkerThread(String url){ public WebsocketWorkerThread(String url){
try { try {
WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(TIMEOUT); WebSocketFactory factory = new WebSocketFactory().setConnectionTimeout(TIMEOUT);
@ -49,9 +55,12 @@ public class WebsocketWorkerThread extends Thread {
} }
/** /**
* Constructor with connection error listener * Constructor with connection error listener.
* @param url *
* @param errorListener * @param url URL of the WebSocket
* @param errorListener a class implementing the NodeErrorListener interface. This
* should be implemented by the party interested in being notified
* about the failure of the connection.
*/ */
public WebsocketWorkerThread(String url, NodeErrorListener errorListener){ public WebsocketWorkerThread(String url, NodeErrorListener errorListener){
try { try {
@ -75,6 +84,9 @@ public class WebsocketWorkerThread extends Thread {
} }
} }
/**
* Method call when the thread is started.
*/
@Override @Override
public void run() { public void run() {
try { try {
@ -85,6 +97,13 @@ public class WebsocketWorkerThread extends Thread {
} }
} }
/**
* Add a WebSocketListener to the thread that will run. This should be implemented by the party
* interested in being notified about the response value of a request.
*
* @param listener listener implemented to be notified when the socket get a response from the
* node
*/
public void addListener(WebSocketListener listener){ public void addListener(WebSocketListener listener){
mWebSocket.addListener(listener); mWebSocket.addListener(listener);
} }