]> git.argeo.org Git - lgpl/argeo-commons.git/blob - internal/jetty/JettyServiceFactory.java
Prepare next development cycle
[lgpl/argeo-commons.git] / internal / jetty / JettyServiceFactory.java
1 package org.argeo.cms.servlet.internal.jetty;
2
3 import java.util.Dictionary;
4
5 import org.argeo.api.cms.CmsConstants;
6 import org.argeo.api.cms.CmsLog;
7 import org.eclipse.equinox.http.jetty.JettyConfigurator;
8 import org.osgi.framework.FrameworkUtil;
9 import org.osgi.service.cm.ConfigurationException;
10 import org.osgi.service.cm.ManagedServiceFactory;
11
12 public class JettyServiceFactory implements ManagedServiceFactory {
13 private final CmsLog log = CmsLog.getLog(JettyServiceFactory.class);
14
15 public void start() {
16
17 }
18
19 @Override
20 public String getName() {
21 return "Jetty Service Factory";
22 }
23
24 @Override
25 public void updated(String pid, Dictionary<String, ?> properties) throws ConfigurationException {
26 // Explicitly configures Jetty so that the default server is not started by the
27 // activator of the Equinox Jetty bundle.
28
29 // if (!webServerConfig.isEmpty()) {
30 // webServerConfig.put("customizer.class", KernelConstants.CMS_JETTY_CUSTOMIZER_CLASS);
31 //
32 // // TODO centralise with Jetty extender
33 // Object webSocketEnabled = webServerConfig.get(InternalHttpConstants.WEBSOCKET_ENABLED);
34 // if (webSocketEnabled != null && webSocketEnabled.toString().equals("true")) {
35 // bc.registerService(ServerEndpointConfig.Configurator.class, new CmsWebSocketConfigurator(), null);
36 // webServerConfig.put(InternalHttpConstants.WEBSOCKET_ENABLED, "true");
37 // }
38 // }
39
40 int tryCount = 60;
41 try {
42 tryGettyJetty: while (tryCount > 0) {
43 try {
44 // FIXME deal with multiple ids
45 JettyConfigurator.startServer(CmsConstants.DEFAULT, properties);
46 // Explicitly starts Jetty OSGi HTTP bundle, so that it gets triggered if OSGi
47 // configuration is not cleaned
48 FrameworkUtil.getBundle(JettyConfigurator.class).start();
49 break tryGettyJetty;
50 } catch (IllegalStateException e) {
51 // Jetty may not be ready
52 try {
53 Thread.sleep(1000);
54 } catch (Exception e1) {
55 // silent
56 }
57 tryCount--;
58 }
59 }
60 } catch (Exception e) {
61 log.error("Cannot start default Jetty server with config " + properties, e);
62 }
63
64 }
65
66 @Override
67 public void deleted(String pid) {
68 }
69
70 public void stop() {
71 try {
72 JettyConfigurator.stopServer(CmsConstants.DEFAULT);
73 } catch (Exception e) {
74 log.error("Cannot stop default Jetty server.", e);
75 }
76
77 }
78
79 }