Example usage for java.net InetSocketAddress getPort

List of usage examples for java.net InetSocketAddress getPort

Introduction

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

Prototype

public final int getPort() 

Source Link

Document

Gets the port number.

Usage

From source file:com.dianping.dpsf.jmx.DpsfResponsorMonitor.java

@MBeanMeta(ignore = true)
public Collection<String> requestorsAtPort(int port) {
    Collection<String> requestors = new HashSet<String>();
    RequestProcessor requestProcessor = getRequestProcessor(port);
    if (requestProcessor == null) {
        return Collections.emptySet();
    }//  w  w  w .  j  a  v  a2  s.  c  o  m
    ChannelGroup serverChannels = requestProcessor.getServerChannels();
    for (Channel channel : serverChannels) {
        InetSocketAddress remoteAddress = (InetSocketAddress) channel.getRemoteAddress();
        requestors.add(remoteAddress.getAddress().getHostAddress() + ":" + remoteAddress.getPort());
    }
    return requestors;
}

From source file:org.apache.hadoop.hbase.rest.TestTableResource.java

void checkTableInfo(TableInfoModel model) {
    assertEquals(model.getName(), TABLE);
    Iterator<TableRegionModel> regions = model.getRegions().iterator();
    assertTrue(regions.hasNext());/*  w  ww  .java 2  s  .c o m*/
    while (regions.hasNext()) {
        TableRegionModel region = regions.next();
        boolean found = false;
        for (Map.Entry<HRegionInfo, ServerName> e : regionMap.entrySet()) {
            HRegionInfo hri = e.getKey();
            String hriRegionName = hri.getRegionNameAsString();
            String regionName = region.getName();
            if (hriRegionName.equals(regionName)) {
                found = true;
                byte[] startKey = hri.getStartKey();
                byte[] endKey = hri.getEndKey();
                InetSocketAddress sa = new InetSocketAddress(e.getValue().getHostname(),
                        e.getValue().getPort());
                String location = sa.getHostName() + ":" + Integer.valueOf(sa.getPort());
                assertEquals(hri.getRegionId(), region.getId());
                assertTrue(Bytes.equals(startKey, region.getStartKey()));
                assertTrue(Bytes.equals(endKey, region.getEndKey()));
                assertEquals(location, region.getLocation());
                break;
            }
        }
        assertTrue(found);
    }
}

From source file:com.chinamobile.bcbsp.bspstaff.StaffRunner.java

/**
 * Start to run a BSP staff./*w  w  w. j  ava  2  s  . c  o  m*/
 */
@Override
public void run() {
    try {
        String sep = System.getProperty("path.separator");
        File workDir = new File(new File(staff.getJobFile()).getParent(), "work");
        boolean isCreated = workDir.mkdirs();
        if (!isCreated) {
            LOG.debug("StaffRunner.workDir : " + workDir);
        }
        StringBuffer classPath = new StringBuffer();
        classPath.append(System.getProperty("java.class.path"));
        classPath.append(sep);
        if (Constants.USER_BC_BSP_JOB_TYPE_C.equals(this.conf.getJobType())) {
            String exe = conf.getJobExe();
            if (exe != null) {
                classPath.append(sep);
                classPath.append(exe);
                classPath.append(sep);
                classPath.append(workDir);
            }
        } else {
            String jar = conf.getJar();
            // if jar exists, it into workDir
            if (jar != null) {
                RunJar.unJar(new File(jar), workDir);
                File[] libs = new File(workDir, "lib").listFiles();
                if (libs != null) {
                    for (int i = 0; i < libs.length; i++) {
                        // add libs from jar to classpath
                        classPath.append(sep);
                        classPath.append(libs[i]);
                    }
                }
                classPath.append(sep);
                classPath.append(new File(workDir, "classes"));
                classPath.append(sep);
                classPath.append(workDir);
            }
        }
        // Build exec child jmv args.
        Vector<String> vargs = new Vector<String>();
        File jvm = new File(new File(System.getProperty("java.home"), "bin"), "java");
        vargs.add(jvm.toString());

        // bsp.child.java.opts
        String javaOpts = conf.getConf().get("bsp.child.java.opts", "-Xmx200m");
        javaOpts = javaOpts.replace("@taskid@", staff.getStaffID().toString());
        String[] javaOptsSplit = javaOpts.split(" ");
        for (int i = 0; i < javaOptsSplit.length; i++) {
            vargs.add(javaOptsSplit[i]);
        }

        // Add classpath.
        vargs.add("-classpath");
        vargs.add(classPath.toString());

        // Setup the log4j prop
        long logSize = StaffLog.getStaffLogLength(((BSPConfiguration) conf.getConf()));
        vargs.add("-Dbcbsp.log.dir=" + new File(System.getProperty("bcbsp.log.dir")).getAbsolutePath());
        vargs.add("-Dbcbsp.root.logger=INFO,TLA");

        LOG.info("debug: staff ID is " + staff.getStaffID());

        vargs.add("-Dbcbsp.tasklog.taskid=" + staff.getStaffID());
        vargs.add("-Dbcbsp.tasklog.totalLogFileSize=" + logSize);

        // Add main class and its arguments
        vargs.add(WorkerManager.Child.class.getName());
        InetSocketAddress addr = workerManager.getStaffTrackerReportAddress();

        vargs.add(addr.getHostName());
        vargs.add(Integer.toString(addr.getPort()));
        vargs.add(staff.getStaffID().toString());
        vargs.add(Integer.toString(getFaultSSStep()));
        vargs.add(workerManager.getHostName());
        vargs.add(this.conf.getJobType());

        // Run java
        runChild(vargs.toArray(new String[0]), workDir);
    } catch (Exception e) {
        LOG.error("[run]", e);
    }
}

