List of usage examples for java.net InetSocketAddress InetSocketAddress
public InetSocketAddress(int port)
From source file:AppMain.java
public static void main(String[] list) throws IOException { setProxy();// ww w .j ava2 s . c o m System.out.println("loading Italian model..."); ItalianModel im = null; try { im = new ItalianModel(); } catch (ClassNotFoundException e) { e.printStackTrace(); System.exit(2); } catch (SQLException e) { e.printStackTrace(); } System.out.println("starting matcher..."); fm = new FlexiMatcher(); fm.bind("it-pos", new ItPosRuleFactory(im)); fm.bind("it-token", new ItTokenRuleFactory(im)); fm.bind("it-verb-conjugated", new ItSpecificVerbRuleFactory(im)); fm.bind("it-verb-form", new ItVerbFormRuleFactory(im)); String fname = "rule_list.tsv"; FileTagLoader.readTagsFromTSV(fname, fm); fwTag = new FileWriter(fname, true); System.out.println("starting server at port " + portToUse + "..."); Container container = new AppMain(); Server server; server = new ContainerServer(container); @SuppressWarnings("resource") Connection connection = new SocketConnection(server); SocketAddress address = new InetSocketAddress(portToUse); connection.connect(address); }
From source file:pl.bristleback.server.bristle.engine.netty.NettyServerEngine.java
@Override public void startServer() { log.info("Starting Netty engine (" + getClass().getName() + ") on port " + getEngineConfiguration().getPort()); EngineConfig engineConfig = getEngineConfiguration(); ChannelFactory nioChannelFactory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); ServerBootstrap bootstrap = new ServerBootstrap(nioChannelFactory); pipelineFactory.init(this); bootstrap.setPipelineFactory(pipelineFactory); serverChannel = bootstrap.bind(new InetSocketAddress(engineConfig.getPort())); log.info("Netty engine (" + getClass().getName() + ") on port " + getEngineConfiguration().getPort() + " has started."); }
From source file:com.yanzhenjie.andserver.DefaultAndServer.java
@Override public void run() { try {// w w w . j ava 2 s . co m mServerSocket = new ServerSocket(); mServerSocket.setReuseAddress(true); mServerSocket.bind(new InetSocketAddress(mPort)); // HTTP?? BasicHttpProcessor httpProcessor = new BasicHttpProcessor(); httpProcessor.addInterceptor(new ResponseDate()); httpProcessor.addInterceptor(new ResponseServer()); httpProcessor.addInterceptor(new ResponseContent()); httpProcessor.addInterceptor(new ResponseConnControl()); // HTTP Attribute. HttpParams httpParams = new BasicHttpParams(); httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "WebServer/1.1"); // Http? HttpRequestHandlerRegistry handlerRegistry = new HttpRequestHandlerRegistry(); for (Map.Entry<String, AndServerRequestHandler> handlerEntry : mRequestHandlerMap.entrySet()) { handlerRegistry.register("/" + handlerEntry.getKey(), new DefaultHttpRequestHandler(handlerEntry.getValue())); } // HTTP? HttpService httpService = new HttpService(httpProcessor, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory()); httpService.setParams(httpParams); httpService.setHandlerResolver(handlerRegistry); /** * ? */ while (isLoop) { // if (!mServerSocket.isClosed()) { Socket socket = mServerSocket.accept(); DefaultHttpServerConnection serverConnection = new DefaultHttpServerConnection(); serverConnection.bind(socket, httpParams); // Dispatch request handler. RequestHandleTask requestTask = new RequestHandleTask(this, httpService, serverConnection); requestTask.setDaemon(true); AndWebUtil.executeRunnable(requestTask); } } } catch (Exception e) { } finally { close(); } }
From source file:com.devoteam.srit.xmlloader.http.nio.NIOSocketServerListener.java
/** Creates a new instance of SocketServerHttpListener */ public NIOSocketServerListener(int port, boolean secure) throws ExecutionException { super(secure); if (secure) { StatPool.beginStatisticProtocol(StatPool.LISTENPOINT_KEY, StatPool.NIO_KEY, StackFactory.PROTOCOL_TLS, StackFactory.PROTOCOL_HTTP); } else {/* w ww . ja v a 2 s.co m*/ StatPool.beginStatisticProtocol(StatPool.LISTENPOINT_KEY, StatPool.NIO_KEY, StackFactory.PROTOCOL_TCP, StackFactory.PROTOCOL_HTTP); } this.startTimestamp = System.currentTimeMillis(); try { if (secure) StackHttp.ioReactor.openTLSServer(new InetSocketAddress(port), this, StackHttp.context); else StackHttp.ioReactor.openTCPServer(new InetSocketAddress(port), this); } catch (Exception e) { throw new ExecutionException("Can't instantiate the HTTP SocketServerListener secure=" + secure, e); } }
From source file:org.devtcg.five.server.AbstractHttpServer.java
public void bind(int port) throws IOException { try {/* ww w. j av a2s .co m*/ mSocket.bind(new InetSocketAddress(port)); } catch (UnknownHostException e) { throw new RuntimeException(e); } }
From source file:com.cloudera.knittingboar.sgd.iterativereduce.TestPOLRIterativeReduce.java
@Before public void setUp() throws Exception { masterAddress = new InetSocketAddress(9999); pool = Executors.newFixedThreadPool(4); baseDir = Files.createTempDir(); configuration = new Configuration(); configuration.setInt("com.cloudera.knittingboar.setup.FeatureVectorSize", 10000); configuration.setInt("com.cloudera.knittingboar.setup.numCategories", 20); configuration.setInt("com.cloudera.knittingboar.setup.BatchSize", 200); configuration.setInt("com.cloudera.knittingboar.setup.NumberPasses", 1); // local input split path configuration.set("com.cloudera.knittingboar.setup.LocalInputSplitPath", "hdfs://127.0.0.1/input/0"); // setup 20newsgroups configuration.set("com.cloudera.knittingboar.setup.RecordFactoryClassname", "com.cloudera.knittingboar.records.TwentyNewsgroupsRecordFactory"); workerServices = new ArrayList<ApplicationWorkerService<ParameterVectorGradientUpdatable>>(); workers = new ArrayList<Future<Integer>>(); computableWorkers = new ArrayList<ComputableWorker<ParameterVectorGradientUpdatable>>(); setUpMaster();// w ww.j ava 2s. c om setUpWorker("worker1"); setUpWorker("worker2"); setUpWorker("worker3"); }
From source file:com.netflix.iep.http.RxHttpTest.java
@BeforeClass public static void startServer() throws Exception { rxHttp.start();//w w w . j av a2s .c o m server = HttpServer.create(new InetSocketAddress(0), 100); server.setExecutor(Executors.newFixedThreadPool(10, new ThreadFactory() { @Override public Thread newThread(Runnable r) { return new Thread(r, "HttpServer"); } })); port = server.getAddress().getPort(); server.createContext("/empty", new HttpHandler() { @Override public void handle(HttpExchange exchange) throws IOException { ignore(exchange.getRequestBody()); int port = exchange.getRemoteAddress().getPort(); exchange.getResponseHeaders().add("X-Test-Port", "" + port); statusCounts.incrementAndGet(statusCode.get()); exchange.sendResponseHeaders(statusCode.get(), -1L); exchange.close(); } }); server.createContext("/echo", new HttpHandler() { @Override public void handle(HttpExchange exchange) throws IOException { Headers headers = exchange.getRequestHeaders(); int contentLength = Integer.parseInt(headers.getFirst("Content-Length")); String contentEnc = headers.getFirst("Content-Encoding"); if (contentEnc != null) { exchange.getResponseHeaders().add("Content-Encoding", contentEnc); } int code = statusCode.get(); if (contentLength > 512 && !"gzip".equals(contentEnc)) { code = 400; } statusCounts.incrementAndGet(code); exchange.sendResponseHeaders(code, contentLength); try (InputStream input = exchange.getRequestBody(); OutputStream output = exchange.getResponseBody()) { byte[] buf = new byte[1024]; int length; while ((length = input.read(buf)) > 0) { output.write(buf, 0, length); } } exchange.close(); } }); server.createContext("/relativeRedirect", new HttpHandler() { @Override public void handle(HttpExchange exchange) throws IOException { ignore(exchange.getRequestBody()); if (redirects.get() <= 0) { statusCounts.incrementAndGet(statusCode.get()); exchange.getResponseHeaders().add("Location", "/empty"); exchange.sendResponseHeaders(statusCode.get(), -1L); exchange.close(); } else { redirects.decrementAndGet(); statusCounts.incrementAndGet(302); exchange.getResponseHeaders().add("Location", "/relativeRedirect"); exchange.sendResponseHeaders(302, -1L); exchange.close(); } } }); server.createContext("/absoluteRedirect", new HttpHandler() { @Override public void handle(HttpExchange exchange) throws IOException { String host = "http://" + exchange.getRequestHeaders().getFirst("Host"); ignore(exchange.getRequestBody()); if (redirects.get() <= 0) { statusCounts.incrementAndGet(302); exchange.getResponseHeaders().add("Location", host + "/empty"); exchange.sendResponseHeaders(302, -1L); exchange.close(); } else { redirects.decrementAndGet(); statusCounts.incrementAndGet(302); exchange.getResponseHeaders().add("Location", host + "/absoluteRedirect"); exchange.sendResponseHeaders(302, -1L); exchange.close(); } } }); server.createContext("/notModified", new HttpHandler() { @Override public void handle(HttpExchange exchange) throws IOException { ignore(exchange.getRequestBody()); statusCounts.incrementAndGet(304); exchange.sendResponseHeaders(304, -1L); exchange.close(); } }); server.createContext("/redirectNoLocation", new HttpHandler() { @Override public void handle(HttpExchange exchange) throws IOException { ignore(exchange.getRequestBody()); statusCounts.incrementAndGet(302); exchange.sendResponseHeaders(302, -1L); exchange.close(); } }); server.createContext("/readTimeout", new HttpHandler() { @Override public void handle(HttpExchange exchange) throws IOException { ignore(exchange.getRequestBody()); statusCounts.incrementAndGet(statusCode.get()); // So we can track retries Object lock = new Object(); try { synchronized (lock) { lock.wait(); } } catch (InterruptedException e) { e.printStackTrace(); } } }); server.start(); set(client + ".niws.client.MaxAutoRetriesNextServer", "" + retries); set(client + ".niws.client.RetryDelay", "100"); set(client + ".niws.client.ReadTimeout", "1000"); }
From source file:edu.berkeley.sparrow.daemon.util.TestThriftClientPool.java
@Test public void testPoolExpiration() throws Exception { // Makes sure that a thrift client gets evicted (and therefore closed) if it is not // used for a certain amount of time. Config conf = ThriftClientPool.getPoolConfig(); // We decrease the defaults here so the test runs in reasonable time conf.minEvictableIdleTimeMillis = 10; conf.timeBetweenEvictionRunsMillis = 50; InetSocketAddress sock = new InetSocketAddress(12345); ThriftClientPool<TAsyncClient> pool = new ThriftClientPool<TAsyncClient>(new MockedMakerFactory(), conf); assertEquals(0, pool.getNumIdle(sock)); assertEquals(0, pool.getNumActive(sock)); TAsyncClient client = pool.borrowClient(sock); assertEquals(0, pool.getNumIdle(sock)); assertEquals(1, pool.getNumActive(sock)); pool.returnClient(sock, client);//w w w. j av a 2 s .co m assertEquals(1, pool.getNumIdle(sock)); assertEquals(0, pool.getNumActive(sock)); Thread.sleep(conf.timeBetweenEvictionRunsMillis * 2); assertEquals(0, pool.getNumIdle(sock)); assertEquals(0, pool.getNumActive(sock)); }
From source file:com.qubole.rubix.hadoop1.TestClusterManager.java
private HttpServer startServer(boolean master) throws IOException { HttpServer server = HttpServer.create(new InetSocketAddress(45326), 0); if (master) { server.createContext("/dfsnodelist.jsp", new masterDFSAdminHandler()); }//from w w w .j av a 2s . co m server.setExecutor(null); // creates a default executor server.start(); return server; }
From source file:edu.uci.ics.hyracks.api.client.HyracksConnection.java
/** * Constructor to create a connection to the Hyracks Cluster Controller. * /*from w w w.ja va 2 s . c o m*/ * @param ccHost * Host name (or IP Address) where the Cluster Controller can be * reached. * @param ccPort * Port to reach the Hyracks Cluster Controller at the specified * host name. * @throws Exception */ public HyracksConnection(String ccHost, int ccPort) throws Exception { this.ccHost = ccHost; RPCInterface rpci = new RPCInterface(); ipc = new IPCSystem(new InetSocketAddress(0), rpci, new JavaSerializationBasedPayloadSerializerDeserializer()); ipc.start(); IIPCHandle ccIpchandle = ipc.getHandle(new InetSocketAddress(ccHost, ccPort)); this.hci = new HyracksClientInterfaceRemoteProxy(ccIpchandle, rpci); ccInfo = hci.getClusterControllerInfo(); }