當前位置: 首頁>>代碼示例>>Java>>正文


Java Connector.setPort方法代碼示例

本文整理匯總了Java中org.mortbay.jetty.Connector.setPort方法的典型用法代碼示例。如果您正苦於以下問題:Java Connector.setPort方法的具體用法?Java Connector.setPort怎麽用?Java Connector.setPort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.mortbay.jetty.Connector的用法示例。


在下文中一共展示了Connector.setPort方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: startup

import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
public void startup() {
    if (adminPort > 0) {
        Connector httpConnector = new SelectChannelConnector();
        httpConnector.setHost(adminHost);
        httpConnector.setPort(adminPort);
        adminServer.addConnector(httpConnector);
    }

    if (adminServer.getConnectors() == null
            || adminServer.getConnectors().length == 0) {
        adminServer = null;
        log.warn("Admin console not started due to configuration error.");
        return;
    }

    adminServer
            .setHandlers(new Handler[] { contexts, new DefaultHandler() });

    try {
        adminServer.start();
        httpStarted = true;
        log.debug("Admin console started.");
    } catch (Exception e) {
        log.error("Could not start admin conosle server", e);
    }
}
 
開發者ID:elphinkuo,項目名稱:Androidpn,代碼行數:27,代碼來源:AdminConsole.java

示例2: putUpJettyServer

import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
private void putUpJettyServer() throws IOException {
  if (!conf.getBoolean("hbase.master.infoserver.redirect", true)) {
    return;
  }
  int infoPort = conf.getInt("hbase.master.info.port.orig",
    HConstants.DEFAULT_MASTER_INFOPORT);
  // -1 is for disabling info server, so no redirecting
  if (infoPort < 0 || infoServer == null) {
    return;
  }

  RedirectServlet.regionServerInfoPort = infoServer.getPort();
  masterJettyServer = new org.mortbay.jetty.Server();
  Connector connector = new SelectChannelConnector();
  connector.setHost(conf.get("hbase.master.info.bindAddress", "0.0.0.0"));
  connector.setPort(infoPort);
  masterJettyServer.addConnector(connector);
  masterJettyServer.setStopAtShutdown(true);
  Context context = new Context(masterJettyServer, "/", Context.NO_SESSIONS);
  context.addServlet(RedirectServlet.class, "/*");
  try {
    masterJettyServer.start();
  } catch (Exception e) {
    throw new IOException("Failed to start redirecting jetty server", e);
  }
}
 
開發者ID:shenli-uiuc,項目名稱:PyroDB,代碼行數:27,代碼來源:HMaster.java

示例3: openListeners

import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
/**
 * Open the main listener for the server
 * @throws Exception
 */
