Search in sources :

Example 1 with BayeuxServerImpl

use of org.cometd.server.BayeuxServerImpl in project camel by apache.

the class CometdComponent method connect.

/**
     * Connects the URL specified on the endpoint to the specified processor.
     */
public void connect(CometdProducerConsumer prodcon) throws Exception {
    Server server = null;
    // Make sure that there is a connector for the requested endpoint.
    CometdEndpoint endpoint = prodcon.getEndpoint();
    String connectorKey = endpoint.getProtocol() + ":" + endpoint.getUri().getHost() + ":" + endpoint.getPort();
    synchronized (connectors) {
        ConnectorRef connectorRef = connectors.get(connectorKey);
        if (connectorRef == null) {
            ServerConnector connector;
            server = createServer();
            if ("cometds".equals(endpoint.getProtocol())) {
                connector = getSslSocketConnector(server);
            } else {
                connector = new ServerConnector(server);
            }
            connector.setPort(endpoint.getPort());
            connector.setHost(endpoint.getUri().getHost());
            if ("localhost".equalsIgnoreCase(endpoint.getUri().getHost())) {
                LOG.warn("You use localhost interface! It means that no external connections will be available." + " Don't you want to use 0.0.0.0 instead (all network interfaces)?");
            }
            server.addConnector(connector);
            CometDServlet servlet = createServletForConnector(server, connector, endpoint);
            connectorRef = new ConnectorRef(connector, servlet, server);
            server.start();
            connectors.put(connectorKey, connectorRef);
        } else {
            connectorRef.increment();
        }
        BayeuxServerImpl bayeux = connectorRef.servlet.getBayeux();
        if (securityPolicy != null) {
            bayeux.setSecurityPolicy(securityPolicy);
        }
        if (extensions != null) {
            for (BayeuxServer.Extension extension : extensions) {
                bayeux.addExtension(extension);
            }
        }
        if (serverListeners != null) {
            for (BayeuxServer.BayeuxServerListener serverListener : serverListeners) {
                bayeux.addListener(serverListener);
            }
        }
        prodcon.setBayeux(bayeux);
    }
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) BayeuxServerImpl(org.cometd.server.BayeuxServerImpl) Server(org.eclipse.jetty.server.Server) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) BayeuxServer(org.cometd.bayeux.server.BayeuxServer) CometDServlet(org.cometd.server.CometDServlet)

Aggregations

BayeuxServer (org.cometd.bayeux.server.BayeuxServer)1 BayeuxServerImpl (org.cometd.server.BayeuxServerImpl)1 CometDServlet (org.cometd.server.CometDServlet)1 Server (org.eclipse.jetty.server.Server)1 ServerConnector (org.eclipse.jetty.server.ServerConnector)1