當前位置: 首頁>>代碼示例>>Java>>正文


Java Managed類代碼示例

本文整理匯總了Java中io.dropwizard.lifecycle.Managed的典型用法代碼示例。如果您正苦於以下問題:Java Managed類的具體用法?Java Managed怎麽用?Java Managed使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Managed類屬於io.dropwizard.lifecycle包,在下文中一共展示了Managed類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: build

import io.dropwizard.lifecycle.Managed; //導入依賴的package包/類
public DBClient build(Environment environment) {
    String dbServer = System.getenv("DB");
    if (dbServer != null) {
        server = dbServer;
    }
    dbClient = dbFactory.create(server, port, dbName);
    log.info("Connected to db");
    environment.lifecycle().manage(new Managed() {
        @Override
        public void start() throws Exception {
            dbClient.useDB(dbName);
        }

        @Override
        public void stop() throws Exception {
            dbClient.close();
        }
    });
    return dbClient;
}
 
開發者ID:sjsucohort6,項目名稱:amigo-chatbot,代碼行數:21,代碼來源:DBConfig.java

示例2: run

import io.dropwizard.lifecycle.Managed; //導入依賴的package包/類
@Override
public void run(final Configuration configuration,
                final Environment environment) {

    environment.jersey().register(new RateLimitingFactoryProvider.Binder(requestRateLimiterFactory));
    environment.jersey().register(new RateLimited429EnforcerFeature());

    environment.lifecycle().manage(new Managed() {
        @Override
        public void start() {
        }

        @Override
        public void stop() throws Exception {
            requestRateLimiterFactory.close();
        }
    });
}
 
開發者ID:mokies,項目名稱:ratelimitj,代碼行數:19,代碼來源:RateLimitBundle.java

示例3: ReplicationEnabledTask

