Example usage for java.net InetSocketAddress getAddress

List of usage examples for java.net InetSocketAddress getAddress

Introduction

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

Prototype

public final InetAddress getAddress() 

Source Link

Document

Gets the InetAddress .

Usage

From source file:eu.stratosphere.client.CliFrontend.java

protected ExtendedManagementProtocol getJobManagerConnection(CommandLine line) throws IOException {
    InetSocketAddress jobManagerAddress = getJobManagerAddress(line);
    if (jobManagerAddress == null) {
        return null;
    }/*from  www  . j  a v a  2 s  . c  om*/

    String address = jobManagerAddress.getAddress().getHostAddress();
    int port = jobManagerAddress.getPort();

    return RPC.getProxy(ExtendedManagementProtocol.class, new InetSocketAddress(address, port),
            NetUtils.getSocketFactory());
}

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

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

    ProtocolServer server = null;//from   w w  w.  j  av a2s .  com
    try {
        String identifier = "id";
        TestPassCmdHandler factory = new TestPassCmdHandler();

        factory.add("valid", new MockMailbox(identifier, MESSAGE1));
        server = createServer(createProtocol(factory), address);
        server.bind();

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

        assertThat(client.login("valid", "valid")).isTrue();
        assertThat(client.listMessages().length).isEqualTo(1);
        assertThat(client.deleteMessage(1)).isTrue();
        assertThat(client.listMessages().length).isEqualTo(0);

        // call RSET. After this the deleted mark should be removed again
        assertThat(client.reset()).isTrue();
        assertThat(client.listMessages().length).isEqualTo(1);

        assertThat(client.logout()).isTrue();

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

}

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

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

    ProtocolServer server = null;//from   www .ja v a  2s  .  c om
    try {
        String identifier = "id";
        TestPassCmdHandler factory = new TestPassCmdHandler();

        factory.add("valid", new MockMailbox(identifier, MESSAGE1, MESSAGE2));
        server = createServer(createProtocol(factory), address);
        server.bind();

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

        assertThat(client.login("valid", "valid")).isTrue();
        POP3MessageInfo info = client.status();
        assertThat(info.size).isEqualTo((int) (MESSAGE1.meta.getSize() + MESSAGE2.meta.getSize()));
        assertThat(info.number).isEqualTo(2);
        assertThat(client.logout()).isTrue();

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

}

From source file:org.red5.server.tomcat.TomcatLoader.java

/**
 * The address to which we will bind./*from  w w  w.j  av a  2s .c  om*/
 * 
 * @param address
 */
public void setAddress(InetSocketAddress address) {
    log.info("Address to bind: {}", address);
    this.address = address.getAddress();
}

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

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

    ProtocolServer server = null;/*from w  ww. j  a  v  a2  s.co  m*/
    try {
        String identifier = "id";
        TestPassCmdHandler factory = new TestPassCmdHandler();

        factory.add("valid", new MockMailbox(identifier, MESSAGE1, MESSAGE2));
        server = createServer(createProtocol(factory), address);
        server.bind();

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

        assertThat(client.login("valid", "valid")).isTrue();
        Reader reader = client.retrieveMessage(1);
        assertThat(reader).isNotNull();
        checkMessage(MESSAGE1, reader);
        reader.close();

        // does not exist
        reader = client.retrieveMessage(10);
        assertThat(reader).isNull();

        // delete and check for the message again, should now be deleted
        assertThat(client.deleteMessage(1)).isTrue();
        reader = client.retrieveMessage(1);
        assertThat(reader).isNull();

        assertThat(client.logout()).isTrue();

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

}

From source file:org.rhq.plugins.apache.ApacheServerDiscoveryComponent.java

/**
 * Performs discovery on the single process scan result.
 * //from   ww w . j a  v  a 2  s .  c  o  m
 * @param discoveryContext the discovery context
 * @param process the process discovered by the scan
 * @return resource details
 * @throws DiscoveryFailureException if the discovery failed due to inability to detect necessary data from
 * the process info.
 * @throws Exception other unhandled exception
 */
