List of usage examples for java.net InetSocketAddress InetSocketAddress
public InetSocketAddress(int port)
From source file:com.baidu.jprotobuf.pbrpc.transport.ChannelPoolObjectFactory.java
@Override public PooledObject<Connection> wrap(Connection connection) { InetSocketAddress address;// w w w . jav a 2 s .c om if (host == null) { address = new InetSocketAddress(port); } else { address = new InetSocketAddress(host, port); } ChannelFuture future = this.rpcClient.connect(address); // Wait until the connection is made successfully. future.awaitUninterruptibly(); if (!future.isSuccess()) { LOGGER.log(Level.SEVERE, "failed to get result from stp", future.cause()); } else { connection.setIsConnected(true); } future.addListener(new RpcChannelFutureListener(connection)); connection.setFuture(future); return new DefaultPooledObject<Connection>(connection); }
From source file:com.chiralBehaviors.slp.hive.configuration.BroadcastConfiguration.java
@Override public Engine construct() throws IOException { Tuple<NetworkInterface, InetSocketAddress> tuple = getNetworkInterface(); DatagramSocket socket = new MulticastSocket(new InetSocketAddress(port)); socket.setReuseAddress(true);//from w w w.ja va 2s . c om socket.setBroadcast(true); return new MulticastEngine(getFdFactory(), Generators.timeBasedGenerator(), heartbeatPeriod, heartbeatUnit, socket, tuple.b, receiveBufferMultiplier, sendBufferMultiplier, getMac(), tuple.a); }
From source file:com.blackberry.bdp.test.utils.LocalZkServer.java
public LocalZkServer() throws InstantiationException, IllegalAccessException, SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException { String dataDirectory = System.getProperty("java.io.tmpdir"); dir = new File(dataDirectory, "zookeeper").getAbsoluteFile(); while (dir.exists()) { LOG.info("deleting {}", dir); FileUtils.deleteDirectory(dir);/*from ww w . j av a 2 s . c o m*/ } server = new ZooKeeperServer(dir, dir, tickTime); // The class that we need changed name between CDH3 and CDH4, so let's check // for the right version here. try { factoryClass = Class.forName("org.apache.zookeeper.server.NIOServerCnxnFactory"); standaloneServerFactory = factoryClass.newInstance(); Method configure = factoryClass.getMethod("configure", InetSocketAddress.class, Integer.TYPE); configure.invoke(standaloneServerFactory, new InetSocketAddress(clientPort), numConnections); Method startup = factoryClass.getMethod("startup", ZooKeeperServer.class); startup.invoke(standaloneServerFactory, server); } catch (ClassNotFoundException e) { LOG.info("Did not find NIOServerCnxnFactory"); try { factoryClass = Class.forName("org.apache.zookeeper.server.NIOServerCnxn$Factory"); Constructor<?> constructor = factoryClass.getConstructor(InetSocketAddress.class, Integer.TYPE); standaloneServerFactory = constructor.newInstance(new InetSocketAddress(clientPort), numConnections); Method startup = factoryClass.getMethod("startup", ZooKeeperServer.class); startup.invoke(standaloneServerFactory, server); } catch (ClassNotFoundException e1) { LOG.info("Did not find NIOServerCnxn.Factory"); throw new ClassNotFoundException("Can't find NIOServerCnxnFactory or NIOServerCnxn.Factory"); } } }
From source file:com.blackberry.bdp.common.versioned.LocalZkServer.java
public LocalZkServer() throws InstantiationException, IllegalAccessException, SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException { String dataDirectory = System.getProperty("java.io.tmpdir"); dir = new File(dataDirectory, "zookeeper").getAbsoluteFile(); while (dir.exists()) { LOG.info("deleting {}", dir); FileUtils.deleteDirectory(dir);/* w ww. j av a 2s . c om*/ } server = new ZooKeeperServer(dir, dir, tickTime); // The class that we need changed name between CDH3 and CDH4, so let's // check // for the right version here. try { factoryClass = Class.forName("org.apache.zookeeper.server.NIOServerCnxnFactory"); standaloneServerFactory = factoryClass.newInstance(); Method configure = factoryClass.getMethod("configure", InetSocketAddress.class, Integer.TYPE); configure.invoke(standaloneServerFactory, new InetSocketAddress(clientPort), numConnections); Method startup = factoryClass.getMethod("startup", ZooKeeperServer.class); startup.invoke(standaloneServerFactory, server); } catch (ClassNotFoundException e) { LOG.info("Did not find NIOServerCnxnFactory"); try { factoryClass = Class.forName("org.apache.zookeeper.server.NIOServerCnxn$Factory"); Constructor<?> constructor = factoryClass.getConstructor(InetSocketAddress.class, Integer.TYPE); standaloneServerFactory = constructor.newInstance(new InetSocketAddress(clientPort), numConnections); Method startup = factoryClass.getMethod("startup", ZooKeeperServer.class); startup.invoke(standaloneServerFactory, server); } catch (ClassNotFoundException e1) { LOG.info("Did not find NIOServerCnxn.Factory"); throw new ClassNotFoundException("Can't find NIOServerCnxnFactory or NIOServerCnxn.Factory"); } } }
From source file:edu.tsinghua.lumaqq.qq.net.UDPSocks5Port.java
/** * /*from w w w .j av a 2 s .co m*/ * * @param policy * ? * @param serverAddress * ?? * @throws IOException * port */ public UDPSocks5Port(IConnectionPolicy policy, InetSocketAddress serverAddress) throws IOException { super(policy); ready = false; this.remoteAddress = serverAddress; // UDP relaychannel channel = DatagramChannel.open(); channel.configureBlocking(false); channel.socket().bind(new InetSocketAddress(0)); // ? proxy = new Socks5Proxy(this, policy.getProxyUsername(), policy.getProxyPassword(), channel); proxy.setProxyAddress(policy.getProxy()); proxy.setRemoteAddress(serverAddress); proxy.setClientPort(channel.socket().getLocalPort()); }
From source file:com.palantir.curatortestrule.DefaultZooKeeperRuleConfig.java
@Override public ServerCnxnFactory getServer(int port) { ZooKeeperServer zkServer = new NoJMXZooKeeperServer(); FileTxnSnapLog ftxn;//from w w w.j a v a2s .c o m try { File dataDir = Files.createTempDir(); File snapDir = Files.createTempDir(); if (cleanupOnExit) { directoriesToCleanup.add(dataDir); directoriesToCleanup.add(snapDir); } ftxn = new FileTxnSnapLog(dataDir, snapDir); } catch (IOException e) { throw new RuntimeException(e); } zkServer.setTxnLogFactory(ftxn); try { ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory(); cnxnFactory.configure(new InetSocketAddress(port), cnxnFactory.getMaxClientCnxnsPerHost()); cnxnFactory.startup(zkServer); return cnxnFactory; } catch (IOException | InterruptedException e) { throw new RuntimeException(e); } }
From source file:com.linkedin.parseq.zk.server.ZKServer.java
/** * Create a ZK server with specified data and log dirs. * @param dataDir/*from ww w .ja v a2s .c o m*/ * @param logDir * @param port * @param erase if true, dataDir and logDir will be erased when shutdown() is called * @throws IOException */ public ZKServer(File dataDir, File logDir, int port, boolean erase) throws IOException { _dataDir = dataDir; _logDir = logDir; _port = port; _zk = new ZooKeeperServer(dataDir, logDir, 5000); _factory = new NIOServerCnxnFactory(); _factory.configure(new InetSocketAddress(port), 60); _erase = erase; }
From source file:com.iveely.framework.net.AsynServer.java
/** * Open service./* w ww . j a v a 2 s . c o m*/ */ public boolean open() throws IOException { if (acceptor == null) { acceptor = new NioSocketAcceptor(Runtime.getRuntime().availableProcessors() + 1); LoggingFilter loggingFilter = new LoggingFilter(); loggingFilter.setSessionClosedLogLevel(LogLevel.NONE); loggingFilter.setSessionCreatedLogLevel(LogLevel.NONE); loggingFilter.setSessionOpenedLogLevel(LogLevel.NONE); loggingFilter.setMessageSentLogLevel(LogLevel.NONE); loggingFilter.setMessageReceivedLogLevel(LogLevel.NONE); acceptor.getFilterChain().addLast("logger", loggingFilter); acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new PacketCodecFactory())); acceptor.setHandler(new InnerHandler()); acceptor.bind(new InetSocketAddress(this.port)); return true; } return false; }
From source file:com.linkedin.d2.discovery.stores.zk.ZKServer.java
/** * Create a ZK server with specified data and log dirs. * @param dataDir/*from ww w . j ava 2s . co m*/ * @param logDir * @param port * @param erase if true, dataDir and logDir will be erased when shutdown() is called * @throws IOException */ public ZKServer(File dataDir, File logDir, int port, boolean erase) throws IOException { _dataDir = dataDir; _logDir = logDir; _port = port; _zk = new ZooKeeperServer(dataDir, logDir, 5000); _factory = new NIOServerCnxnFactory(); _factory.configure(new InetSocketAddress(port), 60 /* default maximum client sockets */); _erase = erase; }
From source file:code.google.nfs.rpc.netty.server.NettyServer.java
public void start(int listenPort, final ExecutorService threadPool) throws Exception { if (!startFlag.compareAndSet(false, true)) { return;/* w ww . ja va 2s. c om*/ } bootstrap.setPipelineFactory(new ChannelPipelineFactory() { public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = new DefaultChannelPipeline(); pipeline.addLast("decoder", new NettyProtocolDecoder()); pipeline.addLast("encoder", new NettyProtocolEncoder()); pipeline.addLast("handler", new NettyServerHandler(threadPool)); return pipeline; } }); bootstrap.bind(new InetSocketAddress(listenPort)); LOGGER.warn("Server started,listen at: " + listenPort); }