Example usage for java.net InetSocketAddress InetSocketAddress

List of usage examples for java.net InetSocketAddress InetSocketAddress

Introduction

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

Prototype

private InetSocketAddress(int port, String hostname) 

Source Link

Usage

From source file:com.googlecode.jmxtrans.model.output.OpenTSDBWriterFactory.java

@JsonCreator
public OpenTSDBWriterFactory(@JsonProperty("typeNames") ImmutableList<String> typeNames,
        @JsonProperty("booleanAsNumber") boolean booleanAsNumber, @JsonProperty("host") String host,
        @JsonProperty("port") Integer port, @JsonProperty("tags") Map<String, String> tags,
        @JsonProperty("tagName") String tagName, @JsonProperty("mergeTypeNamesTags") Boolean mergeTypeNamesTags,
        @JsonProperty("metricNamingExpression") String metricNamingExpression,
        @JsonProperty("addHostnameTag") Boolean addHostnameTag,
        @JsonProperty("flushStrategy") String flushStrategy,
        @JsonProperty("flushDelayInSeconds") Integer flushDelayInSeconds,
        @JsonProperty("poolSize") Integer poolSize) throws LifecycleException, UnknownHostException {

    this.booleanAsNumber = booleanAsNumber;
    this.server = new InetSocketAddress(firstNonNull(host, "localhost"), firstNonNull(port, 3030));

    ImmutableMap<String, String> immutableTags = tags == null ? ImmutableMap.<String, String>of()
            : ImmutableMap.copyOf(tags);

    mergeTypeNamesTags = firstNonNull(mergeTypeNamesTags, true);

    messageFormatter = new OpenTSDBMessageFormatter(
            (typeNames == null) ? ImmutableList.<String>of() : typeNames, immutableTags, tagName,
            metricNamingExpression, mergeTypeNamesTags, firstNonNull(addHostnameTag, false));
    this.flushStrategy = createFlushStrategy(flushStrategy, flushDelayInSeconds);
    this.poolSize = firstNonNull(poolSize, 1);
}

From source file:net.beaconpe.jraklib.protocol.Packet.java

protected InetSocketAddress getAddress() {
    int version = getByte();
    if (version == 4) {
        String address = ((~getByte()) & 0xff) + "." + ((~getByte()) & 0xff) + "." + ((~getByte()) & 0xff) + "."
                + ((~getByte()) & 0xff);
        int port = getShort(false);
        return new InetSocketAddress(address, port);
    } else {/*  w  ww  . j  a  v  a 2 s.co m*/
        //TODO: IPv6
        return new InetSocketAddress("0.0.0.0", 0);
    }
}

From source file:com.couchbase.client.ViewConnectionTest.java

@Test
public void shouldAddHostsOnRebalance() throws Exception {
    List<InetSocketAddress> initialNodes = Collections.singletonList(new InetSocketAddress("10.0.0.1", PORT));

    ViewConnection conn = new ViewConnection(factoryMock, initialNodes, DEFAULT_USER, DEFAULT_PASS);

    List<URL> viewServers = Arrays.asList(new URL("http://10.0.0.1:" + PORT),
            new URL("http://10.0.0.2:" + PORT), new URL("http://10.0.0.3:" + PORT));
    when(configMock.getCouchServers()).thenReturn(viewServers);

    assertEquals(1, conn.getConnectedHosts().size());
    conn.reconfigure(bucketMock);/*from  ww  w.ja va2 s.  c  om*/

    List<HttpHost> connected = conn.getConnectedHosts();
    assertEquals(3, conn.getConnectedHosts().size());
    assertEquals("10.0.0.1:" + PORT, connected.get(0).toHostString());
    assertEquals("10.0.0.2:" + PORT, connected.get(1).toHostString());
    assertEquals("10.0.0.3:" + PORT, connected.get(2).toHostString());
}

From source file:com.twitter.common.net.InetSocketAddressHelper.java

public static InetSocketAddress getLocalAddress(int port) throws UnknownHostException {
    String ipAddress = InetAddress.getLocalHost().getHostAddress();
    return new InetSocketAddress(ipAddress, port);
}

From source file:org.apache.mina.springrpc.DefaultMinaRequestExecutorTest.java

@Test
public void executeRequest() throws Exception {
    ReturnAddress returnAddress = new UniqueStringReturnAddress();
    Object value = new Object();
    ReturnAddressAwareRemoteInvocationResult expected = new ReturnAddressAwareRemoteInvocationResult(
            returnAddress, value);/*w ww. j a v a2s .  c  o  m*/

    MinaClientConfiguration configuration = new StaticConfiguration();
    IoConnector connector = EasyMock.createMock(IoConnector.class);
    connector.setHandler((IoHandler) EasyMock.anyObject());
    EasyMock.expectLastCall().asStub();

    ResultReceiver resultReceiver = EasyMock.createMock(ResultReceiver.class);
    resultReceiver.interrupt();
    EasyMock.expectLastCall().asStub();

    ConnectFuture connectFuture = EasyMock.createMock(ConnectFuture.class);
    InetSocketAddress socketAddress = new InetSocketAddress(configuration.getHostName(),
            configuration.getPort());
    EasyMock.expect(connector.connect(socketAddress)).andReturn(connectFuture);
    EasyMock.expect(connectFuture.awaitUninterruptibly()).andReturn(connectFuture);
    IoSession session = EasyMock.createMock(IoSession.class);
    EasyMock.expect(connectFuture.getSession()).andReturn(session);

    RemoteInvocation decorated = RemoteInvocationFactory.createHashCodeRemoteInvocation();
    ReturnAddressAwareRemoteInvocation invocation = new ReturnAddressAwareRemoteInvocation(returnAddress,
            decorated);
    WriteFuture writeFuture = EasyMock.createMock(WriteFuture.class);
    EasyMock.expect(session.write(invocation)).andReturn(writeFuture);
    //      EasyMock.expect(writeFuture.awaitUninterruptibly()).andReturn(writeFuture);

    resultReceiver.resultReceived(expected);
    EasyMock.expectLastCall().asStub();
    EasyMock.expect(resultReceiver.takeResult(returnAddress)).andReturn(expected);

    CloseFuture closeFuture = EasyMock.createMock(CloseFuture.class);
    EasyMock.expect(session.close(true)).andReturn(closeFuture);
    //      EasyMock.expect(closeFuture.awaitUninterruptibly()).andReturn(closeFuture);
    connector.dispose();
    EasyMock.expectLastCall().asStub();

    Object[] mocks = new Object[] { connector, connectFuture, session, writeFuture, resultReceiver,
            closeFuture };

    EasyMock.replay(mocks);

    MinaRequestExecutor executor = new DefaultMinaRequestExecutor();
    executor.setMinaClientConfiguration(configuration);
    executor.setConnector(connector);
    executor.setResultReceiver(resultReceiver);
    executor.afterPropertiesSet();
    ReturnAddressAwareRemoteInvocationResult result = executor.executeRequest(invocation);
    assertEquals(expected, result);
    executor.destroy();

    EasyMock.verify(mocks);
}

From source file:org.openqa.selenium.remote.ReusingSocketSocketFactory.java

public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort,
        HttpParams params) throws IOException {

    if (host == null) {
        throw new IllegalArgumentException("Target host may not be null.");
    }//  ww w.  ja  v a 2s  .co  m
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null.");
    }

    if (sock == null)
        sock = createSocket();

    sock.setReuseAddress(true); // This is the 1 line added by kristian
    if ((localAddress != null) || (localPort > 0)) {

        // we need to bind explicitly
        if (localPort < 0)
            localPort = 0; // indicates "any"

        InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
        sock.bind(isa);
    }

    int timeout = HttpConnectionParams.getConnectionTimeout(params);

    InetSocketAddress remoteAddress;
    if (this.nameResolver != null) {
        remoteAddress = new InetSocketAddress(this.nameResolver.resolve(host), port);
    } else {
        remoteAddress = new InetSocketAddress(host, port);
    }
    try {
        sock.connect(remoteAddress, timeout);
    } catch (SocketTimeoutException ex) {
        throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out");
    }
    return sock;
}

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

private void startClient() {

    try {/*from www.  java 2 s. com*/
        String clientIP = PropertyAccessor.getProperty(NhincConstants.GATEWAY_PROPERTY_FILE,
                NhincConstants.LIFT_CLIENT_IP);
        String clientPort = PropertyAccessor.getProperty(NhincConstants.GATEWAY_PROPERTY_FILE,
                NhincConstants.LIFT_CLIENT_PORT);
        SocketAddress saddr = new InetSocketAddress(clientIP, Integer.parseInt(clientPort));
        ServerSocket server = new ServerSocket();
        server.bind(saddr);
        log.debug("Client listening on " + saddr);

        ClientPropertiesFacade props = new ClientPropertiesService();
        ConsumerProxyPropertiesFacade proxyProps = new ConsumerProxyPropertiesFacadeRI();
        proxyProps.setTrustStore();
        proxyProps.setKeyStoreProperty();

        LSTClientManager manager = new LSTClientManager(props, proxyProps);
        SocketClientManagerController con = new SocketClientManagerController(server, manager);

        (new Thread(con)).start();
        System.out.println("ClientApp started. ");

    } catch (PropertyAccessException ex) {
        log.error(ex.getMessage());
    } catch (IOException ex) {
        log.error(ex.getMessage());
    }
}

From source file:com.linkedin.d2.quorum.ZKPeer.java

public void setQuorumPeer(int peersCount, Map<Long, QuorumServer> peersView, FileTxnSnapLog fts)
        throws IOException {
    NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory();
    cnxnFactory.configure(new InetSocketAddress("127.0.0.1", _clientPort), _maxClientCnxns);

    _peer = new QuorumPeer();
    _peer.setClientPortAddress(new InetSocketAddress("127.0.0.1", _clientPort));
    _peer.setTxnFactory(fts);// w w w  .  jav  a  2 s. c om
    _peer.setQuorumPeers(peersView);
    _peer.setElectionType(_electionAlg);
    _peer.setMyid(_id);
    _peer.setTickTime(_tickTime);
    _peer.setMinSessionTimeout(_minSessionTimeout);
    _peer.setMaxSessionTimeout(_maxSessionTimeout);
    _peer.setInitLimit(_initLimit);
    _peer.setSyncLimit(_syncLimit);
    _peer.setQuorumVerifier(new QuorumMaj(peersCount));
    _peer.setCnxnFactory(cnxnFactory);
    _peer.setZKDatabase(new ZKDatabase(_peer.getTxnFactory()));
    _peer.setLearnerType(LearnerType.PARTICIPANT);

}