Search in sources :

Example 1 with ConnectorFactory

use of org.apache.felix.http.jetty.ConnectorFactory in project felix by apache.

the class HttpJettyConnectorTest method testRegisterConnectorFactoryOk.

@Test
public void testRegisterConnectorFactoryOk() throws Exception {
    final CountDownLatch openLatch = new CountDownLatch(1);
    final CountDownLatch closeLatch = new CountDownLatch(1);
    ConnectorFactory factory = new ConnectorFactory() {

        @Override
        public Connector createConnector(Server server) {
            return new LocalConnector(server) {

                @Override
                public void doStart() throws Exception {
                    openLatch.countDown();
                    super.doStart();
                }

                @Override
                public void doStop() throws Exception {
                    closeLatch.countDown();
                    super.doStop();
                }
            };
        }
    };
    ServiceRegistration reg = m_context.registerService(ConnectorFactory.class.getName(), factory, null);
    // Should be opened automatically when picked up by the Jetty implementation...
    assertTrue("Felix HTTP Jetty did not open the Connection or pick up the registered ConnectionFactory", openLatch.await(5, TimeUnit.SECONDS));
    // Should close our connection...
    reg.unregister();
    assertTrue("Felix HTTP Jetty did not close the Connection", closeLatch.await(5, TimeUnit.SECONDS));
}
Also used : ConnectorFactory(org.apache.felix.http.jetty.ConnectorFactory) Server(org.eclipse.jetty.server.Server) LocalConnector(org.eclipse.jetty.server.LocalConnector) CountDownLatch(java.util.concurrent.CountDownLatch) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Example 2 with ConnectorFactory

use of org.apache.felix.http.jetty.ConnectorFactory in project felix by apache.

the class ConnectorFactoryTracker method addingService.

@Override
public Connector addingService(ServiceReference<ConnectorFactory> reference) {
    ConnectorFactory factory = (ConnectorFactory) super.addingService(reference);
    Connector connector = factory.createConnector(server);
    try {
        this.server.addConnector(connector);
        connector.start();
        return connector;
    } catch (Exception e) {
        SystemLogger.error("Failed starting connector '" + connector + "' provided by " + reference, e);
    }
    // connector failed to start, don't continue tracking
    return null;
}
Also used : Connector(org.eclipse.jetty.server.Connector) ConnectorFactory(org.apache.felix.http.jetty.ConnectorFactory)

Aggregations

ConnectorFactory (org.apache.felix.http.jetty.ConnectorFactory)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 Connector (org.eclipse.jetty.server.Connector)1 LocalConnector (org.eclipse.jetty.server.LocalConnector)1 Server (org.eclipse.jetty.server.Server)1 Test (org.junit.Test)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1