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.launcher.request.RequestException;
|
||||||
import ru.gravit.launchserver.socket.SocketContext;
|
import ru.gravit.launchserver.socket.SocketContext;
|
||||||
|
|
||||||
|
import java.net.Socket;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class SocketHookManager {
|
public class SocketHookManager {
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
interface SocketPreHook
|
public interface SocketPreHook
|
||||||
{
|
{
|
||||||
boolean preHook(SocketContext context); //Вернуть true если необходимо продолжть обработку, false если остановить обработку
|
boolean preHook(SocketContext context); //Вернуть true если необходимо продолжть обработку, false если остановить обработку
|
||||||
}
|
}
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
interface SocketPostHook
|
public interface SocketPostHook
|
||||||
{
|
{
|
||||||
void postHook(SocketContext context);
|
void postHook(SocketContext context);
|
||||||
}
|
}
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
interface SocketErrorHook
|
public interface SocketErrorHook
|
||||||
{
|
{
|
||||||
boolean errorHook(SocketContext context, RequestException e); //Вернуть true если необходимо продолжть обработку, false если остановить обработку
|
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<SocketPostHook> POST_HOOKS;
|
||||||
private Set<SocketPreHook> PRE_HOOKS;
|
private Set<SocketPreHook> PRE_HOOKS;
|
||||||
private Set<SocketErrorHook> ERROR_HOOKS;
|
private Set<SocketErrorHook> ERROR_HOOKS;
|
||||||
|
private Set<SocketFatalErrorHook> FATALERROR_HOOKS;
|
||||||
public void registerPostHook(SocketPostHook hook)
|
public void registerPostHook(SocketPostHook hook)
|
||||||
{
|
{
|
||||||
if(POST_HOOKS == null) POST_HOOKS = new HashSet<>();
|
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<>();
|
if(ERROR_HOOKS == null) ERROR_HOOKS = new HashSet<>();
|
||||||
ERROR_HOOKS.add(hook);
|
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)
|
public boolean preHook(SocketContext context)
|
||||||
{
|
{
|
||||||
if(PRE_HOOKS == null) return true;
|
if(PRE_HOOKS == null) return true;
|
||||||
|
@ -66,4 +78,13 @@ public boolean errorHook(SocketContext context, RequestException e)
|
||||||
}
|
}
|
||||||
return true;
|
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,6 +133,7 @@ public void run() {
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
savedError = e;
|
savedError = e;
|
||||||
|
if(server.socketHookManager.fatalErrorHook(socket,e))
|
||||||
LogHelper.error(e);
|
LogHelper.error(e);
|
||||||
} finally {
|
} finally {
|
||||||
IOHelper.close(socket);
|
IOHelper.close(socket);
|
||||||
|
|
|
@ -101,7 +101,11 @@ public void run() {
|
||||||
// Invoke pre-connect listener
|
// Invoke pre-connect listener
|
||||||
long id = idCounter.incrementAndGet();
|
long id = idCounter.incrementAndGet();
|
||||||
if (listener != null && !listener.onConnect(socket.getInetAddress()))
|
if (listener != null && !listener.onConnect(socket.getInetAddress()))
|
||||||
|
{
|
||||||
|
socket.close();
|
||||||
continue; // Listener didn't accepted this connection
|
continue; // Listener didn't accepted this connection
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Reply in separate thread
|
// Reply in separate thread
|
||||||
threadPool.execute(new ResponseThread(server, id, socket, sessionManager, server.socketHookManager));
|
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
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-bin.zip
|
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip
|
||||||
|
|
Loading…
Reference in a new issue