
JBridge.Anchor.Entrance.ExclusiveEntrance Maven / Gradle / Ivy
package JBridge.Anchor.Entrance;
import JBridge.Bridge;
import Logging.Logger;
import java.io.IOException;
import java.net.Socket;
/**
* An entrance that only has a single {@link Bridge} and cannot be connected to
*/
public abstract class ExclusiveEntrance extends Entrance {
public ExclusiveEntrance(Socket host) throws IOException {
bridge = getBridge(host);
}
/**
* the bridge is guaranteed to be a client bridge (bridge with client socket), so in the event of an disconnect it tries to reconnect
*
* @param bridge
*/
@Override
public void eventDisconnected(Bridge bridge) {
do {
//wait a little before attempting to reconnect
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
Logger.addLog(e);
}
} while (!bridge.reconnect());
//if the connection was successful, the bridge can resume with its usual execution
bridge.startBT();
}
/**
* Shuts this Entrance down entirely
* @param bridge
*/
@Override
public void shutdown(Bridge bridge) {
running.set(false);
bridge.shutdown();
worker.shutdownNow();
}
/**
* Beware of using complete daemon threads. {@link #shutdown(Bridge)} should shutdown all threads associated with this instance
*/
@Override
public void run() {
synchronized (this) {
if (running.get()) {
throw new UnsupportedOperationException("Platform already running");
}
running.set(true);
}
//blocking heartbeating loop
heartbeating();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy