Example usage for java.net InetSocketAddress toString

List of usage examples for java.net InetSocketAddress toString

Introduction

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

Prototype

@Override
public String toString() 

Source Link

Document

Constructs a string representation of this InetSocketAddress.

Usage

From source file:gov.hhs.fha.nhinc.lift.ServerApp.java

private InetSocketAddress createSocketAddr() {
    InetSocketAddress addr = null;
    String proxyAddr = "";
    String proxyPort = "";
    try {/*from  w ww .  j  a va  2 s .c  om*/
        proxyAddr = PropertyAccessor.getProperty(NhincConstants.GATEWAY_PROPERTY_FILE,
                NhincConstants.LIFT_PROXY_ADDRESS);
        proxyPort = PropertyAccessor.getProperty(NhincConstants.GATEWAY_PROPERTY_FILE,
                NhincConstants.LIFT_PROXY_PORT);
        int portNum = Integer.parseInt(proxyPort);

        InetAddress inetAddr = InetAddress.getByName(proxyAddr);
        addr = new InetSocketAddress(inetAddr, portNum);
        log.debug("LiFT Server Address defined as: " + addr.toString());
    } catch (UnknownHostException ex) {
        log.error("Unknown LiFT Proxy Address and Port " + proxyAddr + ":" + proxyPort + " " + ex.getMessage());
    } catch (PropertyAccessException ex) {
        log.error("Missing LiFT Proxy Address and Port Properties " + ex.getMessage());
    }
    return addr;
}

From source file:org.apache.synapse.transport.passthru.PassThroughHttpListener.java

private void startEndpoints() throws AxisFault {

    Set<InetSocketAddress> addressSet = new HashSet<InetSocketAddress>();
    addressSet.addAll(connFactory.getBindAddresses());

    if (PassThroughConfiguration.getInstance().getMaxActiveConnections() != -1) {
        addMaxActiveConnectionCountController(PassThroughConfiguration.getInstance().getMaxActiveConnections());
    }/* www.ja v  a  2  s  . c  o m*/

    if (addressSet.isEmpty()) {
        addressSet.add(new InetSocketAddress(
                Integer.parseInt((String) pttInDescription.getParameter("port").getValue())));
    }

    // Ensure simple but stable order
    List<InetSocketAddress> addressList = new ArrayList<InetSocketAddress>(addressSet);
    Collections.sort(addressList, new Comparator<InetSocketAddress>() {

        public int compare(InetSocketAddress a1, InetSocketAddress a2) {
            String s1 = a1.toString();
            String s2 = a2.toString();
            return s1.compareTo(s2);
        }

    });
    for (InetSocketAddress address : addressList) {
        passThroughListeningIOReactorManager.startPTTEndpoint(address, ioReactor, namePrefix);
    }

}

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;
                }/* w ww .  j  a  v a2  s .com*/
            }
        } 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:ch.epfl.eagle.daemon.scheduler.Scheduler.java

public void relocateMissingProbes(String requestId, List<InetSocketAddress> probestoRelocate) {
    TaskPlacer taskPlacer = requestTaskPlacers.get(requestId);
    Map<InetSocketAddress, TEnqueueTaskReservationsRequest> enqueueTaskReservationsRequests;
    if (taskPlacer == null)
        return;//from   w w w.  j a v  a 2s.com
    LOG.debug("RELOCATING request " + requestId + " rounds left " + outstandingRequestsRoundsLeft.get(requestId)
            + " getschedulingrequest " + taskPlacer.getSchedulingRequest());
    String app = taskPlacer.getSchedulingRequest().getApp();
    Set<InetSocketAddress> allBackends = state.getBackends(app);

    // Put the ones in the list only
    Set<InetSocketAddress> backends = new HashSet<InetSocketAddress>();
    for (InetSocketAddress backend : allBackends) {
        if (distributedNotExecutingLong.contains(backend.toString())) {
            backends.add(backend);
        }
    }
    int roundsLeft = outstandingRequestsRoundsLeft.get(requestId);
    roundsLeft--;
    assert (roundsLeft >= 0);
    LOG.debug("relocateMissingProbes distributedNotExecutingLong.size() " + distributedNotExecutingLong.size()
            + " free backends " + backends.size());

    enqueueTaskReservationsRequests = taskPlacer.getRelocateEnqueueTaskRequests(requestId, probestoRelocate,
            backends, address, roundsLeft == 0);
    long start = System.currentTimeMillis();

    int pendingRequests = enqueueTaskReservationsRequests.entrySet().size();
    LOG.debug("relocateMissingProbes pendingRequests " + pendingRequests);
    outstandingCallbackRequests.put(requestId, pendingRequests);
    //requestsToRelocate.remove(requestId);
    requestsToRelocate.put(requestId, new ArrayList<InetSocketAddress>());

    // Request to enqueue a task at each of the selected nodes.
    for (Entry<InetSocketAddress, TEnqueueTaskReservationsRequest> entry : enqueueTaskReservationsRequests
            .entrySet()) {
        try {
            InternalService.AsyncClient client = nodeMonitorClientPool.borrowClient(entry.getKey());
            LOG.debug("RELaunching enqueueTask for request " + requestId + "on node: " + entry.getKey()
                    + " rounds left " + roundsLeft);
            if (roundsLeft == 0) // End normally as before
                client.enqueueTaskReservations(entry.getValue(),
                        new EnqueueTaskReservationsCallback(requestId, entry.getKey()));
            else {
                client.probeEnqueueTaskReservations(entry.getValue(),
                        new ProbeEnqueueTaskReservationsCallback(requestId, entry.getKey()));
                outstandingRequestsRoundsLeft.put(requestId, roundsLeft);
            }
        } catch (Exception e) {
            LOG.error("Error enqueuing task on node " + entry.getKey().toString() + ":" + e);
        }
    }

    long end = System.currentTimeMillis();
    LOG.debug("All tasks rescheduled for request " + requestId + "; returning. Total time: " + (end - start)
            + " milliseconds");
}

From source file:org.apache.hadoop.hbase.ipc.AsyncRpcChannel.java

/**
 * Constructor for netty RPC channel//from  w ww .j  a  va2s  .com
 *
 * @param bootstrap to construct channel on
 * @param client    to connect with
 * @param ticket of user which uses connection
 *               @param serviceName name of service to connect to
 * @param address to connect to
 */
public AsyncRpcChannel(Bootstrap bootstrap, final AsyncRpcClient client, User ticket, String serviceName,
        InetSocketAddress address) {
    this.client = client;

    this.ticket = ticket;
    this.serviceName = serviceName;
    this.address = address;

    this.channel = connect(bootstrap).channel();

    name = ("IPC Client (" + channel.hashCode() + ") to " + address.toString()
            + ((ticket == null) ? " from unknown user" : (" from " + ticket.getName())));
}

From source file:org.apache.synapse.transport.nhttp.HttpCoreNIOListener.java

/**
 * Start specific end points given by InetSockeAddress list
 *
 * @param endpointsClosed InetSocketAddresses of endpoints to be started
 * @throws AxisFault//from  w w w.j  av  a  2s . c om
 */
private void startSpecificEndpoints(List<InetSocketAddress> endpointsClosed) throws AxisFault {
    Queue<ListenerEndpoint> endpoints = new LinkedList<ListenerEndpoint>();

    // Ensure simple but stable order
    List<InetSocketAddress> addressList = endpointsClosed;
    Collections.sort(addressList, new Comparator<InetSocketAddress>() {

        public int compare(InetSocketAddress a1, InetSocketAddress a2) {
            String s1 = a1.toString();
            String s2 = a2.toString();
            return s1.compareTo(s2);
        }

    });

    for (InetSocketAddress address : addressList) {
        endpoints.add(ioReactor.listen(address));
    }

    // Wait for the endpoint to become ready, i.e. for the listener to start accepting
    // requests.
    while (!endpoints.isEmpty()) {
        ListenerEndpoint endpoint = endpoints.remove();
        try {
            endpoint.waitFor();
            if (log.isInfoEnabled()) {
                InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
                if (!address.isUnresolved()) {
                    log.info(name + " started on " + address.getHostName() + ":" + address.getPort());
                } else {
                    log.info(name + " started on " + address);
                }
            }
        } catch (InterruptedException e) {
            log.warn("Listener startup was interrupted");
            break;
        }
    }
}

From source file:org.apache.hadoop.hbase.ipc.AsyncRpcChannelImpl.java

/**
 * Constructor for netty RPC channel/* w ww  . j a  v  a2  s  . co  m*/
 * @param bootstrap to construct channel on
 * @param client to connect with
 * @param ticket of user which uses connection
 * @param serviceName name of service to connect to
 * @param address to connect to
 */
public AsyncRpcChannelImpl(Bootstrap bootstrap, final AsyncRpcClient client, User ticket, String serviceName,
        InetSocketAddress address) {
    this.client = client;

    this.ticket = ticket;
    this.serviceName = serviceName;
    this.address = address;

    this.channel = connect(bootstrap).channel();

    name = ("IPC Client (" + channel.hashCode() + ") to " + address.toString()
            + ((ticket == null) ? " from unknown user" : (" from " + ticket.getName())));
}

