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.lmtp.AbstractLMTPServerTest.java

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

    ProtocolServer server = null;//  w ww.j  av  a 2 s .  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.helo("localhost");
        assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));

        client.mail(SENDER);
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(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();
        }
    }

}

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

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

    ProtocolServer server = null;/*from w  w  w. j ava 2 s.  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.helo("localhost");
        assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));

        client.setSender(SENDER);
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));

        client.rcpt(RCPT1);
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(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();
        }
    }
}

From source file:eu.operando.proxy.OperandoProxyStatus.java

private void updateStatusView() {

    OperandoProxyStatus proxyStatus = OperandoProxyStatus.STOPPED;
    OperandoProxyLink proxyLink = OperandoProxyLink.INVALID;

    boolean isProxyRunning = MainUtil.isServiceRunning(mainContext.getContext(), ProxyService.class);
    boolean isProxyPaused = MainUtil.isProxyPaused(mainContext);

    if (isProxyRunning) {
        if (isProxyPaused) {
            proxyStatus = OperandoProxyStatus.PAUSED;
        } else {/*from  w ww  .  j  a  v a 2  s .co  m*/
            proxyStatus = OperandoProxyStatus.ACTIVE;
        }
    }

    try {
        Proxy proxy = APL.getCurrentHttpProxyConfiguration();
        InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
        if (proxyAddress != null) {
            //TODO: THIS SHOULD BE DYNAMIC
            String proxyHost = proxyAddress.getHostName();
            int proxyPort = proxyAddress.getPort();

            if (proxyHost.equals("127.0.0.1") && proxyPort == 8899) {
                proxyLink = OperandoProxyLink.VALID;
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    String info = "";
    try {
        InputStream is = getResources().openRawResource(R.raw.info_template);
        info = IOUtils.toString(is);
        IOUtils.closeQuietly(is);
    } catch (IOException e) {
        e.printStackTrace();
    }

    info = info.replace("@@status@@", proxyStatus.name());
    info = info.replace("@@link@@", proxyLink.name());
    webView.loadDataWithBaseURL("", info, "text/html", "UTF-8", "");
    webView.setBackgroundColor(Color.TRANSPARENT); //TRANSPARENT

}

From source file:org.apache.hadoop.mapred.TrackerClientCache.java

/**
 * Connect to the task tracker and get the RPC client.
 * @param host The host./* w  w  w.  j av  a2 s  .c  o  m*/
 * @param port the port.
 * @return The RPC client.
 * @throws IOException
 */
private CoronaTaskTrackerProtocol createClient(String host, int port) throws IOException {
    String staticHost = NetUtils.getStaticResolution(host);
    InetSocketAddress s = null;
    InetAddress inetAddress = null;
    byte[] byteArr = null;
    if (staticHost != null) {
        inetAddress = InetAddress.getByName(staticHost);
    } else {
        byteArr = Utilities.asBytes(host);
        if (byteArr == null) {
            inetAddress = InetAddress.getByName(host);
        } else {
            inetAddress = InetAddress.getByAddress(byteArr);
        }
    }
    s = new InetSocketAddress(inetAddress, port);
    LOG.info("Creating client to " + (staticHost != null ? staticHost : host) + ":" + s.getPort());
    long connectTimeout = conf.getLong(CoronaJobTracker.TT_CONNECT_TIMEOUT_MSEC_KEY, 10000L);
    int rpcTimeout = conf.getInt(CoronaJobTracker.TT_RPC_TIMEOUT_MSEC_KEY, 60000);
    return RPC.waitForProxy(CoronaTaskTrackerProtocol.class, CoronaTaskTrackerProtocol.versionID, s, conf,
            connectTimeout, rpcTimeout);
}

From source file:org.apache.james.protocols.pop3.AbstractStartTlsPOP3ServerTest.java

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

    ProtocolServer server = null;//w  ww .  j  av a  2s .c  om
    try {
        String identifier = "id";
        TestPassCmdHandler handler = new TestPassCmdHandler();

        handler.add("valid", new MockMailbox(identifier));
        server = createServer(createProtocol(handler), address,
                Encryption.createStartTls(BogusSslContextFactory.getServerContext()));
        server.bind();

        POP3SClient client = createClient();
        client.connect(address.getAddress().getHostAddress(), address.getPort());

        // TODO: Make use of client.capa() once possible
        //       See NET-438
        assertEquals(POP3Reply.OK, client.sendCommand("CAPA"));
        client.getAdditionalReply();

        boolean startTlsCapa = false;
        for (String cap : client.getReplyStrings()) {
            if (cap.equalsIgnoreCase("STLS")) {
                startTlsCapa = true;
                break;
            }
        }
        assertTrue(startTlsCapa);

        assertTrue(client.execTLS());
        // TODO: Reenable when commons-net 3.1.0 was released
        //       See NET-430
        //
        //assertTrue(client.logout());
        client.disconnect();

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

}

From source file:org.apache.accumulo.server.gc.SimpleGarbageCollector.java

private void getZooLock(InetSocketAddress addr) throws KeeperException, InterruptedException {
    String address = addr.getHostName() + ":" + addr.getPort();
    String path = ZooUtil.getRoot(HdfsZooInstance.getInstance()) + Constants.ZGC_LOCK;

    LockWatcher lockWatcher = new LockWatcher() {
        public void lostLock(LockLossReason reason) {
            Halt.halt("GC lock in zookeeper lost (reason = " + reason + "), exiting!");
        }//from   www .  j  a  va2 s . c  o m
    };

    while (true) {
        lock = new ZooLock(path);
        if (lock.tryLock(lockWatcher, new ServerServices(address, Service.GC_CLIENT).toString().getBytes())) {
            break;
        }
        UtilWaitThread.sleep(1000);
    }
}

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

@Test
public void testDeliveryHook() throws Exception {
    TestDeliverHook deliverHook = new TestDeliverHook();

    InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());

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

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

        client.helo("localhost");
        assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));

        client.setSender(SENDER);
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));

        client.addRecipient(RCPT1);
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));

        client.addRecipient(RCPT2);
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));

        assertTrue(client.sendShortMessageData(MSG1));

        int[] replies = ((LMTPClient) client).getReplies();

        assertEquals("Expected two replies", 2, replies.length);

        assertTrue(SMTPReply.isNegativePermanent(replies[0]));
        assertTrue(SMTPReply.isPositiveCompletion(replies[1]));

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

        Iterator<MailEnvelope> queued = deliverHook.getDelivered().iterator();
        assertTrue(queued.hasNext());

        MailEnvelope env = queued.next();
        checkEnvelope(env, SENDER, Arrays.asList(RCPT1, RCPT2), MSG1);
        assertFalse(queued.hasNext());

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

}

