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.james.protocols.lib.netty.AbstractConfigurableAsyncServer.java

/**
 * @see org.apache.james.protocols.lib.jmx.ServerMBean#getBoundAddresses()
 */// w  ww  .j a  v  a2  s  .  c  o  m
public String[] getBoundAddresses() {

    List<InetSocketAddress> addresses = getListenAddresses();
    String[] addrs = new String[addresses.size()];
    for (int i = 0; i < addresses.size(); i++) {
        InetSocketAddress address = addresses.get(i);
        addrs[i] = address.getHostName() + ":" + address.getPort();
    }

    return addrs;
}

From source file:com.alibaba.dragoon.common.protocol.transport.socket.SocketConnector.java

public Future<DragoonSession> connect(final SocketAddress address, final MessageHandler messageHandler) {
    if (address == null) {
        throw new IllegalArgumentException("address is null");
    }/*  w w  w .  j a  v a2  s .c om*/

    if (!(address instanceof InetSocketAddress)) {
        throw new IllegalArgumentException("address must be VmPipeAddress.");
    }

    final InetSocketAddress inetSocketAddress = (InetSocketAddress) address;

    FutureTask<DragoonSession> task = new FutureTask<DragoonSession>(new Callable<DragoonSession>() {

        public DragoonSession call() throws Exception {
            connectCount.incrementAndGet();
            if (LOG.isInfoEnabled()) {
                LOG.info("CONNECT TO " + inetSocketAddress);
            }

            remoteAddress = inetSocketAddress.toString();
            Socket socket = new Socket(inetSocketAddress.getAddress(), inetSocketAddress.getPort());

            connectEstablishedCount.incrementAndGet();

            if (LOG.isInfoEnabled()) {
                LOG.info("CONNECTED TO " + inetSocketAddress);
            }

            SocketSessionImpl impl = new SocketSessionImpl(socket, receivedBytes, receivedMessages, sentBytes,
                    sentMessages);

            final long sessionId = generateSessionId();

            DragoonSession session = new DragoonSession(sessionId, new DragoonSessionConfig(messageHandler),
                    impl);
            impl.init(session);

            return session;
        }

    });
    connectorExecutor.submit(task);

    return task;
}

From source file:hudson.TcpSlaveAgentListener.java

/**
 * Initiates the shuts down of the listener.
 *///from  www . j  a v  a  2s .  com
public void shutdown() {
    shuttingDown = true;
    try {
        SocketAddress localAddress = serverSocket.getLocalAddress();
        if (localAddress instanceof InetSocketAddress) {
            InetSocketAddress address = (InetSocketAddress) localAddress;
            Socket client = new Socket(address.getHostName(), address.getPort());
            client.setSoTimeout(1000); // waking the acceptor loop should be quick
            new PingAgentProtocol().connect(client);
        }
    } catch (IOException e) {
        LOGGER.log(Level.FINE, "Failed to send Ping to wake acceptor loop", e);
    }
    try {
        serverSocket.close();
    } catch (IOException e) {
        LOGGER.log(Level.WARNING, "Failed to close down TCP port", e);
    }
}

From source file:ch.cyberduck.core.socket.NetworkInterfaceAwareSocketFactory.java

@Override
public Socket createSocket() throws IOException {
    return new HttpProxyAwareSocket(proxy) {
        @Override//from   w  w w .j a  va 2s  .co  m
        public void connect(final SocketAddress endpoint, final int timeout) throws IOException {
            if (endpoint instanceof InetSocketAddress) {
                final InetSocketAddress address = (InetSocketAddress) endpoint;
                if (address.getAddress() instanceof Inet6Address) {
                    final NetworkInterface network = findIPv6Interface((Inet6Address) address.getAddress());
                    if (null != network) {
                        super.connect(new InetSocketAddress(NetworkInterfaceAwareSocketFactory.this
                                .getByAddressForInterface(network, address.getAddress()), address.getPort()),
                                timeout);
                        return;
                    }
                }
            }
            super.connect(endpoint, timeout);
        }
    };
}