From source file:org.apache.synapse.transport.nhttp.HttpCoreNIOListener.java

private void startEndpoints() throws AxisFault {
    Queue<ListenerEndpoint> endpoints = new LinkedList<ListenerEndpoint>();

    Set<InetSocketAddress> addressSet = new HashSet<InetSocketAddress>();
    addressSet.addAll(connFactory.getBindAddresses());
    if (NHttpConfiguration.getInstance().getMaxActiveConnections() != -1) {
        addMaxConnectionCountController(NHttpConfiguration.getInstance().getMaxActiveConnections());
    }//  w w w.  j av a 2 s  .  c o m
    if (listenerContext.getBindAddress() != null) {
        addressSet.add(new InetSocketAddress(listenerContext.getBindAddress(), listenerContext.getPort()));
    }
    if (addressSet.isEmpty()) {
        addressSet.add(new InetSocketAddress(listenerContext.getPort()));
    }

    // Ensure simple but stable order
    List<InetSocketAddress> addressList = new ArrayList<InetSocketAddress>(addressSet);
    Collections.sort(addressList, new Comparator<InetSocketAddress>() {

        public int compare(InetSocketAddress a1, InetSocketAddress a2) {
            String s1 = a1.toString();
            String s2 = a2.toString();
            return s1.compareTo(s2);
        }

    });
    for (InetSocketAddress address : addressList) {
        endpoints.add(ioReactor.listen(address));
    }

    // Wait for the endpoint to become ready, i.e. for the listener to start accepting
    // requests.
    while (!endpoints.isEmpty()) {
        ListenerEndpoint endpoint = endpoints.remove();
        try {
            endpoint.waitFor();
            if (log.isInfoEnabled()) {
                InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
                if (!address.isUnresolved()) {
                    log.info(name + " started on " + address.getHostName() + ":" + address.getPort());
                } else {
                    log.info(name + " started on " + address);
                }
            }
        } catch (InterruptedException e) {
            log.warn("Listener startup was interrupted");
            break;
        }
    }
}

From source file:com.robonobo.eon.EONManager.java

public EONManager(String instanceName, ScheduledThreadPoolExecutor executor, InetSocketAddress localEP)
        throws EONException {
    this.instanceName = instanceName;
    log = getLogger(getClass());//from w w w.j  a  v  a 2 s.  c  o m
    debugLogging = log.isDebugEnabled();
    this.executor = executor;
    try {
        chan = DatagramChannel.open();
        chan.socket().setReceiveBufferSize(SOCKET_BUFFER_SIZE);
        chan.socket().setSendBufferSize(SOCKET_BUFFER_SIZE);
        chan.socket().bind(localEP);
        // Re-grab the value to see what we ended up on
        this.localEP = (InetSocketAddress) chan.socket().getLocalSocketAddress();
    } catch (IOException e) {
        throw new EONException("Unable to construct udp socket on " + localEP.toString(), e);
    }
    sockOK = true;
    pktSender = new PktSender(chan);
    recvThread = null;
    conns = new ConnectionHolder(this);
    mod = new Modulo((long) Integer.MAX_VALUE + 1);
    log.debug("EONManager created on endpoint " + this.localEP.getAddress().getHostAddress() + ":"
            + this.localEP.getPort());
}

From source file:ch.epfl.eagle.daemon.nodemonitor.NodeMonitor.java

private void gossipNotExecutingLong(int round) {
    List<InetSocketAddress> listBackends = getCleanWorkersList();
    // Choose randomly log(n) workers
    Collections.shuffle(listBackends);
    int gossip_fanout = (int) (Math.ceil(Math.log(listBackends.size())));
    for (int i = 0; i < gossip_fanout; i++) {
        InetSocketAddress chosenBackend = listBackends.get(i);
        try {/*from   w ww .j  ava2s . c  om*/
            InternalService.AsyncClient client = nodeMonitorClientPool.borrowClient(chosenBackend);
            LOG.debug(
                    "STEALING: Launching gossipNotExecutingLong on node: " + chosenBackend + " round " + round);
            client.receiveGossip(notExecutingLong, longStatusTimestamp, round,
                    new ReceiveGossipCallback(chosenBackend, client));
        } catch (Exception e) {
            LOG.error("Error enqueuing task on node " + chosenBackend.toString() + ":" + e);
        }
    }
}