Ref: remove duplicate handle code
This commit is contained in:
@@ -19,7 +19,9 @@
|
||||
|
||||
package com.sheepit.client.exception;
|
||||
|
||||
public class SheepItExceptionBadResponseFromServer extends SheepItException {
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class SheepItExceptionBadResponseFromServer extends SheepItExceptionWithRequiredWait {
|
||||
public SheepItExceptionBadResponseFromServer() {
|
||||
super();
|
||||
}
|
||||
@@ -27,4 +29,12 @@ public class SheepItExceptionBadResponseFromServer extends SheepItException {
|
||||
public SheepItExceptionBadResponseFromServer(String message_) {
|
||||
super(message_);
|
||||
}
|
||||
|
||||
public String getHumanText() {
|
||||
return "Bad answer from the server. Will try again at %tR";
|
||||
}
|
||||
|
||||
public int getWaitDuration() {
|
||||
return 1000 * 60 * ThreadLocalRandom.current().nextInt(15, 30 + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
|
||||
package com.sheepit.client.exception;
|
||||
|
||||
public class SheepItExceptionServerInMaintenance extends SheepItException {
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class SheepItExceptionServerInMaintenance extends SheepItExceptionWithRequiredWait {
|
||||
public SheepItExceptionServerInMaintenance() {
|
||||
super();
|
||||
}
|
||||
@@ -27,4 +29,12 @@ public class SheepItExceptionServerInMaintenance extends SheepItException {
|
||||
public SheepItExceptionServerInMaintenance(String message_) {
|
||||
super(message_);
|
||||
}
|
||||
|
||||
public String getHumanText() {
|
||||
return "The server is under maintenance and cannot allocate a job. Will try again at %tR";
|
||||
}
|
||||
|
||||
public int getWaitDuration() {
|
||||
return 1000 * 60 * ThreadLocalRandom.current().nextInt(20, 30 + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
|
||||
package com.sheepit.client.exception;
|
||||
|
||||
public class SheepItExceptionServerOverloaded extends SheepItException {
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class SheepItExceptionServerOverloaded extends SheepItExceptionWithRequiredWait {
|
||||
public SheepItExceptionServerOverloaded() {
|
||||
super();
|
||||
}
|
||||
@@ -27,4 +29,12 @@ public class SheepItExceptionServerOverloaded extends SheepItException {
|
||||
public SheepItExceptionServerOverloaded(String message_) {
|
||||
super(message_);
|
||||
}
|
||||
|
||||
public String getHumanText() {
|
||||
return "The server is overloaded and cannot allocate a job. Will try again at %tR";
|
||||
}
|
||||
|
||||
public int getWaitDuration() {
|
||||
return 1000 * 60 * ThreadLocalRandom.current().nextInt(10, 30 + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Laurent CLOUET
|
||||
* Author Laurent CLOUET <laurent.clouet@nopnop.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; version 2
|
||||
* of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package com.sheepit.client.exception;
|
||||
|
||||
/**
|
||||
* When a request to the server generate this exception.
|
||||
* The client must wait a bit before retrying.
|
||||
*/
|
||||
public class SheepItExceptionWithRequiredWait extends SheepItException {
|
||||
public SheepItExceptionWithRequiredWait() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SheepItExceptionWithRequiredWait(String message_) {
|
||||
super(message_);
|
||||
}
|
||||
|
||||
public String getHumanText() {
|
||||
return "Please wait a bit";
|
||||
}
|
||||
|
||||
/** how much time, it needs to wait
|
||||
*
|
||||
* @return duration in ms
|
||||
*/
|
||||
public int getWaitDuration() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -19,10 +19,12 @@
|
||||
|
||||
package com.sheepit.client.exception;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* Server down (server side error) or unreachable (client side error)
|
||||
*/
|
||||
public class SheepItServerDown extends SheepItException {
|
||||
public class SheepItServerDown extends SheepItExceptionWithRequiredWait {
|
||||
public SheepItServerDown() {
|
||||
super();
|
||||
}
|
||||
@@ -30,4 +32,12 @@ public class SheepItServerDown extends SheepItException {
|
||||
public SheepItServerDown(String message_) {
|
||||
super(message_);
|
||||
}
|
||||
|
||||
public String getHumanText() {
|
||||
return "Cannot connect to the server. Please check your connectivity. Will try again at %tR";
|
||||
}
|
||||
|
||||
public int getWaitDuration() {
|
||||
return 1000 * 60 * ThreadLocalRandom.current().nextInt(10, 30 + 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user