From source file:co.rsk.net.discovery.PeerExplorer.java

public PongPeerMessage sendPong(InetSocketAddress nodeAddress, String id) {
    InetSocketAddress localAddress = this.localNode.getAddress();
    PongPeerMessage pongPeerMessage = PongPeerMessage.create(localAddress.getHostName(), localAddress.getPort(),
            id, this.key);
    udpChannel.write(new DiscoveryEvent(pongPeerMessage, nodeAddress));
    return pongPeerMessage;
}

From source file:backup.namenode.NameNodeBackupServicePlugin.java

@Override
public void start(Object service) {
    UserGroupInformation ugi;/*from   ww w . j av  a  2s .c o  m*/
    try {
        ugi = UserGroupInformation.getCurrentUser();
        LOG.info("Starting NameNodeBackupServicePlugin with ugi {}", ugi);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    Configuration conf = getConf();
    NameNode namenode = (NameNode) service;
    BlockManager blockManager = namenode.getNamesystem().getBlockManager();
    // This object is created here so that it's lifecycle follows the namenode
    try {
        restoreProcessor = SingletonManager.getManager(NameNodeRestoreProcessor.class).getInstance(namenode,
                () -> new NameNodeRestoreProcessor(getConf(), namenode, ugi));
        LOG.info("NameNode Backup plugin setup using UGI {}", ugi);

        NameNodeBackupRPCImpl backupRPCImpl = new NameNodeBackupRPCImpl(blockManager);

        InetSocketAddress listenerAddress = namenode.getServiceRpcAddress();
        int ipcPort = listenerAddress.getPort();
        String bindAddress = listenerAddress.getAddress().getHostAddress();
        int port = conf.getInt(DFS_BACKUP_NAMENODE_RPC_PORT_KEY, DFS_BACKUP_NAMENODE_RPC_PORT_DEFAULT);
        if (port == 0) {
            port = ipcPort + 1;
        }
        server = new RPC.Builder(conf).setBindAddress(bindAddress).setPort(port).setInstance(backupRPCImpl)
                .setProtocol(NameNodeBackupRPC.class).build();
        ServiceAuthorizationManager serviceAuthorizationManager = server.getServiceAuthorizationManager();
        serviceAuthorizationManager.refresh(conf, new BackupPolicyProvider());
        server.start();

        LOG.info("NameNode Backup RPC listening on {}", port);

        int httpPort = getConf().getInt(DFS_BACKUP_NAMENODE_HTTP_PORT_KEY,
                DFS_BACKUP_NAMENODE_HTTP_PORT_DEFAULT);
        if (httpPort != 0) {
            ClassLoader classLoader = getClassLoader();
            if (classLoader != null) {
                ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
                try {
                    BackupWebService<Stats> stats = getBackupWebService(ugi, blockManager, restoreProcessor);

                    // Have to setup classloader in thread context to get the static
                    // files in the http server tp be setup correctly.
                    Thread.currentThread().setContextClassLoader(classLoader);
                    Class<?> backupStatusServerClass = classLoader.loadClass(BACKUP_WEB_BACKUP_WEB_SERVER);

                    Object server = DuckTypeUtil.newInstance(backupStatusServerClass,
                            new Class[] { Integer.TYPE, BackupWebService.class },
                            new Object[] { httpPort, stats });
                    httpServer = DuckTypeUtil.wrap(HttpServer.class, server);
                    httpServer.start();
                    LOG.info("NameNode Backup HTTP listening on {}", httpPort);
                } finally {
                    Thread.currentThread().setContextClassLoader(contextClassLoader);
                }
            } else {
                LOG.info("NameNode Backup HTTP classes not found.");
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:edu.umass.cs.reconfiguration.deprecated.ReconfigurableClientCreateTester.java

private InetSocketAddress getFirstRCReplica() {
    InetSocketAddress address = this.getReconfigurators().iterator().next();
    return new InetSocketAddress(address.getAddress(), ActiveReplica.getClientFacingPort(address.getPort()));
}

From source file:org.sonar.ide.intellij.wsclient.WSClientFactory.java

/**
 * Workaround for http://jira.codehaus.org/browse/SONAR-1586
 *///from   w  w w. j a  v  a  2s .co m
private void configureProxy(DefaultHttpClient httpClient, Host server) {
    try {
        Proxy proxyData = getIntelliJProxyFor(server);
        if (proxyData != null) {
            InetSocketAddress address = (InetSocketAddress) proxyData.address();
            HttpConfigurable proxySettings = HttpConfigurable.getInstance();
            LOG.debug("Proxy for [" + address.getHostName() + "] - [" + address + "]");
            HttpHost proxy = new HttpHost(address.getHostName(), address.getPort());
            httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
            if (proxySettings.PROXY_AUTHENTICATION) {
                httpClient.getCredentialsProvider().setCredentials(
                        new AuthScope(address.getHostName(), address.getPort()),
                        new UsernamePasswordCredentials(proxySettings.PROXY_LOGIN,
                                proxySettings.getPlainProxyPassword()));
            }
        } else {
            LOG.debug("No proxy for [" + server.getHost() + "]");
        }
    } catch (Exception e) {
        LOG.error("Unable to configure proxy for sonar-ws-client", e);
    }
}

From source file:me.jtalk.socketconnector.SocketResourceAdapter.java

public long listenTCP(long clientId, InetSocketAddress local) throws ResourceException {
    log.trace("TCP listening requested for client ''{}'', address ''{}:{}''", clientId, local.getHostString(),
            local.getPort());
    TCPManager manager = this.getTCPManagerChecked(clientId);
    return manager.listen(local);
}

From source file:org.apache.hadoop.yarn.client.ConfiguredRMFailoverHAProxyProvider.java

private T createProxy(ActiveNode leader) {
    try {//from   ww  w  .j a  va 2s .  c  o m

        final InetSocketAddress rmAddress = rmProxy
                //.getRMAddress(conf, protocol, leader.getRpcServerIpAddress(),
                //    leader.getRpcServerPort());
                .getRMAddress(conf, protocol, leader.getHttpAddress());
        LOG.info("creating proxy from active nodes " + currentRMId + " " + rmAddress.getPort());
        return RMProxy.getProxy(conf, protocol, rmAddress);
    } catch (IOException ioe) {
        LOG.error("Unable to create proxy to the ResourceManager " + leader.toString(), ioe);
        return null;
    }
}

From source file:me.jtalk.socketconnector.SocketResourceAdapter.java

public long createTCPConnection(long clientId, InetSocketAddress target) throws ResourceException {
    log.trace("TCP connection creation requested for client ''{}'', address ''{}:{}''", clientId,
            target.getHostString(), target.getPort());
    TCPManager manager = this.getTCPManagerChecked(clientId);
    return manager.connect(target);
}