org.springframework.context.Lifecycle.start()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(178)

本文整理了Java中org.springframework.context.Lifecycle.start()方法的一些代码示例,展示了Lifecycle.start()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Lifecycle.start()方法的具体详情如下:
包路径:org.springframework.context.Lifecycle
类名称:Lifecycle
方法名:start

Lifecycle.start介绍

[英]Start this component.

Should not throw an exception if the component is already running.

In the case of a container, this will propagate the start signal to all components that apply.
[中]启动此组件。
如果组件已在运行,则不应引发异常。
对于容器,这会将启动信号传播到所有应用的组件。

代码示例

代码示例来源:origin: spring-projects/spring-framework

protected void doStart() {
  if (this.requestUpgradeStrategy instanceof Lifecycle) {
    ((Lifecycle) this.requestUpgradeStrategy).start();
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void start() {
  if (!isRunning()) {
    this.running = true;
    if (this.sockJsService instanceof Lifecycle) {
      ((Lifecycle) this.sockJsService).start();
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void start() {
  if (!isRunning()) {
    this.running = true;
    if (this.handshakeHandler instanceof Lifecycle) {
      ((Lifecycle) this.handshakeHandler).start();
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void start() {
  if (!isRunning()) {
    if (this.webSocketClient instanceof Lifecycle) {
      ((Lifecycle) this.webSocketClient).start();
    }
    else {
      this.running = true;
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void start() {
  if (!isRunning()) {
    this.running = true;
    if (this.handshakeHandler instanceof Lifecycle) {
      ((Lifecycle) this.handshakeHandler).start();
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void start() {
  if (!isRunning()) {
    this.running = true;
    for (TransportHandler handler : this.handlers.values()) {
      if (handler instanceof Lifecycle) {
        ((Lifecycle) handler).start();
      }
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void start() {
  if (!isRunning()) {
    this.running = true;
    for (Object handler : getUrlMap().values()) {
      if (handler instanceof Lifecycle) {
        ((Lifecycle) handler).start();
      }
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

protected void doStart() {
  if (getUpgradeStrategy() instanceof Lifecycle) {
    ((Lifecycle) getUpgradeStrategy()).start();
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void startInternal() {
  if (this.client instanceof Lifecycle && !((Lifecycle) this.client).isRunning()) {
    ((Lifecycle) this.client).start();
  }
  super.startInternal();
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void start() {
  if (!isRunning()) {
    this.running = true;
    for (Transport transport : this.transports) {
      if (transport instanceof Lifecycle) {
        Lifecycle lifecycle = (Lifecycle) transport;
        if (!lifecycle.isRunning()) {
          lifecycle.start();
        }
      }
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void start() {
  if (!isRunning()) {
    this.running = true;
    if (getWebSocketClient() instanceof Lifecycle) {
      ((Lifecycle) getWebSocketClient()).start();
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Start the specified bean as part of the given set of Lifecycle beans,
 * making sure that any beans that it depends on are started first.
 * @param lifecycleBeans a Map with bean name as key and Lifecycle instance as value
 * @param beanName the name of the bean to start
 */
private void doStart(Map<String, ? extends Lifecycle> lifecycleBeans, String beanName, boolean autoStartupOnly) {
  Lifecycle bean = lifecycleBeans.remove(beanName);
  if (bean != null && bean != this) {
    String[] dependenciesForBean = getBeanFactory().getDependenciesForBean(beanName);
    for (String dependency : dependenciesForBean) {
      doStart(lifecycleBeans, dependency, autoStartupOnly);
    }
    if (!bean.isRunning() &&
        (!autoStartupOnly || !(bean instanceof SmartLifecycle) || ((SmartLifecycle) bean).isAutoStartup())) {
      if (logger.isTraceEnabled()) {
        logger.trace("Starting bean '" + beanName + "' of type [" + bean.getClass().getName() + "]");
      }
      try {
        bean.start();
      }
      catch (Throwable ex) {
        throw new ApplicationContextException("Failed to start bean '" + beanName + "'", ex);
      }
      if (logger.isDebugEnabled()) {
        logger.debug("Successfully started bean '" + beanName + "'");
      }
    }
  }
}

代码示例来源:origin: spring-projects/spring-batch

private void waitForResults(Lifecycle lifecycle, int count, int maxTries) throws InterruptedException {
  lifecycle.start();
  int timeout = 0;
  while (processed.size() < count && timeout++ < maxTries) {
    Thread.sleep(5);
  }
  lifecycle.stop();
}

代码示例来源:origin: spring-projects/spring-batch

private void waitForResults(Lifecycle lifecycle, int count, int maxTries) throws InterruptedException {
  lifecycle.start();
  int timeout = 0;
  while (processed.size() < count && timeout++ < maxTries) {
    Thread.sleep(10);
  }
  lifecycle.stop();
}

代码示例来源:origin: spring-projects/spring-batch

private void waitForResults(Lifecycle lifecycle, int count, int maxTries) throws InterruptedException {
  lifecycle.start();
  int timeout = 0;
  while (service.getProcessed().size() < count && timeout++ < maxTries) {
    Thread.sleep(5);
  }
  lifecycle.stop();
}

代码示例来源:origin: spring-projects/spring-batch

private void waitForResults(Lifecycle lifecycle, int count, int maxTries) throws InterruptedException {
  lifecycle.start();
  int timeout = 0;
  while (service.getProcessed().size() < count && timeout++ < maxTries) {
    Thread.sleep(10);
  }
  lifecycle.stop();
}

代码示例来源:origin: spring-projects/spring-framework

@Before
public void setup() throws Exception {
  logger.debug("Setting up '" + this.testName.getMethodName() + "', client=" +
      this.webSocketClient.getClass().getSimpleName() + ", server=" +
      this.server.getClass().getSimpleName());
  this.wac = new AnnotationConfigWebApplicationContext();
  this.wac.register(getAnnotatedConfigClasses());
  this.wac.register(upgradeStrategyConfigTypes.get(this.server.getClass()));
  if (this.webSocketClient instanceof Lifecycle) {
    ((Lifecycle) this.webSocketClient).start();
  }
  this.server.setup();
  this.server.deployConfig(this.wac);
  this.server.start();
  this.wac.setServletContext(this.server.getServletContext());
  this.wac.refresh();
}

代码示例来源:origin: spring-projects/spring-framework

@Before
public void setup() throws Exception {
  this.server.setHandler(createHttpHandler());
  this.server.afterPropertiesSet();
  this.server.start();
  // Set dynamically chosen port
  this.port = this.server.getPort();
  if (this.client instanceof Lifecycle) {
    ((Lifecycle) this.client).start();
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void singleLifecycleShutdown() throws Exception {
  CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<>();
  Lifecycle bean = new TestLifecycleBean(null, stoppedBeans);
  StaticApplicationContext context = new StaticApplicationContext();
  context.getBeanFactory().registerSingleton("bean", bean);
  context.refresh();
  assertFalse(bean.isRunning());
  bean.start();
  assertTrue(bean.isRunning());
  context.stop();
  assertEquals(1, stoppedBeans.size());
  assertFalse(bean.isRunning());
  assertEquals(bean, stoppedBeans.get(0));
}

代码示例来源:origin: spring-projects/spring-framework

assertFalse(bean1.isRunning());
assertFalse(bean4.isRunning());
bean1.start();
bean4.start();
assertTrue(bean1.isRunning());
assertTrue(bean4.isRunning());

相关文章

微信公众号

最新文章

更多