Java 类com.google.common.util.concurrent.AbstractIdleService 实例源码

项目:twill    文件:YarnTwillRunnerService.java   
/**
 * Creates an instance.
 *
 * @param config Configuration of the yarn cluster
 * @param zkConnect ZooKeeper connection string
 * @param locationFactory Factory to create {@link Location} instances that are readable and writable by this service
 */
public YarnTwillRunnerService(YarnConfiguration config, String zkConnect, LocationFactory locationFactory) {
  this.yarnConfig = config;
  this.locationFactory = locationFactory;
  this.zkClientService = getZKClientService(zkConnect);
  this.controllers = HashBasedTable.create();
  this.serviceDelegate = new AbstractIdleService() {
    @Override
    protected void startUp() throws Exception {
      YarnTwillRunnerService.this.startUp();
    }

    @Override
    protected void shutDown() throws Exception {
      YarnTwillRunnerService.this.shutDown();
    }
  };
}
项目:GRIP    文件:StartStoppableButtonTest.java   
@Override
public void start(Stage stage) {
  restartableService = new AutoRestartingService<>(() -> new AbstractIdleService() {
    @Override
    protected void startUp() {
      /* no-op */
    }

    @Override
    protected void shutDown() {
      /* no-op */
    }
  }, ServiceRestartPolicy.IMMEDIATE);
  startStoppableButton = new StartStoppableButton(restartableService);
  Scene scene = new Scene(startStoppableButton, 800, 600);
  stage.setScene(scene);
  stage.show();
}
项目:cultivar_old    文件:DefaultCultivarStartStopManagerTest.java   
@Before
public void setUp() {
    /*
     * Multiple things in AbstractIdleService and ServiceManager are final, necessitating indirect methods of seeing
     * if the service has been started up or shut down.
     */
    Service service = new AbstractIdleService() {
        @Override
        protected void startUp() throws Exception {
            logger.info("startUp");
        }

        @Override
        protected void shutDown() throws Exception {
            logger.info("shutDown");
        }

        @Override
        protected Executor executor() {
            return MoreExecutors.sameThreadExecutor();
        }
    };

    serviceManager = new ServiceManager(ImmutableSet.of(service));

    when(curatorManagementService.startAsync()).thenReturn(curatorManagementService);
    when(curatorManagementService.stopAsync()).thenReturn(curatorManagementService);

    startStopManager = new DefaultCultivarStartStopManager(curatorManagementService, serviceManager);
}
项目:curator-extensions    文件:LeaderServiceTest.java   
/** Test starting multiple instances that compete for leadership. */
@Test
public void testMultipleLeaders() throws Exception {
    final Trigger started = new Trigger();
    final AtomicInteger startCount = new AtomicInteger();
    for (int i = 0; i < 5; i++) {
        newLeaderService(1, TimeUnit.HOURS, new Supplier<Service>() {
            @Override
            public Service get() {
                return new AbstractIdleService() {
                    @Override
                    protected void startUp() throws Exception {
                        started.fire();
                        startCount.incrementAndGet();
                    }

                    @Override
                    protected void shutDown() throws Exception {
                        // Do nothing
                    }
                };
            }
        }).startAsync();
    }
    assertTrue(started.firedWithin(1, TimeUnit.MINUTES));
    // We know one service has started.  Wait a little while and verify no more services are started.
    Thread.sleep(250);
    assertTrue(startCount.get() == 1);
}
项目:cultivar    文件:DefaultCultivarStartStopManagerTest.java   
@Before
public void setUp() {
    /*
     * Multiple things in AbstractIdleService and ServiceManager are final, necessitating indirect methods of seeing
     * if the service has been started up or shut down.
     */
    Service service = new AbstractIdleService() {
        @Override
        protected void startUp() throws Exception {
            logger.info("startUp");

        }

        @Override
        protected void shutDown() throws Exception {
            logger.info("shutDown");
        }

        @Override
        protected Executor executor() {
            return MoreExecutors.directExecutor();
        }
    };

    Service extraService1 = new AbstractIdleService() {
        @Override
        protected void startUp() throws Exception {
            extraLogger1.info("startUp");

        }

        @Override
        protected void shutDown() throws Exception {
            extraLogger1.info("shutDown");
        }

        @Override
        protected Executor executor() {
            return MoreExecutors.directExecutor();
        }
    };

    Service extraService2 = new AbstractIdleService() {
        @Override
        protected void startUp() throws Exception {
            extraLogger2.info("startUp");

        }

        @Override
        protected void shutDown() throws Exception {
            extraLogger2.info("shutDown");
        }

        @Override
        protected Executor executor() {
            return MoreExecutors.directExecutor();
        }
    };

    serviceManager = new ServiceManager(ImmutableSet.of(service));

    extraServiceManager1 = new ServiceManager(ImmutableSet.of(extraService1));

    ServiceManager extraServiceManager2 = new ServiceManager(ImmutableSet.of(extraService2));

    when(curatorManagementService.startAsync()).thenReturn(curatorManagementService);
    when(curatorManagementService.stopAsync()).thenReturn(curatorManagementService);

    startStopManager = new DefaultCultivarStartStopManager(curatorManagementService, serviceManager,
            ImmutableSet.of(extraServiceManager1, extraServiceManager2));
}