Move Connector to api-minecraft

This commit is contained in:
Jedediah Smith 2017-02-06 07:31:55 -05:00
parent 34b9d4f246
commit 315462be73
5 changed files with 13 additions and 23 deletions

View File

@ -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());

View File

@ -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 {};
}

View File

@ -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());

View File

@ -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;

View File

@ -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);
}
}
}