From source file:org.whitesource.agent.client.WssServiceClientImpl.java

private void findDefaultProxy() {
    ProxySearch proxySearch = new ProxySearch();
    proxySearch.addStrategy(ProxySearch.Strategy.JAVA);
    proxySearch.addStrategy(ProxySearch.Strategy.ENV_VAR);
    proxySearch.addStrategy(ProxySearch.Strategy.OS_DEFAULT);
    proxySearch.addStrategy(ProxySearch.Strategy.BROWSER);
    ProxySelector proxySelector = proxySearch.getProxySelector();

    if (proxySelector != null) {
        ProxySelector.setDefault(proxySelector);
        try {//from   ww  w. java2 s .co m
            List<Proxy> proxyList = proxySelector.select(new URI(serviceUrl));
            if (proxyList != null && !proxyList.isEmpty()) {
                for (Proxy proxy : proxyList) {
                    InetSocketAddress address = (InetSocketAddress) proxy.address();
                    if (address != null) {
                        String host = address.getHostName();
                        int port = address.getPort();
                        String username = System.getProperty(HTTP_PROXY_USER);
                        String password = System.getProperty(HTTP_PROXY_PASSWORD);
                        setProxy(host, port, username, password);
                    }
                }
            }
        } catch (URISyntaxException e) {
            logger.error("Bad service url: " + serviceUrl, e);
        }
    }
}

From source file:eu.stratosphere.client.program.Client.java

/**
 * Creates a new instance of the class that submits the jobs to a job-manager.
 * at the given address using the default port.
 * /*from  w w w .j  a  v  a2 s .co  m*/
 * @param jobManagerAddress Address and port of the job-manager.
 */
public Client(InetSocketAddress jobManagerAddress, Configuration config) {
    Preconditions.checkNotNull(config, "Configuration is null");
    this.configuration = config;
    configuration.setString(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY,
            jobManagerAddress.getAddress().getHostAddress());
    configuration.setInteger(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY, jobManagerAddress.getPort());

    this.compiler = new PactCompiler(new DataStatistics(), new DefaultCostEstimator(), jobManagerAddress);

    //  Disable Local Execution when using a Client
    ContextEnvironment.disableLocalExecution();
}

From source file:com.hypersocket.server.HypersocketServerImpl.java

@Override
public boolean isSSLPort(InetSocketAddress localAddress) {
    if (Boolean.getBoolean("hypersocket.development")) {
        return localAddress.getPort() == 8443;
    } else {/*  ww w . j  ava 2 s.c o m*/
        return localAddress.getPort() == configurationService.getIntValue("https.port");
    }
}

From source file:com.hypersocket.server.HypersocketServerImpl.java

@Override
public boolean isPlainPort(InetSocketAddress localAddress) {
    if (Boolean.getBoolean("hypersocket.development")) {
        return localAddress.getPort() == 8080;
    } else {/*w  ww .ja  v a 2  s . c o  m*/
        if (configurationService.getIntValue("http.port") > 0) {
            return localAddress.getPort() == configurationService.getIntValue("http.port");
        }
        return true;
    }
}

From source file:org.apache.james.protocols.lmtp.AbstractLMTPServerTest.java

@Test
public void testEhloNotSupported() throws Exception {
    TestMessageHook hook = new TestMessageHook();
    InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());

    ProtocolServer server = null;/*from   ww  w .j  av  a  2s .c o  m*/
    try {
        server = createServer(createProtocol(hook), address);
        server.bind();

        SMTPClient client = createClient();
        client.connect(address.getAddress().getHostAddress(), address.getPort());
        assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));

        client.sendCommand("HELO localhost");
        assertTrue(SMTPReply.isNegativePermanent(client.getReplyCode()));

        client.quit();
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
        client.disconnect();

        Iterator<MailEnvelope> queued = hook.getQueued().iterator();
        assertFalse(queued.hasNext());

    } finally {
        if (server != null) {
            server.unbind();
        }
    }
}