List of usage examples for org.apache.hadoop.net NetUtils getConnectAddress
public static InetSocketAddress getConnectAddress(InetSocketAddress addr)
From source file:org.apache.hoya.yarn.service.RpcService.java
License:Apache License
public InetSocketAddress getConnectAddress() { return NetUtils.getConnectAddress(server); }
From source file:org.apache.slider.server.services.workflow.WorkflowRpcService.java
License:Apache License
/** * Get the socket address of this server * @return the address this server is listening on *//* ww w . ja v a 2 s . co m*/ public InetSocketAddress getConnectAddress() { return NetUtils.getConnectAddress(server); }
From source file:org.apache.tez.dag.api.client.DAGClientServer.java
License:Apache License
@Override public void serviceStart() { try {/*from w ww .j a va2 s . c o m*/ Configuration conf = getConfig(); InetSocketAddress addr = new InetSocketAddress(0); DAGClientAMProtocolBlockingPBServerImpl service = new DAGClientAMProtocolBlockingPBServerImpl( realInstance); BlockingService blockingService = DAGClientAMProtocol.newReflectiveBlockingService(service); int numHandlers = conf.getInt(TezConfiguration.TEZ_AM_CLIENT_THREAD_COUNT, TezConfiguration.TEZ_AM_CLIENT_THREAD_COUNT_DEFAULT); server = createServer(DAGClientAMProtocolBlockingPB.class, addr, conf, numHandlers, blockingService, TezConfiguration.TEZ_AM_CLIENT_AM_PORT_RANGE); // Enable service authorization? if (conf.getBoolean(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, false)) { refreshServiceAcls(conf, new TezAMPolicyProvider()); } server.start(); InetSocketAddress serverBindAddress = NetUtils.getConnectAddress(server); this.bindAddress = NetUtils.createSocketAddrForHost( serverBindAddress.getAddress().getCanonicalHostName(), serverBindAddress.getPort()); LOG.info("Instantiated DAGClientRPCServer at " + bindAddress); } catch (Exception e) { LOG.error("Failed to start DAGClientServer: ", e); throw new TezUncheckedException(e); } }
From source file:org.apache.tez.dag.app.TaskAttemptListenerImpTezDag.java
License:Apache License
protected void startRpcServer() { Configuration conf = getConfig(); if (!conf.getBoolean(TezConfiguration.TEZ_LOCAL_MODE, TezConfiguration.TEZ_LOCAL_MODE_DEFAULT)) { try {/* w w w .j a v a 2 s. co m*/ server = new RPC.Builder(conf).setProtocol(TezTaskUmbilicalProtocol.class).setBindAddress("0.0.0.0") .setPort(0).setInstance(this) .setNumHandlers(conf.getInt(TezConfiguration.TEZ_AM_TASK_LISTENER_THREAD_COUNT, TezConfiguration.TEZ_AM_TASK_LISTENER_THREAD_COUNT_DEFAULT)) .setSecretManager(jobTokenSecretManager).build(); // Enable service authorization? if (conf.getBoolean(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, false)) { refreshServiceAcls(conf, new TezAMPolicyProvider()); } server.start(); this.address = NetUtils.getConnectAddress(server); } catch (IOException e) { throw new TezUncheckedException(e); } } else { try { this.address = new InetSocketAddress(InetAddress.getLocalHost(), 0); } catch (UnknownHostException e) { throw new TezUncheckedException(e); } if (LOG.isDebugEnabled()) { LOG.debug("Not starting TaskAttemptListener RPC in LocalMode"); } } }
From source file:org.apache.tez.dag.app.TezTaskCommunicatorImpl.java
License:Apache License
protected void startRpcServer() { try {/*from ww w. j a va2 s . co m*/ JobTokenSecretManager jobTokenSecretManager = new JobTokenSecretManager(); jobTokenSecretManager.addTokenForJob(tokenIdentifier, sessionToken); server = new RPC.Builder(conf).setProtocol(TezTaskUmbilicalProtocol.class).setBindAddress("0.0.0.0") .setPort(0).setInstance(taskUmbilical) .setNumHandlers(conf.getInt(TezConfiguration.TEZ_AM_TASK_LISTENER_THREAD_COUNT, TezConfiguration.TEZ_AM_TASK_LISTENER_THREAD_COUNT_DEFAULT)) .setPortRangeConfig(TezConfiguration.TEZ_AM_TASK_AM_PORT_RANGE) .setSecretManager(jobTokenSecretManager).build(); // Enable service authorization? if (conf.getBoolean(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, false)) { refreshServiceAcls(conf, new TezAMPolicyProvider()); } server.start(); InetSocketAddress serverBindAddress = NetUtils.getConnectAddress(server); this.address = NetUtils.createSocketAddrForHost(serverBindAddress.getAddress().getCanonicalHostName(), serverBindAddress.getPort()); LOG.info("Instantiated TezTaskCommunicator RPC at " + this.address); } catch (IOException e) { throw new TezUncheckedException(e); } }
From source file:org.apache.tez.service.impl.TezTestServiceProtocolServerImpl.java
License:Apache License
@Override public void serviceStart() { Configuration conf = getConfig(); int numHandlers = 3; InetSocketAddress addr = new InetSocketAddress(0); try {// ww w. jav a 2 s. com server = createServer(TezTestServiceProtocolBlockingPB.class, addr, conf, numHandlers, TezTestServiceProtocolProtos.TezTestServiceProtocol.newReflectiveBlockingService(this)); server.start(); } catch (IOException e) { LOG.error("Failed to run RPC Server", e); throw new RuntimeException(e); } InetSocketAddress serverBindAddress = NetUtils.getConnectAddress(server); this.bindAddress.set(NetUtils.createSocketAddrForHost(serverBindAddress.getAddress().getCanonicalHostName(), serverBindAddress.getPort())); LOG.info("Instantiated TestTestServiceListener at " + bindAddress); }
From source file:rpc.TestRPC.java
License:Apache License
@Test public void testProxyAddress() throws IOException { Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class).setInstance(new TestImpl()) .setBindAddress(ADDRESS).setPort(0).build(); TestProtocol proxy = null;// w w w .j a va 2s. co m try { server.start(); InetSocketAddress addr = NetUtils.getConnectAddress(server); // create a client proxy = RPC.getProxy(TestProtocol.class, TestProtocol.versionID, addr, conf); assertEquals(addr, RPC.getServerAddress(proxy)); } finally { server.stop(); if (proxy != null) { RPC.stopProxy(proxy); } } }
From source file:rpc.TestRPC.java
License:Apache License
@Test public void testSlowRpc() throws IOException { System.out.println("Testing Slow RPC"); // create a server with two handlers Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class).setInstance(new TestImpl()) .setBindAddress(ADDRESS).setPort(0).setNumHandlers(2).setVerbose(false).build(); TestProtocol proxy = null;//from w w w. ja v a 2s .com try { server.start(); InetSocketAddress addr = NetUtils.getConnectAddress(server); // create a client proxy = RPC.getProxy(TestProtocol.class, TestProtocol.versionID, addr, conf); SlowRPC slowrpc = new SlowRPC(proxy); Thread thread = new Thread(slowrpc, "SlowRPC"); thread.start(); // send a slow RPC, which won't return until two // fast pings assertTrue("Slow RPC should not have finished1.", !slowrpc.isDone()); proxy.slowPing(false); // first fast ping // verify that the first RPC is still stuck assertTrue("Slow RPC should not have finished2.", !slowrpc.isDone()); proxy.slowPing(false); // second fast ping // Now the slow ping should be able to be executed while (!slowrpc.isDone()) { System.out.println("Waiting for slow RPC to get done."); try { Thread.sleep(1000); } catch (InterruptedException e) { } } } finally { server.stop(); if (proxy != null) { RPC.stopProxy(proxy); } System.out.println("Down slow rpc testing"); } }
From source file:rpc.TestRPC.java
License:Apache License
private void testCallsInternal(Configuration conf) throws IOException { Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class).setInstance(new TestImpl()) .setBindAddress(ADDRESS).setPort(0).build(); TestProtocol proxy = null;/* w ww. j av a 2 s . c om*/ try { server.start(); InetSocketAddress addr = NetUtils.getConnectAddress(server); proxy = RPC.getProxy(TestProtocol.class, TestProtocol.versionID, addr, conf); proxy.ping(); String stringResult = proxy.echo("foo"); assertEquals(stringResult, "foo"); stringResult = proxy.echo((String) null); assertEquals(stringResult, null); String[] stringResults = proxy.echo(new String[] { "foo", "bar" }); assertTrue(Arrays.equals(stringResults, new String[] { "foo", "bar" })); stringResults = proxy.echo((String[]) null); assertTrue(Arrays.equals(stringResults, null)); // create multiple threads and make them do large data transfers System.out.println("Starting multi-threaded RPC test..."); server.setSocketSendBufSize(1024); Thread threadId[] = new Thread[numThreads]; for (int i = 0; i < numThreads; i++) { Transactions trans = new Transactions(proxy, datasize); threadId[i] = new Thread(trans, "TransactionThread-" + i); threadId[i].start(); } // wait for all transactions to get over System.out.println("Waiting for all threads to finish RPCs..."); for (int i = 0; i < numThreads; i++) { try { threadId[i].join(); } catch (InterruptedException e) { i--; // retry } } } catch (Exception e) { e.printStackTrace(); } finally { server.stop(); if (proxy != null) RPC.stopProxy(proxy); } }
From source file:rpc.TestRPC.java
License:Apache License
@Test public void testServerAddress() throws IOException { Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class).setInstance(new TestImpl()) .setBindAddress(ADDRESS).setPort(0).setNumHandlers(5).setVerbose(true).build(); InetSocketAddress bindAddr = null; try {/* w ww .j a v a2 s .c o m*/ bindAddr = NetUtils.getConnectAddress(server); } finally { server.stop(); } assertEquals(InetAddress.getLocalHost(), bindAddr.getAddress()); }