Example usage for java.net InetSocketAddress getPort

List of usage examples for java.net InetSocketAddress getPort

Introduction

In this page you can find the example usage for java.net InetSocketAddress getPort.

Prototype

public final int getPort() 

Source Link

Document

Gets the port number.

Usage

From source file:org.apache.hadoop.hdfsproxy.ProxyHttpServer.java

public ProxyHttpServer(InetSocketAddress addr, Configuration conf) throws IOException {
    super("", addr.getHostName(), addr.getPort(), 0 <= addr.getPort(), conf);
}

From source file:com.buaa.cfs.common.oncrpc.SimpleUdpServer.java

public void run() {
    // Configure the client.
    DatagramChannelFactory f = new NioDatagramChannelFactory(Executors.newCachedThreadPool(), workerCount);

    server = new ConnectionlessBootstrap(f);
    server.setPipeline(//from   w w  w .ja  va 2  s .c o  m
            Channels.pipeline(RpcUtil.STAGE_RPC_MESSAGE_PARSER, rpcProgram, RpcUtil.STAGE_RPC_UDP_RESPONSE));

    server.setOption("broadcast", "false");
    server.setOption("sendBufferSize", SEND_BUFFER_SIZE);
    server.setOption("receiveBufferSize", RECEIVE_BUFFER_SIZE);

    // Listen to the UDP port
    ch = server.bind(new InetSocketAddress(port));
    InetSocketAddress socketAddr = (InetSocketAddress) ch.getLocalAddress();
    boundPort = socketAddr.getPort();

    LOG.info("Started listening to UDP requests at port " + boundPort + " for " + rpcProgram
            + " with workerCount " + workerCount);
}

From source file:org.apache.hadoop.hdfs.server.namenode.NameNode.java

public static URI getUri(InetSocketAddress namenode) {
    int port = namenode.getPort();
    String portString = port == DEFAULT_PORT ? "" : (":" + port);
    return URI.create("hdfs://" + namenode.getHostName() + portString);
}

From source file:me.haohui.libhdfspp.NativeRpcEngine.java

void connect(InetSocketAddress addr) throws IOException {
    byte[] status = connect(handle, addr.getAddress().getHostAddress(), addr.getPort());
    NativeStatus stat = new NativeStatus(status);
    stat.checkForIOException();/*w  w w. j a v  a  2 s  . c  o  m*/
}

From source file:org.fedoraproject.copr.client.impl.RpcTest.java

@Before
public void setUp() throws Exception {
    server = new LocalTestServer(null, null);
    server.register("/api/*", new HttpMock(this));
    server.start();/*w w w .j  av a  2s.c  o m*/

    InetSocketAddress address = server.getServiceAddress();
    url = "http://" + address.getHostName() + ":" + address.getPort();

    CoprConfiguration configuration = getConfiguration();
    configuration.setUrl(url);

    CoprService copr = new DefaultCoprService();

    session = copr.newSession(configuration);
}

From source file:com.googlecode.jmxtrans.connections.SocketFactory.java

/**
 * Creates the socket and the writer to go with it.
 *///from  w w w .  j a  v  a  2 s  .c  om
@Override
public Socket makeObject(InetSocketAddress address) throws Exception {
    Socket socket = new Socket(address.getHostName(), address.getPort());
    socket.setKeepAlive(true);
    return socket;
}

From source file:org.apache.hadoop.hdfs.qjournal.server.JournalNodeHttpServer.java

/**
 * Return the actual address bound to by the running server.
 *//* ww  w  .j  av a2 s  .c  om*/
public InetSocketAddress getAddress() {
    InetSocketAddress addr = httpServer.getListenerAddress();
    assert addr.getPort() != 0;
    return addr;
}

From source file:edu.umass.cs.gigapaxos.PaxosConfig.java

/**
 * @param servers//from   w w w  . jav  a  2  s. c  o m
 * @param globalInt
 * @return Socket addresses with the port offset added to each element.
 */
public static Set<InetSocketAddress> offsetSocketAddresses(Set<InetSocketAddress> servers, int globalInt) {
    Set<InetSocketAddress> offsetted = new HashSet<InetSocketAddress>();
    for (InetSocketAddress isa : servers) {
        offsetted.add(new InetSocketAddress(isa.getAddress(), isa.getPort() + globalInt));
    }
    return offsetted;
}

From source file:com.groupon.jenkins.util.HttpPoster.java

private HttpHost getProxy(HttpUriRequest method) throws URIException {

    ProxyConfiguration proxy = Jenkins.getInstance().proxy;
    if (proxy == null)
        return null;

    Proxy p = proxy.createProxy(method.getURI().getHost());
    switch (p.type()) {
    case DIRECT:/*w w w  .  ja v a 2s.c  om*/
        return null;
    case HTTP:
        InetSocketAddress sa = (InetSocketAddress) p.address();
        return new HttpHost(sa.getHostName(), sa.getPort());
    case SOCKS:
    default:
        return null;
    }
}

From source file:com.buaa.cfs.common.oncrpc.SimpleTcpServer.java

public void run() {
    // Configure the Server.
    ChannelFactory factory;//from ww  w  .j a va  2s  . c  o  m
    if (workerCount == 0) {
        // Use default workers: 2 * the number of available processors
        factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
                Executors.newCachedThreadPool());
    } else {
        factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
                Executors.newCachedThreadPool(), workerCount);
    }

    server = new ServerBootstrap(factory);
    server.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            return Channels.pipeline(RpcUtil.constructRpcFrameDecoder(), RpcUtil.STAGE_RPC_MESSAGE_PARSER,
                    rpcProgram, RpcUtil.STAGE_RPC_TCP_RESPONSE);
        }
    });
    server.setOption("child.tcpNoDelay", true);
    server.setOption("child.keepAlive", true);

    // Listen to TCP port
    ch = server.bind(new InetSocketAddress(port));
    InetSocketAddress socketAddr = (InetSocketAddress) ch.getLocalAddress();
    boundPort = socketAddr.getPort();

    LOG.info("Started listening to TCP requests at port " + boundPort + " for " + rpcProgram
            + " with workerCount " + workerCount);
}