From source file:org.apache.flink.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  va  2s  . com*/
 * @param jobManagerAddress Address and port of the job-manager.
 */
public Client(InetSocketAddress jobManagerAddress, Configuration config, ClassLoader userCodeClassLoader) {
    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.userCodeClassLoader = userCodeClassLoader;
    this.compiler = new PactCompiler(new DataStatistics(), new DefaultCostEstimator());
}

From source file:org.apache.hadoop.mapreduce.v2.app.rm.RMCommunicator.java

protected void register() {
    //Register//w  w  w .  j a v  a 2 s.  co m
    InetSocketAddress serviceAddr = null;
    if (clientService != null) {
        serviceAddr = clientService.getBindAddress();
    }
    try {
        RegisterApplicationMasterRequest request = recordFactory
                .newRecordInstance(RegisterApplicationMasterRequest.class);
        if (serviceAddr != null) {
            request.setHost(serviceAddr.getHostName());
            request.setRpcPort(serviceAddr.getPort());
            request.setTrackingUrl(MRWebAppUtil.getAMWebappScheme(getConfig()) + serviceAddr.getHostName() + ":"
                    + clientService.getHttpPort());
        }
        RegisterApplicationMasterResponse response = scheduler.registerApplicationMaster(request);
        isApplicationMasterRegistered = true;
        maxContainerCapability = response.getMaximumResourceCapability();
        this.context.getClusterInfo().setMaxContainerCapability(maxContainerCapability);
        if (UserGroupInformation.isSecurityEnabled()) {
            setClientToAMToken(response.getClientToAMTokenMasterKey());
        }
        this.applicationACLs = response.getApplicationACLs();
        LOG.info("maxContainerCapability: " + maxContainerCapability);
        String queue = response.getQueue();
        LOG.info("queue: " + queue);
        job.setQueueName(queue);
        this.schedulerResourceTypes.addAll(response.getSchedulerResourceTypes());
    } catch (Exception are) {
        LOG.error("Exception while registering", are);
        throw new YarnRuntimeException(are);
    }
}

From source file:org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebAppFilter.java

@Inject
public RMWebAppFilter(Injector injector, Configuration conf) {
    super(injector);
    this.injector = injector;
    InetSocketAddress sock = YarnConfiguration.useHttps(conf)
            ? conf.getSocketAddr(YarnConfiguration.RM_WEBAPP_HTTPS_ADDRESS,
                    YarnConfiguration.DEFAULT_RM_WEBAPP_HTTPS_ADDRESS,
                    YarnConfiguration.DEFAULT_RM_WEBAPP_HTTPS_PORT)
            : conf.getSocketAddr(YarnConfiguration.RM_WEBAPP_ADDRESS,
                    YarnConfiguration.DEFAULT_RM_WEBAPP_ADDRESS, YarnConfiguration.DEFAULT_RM_WEBAPP_PORT);

    path = sock.getHostName() + ":" + Integer.toString(sock.getPort());
    path = YarnConfiguration.useHttps(conf) ? "https://" + path : "http://" + path;
    ahsEnabled = conf.getBoolean(YarnConfiguration.APPLICATION_HISTORY_ENABLED,
            YarnConfiguration.DEFAULT_APPLICATION_HISTORY_ENABLED);
    ahsPageURLPrefix = pjoin(/*from www .j a v  a2  s.c o  m*/
            WebAppUtils.getHttpSchemePrefix(conf) + WebAppUtils.getAHSWebAppURLWithoutScheme(conf),
            "applicationhistory");
}