Java 类io.dropwizard.server.SimpleServerFactory 实例源码

项目:Baragon    文件:BaragonAgentServiceModule.java   
@Provides
@Singleton
public BaragonAgentMetadata providesAgentMetadata(BaragonAgentConfiguration config) throws Exception {
  final SimpleServerFactory simpleServerFactory = (SimpleServerFactory) config.getServerFactory();
  final HttpConnectorFactory httpFactory = (HttpConnectorFactory) simpleServerFactory.getConnector();

  final int httpPort = httpFactory.getPort();
  final String hostname = config.getHostname().or(JavaUtils.getHostAddress());
  final Optional<String> domain = config.getLoadBalancerConfiguration().getDomain();
  final String appRoot = simpleServerFactory.getApplicationContextPath();

  final String baseAgentUri = String.format(config.getBaseUrlTemplate(), hostname, httpPort, appRoot);
  final String agentId = String.format("%s:%s", hostname, httpPort);

  return new BaragonAgentMetadata(baseAgentUri, agentId, domain, BaragonAgentEc2Metadata.fromEnvironment(), config.getExtraAgentData(), true);
}
项目:Mastering-Mesos    文件:SingularityMainModule.java   
@Inject
SingularityHostAndPortProvider(final SingularityConfiguration configuration, @Named(HOST_NAME_PROPERTY) String hostname) {
  checkNotNull(configuration, "configuration is null");
  this.hostname = configuration.getHostname().or(hostname);

  SimpleServerFactory simpleServerFactory = (SimpleServerFactory) configuration.getServerFactory();
  HttpConnectorFactory httpFactory = (HttpConnectorFactory) simpleServerFactory.getConnector();

  this.httpPort = httpFactory.getPort();
}
项目:emodb    文件:ScanUploadTest.java   
private static void updatePortsToAvoidCollision(ServerFactory serverFactory) {
    if (serverFactory instanceof DefaultServerFactory) {
        DefaultServerFactory defaultServerFactory = (DefaultServerFactory)serverFactory;
        updatePortsToAvoidCollision(defaultServerFactory.getApplicationConnectors());
        updatePortsToAvoidCollision(defaultServerFactory.getAdminConnectors());
    } else if (serverFactory instanceof SimpleServerFactory) {
        SimpleServerFactory simpleServerFactory = (SimpleServerFactory)serverFactory;
        updatePortsToAvoidCollision(Collections.singleton(simpleServerFactory.getConnector()));
    } else {
        throw new IllegalStateException("Encountered an unexpected ServerFactory type");
    }
}
项目:emodb    文件:SelfHostAndPortModule.java   
@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);
}
项目:emodb    文件:SelfHostAndPortModule.java   
@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);
}
项目:log-dropwizard-eureka-mongo-sample    文件:DropwizardServerHelpers.java   
public static Integer getPort(ServerFactory serverFactory) {
   if(serverFactory instanceof SimpleServerFactory) {
      return getPort(((SimpleServerFactory)serverFactory).getConnector());
   }
   else if(serverFactory instanceof DefaultServerFactory) {
      return getPort(((DefaultServerFactory)serverFactory).getApplicationConnectors().get(0));
   }
   throw new RuntimeException("Unable to infer Port of " + serverFactory);
}
项目:log-dropwizard-eureka-mongo-sample    文件:DropwizardServerHelpers.java   
public static Integer getAdminPort(ServerFactory serverFactory) {
   if(serverFactory instanceof SimpleServerFactory) {
      return getPort(((SimpleServerFactory)serverFactory).getConnector());
   }
   else if(serverFactory instanceof DefaultServerFactory) {
      return getPort(((DefaultServerFactory)serverFactory).getAdminConnectors().get(0));
   }
   throw new RuntimeException("Unable to infer AdminPort of " + serverFactory);
}
项目:log-dropwizard-eureka-mongo-sample    文件:DropwizardServerHelpers.java   
public static Integer getPort(ServerFactory serverFactory) {
   if(serverFactory instanceof SimpleServerFactory) {
      return getPort(((SimpleServerFactory)serverFactory).getConnector());
   }
   else if(serverFactory instanceof DefaultServerFactory) {
      return getPort(((DefaultServerFactory)serverFactory).getApplicationConnectors().get(0));
   }
   throw new RuntimeException("Unable to infer Port of " + serverFactory);
}
项目:log-dropwizard-eureka-mongo-sample    文件:DropwizardServerHelpers.java   
public static Integer getAdminPort(ServerFactory serverFactory) {
   if(serverFactory instanceof SimpleServerFactory) {
      return getPort(((SimpleServerFactory)serverFactory).getConnector());
   }
   else if(serverFactory instanceof DefaultServerFactory) {
      return getPort(((DefaultServerFactory)serverFactory).getAdminConnectors().get(0));
   }
   throw new RuntimeException("Unable to infer AdminPort of " + serverFactory);
}
项目:log-dropwizard-eureka-mongo-sample    文件:DropwizardServerHelpers.java   
public static Integer getPort(ServerFactory serverFactory) {
   if(serverFactory instanceof SimpleServerFactory) {
      return getPort(((SimpleServerFactory)serverFactory).getConnector());
   }
   else if(serverFactory instanceof DefaultServerFactory) {
      return getPort(((DefaultServerFactory)serverFactory).getApplicationConnectors().get(0));
   }
   throw new RuntimeException("Unable to infer Port of " + serverFactory);
}
项目:log-dropwizard-eureka-mongo-sample    文件:DropwizardServerHelpers.java   
public static Integer getAdminPort(ServerFactory serverFactory) {
   if(serverFactory instanceof SimpleServerFactory) {
      return getPort(((SimpleServerFactory)serverFactory).getConnector());
   }
   else if(serverFactory instanceof DefaultServerFactory) {
      return getPort(((DefaultServerFactory)serverFactory).getAdminConnectors().get(0));
   }
   throw new RuntimeException("Unable to infer AdminPort of " + serverFactory);
}
项目:FeedExpander    文件:ExpanderApplication.java   
private @Nonnull HttpConnectorFactory getConnectorFactoy(ServerFactory serverFactory) {
    if(serverFactory instanceof DefaultServerFactory) {
        return getDefaultServerFactory(serverFactory);
    } else if(serverFactory instanceof SimpleServerFactory) {
        return getSimpleServerFactory(serverFactory);
    }
    throw new IllegalArgumentException(
            String.format("Unknonw ServerFactory instance '%s'", serverFactory.getClass().getName()));
}
项目:FeedExpander    文件:ExpanderApplication.java   
private @Nonnull HttpConnectorFactory getSimpleServerFactory(ServerFactory serverFactory) {
    HttpConnectorFactory connector = (HttpConnectorFactory) ((SimpleServerFactory)serverFactory).getConnector();
    if (connector.getClass().isAssignableFrom(HttpConnectorFactory.class)) {
        return connector;
    }
    throw new IllegalArgumentException(String.format("Failed to find any server ConnectorFactory in serverFactory '%s'",
            serverFactory.getClass().getName()));       
}
项目:Singularity    文件:SingularityMainModule.java   
@Provides
@Named(SingularityServiceUIModule.SINGULARITY_URI_BASE)
String getSingularityUriBase(final SingularityConfiguration configuration) {
  final String singularityUiPrefix;
  if (configuration.getServerFactory() instanceof  SimpleServerFactory) {
    singularityUiPrefix = configuration.getUiConfiguration().getBaseUrl().or(((SimpleServerFactory) configuration.getServerFactory()).getApplicationContextPath());
  } else {
    singularityUiPrefix = configuration.getUiConfiguration().getBaseUrl().or(((DefaultServerFactory) configuration.getServerFactory()).getApplicationContextPath());
  }
  return (singularityUiPrefix.endsWith("/")) ?  singularityUiPrefix.substring(0, singularityUiPrefix.length() - 1) : singularityUiPrefix;
}
项目:Mastering-Mesos    文件:SingularityMainModule.java   
@Provides
@Named(SINGULARITY_URI_BASE)
String getSingularityUriBase(final SingularityConfiguration configuration) {
  final String singularityUiPrefix = configuration.getUiConfiguration().getBaseUrl().or(((SimpleServerFactory) configuration.getServerFactory()).getApplicationContextPath());
  return (singularityUiPrefix.endsWith("/")) ?  singularityUiPrefix.substring(0, singularityUiPrefix.length() - 1) : singularityUiPrefix;
}
项目:emodb    文件:CasDataStoreTest.java   
@BeforeClass
public void setup() throws Exception {
    _lifeCycle = new SimpleLifeCycleRegistry();
    _healthChecks = mock(HealthCheckRegistry.class);

    // Start test instance of ZooKeeper in the current JVM
    TestingServer testingServer = new TestingServer();
    _lifeCycle.manage(testingServer);

    // Connect to ZooKeeper
    final CuratorFramework curator = CuratorFrameworkFactory.newClient(testingServer.getConnectString(),
            new BoundedExponentialBackoffRetry(100, 1000, 5));
    _lifeCycle.manage(curator).start();

    // Setup the DataStoreModule
    Injector injector = Guice.createInjector(new AbstractModule() {
        @Override
        protected void configure() {
            bind(LifeCycleRegistry.class).toInstance(_lifeCycle);
            bind(HealthCheckRegistry.class).toInstance(_healthChecks);
            bind(TaskRegistry.class).toInstance(mock(TaskRegistry.class));

            bind(DataStoreConfiguration.class).toInstance(new DataStoreConfiguration()
                    .setSystemTablePlacement("app_global:sys")
                    .setValidTablePlacements(ImmutableSet.of("app_global:sys", "ugc_global:ugc"))
                    .setCassandraClusters(ImmutableMap.<String, CassandraConfiguration>of(
                            "ugc_global", new TestCassandraConfiguration("ugc_global", "ugc_delta"),
                            "app_global", new TestCassandraConfiguration("app_global", "sys_delta")))
                    .setHistoryTtl(Period.days(2)));
            bind(DataStore.class).annotatedWith(SystemDataStore.class).toInstance(mock(DataStore.class));
            bind(JobService.class).toInstance(mock(JobService.class));
            bind(JobHandlerRegistry.class).toInstance(mock(JobHandlerRegistry.class));

            bind(DataCenterConfiguration.class).toInstance(new DataCenterConfiguration()
                    .setCurrentDataCenter("datacenter1")
                    .setSystemDataCenter("datacenter1")
                    .setDataCenterServiceUri(URI.create("http://localhost:8080"))
                    .setDataCenterAdminUri(URI.create("http://localhost:8080")));

            bind(CqlDriverConfiguration.class).toInstance(new CqlDriverConfiguration());

            bind(KeyspaceDiscovery.class).annotatedWith(Names.named("blob")).toInstance(mock(KeyspaceDiscovery.class));
            bind(String.class).annotatedWith(ServerCluster.class).toInstance("local_default");

            bind(String.class).annotatedWith(ReplicationKey.class).toInstance("password");
            bind(String.class).annotatedWith(InvalidationService.class).toInstance("emodb-cachemgr");

            bind(CuratorFramework.class).annotatedWith(Global.class).toInstance(curator);
            bind(CuratorFramework.class).annotatedWith(DataStoreZooKeeper.class)
                    .toInstance(ZKNamespaces.usingChildNamespace(curator, "applications/emodb-sor"));
            bind(CuratorFramework.class).annotatedWith(GlobalFullConsistencyZooKeeper.class)
                    .toInstance(ZKNamespaces.usingChildNamespace(curator, "applications/emodb-fct"));

            bind(new TypeLiteral<Supplier<Boolean>>(){}).annotatedWith(CqlForScans.class)
                    .toInstance(Suppliers.ofInstance(true));
            bind(new TypeLiteral<Supplier<Boolean>>(){}).annotatedWith(CqlForMultiGets.class)
                    .toInstance(Suppliers.ofInstance(true));

            bind(ServerFactory.class).toInstance(new SimpleServerFactory());

            bind(ServiceRegistry.class).toInstance(mock(ServiceRegistry.class));

            bind(Clock.class).toInstance(Clock.systemDefaultZone());

            EmoServiceMode serviceMode = EmoServiceMode.STANDARD_ALL;
            install(new SelfHostAndPortModule());
            install(new DataCenterModule(serviceMode));
            install(new CacheManagerModule());
            install(new DataStoreModule(serviceMode));
        }
    });
    _store = injector.getInstance(DataStore.class);
    _lifeCycle.start();

    Map<String, Object> template = Collections.emptyMap();
    _store.createTable(TABLE, new TableOptionsBuilder().setPlacement("ugc_global:ugc").build(), template, newAudit("create table"));
}