本文整理匯總了Java中org.eclipse.jetty.util.component.LifeCycle類的典型用法代碼示例。如果您正苦於以下問題:Java LifeCycle類的具體用法?Java LifeCycle怎麽用?Java LifeCycle使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LifeCycle類屬於org.eclipse.jetty.util.component包,在下文中一共展示了LifeCycle類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: roundtrip_works
import org.eclipse.jetty.util.component.LifeCycle; //導入依賴的package包/類
@Test
public void roundtrip_works() throws Exception {
when(managedBean.getValue()).thenReturn("mocked");
final URI uri = URI.create("ws://localhost:" + restServer.getPort() + "/websockets/echo");
final CountDownLatch latch = new CountDownLatch(1);
final WebSocketContainer container = ContainerProvider.getWebSocketContainer();
final Client client = new Client(() -> latch.countDown());
try (final Session session = container.connectToServer(client, uri)) {
session.getBasicRemote().sendText("Hello");
assertTrue(latch.await(5, SECONDS));
} finally {
((LifeCycle) container).stop();
}
assertEquals("mocked:Hello", client.message);
}
示例2: lifeCycleStarted
import org.eclipse.jetty.util.component.LifeCycle; //導入依賴的package包/類
@Override
public void lifeCycleStarted(final LifeCycle event) {
LOGGER.info("Starting End Point Health server");
final Injector injector = (Injector) servletContext.getAttribute(Injector.class.getName());
endPointCheckSchedulerService = Optional.ofNullable(injector.getInstance(EndPointCheckSchedulerService.class));
if (endPointCheckSchedulerService.isPresent()) {
endPointCheckSchedulerService.get().start();
} else {
throw new EndPointHealthException("Unable to get EndPointCheckService instance");
}
LOGGER.info("End Point Health server started");
}
示例3: main
import org.eclipse.jetty.util.component.LifeCycle; //導入依賴的package包/類
public static void main(final String[] args) {
URI uri = URI.create("ws://localhost:8080/ws/");
try {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
try {
Session session = container.connectToServer(EventSocket.class, uri);
session.getBasicRemote().sendText("Hello");
session.close();
} finally {
if (container instanceof LifeCycle) {
((LifeCycle) container).stop();
}
}
} catch (Throwable t) {
t.printStackTrace(System.err);
}
}
示例4: setUp
import org.eclipse.jetty.util.component.LifeCycle; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
environment = new Environment("test", new ObjectMapper(), Validators.newValidator(),
metricRegistry, ClassLoader.getSystemClassLoader());
DataSourceFactory dataSourceFactory = new DataSourceFactory();
dataSourceFactory.setUrl("jdbc:h2:mem:jdbi3-test");
dataSourceFactory.setUser("sa");
dataSourceFactory.setDriverClass("org.h2.Driver");
dataSourceFactory.asSingleConnectionPool();
dbi = new JdbiFactory(new TimedAnnotationNameStrategy()).build(environment, dataSourceFactory, "h2");
dbi.useTransaction(h -> {
h.createScript(Resources.toString(Resources.getResource("schema.sql"), Charsets.UTF_8)).execute();
h.createScript(Resources.toString(Resources.getResource("data.sql"), Charsets.UTF_8)).execute();
});
dao = dbi.onDemand(GameDao.class);
for (LifeCycle lc : environment.lifecycle().getManagedObjects()) {
lc.start();
}
}
示例5: lifeCycleStarted
import org.eclipse.jetty.util.component.LifeCycle; //導入依賴的package包/類
@Override
public void lifeCycleStarted(LifeCycle bean) {
if (bean instanceof Server) {
Server server = (Server)bean;
Connector[] connectors = server.getConnectors();
if (connectors == null || connectors.length == 0) {
server.dumpStdErr();
throw new IllegalStateException("No Connector");
} else if (!Arrays.stream(connectors).allMatch(Connector::isStarted)) {
server.dumpStdErr();
throw new IllegalStateException("Connector not started");
}
ContextHandler context = server.getChildHandlerByClass(ContextHandler.class);
if (context == null || !context.isAvailable()) {
server.dumpStdErr();
throw new IllegalStateException("No Available Context");
}
}
}
示例6: run
import org.eclipse.jetty.util.component.LifeCycle; //導入依賴的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);
}
示例7: stopComponents
import org.eclipse.jetty.util.component.LifeCycle; //導入依賴的package包/類
public void stopComponents() throws Exception {
Collections.reverse(components);
// if Jetty thread is still waiting for a component to start, this should unblock it
interrupt();
for (LifeCycle component : components) {
if (component.isRunning()) {
log.info("Stopping: {}", component);
component.stop();
}
}
components.clear();
stopped.await();
}
示例8: run
import org.eclipse.jetty.util.component.LifeCycle; //導入依賴的package包/類
@Override
public void run(MockConfiguration configuration, Environment environment) throws Exception
{
AbstractBinder abstractBinder = new AbstractBinder()
{
@Override
protected void configure()
{
bind(new MockHK2Injected()).to(MockHK2Injected.class);
}
};
environment.jersey().register(abstractBinder);
environment.jersey().register(MockResource.class);
LifeCycle.Listener listener = new AbstractLifeCycle.AbstractLifeCycleListener()
{
@Override
public void lifeCycleStarted(LifeCycle event)
{
System.out.println("Starting...");
startedLatch.countDown();
}
};
environment.lifecycle().addLifeCycleListener(listener);
}
示例9: toggleManagedObjects
import org.eclipse.jetty.util.component.LifeCycle; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private void toggleManagedObjects(boolean start) throws Exception
{
Field managedObjectsField = environment.lifecycle().getClass().getDeclaredField("managedObjects");
managedObjectsField.setAccessible(true);
List<LifeCycle> managedObjects = (List<LifeCycle>) managedObjectsField.get(environment.lifecycle());
for (LifeCycle managedObject : managedObjects)
{
if (start)
{
managedObject.start();
}
else
{
managedObject.stop();
}
}
}
示例10: JettyServiceConfig
import org.eclipse.jetty.util.component.LifeCycle; //導入依賴的package包/類
JettyServiceConfig(String hostname,
Boolean dumpAfterStart, Boolean dumpBeforeStop, Long stopTimeoutMillis,
Handler handler, RequestLog requestLog,
Function<? super Server, ? extends SessionIdManager> sessionIdManagerFactory,
Map<String, Object> attrs, List<Bean> beans, List<HandlerWrapper> handlerWrappers,
List<Listener> eventListeners, List<LifeCycle.Listener> lifeCycleListeners,
List<Consumer<? super Server>> configurators) {
this.hostname = hostname;
this.dumpAfterStart = dumpAfterStart;
this.dumpBeforeStop = dumpBeforeStop;
this.stopTimeoutMillis = stopTimeoutMillis;
this.handler = handler;
this.requestLog = requestLog;
this.sessionIdManagerFactory = sessionIdManagerFactory;
this.attrs = Collections.unmodifiableMap(attrs);
this.beans = Collections.unmodifiableList(beans);
this.handlerWrappers = Collections.unmodifiableList(handlerWrappers);
this.eventListeners = Collections.unmodifiableList(eventListeners);
this.lifeCycleListeners = Collections.unmodifiableList(lifeCycleListeners);
this.configurators = Collections.unmodifiableList(configurators);
}
示例11: toString
import org.eclipse.jetty.util.component.LifeCycle; //導入依賴的package包/類
static String toString(
Object holder, String hostname, Boolean dumpAfterStart, Boolean dumpBeforeStop, Long stopTimeout,
Handler handler, RequestLog requestLog,
Function<? super Server, ? extends SessionIdManager> sessionIdManagerFactory,
Map<String, Object> attrs, List<Bean> beans, List<HandlerWrapper> handlerWrappers,
List<Listener> eventListeners, List<LifeCycle.Listener> lifeCycleListeners,
List<Consumer<? super Server>> configurators) {
return MoreObjects.toStringHelper(holder)
.add("hostname", hostname)
.add("dumpAfterStart", dumpAfterStart)
.add("dumpBeforeStop", dumpBeforeStop)
.add("stopTimeoutMillis", stopTimeout)
.add("handler", handler)
.add("requestLog", requestLog)
.add("sessionIdManagerFactory", sessionIdManagerFactory)
.add("attrs", attrs)
.add("beans", beans)
.add("handlerWrappers", handlerWrappers)
.add("eventListeners", eventListeners)
.add("lifeCycleListeners", lifeCycleListeners)
.add("configurators", configurators)
.toString();
}
示例12: run
import org.eclipse.jetty.util.component.LifeCycle; //導入依賴的package包/類
@Override
public void run(Configuration configuration, Environment environment) throws InvalidKeySpecException, NoSuchAlgorithmException, ServletException, DeploymentException {
environment.lifecycle().addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener() {
@Override
public void lifeCycleStarted(LifeCycle event) {
cdl.countDown();
}
});
environment.jersey().register(new MyResource());
environment.healthChecks().register("alive", new HealthCheck() {
@Override
protected HealthCheck.Result check() throws Exception {
return HealthCheck.Result.healthy();
}
});
// Using ServerEndpointConfig lets you inject objects to the websocket endpoint:
final ServerEndpointConfig config = ServerEndpointConfig.Builder.create(EchoServer.class, "/extends-ws").build();
// config.getUserProperties().put(Environment.class.getName(), environment);
// Then you can get it from the Session object
// - obj = session.getUserProperties().get("objectName");
websocketBundle.addEndpoint(config);
}
示例13: send
import org.eclipse.jetty.util.component.LifeCycle; //導入依賴的package包/類
public void send(String url, String message) {
receivedMessage = null;
URI uri = URI.create(url);
try {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
try {
// Attempt Connect
Session session = container.connectToServer(EventSocketClient.class, uri);
// Send a message
session.getBasicRemote().sendText(message);
// Close session
session.close();
} finally {
// Force lifecycle stop when done with container.
// This is to free up threads and resources that the
// JSR-356 container allocates. But unfortunately
// the JSR-356 spec does not handle lifecycles (yet)
if (container instanceof LifeCycle) {
((LifeCycle) container).stop();
}
}
} catch (Throwable t) {
log.error(t);
}
}
示例14: connect
import org.eclipse.jetty.util.component.LifeCycle; //導入依賴的package包/類
public void connect(String url) {
URI uri = URI.create(url);
try {
container = ContainerProvider.getWebSocketContainer();
// Attempt Connect
session = container.connectToServer(EventSocketClient.class, uri);
if (session == null) {
throw new RuntimeException("Cannot connect to url :" + url);
}
} catch (Throwable t) {
log.error(t);
if (container != null) {
if (container instanceof LifeCycle) {
try {
((LifeCycle) container).stop();
} catch (Exception e) {
log.error(e);
}
}
}
}
}
示例15: send
import org.eclipse.jetty.util.component.LifeCycle; //導入依賴的package包/類
public void send(String message) {
try {
// Send a message
session.getBasicRemote().sendText(message);
} catch (Throwable t) {
log.error(t);
if (container != null) {
if (container instanceof LifeCycle) {
try {
((LifeCycle) container).stop();
} catch (Exception e) {
log.error(e);
}
}
}
}
}