private DiscoveredResourceDetails discoverSingleProcess(
        ResourceDiscoveryContext<PlatformComponent> discoveryContext, ProcessScanResult process)
        throws DiscoveryFailureException, Exception {

    if (isWindowsServiceRootInstance(process)) {
        return null;
    }

    File executablePath = getExecutableAbsolutePath(process);
    log.debug("Apache executable path: " + executablePath);

    ApacheBinaryInfo binaryInfo;
    try {
        binaryInfo = ApacheBinaryInfo.getInfo(executablePath.getPath(),
                discoveryContext.getSystemInformation());
    } catch (Exception e) {
        throw new DiscoveryFailureException(
                "'" + executablePath + "' is not a valid Apache executable (" + e + ").");
    }

    if (!isSupportedVersion(binaryInfo.getVersion())) {
        throw new DiscoveryFailureException("Apache " + binaryInfo.getVersion() + " is not suppported.");
    }

    String serverRoot = getServerRoot(binaryInfo, process.getProcessInfo());
    if (serverRoot == null) {
        throw new DiscoveryFailureException("Unable to determine server root.");
    }

    File serverConfigFile = getServerConfigFile(binaryInfo, process.getProcessInfo(), serverRoot);
    if (serverConfigFile == null) {
        throw new DiscoveryFailureException("Unable to determine server config file.");
    }

    Configuration pluginConfig = discoveryContext.getDefaultPluginConfiguration();

    PropertySimple executablePathProp = new PropertySimple(
            ApacheServerComponent.PLUGIN_CONFIG_PROP_EXECUTABLE_PATH, executablePath);
    pluginConfig.put(executablePathProp);

    PropertySimple serverRootProp = new PropertySimple(ApacheServerComponent.PLUGIN_CONFIG_PROP_SERVER_ROOT,
            serverRoot);
    pluginConfig.put(serverRootProp);

    PropertySimple configFile = new PropertySimple(ApacheServerComponent.PLUGIN_CONFIG_PROP_HTTPD_CONF,
            serverConfigFile);
    pluginConfig.put(configFile);

    PropertySimple inclusionGlobs = new PropertySimple(
            PluginDescriptorBasedAugeasConfiguration.INCLUDE_GLOBS_PROP, serverConfigFile);
    pluginConfig.put(inclusionGlobs);

    pluginConfig.put(new PropertyList(ApacheServerComponent.PLUGIN_CONFIG_CUSTOM_MODULE_NAMES));

    ApacheDirectiveTree serverConfig = parseRuntimeConfiguration(serverConfigFile.getAbsolutePath(),
            process.getProcessInfo(), binaryInfo);

    String serverUrl = null;
    String vhostsGlobInclude = null;

    //now check if the httpd.conf doesn't redefine the ServerRoot
    List<ApacheDirective> serverRoots = serverConfig.search("/ServerRoot");
    if (!serverRoots.isEmpty()) {
        serverRoot = AugeasNodeValueUtil.unescape(serverRoots.get(0).getValuesAsString());
        serverRootProp.setValue(serverRoot);
    }

    serverUrl = getUrl(serverConfig, binaryInfo.getVersion());
    vhostsGlobInclude = scanForGlobInclude(serverConfig);

    if (serverUrl != null) {
        Property urlProp = new PropertySimple(ApacheServerComponent.PLUGIN_CONFIG_PROP_URL, serverUrl);
        pluginConfig.put(urlProp);
    }

    if (vhostsGlobInclude != null) {
        pluginConfig.put(new PropertySimple(ApacheServerComponent.PLUGIN_CONFIG_PROP_VHOST_FILES_MASK,
                vhostsGlobInclude));
    } else {
        if (serverConfigFile.exists())
            pluginConfig.put(new PropertySimple(ApacheServerComponent.PLUGIN_CONFIG_PROP_VHOST_FILES_MASK,
                    serverConfigFile.getParent() + File.separator + "*"));
    }

    List<InetSocketAddress> snmpAddresses = findSNMPAddresses(serverConfig, new File(serverRoot));
    if (snmpAddresses != null && snmpAddresses.size() > 0) {
        InetSocketAddress addr = snmpAddresses.get(0);
        int port = addr.getPort();
        InetAddress host = addr.getAddress() == null ? InetAddress.getLocalHost() : addr.getAddress();

        pluginConfig.put(new PropertySimple(ApacheServerComponent.PLUGIN_CONFIG_PROP_SNMP_AGENT_HOST,
                host.getHostAddress()));
        pluginConfig.put(new PropertySimple(ApacheServerComponent.PLUGIN_CONFIG_PROP_SNMP_AGENT_PORT, port));
    }

    return createResourceDetails(discoveryContext, pluginConfig, process.getProcessInfo(), binaryInfo);
}

From source file:com.all.dht.DhtManager.java