import io.dropwizard.lifecycle.Managed; //導入依賴的package包/類
@Inject
public ReplicationEnabledTask(TaskRegistry tasks, LifeCycleRegistry lifeCycle,
                              @ReplicationEnabled ValueStore<Boolean> enabled) {
    super("busrepl");
    _enabled = checkNotNull(enabled, "enabled");
    tasks.addTask(this);

    // Default is enabled, so warn if disabled since otherwise essential functionality won't work.
    lifeCycle.manage(new Managed() {
        @Override
        public void start() throws Exception {
            if (!_enabled.get()) {
                _log.warn("Databus inbound event replication from other data centers is: DISABLED");
            }
        }

        @Override
        public void stop() throws Exception {
        }
    });
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:22,代碼來源:ReplicationEnabledTask.java

示例4: newInboundReplication

import io.dropwizard.lifecycle.Managed; //導入依賴的package包/類
private Managed newInboundReplication(final DataCenter dataCenter) {
    // Create a proxy for the remote data center.
    final ReplicationSource replicationSource = newRemoteReplicationSource(dataCenter);

    // Start asynchronously downloading events from the remote data center.
    final Managed fanout = new GuavaServiceController(_replicationEnabled, new Supplier<Service>() {
        @Override
        public Service get() {
            return _fanoutManager.newInboundReplicationFanout(dataCenter, replicationSource);
        }
    });

    // Note: closing the replication source could also be done via a listener on the Guava service...
    return new Managed() {
        @Override
        public void start() throws Exception {
            fanout.start();
        }

        @Override
        public void stop() throws Exception {
            fanout.stop();
            ServicePoolProxies.close(replicationSource);
        }
    };
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:27,代碼來源:DefaultReplicationManager.java

示例5: DedupMigrationTask

import io.dropwizard.lifecycle.Managed; //導入依賴的package包/類
@Inject
public DedupMigrationTask(TaskRegistry tasks, LifeCycleRegistry lifeCycle, DedupEventStore eventStore,
                          @DedupEnabled ValueStore<Boolean> dedupEnabled) {
    super("dedup-databus-migration");
    _eventStore = checkNotNull(eventStore, "eventStore");
    _dedupEnabled = checkNotNull(dedupEnabled, "dedupEnabled");
    tasks.addTask(this);

    // Default is enabled, so at startup warn if disabled since otherwise essential functionality won't work.
    lifeCycle.manage(new Managed() {
        @Override
        public void start() throws Exception {
            if (!_dedupEnabled.get()) {
                _log.warn("Databus deduplication is: DISABLED");
            }
        }

        @Override
        public void stop() throws Exception {
        }
    });
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:23,代碼來源:DedupMigrationTask.java

示例6: TableChangesEnabledTask

import io.dropwizard.lifecycle.Managed; //導入依賴的package包/類
@Inject
public TableChangesEnabledTask(TaskRegistry tasks, LifeCycleRegistry lifeCycle, @Maintenance final String scope,
                               @TableChangesEnabled ValueStore<Boolean> enabled) {
    super(scope + "-table-changes");
    _enabled = checkNotNull(enabled, "enabled");
    tasks.addTask(this);

    // Default is enabled, so at startup warn if disabled since otherwise essential functionality won't work.
    lifeCycle.manage(new Managed() {
        @Override
        public void start() throws Exception {
            if (!_enabled.get()) {
                _log.warn("({}) Table create/drop/update operations and table maintenance are: DISABLED", scope);
            }
        }

        @Override
        public void stop() throws Exception {
        }
    });
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:22,代碼來源:TableChangesEnabledTask.java

示例7: run

import io.dropwizard.lifecycle.Managed; //導入依賴的package包/類
@Override
public void run(Environment environment) {
    ServiceLocatorUtilities.bind(serviceLocator, new EnvBinder(application, environment));

    LifecycleEnvironment lifecycle = environment.lifecycle();
    AdminEnvironment admin = environment.admin();

    listServices(HealthCheck.class).forEach(healthCheck -> {
        String name = healthCheck.getClass().getSimpleName();
        environment.healthChecks().register(name, healthCheck);
    });

    listServices(Managed.class).forEach(lifecycle::manage);
    listServices(LifeCycle.class).forEach(lifecycle::manage);
    listServices(LifeCycle.Listener.class).forEach(lifecycle::addLifeCycleListener);
    listServices(ServerLifecycleListener.class).forEach(lifecycle::addServerLifecycleListener);
    listServices(Task.class).forEach(admin::addTask);

    environment.jersey().register(HK2LifecycleListener.class);

    //Set service locator as parent for Jersey's service locator
    environment.getApplicationContext().setAttribute(ServletProperties.SERVICE_LOCATOR, serviceLocator);
    environment.getAdminContext().setAttribute(ServletProperties.SERVICE_LOCATOR, serviceLocator);

    serviceLocator.inject(application);
}
 
開發者ID:alex-shpak,項目名稱:dropwizard-hk2bundle,代碼行數:27,代碼來源:HK2Bundle.java

示例8: buildClient

import io.dropwizard.lifecycle.Managed; //導入依賴的package包/類
@Override
protected MongoClient buildClient() {
    String database = uri.getDatabase();
    if (database != null) setDbName(database);

    final MongoClient mongoClient = new MongoClient(uri);

    environment.lifecycle().manage(
            new Managed() {
                @Override
                public void start() throws Exception {
                }


                @Override
                public void stop() throws Exception {
                    mongoClient.close();
                }
            }
    );

    return mongoClient;
}
 
開發者ID:serhuz,項目名稱:dropwizard-morphia,代碼行數:24,代碼來源:UriMongoConfiguration.java

示例9: build

import io.dropwizard.lifecycle.Managed; //導入依賴的package包/類
public PGPoolingDataSource build(Environment environment) {
    final PGPoolingDataSource pg_ds = new PGPoolingDataSource();
    pg_ds.setDataSourceName("pg_ds");
    pg_ds.setServerName(this.getHost());
    pg_ds.setDatabaseName(this.getDb());
    pg_ds.setUser(this.getUser());
    pg_ds.setPassword(this.getPassword());
    pg_ds.setPortNumber(this.getPort());
    pg_ds.setMaxConnections(this.getMaxConnections());
    environment.lifecycle().manage(new Managed() {
        @Override
        public void start() {
        }

        @Override
        public void stop() {
            pg_ds.close();
        }
    });
    return pg_ds;
}
 
開發者ID:gurelkaynak,項目名稱:recommendationengine,代碼行數:22,代碼來源:DataSourceFactory.java

示例10: shouldRegisterHealthCheck

import io.dropwizard.lifecycle.Managed; //導入依賴的package包/類
@Test
public void shouldRegisterHealthCheck() throws Exception {
    //GIVEN
    AmazonSQS sqs = mock(AmazonSQS.class);

    SqsBundle spiedBundle = spy(bundle);
    doReturn(sqs).when(spiedBundle).getAmazonSQS();

    LifecycleEnvironment lifecycle = mock(LifecycleEnvironment.class);
    doNothing().when(lifecycle).manage((Managed) anyObject());
    when(environment.lifecycle()).thenReturn(lifecycle);

    HealthCheckRegistry healthChecks = mock(HealthCheckRegistry.class);
    doNothing().when(healthChecks).register(anyObject(), anyObject());
    when(environment.healthChecks()).thenReturn(healthChecks);

    //WHEN
    spiedBundle.run(configurationHolder, environment);

    //THEN
    verify(healthChecks, times(1)).register(eq("SqsBundle"), any(SqsBundleHealthCheck.class));
}
 
開發者ID:sjarrin,項目名稱:dropwizard-sqs-bundle,代碼行數:23,代碼來源:SqsBundleTest.java

示例11: run

import io.dropwizard.lifecycle.Managed; //導入依賴的package包/類
@Override
public void run(T configuration, Environment environment) throws Exception
{
    CuratorConfiguration curatorConfiguration = ComposedConfigurationAccessor.access(configuration, environment, CuratorConfiguration.class);
    // TODO more config
    final CuratorFramework curator = CuratorFrameworkFactory.newClient(curatorConfiguration.getConnectionString(), new RetryOneTime(1));

    Managed managed = new Managed()
    {
        @Override
        public void start() throws Exception
        {
            curator.start();
        }

        @Override
        public void stop() throws Exception
        {
            CloseableUtils.closeQuietly(curator);
        }
    };
    environment.lifecycle().manage(managed);

    SoaBundle.getFeatures(environment).putNamed(curator, CuratorFramework.class, curatorConfiguration.getCuratorName());
}
 
開發者ID:soabase,項目名稱:soabase,代碼行數:26,代碼來源:CuratorBundle.java

示例12: build

import io.dropwizard.lifecycle.Managed; //導入依賴的package包/類
public AnalysisServiceClient build(Environment environment) {
    final HttpClientConfiguration httpConfig = new HttpClientConfiguration();
    httpConfig.setTimeout(Duration.milliseconds(getTimeout()));
    final HttpClient httpClient = new HttpClientBuilder(environment).using(httpConfig)
            .build("analysis-http-client");

    AnalysisServiceClient client = new AnalysisServiceClientAdapter(getHost(), getPort(),
            getPortFailover(), getPath(), httpClient);

    environment.lifecycle().manage(new Managed() {
        @Override
        public void start() {
        }

        @Override
        public void stop() {
        }
    });

    return client;
}
 
開發者ID:ufried,項目名稱:resilience-tutorial,代碼行數:22,代碼來源:AnalysisServiceFactory.java

示例13: registerInjector

import io.dropwizard.lifecycle.Managed; //導入依賴的package包/類
/**
 * Used internally to register application specific injector.
 *
 * @param application application instance
 * @param injector    injector instance
 * @return managed object, which must be registered to remove injector on application stop
 */
public static Managed registerInjector(final Application application, final Injector injector) {
    Preconditions.checkNotNull(application, "Application instance required");
    Preconditions.checkArgument(!INJECTORS.containsKey(application),
            "Injector already registered for application %s", application.getClass().getName());
    INJECTORS.put(application, injector);
    return new Managed() {
        @Override
        public void start() throws Exception {
            // not used
        }

        @Override
        public void stop() throws Exception {
            INJECTORS.remove(application);
        }
    };
}
 
開發者ID:xvik,項目名稱:dropwizard-guicey,代碼行數:25,代碼來源:InjectorLookup.java

示例14: managed_binds_work

import io.dropwizard.lifecycle.Managed; //導入依賴的package包/類
@Test
public void managed_binds_work() {
    final Managed managed = mock(Managed.class);
    final Class<TestManaged> managedClass = TestManaged.class;

    Injector injector = Guice.createInjector(new AbstractPlugin() {
        @Override
        protected void configure() {
            bindManaged(managed);
            bindManaged(managedClass);
        }
    });

    Set<Managed> managedSet = injector.getInstance(Keys.ManagedObjects);
    Set<Class<? extends Managed>> managedClassSet = injector.getInstance(Keys.ManagedObjectClasses);

    assertThat(managedSet, hasSize(1));
    assertThat(managedSet, hasItem(managed));
    assertThat(managedClassSet, hasSize(1));
    assertThat(managedClassSet, hasItem(TestManaged.class));
}
 
開發者ID:graceland,項目名稱:graceland-core,代碼行數:22,代碼來源:AbstractPluginTest.java

示例15: run_adds_managed

import io.dropwizard.lifecycle.Managed; //導入依賴的package包/類
@Test
public void run_adds_managed() throws Exception {
    final Managed managed = mock(Managed.class);
    final Class<TestManaged> managedClass = TestManaged.class;

    Application application = buildApplication(
            new AbstractPlugin() {
                @Override
                protected void configure() {
                    bindManaged(managed);
                    bindManaged(managedClass);
                }
            }
    );

    new Platform(application).run(configuration, environment);

    verify(lifecycleEnvironment).manage(eq(managed));
    verify(lifecycleEnvironment).manage(isA(TestManaged.class));
}
 
開發者ID:graceland,項目名稱:graceland-core,代碼行數:21,代碼來源:PlatformTest.java


注:本文中的io.dropwizard.lifecycle.Managed類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。