From a23d059d1667eb7b1d043fc8624470edd2b6f83b Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Mon, 10 Apr 2017 16:27:56 -0500 Subject: [PATCH] Making other API classes extend the BaseGrapheneHandler --- .../graphenej/api/GetAccountByName.java | 35 +++++---------- .../graphenej/api/GetAccounts.java | 45 +++++-------------- .../graphenej/api/GetMarketHistory.java | 35 +++++---------- .../api/GetRelativeAccountHistory.java | 39 ++++++---------- .../graphenej/api/GetTradeHistory.java | 29 ++++-------- .../graphenej/api/LookupAccounts.java | 30 ++++--------- .../graphenej/api/LookupAssetSymbols.java | 34 ++++---------- 7 files changed, 71 insertions(+), 176 deletions(-) diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountByName.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountByName.java index bb5117a..f4f17f8 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountByName.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountByName.java @@ -1,19 +1,8 @@ package de.bitsharesmunich.graphenej.api; -import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; -import de.bitsharesmunich.graphenej.AccountOptions; -import de.bitsharesmunich.graphenej.Authority; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.AccountProperties; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.WitnessResponse; import com.neovisionaries.ws.client.WebSocket; -import com.neovisionaries.ws.client.WebSocketAdapter; -import com.neovisionaries.ws.client.WebSocketException; import com.neovisionaries.ws.client.WebSocketFrame; import java.io.Serializable; @@ -22,15 +11,24 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import de.bitsharesmunich.graphenej.AccountOptions; +import de.bitsharesmunich.graphenej.Authority; +import de.bitsharesmunich.graphenej.RPC; +import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; +import de.bitsharesmunich.graphenej.models.AccountProperties; +import de.bitsharesmunich.graphenej.models.ApiCall; +import de.bitsharesmunich.graphenej.models.WitnessResponse; + /** * Created by nelson on 11/15/16. */ -public class GetAccountByName extends WebSocketAdapter { +public class GetAccountByName extends BaseGrapheneHandler { private String accountName; private WitnessResponseListener mListener; public GetAccountByName(String accountName, WitnessResponseListener listener){ + super(listener); this.accountName = accountName; this.mListener = listener; } @@ -70,17 +68,4 @@ public class GetAccountByName extends WebSocketAdapter { System.out.println(">>> "+frame.getPayloadText()); } } - - - @Override - public void onError(WebSocket websocket, WebSocketException cause) throws Exception { - mListener.onError(new BaseResponse.Error(cause.getMessage())); - websocket.disconnect(); - } - - @Override - public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception { - mListener.onError(new BaseResponse.Error(cause.getMessage())); - websocket.disconnect(); - } } diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccounts.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccounts.java index 70b9f76..11377db 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccounts.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetAccounts.java @@ -1,23 +1,9 @@ package de.bitsharesmunich.graphenej.api; import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; import com.google.gson.reflect.TypeToken; -import de.bitsharesmunich.graphenej.AccountOptions; -import de.bitsharesmunich.graphenej.Authority; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.AccountProperties; -import de.bitsharesmunich.graphenej.models.BaseResponse; import com.neovisionaries.ws.client.WebSocket; -import com.neovisionaries.ws.client.WebSocketAdapter; -import com.neovisionaries.ws.client.WebSocketException; import com.neovisionaries.ws.client.WebSocketFrame; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.WitnessResponse; import java.io.Serializable; import java.lang.reflect.Type; @@ -25,22 +11,33 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import de.bitsharesmunich.graphenej.AccountOptions; +import de.bitsharesmunich.graphenej.Authority; +import de.bitsharesmunich.graphenej.RPC; +import de.bitsharesmunich.graphenej.UserAccount; +import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; +import de.bitsharesmunich.graphenej.models.AccountProperties; +import de.bitsharesmunich.graphenej.models.ApiCall; +import de.bitsharesmunich.graphenej.models.WitnessResponse; + /** * * @author henry */ -public class GetAccounts extends WebSocketAdapter { +public class GetAccounts extends BaseGrapheneHandler { private String accountId; private List userAccounts; private WitnessResponseListener mListener; public GetAccounts(String accountId, WitnessResponseListener listener){ + super(listener); this.accountId = accountId; this.mListener = listener; } public GetAccounts(List accounts, WitnessResponseListener listener){ + super(listener); this.userAccounts = accounts; this.mListener = listener; } @@ -85,22 +82,4 @@ public class GetAccounts extends WebSocketAdapter { if(frame.isTextFrame()) System.out.println(">>> "+frame.getPayloadText()); } - - @Override - public void onError(WebSocket websocket, WebSocketException cause) throws Exception { - System.out.println("onError"); - mListener.onError(new BaseResponse.Error(cause.getMessage())); - websocket.disconnect(); - } - - @Override - public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception { - System.out.println("handleCallbackError. Msg: "+cause.getMessage()); - StackTraceElement[] stack = cause.getStackTrace(); - for(StackTraceElement element : stack) { - System.out.println("> "+element.getClassName()+"."+element.getMethodName()+" : "+element.getLineNumber()); - } - mListener.onError(new BaseResponse.Error(cause.getMessage())); - websocket.disconnect(); - } } diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetMarketHistory.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetMarketHistory.java index 06a6a81..a7f7c3b 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetMarketHistory.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetMarketHistory.java @@ -4,13 +4,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.neovisionaries.ws.client.WebSocket; -import com.neovisionaries.ws.client.WebSocketAdapter; -import com.neovisionaries.ws.client.WebSocketException; import com.neovisionaries.ws.client.WebSocketFrame; -import de.bitsharesmunich.graphenej.Asset; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.*; import java.io.Serializable; import java.lang.reflect.Type; @@ -20,10 +14,19 @@ import java.util.Date; import java.util.List; import java.util.Map; +import de.bitsharesmunich.graphenej.Asset; +import de.bitsharesmunich.graphenej.RPC; +import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; +import de.bitsharesmunich.graphenej.models.ApiCall; +import de.bitsharesmunich.graphenej.models.BaseResponse; +import de.bitsharesmunich.graphenej.models.BucketObject; +import de.bitsharesmunich.graphenej.models.WitnessResponse; + /** * Created by nelson on 12/22/16. */ -public class GetMarketHistory extends WebSocketAdapter { +public class GetMarketHistory extends BaseGrapheneHandler { + // Sequence of message ids private final static int LOGIN_ID = 1; private final static int GET_HISTORY_ID = 2; @@ -41,6 +44,7 @@ public class GetMarketHistory extends WebSocketAdapter { private int apiId = -1; public GetMarketHistory(Asset base, Asset quote, long bucket, Date start, Date end, WitnessResponseListener listener){ + super(listener); this.base = base; this.quote = quote; this.bucket = bucket; @@ -105,21 +109,4 @@ public class GetMarketHistory extends WebSocketAdapter { if(frame.isTextFrame()) System.out.println(">>> "+frame.getPayloadText()); } - - @Override - public void onError(WebSocket websocket, WebSocketException cause) throws Exception { - System.out.println("onError. Msg: "+cause.getMessage()); - mListener.onError(new BaseResponse.Error(cause.getMessage())); - websocket.disconnect(); - } - - @Override - public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception { - System.out.println("handleCallbackError. cause: "+cause.getMessage()+", error: "+cause.getClass()); - for (StackTraceElement element : cause.getStackTrace()){ - System.out.println(element.getFileName()+"#"+element.getClassName()+":"+element.getLineNumber()); - } - mListener.onError(new BaseResponse.Error(cause.getMessage())); - websocket.disconnect(); - } } diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetRelativeAccountHistory.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetRelativeAccountHistory.java index 5507263..285a78d 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetRelativeAccountHistory.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetRelativeAccountHistory.java @@ -3,18 +3,7 @@ package de.bitsharesmunich.graphenej.api; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; -import de.bitsharesmunich.graphenej.AssetAmount; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.operations.TransferOperation; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.HistoricalTransfer; -import de.bitsharesmunich.graphenej.models.WitnessResponse; import com.neovisionaries.ws.client.WebSocket; -import com.neovisionaries.ws.client.WebSocketAdapter; -import com.neovisionaries.ws.client.WebSocketException; import com.neovisionaries.ws.client.WebSocketFrame; import java.io.Serializable; @@ -23,11 +12,21 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import de.bitsharesmunich.graphenej.AssetAmount; +import de.bitsharesmunich.graphenej.RPC; +import de.bitsharesmunich.graphenej.UserAccount; +import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; +import de.bitsharesmunich.graphenej.models.ApiCall; +import de.bitsharesmunich.graphenej.models.BaseResponse; +import de.bitsharesmunich.graphenej.models.HistoricalTransfer; +import de.bitsharesmunich.graphenej.models.WitnessResponse; +import de.bitsharesmunich.graphenej.operations.TransferOperation; + /** * Class used to encapsulate the communication sequence used to retrieve the transaction history of * a given user. */ -public class GetRelativeAccountHistory extends WebSocketAdapter { +public class GetRelativeAccountHistory extends BaseGrapheneHandler { // Sequence of message ids private final static int LOGIN_ID = 1; private final static int GET_HISTORY_ID = 2; @@ -57,6 +56,7 @@ public class GetRelativeAccountHistory extends WebSocketAdapter { * @param listener Listener to be notified with the result of this query */ public GetRelativeAccountHistory(UserAccount userAccount, int stop, int limit, int start, WitnessResponseListener listener){ + super(listener); if(limit > MAX_LIMIT) limit = MAX_LIMIT; this.mUserAccount = userAccount; this.stop = stop; @@ -71,6 +71,7 @@ public class GetRelativeAccountHistory extends WebSocketAdapter { * @param listener Listener to be notified with the result of this query */ public GetRelativeAccountHistory(UserAccount userAccount, WitnessResponseListener listener){ + super(listener); this.mUserAccount = userAccount; this.stop = DEFAULT_STOP; this.limit = MAX_LIMIT; @@ -132,18 +133,4 @@ public class GetRelativeAccountHistory extends WebSocketAdapter { if(frame.isTextFrame()) System.out.println(">>> "+frame.getPayloadText()); } - - @Override - public void onError(WebSocket websocket, WebSocketException cause) throws Exception { - System.out.println("onError. Msg: "+cause.getMessage()); - mListener.onError(new BaseResponse.Error(cause.getMessage())); - websocket.disconnect(); - } - - @Override - public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception { - System.out.println("handleCallbackError. Msg: "+cause.getMessage()); - mListener.onError(new BaseResponse.Error(cause.getMessage())); - websocket.disconnect(); - } } diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetTradeHistory.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetTradeHistory.java index 073ea25..46dd72d 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetTradeHistory.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/GetTradeHistory.java @@ -3,15 +3,7 @@ package de.bitsharesmunich.graphenej.api; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.neovisionaries.ws.client.WebSocket; -import com.neovisionaries.ws.client.WebSocketAdapter; -import com.neovisionaries.ws.client.WebSocketException; import com.neovisionaries.ws.client.WebSocketFrame; -import de.bitsharesmunich.graphenej.MarketTrade; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.WitnessResponse; import java.io.Serializable; import java.lang.reflect.Type; @@ -19,10 +11,16 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import de.bitsharesmunich.graphenej.MarketTrade; +import de.bitsharesmunich.graphenej.RPC; +import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; +import de.bitsharesmunich.graphenej.models.ApiCall; +import de.bitsharesmunich.graphenej.models.WitnessResponse; + /** * @author henry */ -public class GetTradeHistory extends WebSocketAdapter { +public class GetTradeHistory extends BaseGrapheneHandler { private String a; private String b; @@ -32,6 +30,7 @@ public class GetTradeHistory extends WebSocketAdapter { private WitnessResponseListener mListener; public GetTradeHistory(String a, String b, String toTime, String fromTime,int limit, WitnessResponseListener mListener) { + super(mListener); this.a = a; this.b = b; this.toTime = toTime; @@ -82,16 +81,4 @@ public class GetTradeHistory extends WebSocketAdapter { System.out.println(">>> " + frame.getPayloadText()); } } - - @Override - public void onError(WebSocket websocket, WebSocketException cause) throws Exception { - mListener.onError(new BaseResponse.Error(cause.getMessage())); - websocket.disconnect(); - } - - @Override - public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception { - mListener.onError(new BaseResponse.Error(cause.getMessage())); - websocket.disconnect(); - } } diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAccounts.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAccounts.java index 37274bd..6b424b9 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAccounts.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAccounts.java @@ -2,15 +2,7 @@ package de.bitsharesmunich.graphenej.api; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.UserAccount; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.WitnessResponse; import com.neovisionaries.ws.client.WebSocket; -import com.neovisionaries.ws.client.WebSocketAdapter; -import com.neovisionaries.ws.client.WebSocketException; import com.neovisionaries.ws.client.WebSocketFrame; import java.io.Serializable; @@ -19,10 +11,16 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import de.bitsharesmunich.graphenej.RPC; +import de.bitsharesmunich.graphenej.UserAccount; +import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; +import de.bitsharesmunich.graphenej.models.ApiCall; +import de.bitsharesmunich.graphenej.models.WitnessResponse; + /** * Created by henry on 07/12/16. */ -public class LookupAccounts extends WebSocketAdapter { +public class LookupAccounts extends BaseGrapheneHandler { public static final int DEFAULT_MAX = 1000; private final String accountName; @@ -30,12 +28,14 @@ public class LookupAccounts extends WebSocketAdapter { private final WitnessResponseListener mListener; public LookupAccounts(String accountName, WitnessResponseListener listener){ + super(listener); this.accountName = accountName; this.maxAccounts = DEFAULT_MAX; this.mListener = listener; } public LookupAccounts(String accountName, int maxAccounts, WitnessResponseListener listener){ + super(listener); this.accountName = accountName; this.maxAccounts = maxAccounts; this.mListener = listener; @@ -73,16 +73,4 @@ public class LookupAccounts extends WebSocketAdapter { if(frame.isTextFrame()) System.out.println(">>> "+frame.getPayloadText()); } - - @Override - public void onError(WebSocket websocket, WebSocketException cause) throws Exception { - mListener.onError(new BaseResponse.Error(cause.getMessage())); - websocket.disconnect(); - } - - @Override - public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception { - mListener.onError(new BaseResponse.Error(cause.getMessage())); - websocket.disconnect(); - } } \ No newline at end of file diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAssetSymbols.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAssetSymbols.java index 59e609f..3c24247 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAssetSymbols.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/LookupAssetSymbols.java @@ -3,15 +3,7 @@ package de.bitsharesmunich.graphenej.api; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.neovisionaries.ws.client.WebSocket; -import com.neovisionaries.ws.client.WebSocketAdapter; -import com.neovisionaries.ws.client.WebSocketException; import com.neovisionaries.ws.client.WebSocketFrame; -import de.bitsharesmunich.graphenej.Asset; -import de.bitsharesmunich.graphenej.RPC; -import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; -import de.bitsharesmunich.graphenej.models.ApiCall; -import de.bitsharesmunich.graphenej.models.BaseResponse; -import de.bitsharesmunich.graphenej.models.WitnessResponse; import java.io.Serializable; import java.lang.reflect.Type; @@ -19,14 +11,21 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import de.bitsharesmunich.graphenej.Asset; +import de.bitsharesmunich.graphenej.RPC; +import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; +import de.bitsharesmunich.graphenej.models.ApiCall; +import de.bitsharesmunich.graphenej.models.WitnessResponse; + /** * Created by nelson on 12/12/16. */ -public class LookupAssetSymbols extends WebSocketAdapter { +public class LookupAssetSymbols extends BaseGrapheneHandler { private WitnessResponseListener mListener; private List assets; public LookupAssetSymbols(List assets, WitnessResponseListener listener){ + super(listener); this.assets = assets; this.mListener = listener; } @@ -59,21 +58,4 @@ public class LookupAssetSymbols extends WebSocketAdapter { if(frame.isTextFrame()) System.out.println(">>> "+frame.getPayloadText()); } - - @Override - public void onError(WebSocket websocket, WebSocketException cause) throws Exception { - System.out.println("onError. cause: "+cause.getMessage()); - mListener.onError(new BaseResponse.Error(cause.getMessage())); - websocket.disconnect(); - } - - @Override - public void handleCallbackError(WebSocket websocket, Throwable cause) throws Exception { - System.out.println("handleCallbackError. cause: "+cause.getMessage()+", error: "+cause.getClass()); - for (StackTraceElement element : cause.getStackTrace()){ - System.out.println(element.getFileName()+"#"+element.getClassName()+":"+element.getLineNumber()); - } - mListener.onError(new BaseResponse.Error(cause.getMessage())); - websocket.disconnect(); - } }