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:org.apache.james.protocols.smtp.AbstractSMTPServerTest.java

@Test
public void testMailHookPermanentError() throws Exception {
    MailHook hook = new MailHook() {

        @Override//  ww  w.  j  ava2  s  .c o m
        public void init(Configuration config) throws ConfigurationException {

        }

        @Override
        public void destroy() {

        }

        public HookResult doMail(SMTPSession session, MailAddress sender) {
            return new HookResult(HookReturnCode.DENY);
        }
    };

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

    ProtocolServer server = null;
    try {
        server = createServer(createProtocol(hook), address);
        server.bind();

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

        client.helo("localhost");
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));

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

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

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

}

From source file:org.apache.james.protocols.smtp.AbstractSMTPServerTest.java

@Test
public void testMailHookTemporaryError() throws Exception {
    MailHook hook = new MailHook() {

        @Override/*from  w ww  .  ja v  a  2s . c o  m*/
        public void init(Configuration config) throws ConfigurationException {

        }

        @Override
        public void destroy() {

        }

        public HookResult doMail(SMTPSession session, MailAddress sender) {
            return new HookResult(HookReturnCode.DENYSOFT);
        }
    };

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

    ProtocolServer server = null;
    try {
        server = createServer(createProtocol(hook), address);
        server.bind();

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

        client.helo("localhost");
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));

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

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

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

}

From source file:org.apache.james.protocols.smtp.AbstractSMTPServerTest.java

@Test
public void testDisconnectHandler() throws Exception {

    final AtomicBoolean called = new AtomicBoolean(false);
    DisconnectHandler<SMTPSession> handler = new DisconnectHandler<SMTPSession>() {

        @Override//ww  w. j a va2s. co m
        public void init(Configuration config) throws ConfigurationException {

        }

        @Override
        public void destroy() {

        }

        public void onDisconnect(SMTPSession session) {
            called.set(true);
        }
    };

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

    ProtocolServer server = null;
    try {
        server = createServer(createProtocol(handler), address);
        server.bind();

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

        client.disconnect();

        Thread.sleep(1000);
        assertTrue(called.get());

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

}

From source file:org.apache.james.protocols.smtp.AbstractSMTPServerTest.java

@Test
public void testConnectHandlerTemporary() throws Exception {
    ConnectHandler<SMTPSession> connectHandler = new ConnectHandler<SMTPSession>() {

        @Override/*w w  w  .j  av  a2 s. c  o  m*/
        public void init(Configuration config) throws ConfigurationException {

        }

        @Override
        public void destroy() {

        }

        public Response onConnect(SMTPSession session) {
            return new SMTPResponse("451", "Bye Bye");
        }
    };

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

    ProtocolServer server = null;
    try {
        server = createServer(createProtocol(connectHandler), address);
        server.bind();

        SMTPClient client = createClient();
        client.connect(address.getAddress().getHostAddress(), address.getPort());
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isNegativeTransient(client.getReplyCode()));

        client.disconnect();

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

}

From source file:org.apache.james.protocols.smtp.AbstractSMTPServerTest.java

@Test
public void testConnectHandlerPermananet() throws Exception {
    ConnectHandler<SMTPSession> connectHandler = new ConnectHandler<SMTPSession>() {

        @Override/*from  w w  w.  ja  v a  2 s.  co  m*/
        public void init(Configuration config) throws ConfigurationException {

        }

        @Override
        public void destroy() {

        }

        public Response onConnect(SMTPSession session) {
            return new SMTPResponse("554", "Bye Bye");
        }
    };

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

    ProtocolServer server = null;
    try {

        server = createServer(createProtocol(connectHandler), address);
        server.bind();

        SMTPClient client = createClient();
        client.connect(address.getAddress().getHostAddress(), address.getPort());
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isNegativePermanent(client.getReplyCode()));

        client.disconnect();

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

}

From source file:org.eclipse.smarthome.binding.lifx.internal.LifxLightDiscovery.java

private void handlePacket(Packet packet, InetSocketAddress address) {

    logger.trace("Discovery : Packet type '{}' received from '{}' for '{}' with sequence '{}' and source '{}'",
            new Object[] { packet.getClass().getSimpleName(), address.toString(), packet.getTarget().getHex(),
                    packet.getSequence(), Long.toString(packet.getSource(), 16) });

    if (packet.getSource() == source || packet.getSource() == 0) {

        DiscoveredLight light = discoveredLights.get(packet.getTarget());

        if (packet instanceof StateServiceResponse) {
            int port = (int) ((StateServiceResponse) packet).getPort();
            if (port != 0) {
                try {
                    MACAddress macAddress = packet.getTarget();
                    InetSocketAddress socketAddress = new InetSocketAddress(address.getAddress(), port);
                    light = new DiscoveredLight(macAddress, socketAddress);
                    discoveredLights.put(macAddress, light);
                } catch (Exception e) {
                    logger.warn("An exception occurred while connecting to IP address : '{}'", e.getMessage());
                    return;
                }/*from  w  ww . j  a v a2 s .  c o m*/
            }
        } else if (packet instanceof StateLabelResponse) {
            light.label = ((StateLabelResponse) packet).getLabel().trim();
        } else if (packet instanceof StateVersionResponse) {
            light.products = Products.getProductFromProductID(((StateVersionResponse) packet).getProduct());
        }

        if (light != null && light.isDataComplete()) {
            DiscoveryResult discoveryResult = createDiscoveryResult(light);
            if (discoveryResult != null) {
                thingDiscovered(discoveryResult);
            }
        }
    }
}

From source file:org.apache.james.protocols.smtp.AbstractSMTPServerTest.java

@Test
public void testNullSender() throws Exception {

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

    ProtocolServer server = null;/*from   w ww.j av  a2 s .c  om*/
    try {
        server = createServer(createProtocol(new ProtocolHandler[0]), address);
        server.bind();

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

        client.helo("localhost");
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));

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

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

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

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

}

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

Standby(AvatarNode avatarNode, Configuration startupConf, Configuration conf, InetSocketAddress nameNodeAddr,
        NamenodeProtocol primaryNamenode) throws IOException {
    this.running = true;
    this.avatarNode = avatarNode;
    this.metrics = avatarNode.getAvatarNodeMetrics();
    this.confg = conf;
    this.startupConf = startupConf;
    this.fsImage = avatarNode.getFSImage();
    this.fsnamesys = avatarNode.getNamesystem();
    this.sleepBetweenErrors = startupConf.getInt("hdfs.avatarnode.sleep", 5000);
    this.nameNodeAddr = nameNodeAddr;
    this.primaryNamenode = primaryNamenode;

    initSecondary(startupConf); // start webserver for secondary namenode

    this.machineName = DNS.getDefaultIP(conf.get(FSConstants.DFS_NAMENODE_DNS_INTERFACE, "default"));
    LOG.info("machineName=" + machineName);

    InetSocketAddress addr = NameNode.getClientProtocolAddress(conf);
    this.tmpImageFileForValidation = new File("/tmp",
            "hadoop_image." + addr.getAddress().getHostAddress() + ":" + addr.getPort());

    URI remoteJournalURI = avatarNode.getRemoteSharedEditsURI(conf);
    if (remoteJournalURI.getScheme().equals(NNStorage.LOCAL_URI_SCHEME)) {
        StorageDirectory remoteJournalStorage = fsImage.storage.new StorageDirectory(
                new File(remoteJournalURI.getPath()));
        remoteJournal = new FileJournalManager(remoteJournalStorage, null, null);
    } else if (remoteJournalURI.getScheme().equals(QuorumJournalManager.QJM_URI_SCHEME)) {
        // TODO for now we pass null for NameNodeMetrics
        // once we have shared log we will pass the actual metrics
        remoteJournal = new QuorumJournalManager(conf, remoteJournalURI, new NamespaceInfo(fsImage.storage),
                null, false);//from  w ww.  j a  va2s. c o m
    } else {
        remoteJournal = FSEditLog.createJournal(conf, remoteJournalURI, new NamespaceInfo(fsImage.storage),
                null);
    }
    // we will start ingestion from the txid of the image
    this.currentSegmentTxId = avatarNode.getFSImage().storage.getMostRecentCheckpointTxId() + 1;
    this.inputStreamRetries = confg.getInt("dfs.ingest.retries", 30);
    checkpointStatus("No checkpoint initiated");
}

From source file:org.apache.bookkeeper.client.TestRegionAwareEnsemblePlacementPolicy.java

private void prepareNetworkTopologyForReorderTests(String myRegion) throws Exception {
    repp.uninitalize();/*from w w w  .  j  av a 2 s  .  co m*/
    updateMyRack("/" + myRegion);

    repp = new RegionAwareEnsemblePlacementPolicy();
    repp.initialize(conf);

    InetSocketAddress addr1 = new InetSocketAddress("127.0.0.2", 3181);
    InetSocketAddress addr2 = new InetSocketAddress("127.0.0.3", 3181);
    InetSocketAddress addr3 = new InetSocketAddress("127.0.0.4", 3181);
    InetSocketAddress addr4 = new InetSocketAddress("127.0.0.5", 3181);
    InetSocketAddress addr5 = new InetSocketAddress("127.0.0.6", 3181);
    InetSocketAddress addr6 = new InetSocketAddress("127.0.0.7", 3181);
    InetSocketAddress addr7 = new InetSocketAddress("127.0.0.8", 3181);
    InetSocketAddress addr8 = new InetSocketAddress("127.0.0.9", 3181);
    InetSocketAddress addr9 = new InetSocketAddress("127.0.0.10", 3181);
    // update dns mapping
    StaticDNSResolver.addNodeToRack(addr1.getAddress().getHostAddress(), "/region1/r1");
    StaticDNSResolver.addNodeToRack(addr2.getAddress().getHostAddress(), "/region1/r2");
    StaticDNSResolver.addNodeToRack(addr3.getAddress().getHostAddress(), "/region1/r3");
    StaticDNSResolver.addNodeToRack(addr4.getAddress().getHostAddress(), "/region2/r1");
    StaticDNSResolver.addNodeToRack(addr5.getAddress().getHostAddress(), "/region2/r2");
    StaticDNSResolver.addNodeToRack(addr6.getAddress().getHostAddress(), "/region2/r3");
    StaticDNSResolver.addNodeToRack(addr7.getAddress().getHostAddress(), "/region3/r1");
    StaticDNSResolver.addNodeToRack(addr8.getAddress().getHostAddress(), "/region3/r2");
    StaticDNSResolver.addNodeToRack(addr9.getAddress().getHostAddress(), "/region3/r3");
    // Update cluster
    Set<InetSocketAddress> addrs = new HashSet<InetSocketAddress>();
    addrs.add(addr1);
    addrs.add(addr2);
    addrs.add(addr3);
    addrs.add(addr4);
    addrs.add(addr5);
    addrs.add(addr6);
    addrs.add(addr7);
    addrs.add(addr8);
    addrs.add(addr9);
    repp.onClusterChanged(addrs, new HashSet<InetSocketAddress>());
}

From source file:org.apache.james.protocols.smtp.AbstractSMTPServerTest.java

@Test
public void testRcptHookPermanentError() throws Exception {
    RcptHook hook = new RcptHook() {

        @Override//from  www  .  jav a 2  s  .  c  o m
        public void init(Configuration config) throws ConfigurationException {

        }

        @Override
        public void destroy() {

        }

        public HookResult doRcpt(SMTPSession session, MailAddress sender, MailAddress rcpt) {
            if (RCPT1.equals(rcpt.toString())) {
                return new HookResult(HookReturnCode.DENY);
            } else {
                return new HookResult(HookReturnCode.DECLINED);
            }
        }

    };

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

    ProtocolServer server = null;
    try {
        server = createServer(createProtocol(hook), address);
        server.bind();

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

        client.helo("localhost");
        assertTrue("Reply=" + client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));

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

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

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

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

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

}