void openListeners() throws Exception {
  for (Connector listener : listeners) {
    if (listener.getLocalPort() != -1) {
      // This listener is either started externally or has been bound
      continue;
    }
    int port = listener.getPort();
    while (true) {
      // jetty has a bug where you can't reopen a listener that previously
      // failed to open w/o issuing a close first, even if the port is changed
      try {
        listener.close();
        listener.open();
        LOG.info("Jetty bound to port " + listener.getLocalPort());
        break;
      } catch (BindException ex) {
        if (port == 0 || !findPort) {
          BindException be = new BindException("Port in use: "
              + listener.getHost() + ":" + listener.getPort());
          be.initCause(ex);
          throw be;
        }
      }
      // try the next port number
      listener.setPort(++port);
      Thread.sleep(100);
    }
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:34,代碼來源:HttpServer2.java

示例4: openListeners

import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
/**
 * Open the main listener for the server
 * @throws Exception
 */
void openListeners() throws Exception {
  for (ListenerInfo li : listeners) {
    Connector listener = li.listener;
    if (!li.isManaged || li.listener.getLocalPort() != -1) {
      // This listener is either started externally or has been bound
      continue;
    }
    int port = listener.getPort();
    while (true) {
      // jetty has a bug where you can't reopen a listener that previously
      // failed to open w/o issuing a close first, even if the port is changed
      try {
        listener.close();
        listener.open();
        LOG.info("Jetty bound to port " + listener.getLocalPort());
        break;
      } catch (BindException ex) {
        if (port == 0 || !findPort) {
          BindException be = new BindException("Port in use: "
              + listener.getHost() + ":" + listener.getPort());
          be.initCause(ex);
          throw be;
        }
      }
      // try the next port number
      listener.setPort(++port);
      Thread.sleep(100);
    }
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:35,代碼來源:HttpServer.java

示例5: putUpJettyServer

import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
private int putUpJettyServer() throws IOException {
  if (!conf.getBoolean("hbase.master.infoserver.redirect", true)) {
    return -1;
  }
  int infoPort = conf.getInt("hbase.master.info.port.orig",
    HConstants.DEFAULT_MASTER_INFOPORT);
  // -1 is for disabling info server, so no redirecting
  if (infoPort < 0 || infoServer == null) {
    return -1;
  }
  String addr = conf.get("hbase.master.info.bindAddress", "0.0.0.0");
  if (!Addressing.isLocalAddress(InetAddress.getByName(addr))) {
    String msg =
        "Failed to start redirecting jetty server. Address " + addr
            + " does not belong to this host. Correct configuration parameter: "
            + "hbase.master.info.bindAddress";
    LOG.error(msg);
    throw new IOException(msg);
  }

  RedirectServlet.regionServerInfoPort = infoServer.getPort();
  if(RedirectServlet.regionServerInfoPort == infoPort) {
    return infoPort;
  }
  masterJettyServer = new org.mortbay.jetty.Server();
  Connector connector = new SelectChannelConnector();
  connector.setHost(addr);
  connector.setPort(infoPort);
  masterJettyServer.addConnector(connector);
  masterJettyServer.setStopAtShutdown(true);
  Context context = new Context(masterJettyServer, "/", Context.NO_SESSIONS);
  context.addServlet(RedirectServlet.class, "/*");
  try {
    masterJettyServer.start();
  } catch (Exception e) {
    throw new IOException("Failed to start redirecting jetty server", e);
  }
  return connector.getLocalPort();
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:40,代碼來源:HMaster.java

示例6: main

import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
/** temp main - just to help testing */
public static void main(String[] args)
throws Exception
{
    Server server = new Server();
    Connector connector=new GrizzlyConnector();
    connector.setPort(8080);
    server.setConnectors(new Connector[]{connector});
    
    HandlerCollection handlers = new HandlerCollection();
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    handlers.setHandlers(new Handler[]{contexts,new DefaultHandler()});
    server.setHandler(handlers);
    
    // TODO add javadoc context to contexts
    
    WebAppContext.addWebApplications(server, "../../webapps", "org/mortbay/jetty/webapp/webdefault.xml", true, false);
    
    HashUserRealm userRealm = new HashUserRealm();
    userRealm.setName("Test Realm");
    userRealm.setConfig("../../etc/realm.properties");
    server.setUserRealms(new UserRealm[]{userRealm});
    
    
    server.start();
    server.join();
    
}
 
開發者ID:iMartinezMateu,項目名稱:openbravo-pos,代碼行數:29,代碼來源:GrizzlyConnector.java

示例7: jettyServer

import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
@BeforeClass
public static void jettyServer() throws Exception {

	server = new Server();

	Connector connector = new SelectChannelConnector();
	connector.setPort(PORT);
	server.setConnectors(new Connector[] { connector });
	ConstraintMapping cm = new ConstraintMapping();
	Constraint constraint = new Constraint();
	constraint.setName(Constraint.__BASIC_AUTH);
	constraint.setRoles(new String[] { ROLE_NAME });
	constraint.setAuthenticate(true);
	cm.setConstraint(constraint);
	cm.setPathSpec("/*");

	sh = new SecurityHandler();
	userRealm = new HashUserRealm(REALM);
	userRealm.put(USERNAME, PASSWORD);
	userRealm.addUserToRole(USERNAME, ROLE_NAME);
	sh.setUserRealm(userRealm);
	sh.setConstraintMappings(new ConstraintMapping[] { cm });

	WebAppContext webappcontext = new WebAppContext();
	webappcontext.setContextPath("/");

	URL htmlRoot = HTTPAuthenticatorIT.class.getResource(HTML);
	assertNotNull("Could not find " + HTML, htmlRoot);
	webappcontext.setWar(htmlRoot.toExternalForm());
	
	webappcontext.addHandler(sh);

	HandlerCollection handlers = new HandlerCollection();
	handlers.setHandlers(new Handler[] { webappcontext,
			new DefaultHandler() });

	server.setHandler(handlers);
	server.start();
}
 
開發者ID:apache,項目名稱:incubator-taverna-engine,代碼行數:40,代碼來源:HTTPAuthenticatorIT.java

示例8: putUpJettyServer

import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
private int putUpJettyServer() throws IOException {
    if (!conf.getBoolean("hbase.master.infoserver.redirect", true)) {
        return -1;
    }
    int infoPort = conf.getInt("hbase.master.info.port.orig",
            HConstants.DEFAULT_MASTER_INFOPORT);
    // -1 is for disabling info server, so no redirecting
    if (infoPort < 0 || infoServer == null) {
        return -1;
    }
    String addr = conf.get("hbase.master.info.bindAddress", "0.0.0.0");
    if (!Addressing.isLocalAddress(InetAddress.getByName(addr))) {
        String msg =
                "Failed to start redirecting jetty server. Address " + addr
                        + " does not belong to this host. Correct configuration parameter: "
                        + "hbase.master.info.bindAddress";
        LOG.error(msg);
        throw new IOException(msg);
    }

    RedirectServlet.regionServerInfoPort = infoServer.getPort();
    masterJettyServer = new org.mortbay.jetty.Server();
    Connector connector = new SelectChannelConnector();
    connector.setHost(addr);
    connector.setPort(infoPort);
    masterJettyServer.addConnector(connector);
    masterJettyServer.setStopAtShutdown(true);
    Context context = new Context(masterJettyServer, "/", Context.NO_SESSIONS);
    context.addServlet(RedirectServlet.class, "/*");
    try {
        masterJettyServer.start();
    } catch (Exception e) {
        throw new IOException("Failed to start redirecting jetty server", e);
    }
    return connector.getLocalPort();
}
 
開發者ID:grokcoder,項目名稱:pbase,代碼行數:37,代碼來源:HMaster.java

示例9: build

import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
public HttpServer2 build() throws IOException {
  Preconditions.checkNotNull(name, "name is not set");
  Preconditions.checkState(!endpoints.isEmpty(), "No endpoints specified");

  if (hostName == null) {
    hostName = endpoints.get(0).getHost();
  }

  if (this.conf == null) {
    conf = new Configuration();
  }

  HttpServer2 server = new HttpServer2(this);

  if (this.securityEnabled) {
    server.initSpnego(conf, hostName, usernameConfKey, keytabConfKey);
  }

  for (URI ep : endpoints) {
    final Connector listener;
    String scheme = ep.getScheme();
    if ("http".equals(scheme)) {
      listener = HttpServer2.createDefaultChannelConnector();
    } else if ("https".equals(scheme)) {
      listener = createHttpsChannelConnector();

    } else {
      throw new HadoopIllegalArgumentException(
          "unknown scheme for endpoint:" + ep);
    }
    listener.setHost(ep.getHost());
    listener.setPort(ep.getPort() == -1 ? 0 : ep.getPort());
    server.addListener(listener);
  }
  server.loadListeners();
  return server;
}
 
開發者ID:hopshadoop,項目名稱:hops,代碼行數:38,代碼來源:HttpServer2.java

示例10: startServer

import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
/**
 * Starts Jetty.
 *
 * @param host        the host to bound.
 * @param port        the port to bound.
 * @param contextPath the context path to bound.
 */
private static void startServer(final String host, final int port, final String contextPath) {
    final Logger log = LoggerFactory.getLogger(JaptProxyServer.class);
    log.info("Starting Japt-Proxy {} on host {} port {} using context path '{}'",
        Util.VERSION, StringUtils.defaultIfEmpty(host, "*"), port, contextPath);

    // Spring startup
    final ClassPathXmlApplicationContext classPathXmlApplicationContext =
        new ClassPathXmlApplicationContext("master.xml", "standalone.xml");
    classPathXmlApplicationContext.registerShutdownHook();

    // Jetty startup
    final Server server = new Server();

    final Connector connector = new BlockingChannelConnector();

    if (!StringUtils.isBlank(host)) {
        connector.setHost(host);
    }

    connector.setPort(port);
    server.setConnectors(new Connector[]{connector});

    server.setStopAtShutdown(true);

    final Context root = new Context(server, contextPath);
    final JaptProxyServlet japtProxyServlet =
        classPathXmlApplicationContext
            .getBean("japtProxyServlet", JaptProxyServlet.class);
    root.addServlet(new ServletHolder(japtProxyServlet), "/*");

    try {
        server.start();
    } catch (final Exception e) {
        // shame on Jetty's exception handling
        throw new IllegalStateException("Couldn't start HTTP engine", e);
    }
}
 
開發者ID:osiegmar,項目名稱:japt-proxy,代碼行數:45,代碼來源:JaptProxyServer.java

示例11: startup

import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
/**
 * Starts the Jetty server instance.
 */
public void startup() {
    if (adminPort > 0) {
        Connector httpConnector = new SelectChannelConnector();
        httpConnector.setHost(adminHost);
        httpConnector.setPort(adminPort);
        adminServer.addConnector(httpConnector);
    }

    if (adminServer.getConnectors() == null
            || adminServer.getConnectors().length == 0) {
        adminServer = null;
        log.warn("Admin console not started due to configuration error.");
        return;
    }

    adminServer
            .setHandlers(new Handler[] { contexts, new DefaultHandler() });

    try {
        adminServer.start();
        httpStarted = true;
        log.debug("Admin console started.");
    } catch (Exception e) {
        log.error("Could not start admin conosle server", e);
    }
}
 
開發者ID:elphinkuo,項目名稱:Androidpn,代碼行數:30,代碼來源:AdminConsole.java

示例12: startup

import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
public void startup() {
    // Create connector for http traffic if it's enabled.
    if (adminPort > 0) {
        Connector httpConnector = new SelectChannelConnector();
        httpConnector.setHost(adminHost);
        httpConnector.setPort(adminPort);
        adminServer.addConnector(httpConnector);
    }

    // Make sure that at least one connector was registered.
    if (adminServer.getConnectors() == null
            || adminServer.getConnectors().length == 0) {
        adminServer = null;
        log.warn("Admin console not started due to configuration error.");
        return;
    }

    adminServer
            .setHandlers(new Handler[] { contexts, new DefaultHandler() });

    try {
        adminServer.start();
        httpStarted = true;
        log.debug("Admin Console started.");
    } catch (Exception e) {
        log.error("Could not start admin conosle server", e);
    }
}
 
開發者ID:elphinkuo,項目名稱:Androidpn,代碼行數:29,代碼來源:AdminConsole.java

示例13: main

import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
  Server server = new Server();

  Connector connector = new SelectChannelConnector();
  connector.setPort(8080);
  server.setConnectors(new Connector[] {connector});

  WebAppContext webapp = new WebAppContext("./root", "/example");
  server.addHandler(webapp);

  server.start();
  server.join();
}
 
開發者ID:google,項目名稱:guice,代碼行數:14,代碼來源:Main.java

示例14: tryPort

import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
private Server tryPort(final int portNumber) throws Exception {
  Server srv = new Server();
  final Connector connector = new SocketConnector();
  connector.setHost(addressProvider.getLocalAddress());
  connector.setPort(portNumber);
  srv.addConnector(connector);
  try {
    srv.start();
    LOG.log(Level.INFO, "Jetty Server started with port: {0}", portNumber);
  } catch (final BindException ex) {
    srv = null;
    LOG.log(Level.FINEST, "Cannot use port: {0}. Will try another", portNumber);
  }
  return srv;
}
 
開發者ID:apache,項目名稱:reef,代碼行數:16,代碼來源:HttpServerImpl.java

示例15: main

import org.mortbay.jetty.Connector; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
  Server server = new Server();

  Connector connector = new SelectChannelConnector();
  connector.setPort(8080);
  server.setConnectors(new Connector[] { connector });

  WebAppContext webapp = new WebAppContext("./root", "/example");
  server.addHandler(webapp);

  server.start();
  server.join();
}
 
開發者ID:cgruber,項目名稱:guice-old,代碼行數:14,代碼來源:Main.java


注:本文中的org.mortbay.jetty.Connector.setPort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。