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


Java AbstractIdleService類代碼示例

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


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

示例1: YarnTwillRunnerService

import com.google.common.util.concurrent.AbstractIdleService; //導入依賴的package包/類
/**
 * 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();
    }
  };
}
 
開發者ID:apache,項目名稱:twill,代碼行數:25,代碼來源:YarnTwillRunnerService.java

示例2: start

import com.google.common.util.concurrent.AbstractIdleService; //導入依賴的package包/類
@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();
}
 
開發者ID:WPIRoboticsProjects,項目名稱:GRIP,代碼行數:19,代碼來源:StartStoppableButtonTest.java

示例3: setUp

import com.google.common.util.concurrent.AbstractIdleService; //導入依賴的package包/類
@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);
}
 
開發者ID:dclements,項目名稱:cultivar_old,代碼行數:31,代碼來源:DefaultCultivarStartStopManagerTest.java

示例4: testMultipleLeaders

import com.google.common.util.concurrent.AbstractIdleService; //導入依賴的package包/類
/** 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);
}
 
開發者ID:bazaarvoice,項目名稱:curator-extensions,代碼行數:30,代碼來源:LeaderServiceTest.java

示例5: setUp

import com.google.common.util.concurrent.AbstractIdleService; //導入依賴的package包/類
@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));
}
 
開發者ID:ReadyTalk,項目名稱:cultivar,代碼行數:73,代碼來源:DefaultCultivarStartStopManagerTest.java


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