Move Connector to api-minecraft
This commit is contained in:
parent
34b9d4f246
commit
315462be73
|
@ -1,6 +1,5 @@
|
|||
package tc.oc.api;
|
||||
|
||||
import tc.oc.api.connectable.ConnectablesManifest;
|
||||
import tc.oc.api.document.DocumentsManifest;
|
||||
import tc.oc.api.engagement.EngagementModelManifest;
|
||||
import tc.oc.api.games.GameModelManifest;
|
||||
|
@ -30,7 +29,6 @@ public final class ApiManifest extends HybridManifest {
|
|||
install(new DocumentsManifest());
|
||||
install(new MessagesManifest());
|
||||
install(new ModelsManifest());
|
||||
install(new ConnectablesManifest());
|
||||
|
||||
install(new ServerModelManifest());
|
||||
install(new UserModelManifest());
|
||||
|
|
|
@ -3,7 +3,6 @@ package tc.oc.api.connectable;
|
|||
import java.io.IOException;
|
||||
|
||||
import com.google.inject.binder.ScopedBindingBuilder;
|
||||
import tc.oc.minecraft.api.event.Activatable;
|
||||
|
||||
/**
|
||||
* Service that needs to be connected and disconnected along with the API
|
||||
|
@ -18,7 +17,7 @@ import tc.oc.minecraft.api.event.Activatable;
|
|||
* is provisioned in time to be connected, it is usually scoped with
|
||||
* {@link ScopedBindingBuilder#asEagerSingleton()}
|
||||
*/
|
||||
public interface Connectable extends Activatable {
|
||||
public interface Connectable {
|
||||
default void connect() throws IOException {};
|
||||
default void disconnect() throws IOException {};
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import tc.oc.api.docs.Server;
|
|||
import tc.oc.api.docs.virtual.ServerDoc;
|
||||
import tc.oc.api.minecraft.config.MinecraftApiConfiguration;
|
||||
import tc.oc.api.minecraft.config.MinecraftApiConfigurationImpl;
|
||||
import tc.oc.api.minecraft.connectable.ConnectablesManifest;
|
||||
import tc.oc.api.minecraft.logging.MinecraftLoggingManifest;
|
||||
import tc.oc.api.minecraft.maps.MinecraftMapsManifest;
|
||||
import tc.oc.api.minecraft.model.MinecraftModelsManifest;
|
||||
|
@ -38,6 +39,7 @@ public final class MinecraftApiManifest extends HybridManifest {
|
|||
|
||||
install(new LeakDetectorManifest());
|
||||
install(new MinecraftLoggingManifest());
|
||||
install(new ConnectablesManifest());
|
||||
install(new MinecraftModelsManifest());
|
||||
|
||||
install(new MinecraftServersManifest());
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package tc.oc.api.connectable;
|
||||
package tc.oc.api.minecraft.connectable;
|
||||
|
||||
import javax.inject.Provider;
|
||||
|
||||
import tc.oc.api.connectable.Connectable;
|
||||
import tc.oc.commons.core.inject.HybridManifest;
|
||||
import tc.oc.minecraft.api.event.ListenerBinder;
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package tc.oc.api.connectable;
|
||||
package tc.oc.api.minecraft.connectable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
import java.util.IdentityHashMap;
|
||||
|
@ -10,6 +9,7 @@ import java.util.logging.Logger;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import tc.oc.api.connectable.Connectable;
|
||||
import tc.oc.commons.core.exception.ExceptionHandler;
|
||||
import tc.oc.commons.core.logging.Loggers;
|
||||
import tc.oc.commons.core.util.ExceptionUtils;
|
||||
|
@ -42,20 +42,6 @@ class Connector implements Enableable {
|
|||
}
|
||||
}
|
||||
|
||||
private void connect(Connectable service) throws IOException {
|
||||
if(service.isActive()) {
|
||||
logger.fine(() -> "Connecting " + service.getClass().getName());
|
||||
service.connect();
|
||||
}
|
||||
}
|
||||
|
||||
private void disconnect(Connectable service) throws IOException {
|
||||
if(service.isActive()) {
|
||||
logger.fine(() -> "Disconnecting " + service.getClass().getName());
|
||||
service.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
checkState(!finishedConnecting, "already connected");
|
||||
|
@ -63,7 +49,9 @@ class Connector implements Enableable {
|
|||
for(;;) {
|
||||
final Connectable connectable = pending.poll();
|
||||
if(connectable == null) break;
|
||||
ExceptionUtils.propagate(() -> connect(connectable));
|
||||
|
||||
logger.fine(() -> "Connecting " + connectable.getClass().getName());
|
||||
ExceptionUtils.propagate(connectable::connect);
|
||||
connected.push(connectable);
|
||||
}
|
||||
finishedConnecting = true;
|
||||
|
@ -74,7 +62,9 @@ class Connector implements Enableable {
|
|||
checkState(finishedConnecting, "not connected");
|
||||
logger.fine(() -> "Disconnecting all services");
|
||||
while(!connected.isEmpty()) {
|
||||
exceptionHandler.run(() -> disconnect(connected.pop()));
|
||||
final Connectable connectable = connected.pop();
|
||||
logger.fine(() -> "Disconnecting " + connectable.getClass().getName());
|
||||
exceptionHandler.run(connectable::disconnect);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue