Example usage for java.net InetAddress getLoopbackAddress

List of usage examples for java.net InetAddress getLoopbackAddress

Introduction

In this page you can find the example usage for java.net InetAddress getLoopbackAddress.

Prototype

public static InetAddress getLoopbackAddress() 

Source Link

Document

Returns the loopback address.

Usage

From source file:com.alliander.osgp.acceptancetests.deviceinstallation.RegisterDeviceSteps.java

@DomainStep("the device should be created without owner")
public boolean thenTheDeviceShouldBeCreatedWithoutOwner() {
    LOGGER.info("THEN: \"the device should be created without owner\".");
    final Device expectedDevice = new DeviceBuilder().withDeviceIdentification(DEVICE_ID)
            .withNetworkAddress(InetAddress.getLoopbackAddress()).isActivated(true)
            .ofDeviceType(DeviceType.SSLD.toString()).build();

    try {/*  w w w  .j  a  va2  s  . c om*/
        verify(this.deviceRepositoryMock, timeout(10000).times(1)).save(eq(expectedDevice));
    } catch (final Throwable t) {
        LOGGER.error("Failure: {}", t);
        return false;
    }
    return true;
}

From source file:com.stratio.deep.cassandra.config.CassandraDeepJobConfig.java

/**
 * {@inheritDoc}/*from   w w w.  j a va  2 s.c o m*/
 */

@Override
public CassandraDeepJobConfig<T> initialize() {
    if (isInitialized) {
        return this;
    }

    if (StringUtils.isEmpty(getHost())) {
        try {
            host.add(InetAddress.getLocalHost().getCanonicalHostName());
        } catch (UnknownHostException e) {
            LOG.warn("Cannot resolve local host canonical name, using \"localhost\"");
            host.add(InetAddress.getLoopbackAddress().getCanonicalHostName());
        }
    }

    validate();

    columnDefinitions();
    isInitialized = Boolean.TRUE;

    return this;
}

From source file:com.trsst.server.TrsstAdapter.java

/**
 * Return a one-way hash token for the specified relay url.
 *///from   w  ww  . j a  v  a 2s .c o  m
protected String getLocalRelayId() {
    if (RELAY_ID == null) {
        // shared across all instances
        try {
            RELAY_ID = Integer.toHexString(InetAddress.getLocalHost().hashCode());
        } catch (UnknownHostException e) {
            log.error("Could not obtain local IP address: falling back to loopback address");
            RELAY_ID = Integer.toHexString(InetAddress.getLoopbackAddress().hashCode());
        }
    }
    // FLAG: hash name for a bit of extra obscurity
    // would this be overkill? #paranoid
    // byte[] hostBytes;
    // try {
    // hostBytes = hostName.getBytes("UTF-8");
    // hashName = Base64.encodeBase64String(Common.hash(hostBytes, 0,
    // hostBytes.length));
    // } catch (UnsupportedEncodingException e1) {
    // log.error("Should never happen", e1);
    // hashName = hostName;
    // }
    return RELAY_ID;
}

From source file:org.opendaylight.ovsdb.plugin.ConnectionService.java

private List<InetAddress> getControllerIPAddresses(Connection connection) {
    List<InetAddress> controllers = null;
    InetAddress controllerIP = null;

    controllers = new ArrayList<InetAddress>();
    String addressString = System.getProperty("ovsdb.controller.address");

    if (addressString != null) {
        try {/*  ww w  .j  a va2s.c  om*/
            controllerIP = InetAddress.getByName(addressString);
            if (controllerIP != null) {
                controllers.add(controllerIP);
                return controllers;
            }
        } catch (UnknownHostException e) {
            logger.error("Host {} is invalid", addressString);
        }
    }

    if (clusterServices != null) {
        controllers = clusterServices.getClusteredControllers();
        if (controllers != null && controllers.size() > 0) {
            if (controllers.size() == 1) {
                InetAddress controller = controllers.get(0);
                if (!controller.equals(InetAddress.getLoopbackAddress())) {
                    return controllers;
                }
            } else {
                return controllers;
            }
        }
    }

    addressString = System.getProperty("of.address");

    if (addressString != null) {
        try {
            controllerIP = InetAddress.getByName(addressString);
            if (controllerIP != null) {
                controllers.add(controllerIP);
                return controllers;
            }
        } catch (UnknownHostException e) {
            logger.error("Host {} is invalid", addressString);
        }
    }

    try {
        controllerIP = ((InetSocketAddress) connection.getChannel().localAddress()).getAddress();
        controllers.add(controllerIP);
        return controllers;
    } catch (Exception e) {
        logger.debug("Invalid connection provided to getControllerIPAddresses", e);
    }
    return controllers;
}

From source file:com.alliander.osgp.acceptancetests.adhocmanagement.SetRebootSteps.java

private void createDevice(final String deviceIdentification, final boolean activated) {
    LOGGER.info("Creating device [{}] with active [{}]", deviceIdentification, activated);

    this.device = new DeviceBuilder().withDeviceIdentification(deviceIdentification)
            .withNetworkAddress(activated ? InetAddress.getLoopbackAddress() : null)
            .withPublicKeyPresent(PUBLIC_KEY_PRESENT)
            .withProtocolInfo(ProtocolInfoTestUtils.getProtocolInfo(PROTOCOL, PROTOCOL_VERSION))
            .isActivated(activated).build();

    this.oslpDevice = new OslpDeviceBuilder().withDeviceIdentification(deviceIdentification)
            .withDeviceUid(DEVICE_UID).build();
}

From source file:com.alliander.osgp.acceptancetests.adhocmanagement.ResumeScheduleSteps.java

private void createDevice(final String deviceIdentification, final boolean activated) {
    LOGGER.info("Creating device [{}] with active [{}]", deviceIdentification, activated);

    this.device = (Ssld) new DeviceBuilder().withDeviceIdentification(deviceIdentification)
            .withNetworkAddress(activated ? InetAddress.getLoopbackAddress() : null)
            .withPublicKeyPresent(PUBLIC_KEY_PRESENT)
            .withProtocolInfo(ProtocolInfoTestUtils.getProtocolInfo(PROTOCOL, PROTOCOL_VERSION))
            .ofDeviceType("SSLD").isActivated(activated).build();

    this.oslpDevice = new OslpDeviceBuilder().withDeviceIdentification(deviceIdentification)
            .withDeviceUid(DEVICE_UID).build();
}

From source file:com.alliander.osgp.acceptancetests.deviceinstallation.StopDeviceTestSteps.java

private void createDevice(final String deviceIdentification, final boolean activated) {
    this.device = new DeviceBuilder().withDeviceIdentification(deviceIdentification)
            .withNetworkAddress(activated ? InetAddress.getLoopbackAddress() : null)
            .withPublicKeyPresent(PUBLIC_KEY_PRESENT)
            .withProtocolInfo(ProtocolInfoTestUtils.getProtocolInfo(PROTOCOL, PROTOCOL_VERSION))
            .isActivated(activated).build();

    this.oslpDevice = new OslpDeviceBuilder().withDeviceIdentification(deviceIdentification)
            .withDeviceUid(DEVICE_UID).build();
}

From source file:com.alliander.osgp.acceptancetests.firmwaremanagement.GetFirmwareVersionSteps.java

private void createDevice(final String deviceIdentification, final boolean activated) {
    LOGGER.info("Creating device [{}] with active [{}]", deviceIdentification, activated);

    this.device = new DeviceBuilder().withDeviceIdentification(deviceIdentification)
            .withNetworkAddress(activated ? InetAddress.getLoopbackAddress() : null)
            .withPublicKeyPresent(PUBLIC_KEY_PRESENT)
            .withProtocolInfo(ProtocolInfoTestUtils.getProtocolInfo(PROTOCOL, PROTOCOL_VERSION))
            .isActivated(activated).build();
}

From source file:com.alliander.osgp.acceptancetests.devicemanagement.SetEventNotificationsSteps.java

private Ssld createDevice(final String deviceIdentification) {
    return (Ssld) new DeviceBuilder().withDeviceIdentification(deviceIdentification)
            .withNetworkAddress(InetAddress.getLoopbackAddress()).withPublicKeyPresent(PUBLIC_KEY_PRESENT)
            .withProtocolInfo(ProtocolInfoTestUtils.getProtocolInfo(PROTOCOL, PROTOCOL_VERSION))
            .isActivated(true).build();// ww w  .j a v  a 2  s  .  com
}

From source file:com.alliander.osgp.acceptancetests.schedulemanagement.SetTariffScheduleSteps.java

private void createDevice(final String deviceIdentification, final Boolean activated) {
    LOGGER.info("Creating device [{}] with active [{}]", deviceIdentification, activated);

    this.device = (Ssld) new DeviceBuilder().withDeviceIdentification(deviceIdentification).ofDeviceType("SSLD")
            .withNetworkAddress(activated ? InetAddress.getLoopbackAddress() : null)
            .withPublicKeyPresent(PUBLIC_KEY_PRESENT)
            .withProtocolInfo(ProtocolInfoTestUtils.getProtocolInfo(PROTOCOL, PROTOCOL_VERSION))
            .isActivated(activated).build();

    this.oslpDevice = new OslpDeviceBuilder().withDeviceIdentification(deviceIdentification)
            .withDeviceUid(DEVICE_UID).build();
}