mirror of https://github.com/rusefi/rusefi.git
my test phone is oooooold
This commit is contained in:
parent
3e207b5549
commit
42bf7f03c4
|
@ -0,0 +1,8 @@
|
||||||
|
package com.rusefi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* reducing Android level down from 24
|
||||||
|
*/
|
||||||
|
public interface CompatibleFunction<T, R> {
|
||||||
|
R apply(T t);
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package com.rusefi.io.tcp;
|
package com.rusefi.io.tcp;
|
||||||
|
|
||||||
import com.devexperts.logging.Logging;
|
import com.devexperts.logging.Logging;
|
||||||
|
import com.rusefi.CompatibleFunction;
|
||||||
import com.rusefi.Listener;
|
import com.rusefi.Listener;
|
||||||
import com.rusefi.Timeouts;
|
import com.rusefi.Timeouts;
|
||||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||||
|
@ -32,7 +33,7 @@ public class BinaryProtocolProxy {
|
||||||
public static final int USER_IO_TIMEOUT = 10 * Timeouts.MINUTE;
|
public static final int USER_IO_TIMEOUT = 10 * Timeouts.MINUTE;
|
||||||
|
|
||||||
public static ServerSocketReference createProxy(IoStream targetEcuSocket, int serverProxyPort, AtomicInteger relayCommandCounter) throws IOException {
|
public static ServerSocketReference createProxy(IoStream targetEcuSocket, int serverProxyPort, AtomicInteger relayCommandCounter) throws IOException {
|
||||||
Function<Socket, Runnable> clientSocketRunnableFactory = clientSocket -> () -> {
|
CompatibleFunction<Socket, Runnable> clientSocketRunnableFactory = clientSocket -> () -> {
|
||||||
TcpIoStream clientStream = null;
|
TcpIoStream clientStream = null;
|
||||||
try {
|
try {
|
||||||
clientStream = new TcpIoStream("[[proxy]] ", clientSocket);
|
clientStream = new TcpIoStream("[[proxy]] ", clientSocket);
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.rusefi.io.tcp;
|
||||||
|
|
||||||
import com.devexperts.logging.Logging;
|
import com.devexperts.logging.Logging;
|
||||||
import com.opensr5.ConfigurationImage;
|
import com.opensr5.ConfigurationImage;
|
||||||
|
import com.rusefi.CompatibleFunction;
|
||||||
import com.rusefi.Listener;
|
import com.rusefi.Listener;
|
||||||
import com.rusefi.NamedThreadFactory;
|
import com.rusefi.NamedThreadFactory;
|
||||||
import com.rusefi.Timeouts;
|
import com.rusefi.Timeouts;
|
||||||
|
@ -72,7 +73,7 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
||||||
public void start(LinkManager linkManager, int port, Listener serverSocketCreationCallback, Context context) throws IOException {
|
public void start(LinkManager linkManager, int port, Listener serverSocketCreationCallback, Context context) throws IOException {
|
||||||
log.info("BinaryProtocolServer on " + port);
|
log.info("BinaryProtocolServer on " + port);
|
||||||
|
|
||||||
Function<Socket, Runnable> clientSocketRunnableFactory = clientSocket -> () -> {
|
CompatibleFunction<Socket, Runnable> clientSocketRunnableFactory = clientSocket -> () -> {
|
||||||
try {
|
try {
|
||||||
runProxy(linkManager, clientSocket, context);
|
runProxy(linkManager, clientSocket, context);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -92,11 +93,11 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
||||||
* @param serverSocketCreationCallback this callback is invoked once we open the server socket
|
* @param serverSocketCreationCallback this callback is invoked once we open the server socket
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static ServerSocketReference tcpServerSocket(int port, String threadName, Function<Socket, Runnable> socketRunnableFactory, Listener serverSocketCreationCallback) throws IOException {
|
public static ServerSocketReference tcpServerSocket(int port, String threadName, CompatibleFunction<Socket, Runnable> socketRunnableFactory, Listener serverSocketCreationCallback) throws IOException {
|
||||||
return tcpServerSocket(socketRunnableFactory, port, threadName, serverSocketCreationCallback, PLAIN_SOCKET_FACTORY);
|
return tcpServerSocket(socketRunnableFactory, port, threadName, serverSocketCreationCallback, PLAIN_SOCKET_FACTORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ServerSocketReference tcpServerSocket(Function<Socket, Runnable> clientSocketRunnableFactory, int port, String threadName, Listener serverSocketCreationCallback, ServerSocketFunction nonSecureSocketFunction) throws IOException {
|
public static ServerSocketReference tcpServerSocket(CompatibleFunction<Socket, Runnable> clientSocketRunnableFactory, int port, String threadName, Listener serverSocketCreationCallback, ServerSocketFunction nonSecureSocketFunction) throws IOException {
|
||||||
ThreadFactory threadFactory = getThreadFactory(threadName);
|
ThreadFactory threadFactory = getThreadFactory(threadName);
|
||||||
|
|
||||||
Objects.requireNonNull(serverSocketCreationCallback, "serverSocketCreationCallback");
|
Objects.requireNonNull(serverSocketCreationCallback, "serverSocketCreationCallback");
|
||||||
|
@ -125,7 +126,14 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static ThreadFactory getThreadFactory(String threadName) {
|
public static ThreadFactory getThreadFactory(String threadName) {
|
||||||
return THREAD_FACTORIES_BY_NAME.computeIfAbsent(threadName, NamedThreadFactory::new);
|
synchronized (THREAD_FACTORIES_BY_NAME) {
|
||||||
|
ThreadFactory threadFactory = THREAD_FACTORIES_BY_NAME.get(threadName);
|
||||||
|
if (threadFactory == null) {
|
||||||
|
threadFactory = new NamedThreadFactory(threadName);
|
||||||
|
THREAD_FACTORIES_BY_NAME.put(threadName, threadFactory);
|
||||||
|
}
|
||||||
|
return threadFactory;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("InfiniteLoopStatement")
|
@SuppressWarnings("InfiniteLoopStatement")
|
||||||
|
|
|
@ -70,10 +70,10 @@ public class NetworkConnector implements Closeable {
|
||||||
return start(authToken, context, reconnectListener, controllerConnector);
|
return start(authToken, context, reconnectListener, controllerConnector);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkConnectorResult start(String authToken, NetworkConnectorContext context, ReconnectListener reconnectListener, LinkManager controllerConnector) {
|
public NetworkConnectorResult start(String authToken, NetworkConnectorContext context, ReconnectListener reconnectListener, LinkManager linkManager) {
|
||||||
ControllerInfo controllerInfo;
|
ControllerInfo controllerInfo;
|
||||||
try {
|
try {
|
||||||
controllerInfo = getControllerInfo(controllerConnector, controllerConnector.getConnector().getBinaryProtocol().getStream());
|
controllerInfo = getControllerInfo(linkManager, linkManager.getConnector().getBinaryProtocol().getStream());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return NetworkConnectorResult.ERROR;
|
return NetworkConnectorResult.ERROR;
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ public class NetworkConnector implements Closeable {
|
||||||
proxyReconnectSemaphore.acquire();
|
proxyReconnectSemaphore.acquire();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
start(context.serverPortForControllers(), controllerConnector, authToken, (String message) -> {
|
start(context.serverPortForControllers(), linkManager, authToken, (String message) -> {
|
||||||
log.error(message + " Disconnect from proxy server detected, now sleeping " + context.reconnectDelay() + " seconds");
|
log.error(message + " Disconnect from proxy server detected, now sleeping " + context.reconnectDelay() + " seconds");
|
||||||
sleep(context.reconnectDelay() * Timeouts.SECOND);
|
sleep(context.reconnectDelay() * Timeouts.SECOND);
|
||||||
log.debug("Releasing semaphore");
|
log.debug("Releasing semaphore");
|
||||||
|
|
Loading…
Reference in New Issue