@Override public void run(Configuration configuration, Environment environment) { final SimpleServerFactory serverConfig = new SimpleServerFactory(); configuration.setServerFactory(serverConfig); final HttpConnectorFactory connectorConfig = (HttpConnectorFactory) serverConfig.getConnector(); connectorConfig.setPort(0); environment.healthChecks().register("dummy", new DummyHealthCheck()); for (Object resource : resources) { if (resource instanceof Class<?>) { environment.jersey().register((Class<?>) resource); } else { environment.jersey().register(resource); } } } }
@Inject SingularityHostAndPortProvider(final SingularityConfiguration configuration, @Named(HOST_NAME_PROPERTY) String hostname) { checkNotNull(configuration, "configuration is null"); this.hostname = configuration.getHostname().or(hostname); Integer port = null; if (configuration.getServerFactory() instanceof SimpleServerFactory) { SimpleServerFactory simpleServerFactory = (SimpleServerFactory) configuration.getServerFactory(); HttpConnectorFactory httpFactory = (HttpConnectorFactory) simpleServerFactory.getConnector(); port = httpFactory.getPort(); } else { DefaultServerFactory defaultServerFactory = (DefaultServerFactory) configuration.getServerFactory(); for (ConnectorFactory connectorFactory : defaultServerFactory.getApplicationConnectors()) { // Currently we will default to needing an http connector for service -> service communication if (connectorFactory instanceof HttpConnectorFactory && !(connectorFactory instanceof HttpsConnectorFactory)) { HttpConnectorFactory httpFactory = (HttpConnectorFactory) connectorFactory; port = httpFactory.getPort(); } } } if (port == null) { throw new RuntimeException("Could not determine http port"); } this.httpPort = port; }
@Override public void run(Configuration configuration, Environment environment) { final SimpleServerFactory serverConfig = new SimpleServerFactory(); configuration.setServerFactory(serverConfig); final HttpConnectorFactory connectorConfig = (HttpConnectorFactory) serverConfig.getConnector(); connectorConfig.setPort(0); environment.healthChecks().register("dummy", new DummyHealthCheck()); for (Object resource : resources) { if (resource instanceof Class<?>) { environment.jersey().register((Class<?>) resource); } else { environment.jersey().register(resource); } } } }
private int getPort(Configuration config) { int httpPort = 0; final SimpleServerFactory serverFactory = (SimpleServerFactory) config.getServerFactory(); final HttpConnectorFactory connector = (HttpConnectorFactory) serverFactory.getConnector(); if (connector.getClass().isAssignableFrom(HttpConnectorFactory.class)) { httpPort = connector.getPort(); } return httpPort; } }
@Provides @Singleton @SelfHostAndPort public HostAndPort provideSelfHostAndPort(ServerFactory serverFactory) { // Our method for obtaining connector factories from the server factory varies depending on the latter's type List<ConnectorFactory> appConnectorFactories; if (serverFactory instanceof DefaultServerFactory) { appConnectorFactories = ((DefaultServerFactory) serverFactory).getApplicationConnectors(); } else if (serverFactory instanceof SimpleServerFactory) { appConnectorFactories = Collections.singletonList(((SimpleServerFactory) serverFactory).getConnector()); } else { throw new IllegalStateException("Encountered an unexpected ServerFactory type"); } return getHostAndPortFromConnectorFactories(appConnectorFactories); }
@Provides @Singleton @SelfAdminHostAndPort public HostAndPort provideSelfAdminHostAndPort(ServerFactory serverFactory) { // Our method for obtaining connector factories from the server factory varies depending on the latter's type List<ConnectorFactory> adminConnectorFactories; if (serverFactory instanceof DefaultServerFactory) { adminConnectorFactories = ((DefaultServerFactory) serverFactory).getAdminConnectors(); } else if (serverFactory instanceof SimpleServerFactory) { adminConnectorFactories = Collections.singletonList(((SimpleServerFactory) serverFactory).getConnector()); } else { throw new IllegalStateException("Encountered an unexpected ServerFactory type"); } return getHostAndPortFromConnectorFactories(adminConnectorFactories); }
@Provides @Singleton @SelfAdminHostAndPort public HostAndPort provideSelfAdminHostAndPort(ServerFactory serverFactory) { // Our method for obtaining connector factories from the server factory varies depending on the latter's type List<ConnectorFactory> adminConnectorFactories; if (serverFactory instanceof DefaultServerFactory) { adminConnectorFactories = ((DefaultServerFactory) serverFactory).getAdminConnectors(); } else if (serverFactory instanceof SimpleServerFactory) { adminConnectorFactories = Collections.singletonList(((SimpleServerFactory) serverFactory).getConnector()); } else { throw new IllegalStateException("Encountered an unexpected ServerFactory type"); } return getHostAndPortFromConnectorFactories(adminConnectorFactories); }
@Provides @Singleton @SelfHostAndPort public HostAndPort provideSelfHostAndPort(ServerFactory serverFactory) { // Our method for obtaining connector factories from the server factory varies depending on the latter's type List<ConnectorFactory> appConnectorFactories; if (serverFactory instanceof DefaultServerFactory) { appConnectorFactories = ((DefaultServerFactory) serverFactory).getApplicationConnectors(); } else if (serverFactory instanceof SimpleServerFactory) { appConnectorFactories = Collections.singletonList(((SimpleServerFactory) serverFactory).getConnector()); } else { throw new IllegalStateException("Encountered an unexpected ServerFactory type"); } return getHostAndPortFromConnectorFactories(appConnectorFactories); }
public int getApplicationPort() { AbstractServerFactory sf = serverFactory(); if (sf instanceof SimpleServerFactory) { SimpleServerFactory ssf = (SimpleServerFactory) sf; return ((HttpConnectorFactory)ssf.getConnector()).getPort(); } if (sf instanceof DefaultServerFactory) { DefaultServerFactory dsf = (DefaultServerFactory) sf; return ((HttpConnectorFactory)dsf.getApplicationConnectors().get(0)).getPort(); } throw new IllegalStateException("Unrecognized ServerFactory: "+sf.getClass().getName()); }
public int getAdminPort() { AbstractServerFactory sf = serverFactory(); if (sf instanceof SimpleServerFactory) { SimpleServerFactory ssf = (SimpleServerFactory) sf; return ((HttpConnectorFactory)ssf.getConnector()).getPort(); } if (sf instanceof DefaultServerFactory) { DefaultServerFactory dsf = (DefaultServerFactory) sf; return ((HttpConnectorFactory)dsf.getAdminConnectors().get(0)).getPort(); } throw new IllegalStateException("Unrecognized ServerFactory: "+sf.getClass().getName()); }
@SuppressWarnings("unchecked") public THIS overrideHttpPort(int p) { AbstractServerFactory sf = serverFactory(); if (sf instanceof SimpleServerFactory) { SimpleServerFactory ssf = (SimpleServerFactory) sf; ((HttpConnectorFactory)ssf.getConnector()).setPort(p); } else if (sf instanceof DefaultServerFactory) { DefaultServerFactory dsf = (DefaultServerFactory) sf; ((HttpConnectorFactory)dsf.getApplicationConnectors().get(0)).setPort(p); } else { throw new IllegalStateException("Unrecognized ServerFactory: "+sf.getClass().getName()); } return (THIS) this; }
@Inject SingularityHostAndPortProvider(final SingularityConfiguration configuration, @Named(HOST_NAME_PROPERTY) String hostname) { checkNotNull(configuration, "configuration is null"); this.hostname = configuration.getHostname().or(hostname); Integer port = null; if (configuration.getServerFactory() instanceof SimpleServerFactory) { SimpleServerFactory simpleServerFactory = (SimpleServerFactory) configuration.getServerFactory(); HttpConnectorFactory httpFactory = (HttpConnectorFactory) simpleServerFactory.getConnector(); port = httpFactory.getPort(); } else { DefaultServerFactory defaultServerFactory = (DefaultServerFactory) configuration.getServerFactory(); for (ConnectorFactory connectorFactory : defaultServerFactory.getApplicationConnectors()) { // Currently we will default to needing an http connector for service -> service communication if (connectorFactory instanceof HttpConnectorFactory && !(connectorFactory instanceof HttpsConnectorFactory)) { HttpConnectorFactory httpFactory = (HttpConnectorFactory) connectorFactory; port = httpFactory.getPort(); } } } if (port == null) { throw new RuntimeException("Could not determine http port"); } this.httpPort = port; }
mainPort = adminPort = portFromConnectorFactory(((SimpleServerFactory)serverFactory).getConnector());
@Override public void run(Configuration configuration, Environment environment) { final SimpleServerFactory serverConfig = new SimpleServerFactory(); configuration.setServerFactory(serverConfig); final HttpConnectorFactory connectorConfig = (HttpConnectorFactory) serverConfig.getConnector(); connectorConfig.setPort(0); environment.healthChecks().register("dummy", new DummyHealthCheck()); for (Object resource : resources) { if (resource instanceof Class<?>) { environment.jersey().register((Class<?>) resource); } else { environment.jersey().register(resource); } } } }