private void requestOversizedValue(KUID primaryKey) {
    for (DHTValueEntity valueEntity : get(primaryKey)) {
        InetSocketAddress contactAddress = (InetSocketAddress) valueEntity.getSender().getContactAddress();
        log.info("Will request oversized value to " + contactAddress.getAddress());
        AllMessage<String> message = new AllMessage<String>(OVERSIZED_DHT_VALUE_REQUEST_TYPE,
                primaryKey.toHexString());
        boolean requested = networkingService.send(dht.getLocalNodeID().toHexString(), message,
                contactAddress.getAddress().getHostAddress(), contactAddress.getPort() + 1);
        if (requested) {
            oversizedValueRequests.add(primaryKey.toHexString());
        }//from w  w  w.  j a v a  2 s  .  co m
        break;
    }
}

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

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

    ProtocolServer server = null;//from   w ww. j a v  a2  s . c om
    try {
        String identifier = "id";
        TestPassCmdHandler factory = new TestPassCmdHandler();

        factory.add("valid", new MockMailbox(identifier, MESSAGE1, MESSAGE2));
        server = createServer(createProtocol(factory), address);
        server.bind();

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

        assertThat(client.login("valid", "valid")).isTrue();
        Reader reader = client.retrieveMessageTop(1, 1000);
        assertThat(reader).isNotNull();
        checkMessage(MESSAGE1, reader);
        reader.close();

        reader = client.retrieveMessageTop(2, 1);
        assertThat(reader).isNotNull();
        checkMessage(MESSAGE2, reader, 1);
        reader.close();

        // does not exist
        reader = client.retrieveMessageTop(10, 100);
        assertThat(reader).isNull();

        // delete and check for the message again, should now be deleted
        assertThat(client.deleteMessage(1)).isTrue();
        reader = client.retrieveMessageTop(1, 1000);
        assertThat(reader).isNull();

        assertThat(client.logout()).isTrue();

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

}

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

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

    ProtocolServer server = null;/*from   w ww  .j  a va 2  s .c o  m*/
    try {
        String identifier = "id";
        TestPassCmdHandler factory = new TestPassCmdHandler();

        factory.add("valid", new MockMailbox(identifier, MESSAGE1, MESSAGE2));
        server = createServer(createProtocol(factory), address);
        server.bind();

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

        assertThat(client.login("valid", "valid")).isTrue();
        POP3MessageInfo[] info = client.listMessages();
        assertThat(info.length).isEqualTo(2);

        assertThat(client.deleteMessage(1)).isTrue();
        info = client.listMessages();
        assertThat(info.length).isEqualTo(1);

        assertThat(client.deleteMessage(1)).isFalse();
        info = client.listMessages();
        assertThat(info.length).isEqualTo(1);

        assertThat(client.deleteMessage(2)).isTrue();
        info = client.listMessages();
        assertThat(info.length).isEqualTo(0);

        // logout so the messages get expunged
        assertThat(client.logout()).isTrue();

        client.connect(address.getAddress().getHostAddress(), address.getPort());

        assertThat(client.login("valid", "valid")).isTrue();
        info = client.listMessages();
        assertThat(info.length).isEqualTo(0);

        assertThat(client.logout()).isTrue();

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

}

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

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

    ProtocolServer server = null;/*from  ww w.ja  v  a2  s  .c om*/
    try {
        String identifier = "id";
        TestPassCmdHandler factory = new TestPassCmdHandler();

        factory.add("valid", new MockMailbox(identifier, MESSAGE1, MESSAGE2));
        server = createServer(createProtocol(factory), address);
        server.bind();

        POP3Client client = createClient();

        client.connect(address.getAddress().getHostAddress(), address.getPort());
        assertThat(client.listMessages()).isNull();
        assertThat(client.listUniqueIdentifiers()).isNull();
        assertThat(client.deleteMessage(1)).isFalse();
        assertThat(client.retrieveMessage(1)).isNull();
        assertThat(client.retrieveMessageTop(1, 10)).isNull();
        assertThat(client.status()).isNull();
        assertThat(client.reset()).isFalse();
        client.logout();

        client.connect(address.getAddress().getHostAddress(), address.getPort());

        assertThat(client.login("valid", "valid")).isTrue();
        assertThat(client.listMessages()).isNotNull();
        assertThat(client.listUniqueIdentifiers()).isNotNull();
        Reader reader = client.retrieveMessage(1);
        assertThat(reader).isNotNull();
        reader.close();
        assertThat(client.status()).isNotNull();
        reader = client.retrieveMessageTop(1, 1);
        assertThat(reader).isNotNull();
        reader.close();
        assertThat(client.deleteMessage(1)).isTrue();
        assertThat(client.reset()).isTrue();

        assertThat(client.logout()).isTrue();

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

}