Skip to content

Commit

Permalink
Use super for errors to propagate cause (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia authored Feb 14, 2023
1 parent 1e69b4d commit 857d55d
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class ConfigurationError extends Throwable {
private final Throwable error;

ConfigurationError(Throwable error) {
super(error);
this.error = error;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,55 @@ public String getToken() {
return token;
}

/**
* Set connection token. If your tokens expire and you want SDK to automatically
* refresh tokens then set ConnectionTokenGetter (see below).
*/
public void setToken(String token) {
this.token = token;
}

/* Connection token. This is a token you have to receive from your application backend. */
/**
* Connection token. This is a token you have to receive from your application backend.
*/
private String token = "";

public String getName() {
return name;
public ConnectionTokenGetter getTokenGetter() {
return tokenGetter;
}

public void setName(String name) {
this.name = name;
/**
* Set a method to extract new connection token upon expiration.
*/
public void setTokenGetter(ConnectionTokenGetter tokenGetter) {
this.tokenGetter = tokenGetter;
}

/**
private ConnectionTokenGetter tokenGetter;

public String getName() {
return name;
}

/**
* Set client name - name of this client. This should not be unique per client – it
* identifies client application name actually, so name should have a limited
* number of possible values. By default this client uses "java" as a name.
*/
public void setName(String name) {
this.name = name;
}

private String name = "java";

public String getVersion() {
return version;
}

/**
* Set client version - version of application. This may be used for observability
* on the server (for example in analytics).
*/
public void setVersion(String version) {
this.version = version;
}
Expand All @@ -47,13 +70,19 @@ public byte[] getData() {
return data;
}

/**
* Set custom connection data. This data will be delivered to server in Connect command.
* For Centrifugo this may be useful in case of using connect proxy.
*/
public void setData(byte[] data) {
this.data = data;
}

/* Connect data to send to a server inside Connect command. */
private byte[] data;

/**
* Set custom headers for WebSocket Upgrade request.
*/
public void setHeaders(Map<String, String> headers) {
this.headers = headers;
}
Expand All @@ -69,14 +98,22 @@ public int getTimeout() {
return timeout;
}

/**
* Set custom timeout for requests in milliseconds. By default, 5000 is used.
*/
public void setTimeout(int timeout) {
this.timeout = timeout;
}

private int timeout = 5000;

public int getMinReconnectDelay() {
return minReconnectDelay;
}

/**
* Set minimal time before reconnect attempt in milliseconds. By default, 500 is used.
*/
public void setMinReconnectDelay(int minReconnectDelay) {
this.minReconnectDelay = minReconnectDelay;
}
Expand All @@ -87,24 +124,31 @@ public int getMaxReconnectDelay() {
return maxReconnectDelay;
}

/**
* Set max time between reconnect attempts in milliseconds. By default, 20000 is used.
*/
public void setMaxReconnectDelay(int maxReconnectDelay) {
this.maxReconnectDelay = maxReconnectDelay;
}

private int maxReconnectDelay = 20000;

private int timeout = 5000;

public int getMaxServerPingDelay() {
return maxServerPingDelay;
}

/**
* Set max time of ping delay from server in milliseconds. By default, 10000 is used.
*/
public void setMaxServerPingDelay(int maxServerPingDelay) {
this.maxServerPingDelay = maxServerPingDelay;
}

private int maxServerPingDelay = 10000;

/**
* Set proxy to use.
*/
public void setProxy(Proxy proxy) {
this.proxy = proxy;
}
Expand All @@ -118,6 +162,9 @@ public Proxy getProxy() {
private String proxyLogin;
private String proxyPassword;

/**
* Set proxy credentials.
*/
public void setProxyCredentials(String login, String password) {
this.proxyLogin = login;
this.proxyPassword = password;
Expand All @@ -131,19 +178,13 @@ public String getProxyPassword() {
return proxyPassword;
}

public ConnectionTokenGetter getTokenGetter() {
return tokenGetter;
}

public void setTokenGetter(ConnectionTokenGetter tokenGetter) {
this.tokenGetter = tokenGetter;
}

private ConnectionTokenGetter tokenGetter;

public Dns getDns() {
return this.dns;
}

/**
* Set custom DNS resolver..
*/
public void setDns(Dns dns) {
this.dns = dns;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ public Map<String, ClientInfo> getClients() {
return clients;
}

private Map<String, ClientInfo> clients;
private final Map<String, ClientInfo> clients;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package io.github.centrifugal.centrifuge;

import javax.annotation.Nullable;

public class RefreshError extends Throwable {
private final Throwable error;

RefreshError(@Nullable Throwable error) {
RefreshError(Throwable error) {
super(error);
this.error = error;
}

public @Nullable Throwable getError() {
public Throwable getError() {
return error;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
import javax.annotation.Nullable;

public interface ResultCallback<T> {
/**
* onDone will be called when the operation completed. Either Throwable or T will be not null.
*/
void onDone(@Nullable Throwable e, @Nullable T result);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package io.github.centrifugal.centrifuge;

public class SubscriptionErrorEvent {
public class SubscriptionErrorEvent extends Throwable {
private final Throwable error;

SubscriptionErrorEvent(Throwable t) {
super(t);
this.error = t;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class SubscriptionRefreshError extends Throwable {
private final Throwable error;

SubscriptionRefreshError(Throwable error) {
super(error);
this.error = error;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class SubscriptionSubscribeError extends Throwable {
private final Throwable error;

SubscriptionSubscribeError(Throwable error) {
super(error);
this.error = error;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class SubscriptionTokenError extends Throwable {
private final Throwable error;

SubscriptionTokenError(Throwable error) {
super(error);
this.error = error;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.centrifugal.centrifuge;

public class SubscriptionTokenEvent {
private String channel;
final private String channel;

public SubscriptionTokenEvent(String channel) {
this.channel = channel;
Expand All @@ -10,8 +10,4 @@ public SubscriptionTokenEvent(String channel) {
public String getChannel() {
return channel;
}

void setChannel(String channel) {
this.channel = channel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class TokenError extends Throwable {
private final Throwable error;

TokenError(Throwable error) {
super(error);
this.error = error;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class UnclassifiedError extends Throwable {
private final Throwable error;

UnclassifiedError(Throwable error) {
super(error);
this.error = error;
}

Expand Down

0 comments on commit 857d55d

Please sign in to comment.