mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
Фиксы SocketHookManager
Travis.CI
This commit is contained in:
parent
b892d50e6d
commit
7d89dc1c70
4 changed files with 32 additions and 5 deletions
|
@ -3,28 +3,35 @@
|
|||
import ru.gravit.launcher.request.RequestException;
|
||||
import ru.gravit.launchserver.socket.SocketContext;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class SocketHookManager {
|
||||
@FunctionalInterface
|
||||
interface SocketPreHook
|
||||
public interface SocketPreHook
|
||||
{
|
||||
boolean preHook(SocketContext context); //Вернуть true если необходимо продолжть обработку, false если остановить обработку
|
||||
}
|
||||
@FunctionalInterface
|
||||
interface SocketPostHook
|
||||
public interface SocketPostHook
|
||||
{
|
||||
void postHook(SocketContext context);
|
||||
}
|
||||
@FunctionalInterface
|
||||
interface SocketErrorHook
|
||||
public interface SocketErrorHook
|
||||
{
|
||||
boolean errorHook(SocketContext context, RequestException e); //Вернуть true если необходимо продолжть обработку, false если остановить обработку
|
||||
}
|
||||
@FunctionalInterface
|
||||
public interface SocketFatalErrorHook
|
||||
{
|
||||
boolean fatalErrorHook(Socket socket, Exception e); //Вернуть true если необходимо продолжть обработку, false если остановить обработку
|
||||
}
|
||||
private Set<SocketPostHook> POST_HOOKS;
|
||||
private Set<SocketPreHook> PRE_HOOKS;
|
||||
private Set<SocketErrorHook> ERROR_HOOKS;
|
||||
private Set<SocketFatalErrorHook> FATALERROR_HOOKS;
|
||||
public void registerPostHook(SocketPostHook hook)
|
||||
{
|
||||
if(POST_HOOKS == null) POST_HOOKS = new HashSet<>();
|
||||
|
@ -40,6 +47,11 @@ public void registerErrorHook(SocketErrorHook hook)
|
|||
if(ERROR_HOOKS == null) ERROR_HOOKS = new HashSet<>();
|
||||
ERROR_HOOKS.add(hook);
|
||||
}
|
||||
public void registerFatalErrorHook(SocketFatalErrorHook hook)
|
||||
{
|
||||
if(FATALERROR_HOOKS == null) FATALERROR_HOOKS = new HashSet<>();
|
||||
FATALERROR_HOOKS.add(hook);
|
||||
}
|
||||
public boolean preHook(SocketContext context)
|
||||
{
|
||||
if(PRE_HOOKS == null) return true;
|
||||
|
@ -66,4 +78,13 @@ public boolean errorHook(SocketContext context, RequestException e)
|
|||
}
|
||||
return true;
|
||||
}
|
||||
public boolean fatalErrorHook(Socket socket, Exception e)
|
||||
{
|
||||
if(FATALERROR_HOOKS == null) return true;
|
||||
for(SocketFatalErrorHook errorHook : FATALERROR_HOOKS)
|
||||
{
|
||||
if(!errorHook.fatalErrorHook(socket,e)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,7 +133,8 @@ public void run() {
|
|||
}
|
||||
} catch (Exception e) {
|
||||
savedError = e;
|
||||
LogHelper.error(e);
|
||||
if(server.socketHookManager.fatalErrorHook(socket,e))
|
||||
LogHelper.error(e);
|
||||
} finally {
|
||||
IOHelper.close(socket);
|
||||
if (!cancelled)
|
||||
|
|
|
@ -101,7 +101,11 @@ public void run() {
|
|||
// Invoke pre-connect listener
|
||||
long id = idCounter.incrementAndGet();
|
||||
if (listener != null && !listener.onConnect(socket.getInetAddress()))
|
||||
{
|
||||
socket.close();
|
||||
continue; // Listener didn't accepted this connection
|
||||
}
|
||||
|
||||
|
||||
// Reply in separate thread
|
||||
threadPool.execute(new ResponseThread(server, id, socket, sessionManager, server.socketHookManager));
|
||||
|
|
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,5 +1,6 @@
|
|||
#Wed Jan 02 17:51:09 GMT+07:00 2019
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip
|
||||
|
|
Loading…
Reference in a new issue