List of usage examples for org.apache.hadoop.ipc Server start
public synchronized void start()
From source file:cn.dayutianfei.hadoop.rpc.server.RPCServer.java
License:Apache License
@SuppressWarnings("deprecation") private static Server startRPCServer(String hostName, final int startPort, IRPCHandler handler, int handlerCount) { int serverPort = startPort; int tryCount = 10000; int triedTimes = 0; Server _rpcServer = null; while (_rpcServer == null) { try {// w w w.j a va 2s . c om LOG.info("start rpc server,host:" + hostName + ",port:" + serverPort); _rpcServer = RPC.getServer(handler, "0.0.0.0", serverPort, handlerCount, false, new Configuration()); LOG.info( handler.getClass().getSimpleName() + " server started on : " + hostName + ":" + serverPort); break; } catch (final BindException e) { if (triedTimes < tryCount) { triedTimes++; } else { throw new RuntimeException("tried " + tryCount + " ports and no one is free..."); } } catch (final IOException e) { throw new RuntimeException("unable to create rpc server", e); } } _rpcServer.start(); return _rpcServer; }
From source file:com.dasasian.chok.node.Node.java
License:Apache License
private static Server startRPCServer(String hostName, final int startPort, IContentServer nodeManaged, int handlerCount) { int serverPort = startPort; int tryCount = 10000; Server rpcServer = null; while (rpcServer == null) { try {/*from ww w.ja v a 2 s . c om*/ rpcServer = RPC.getServer(nodeManaged, "0.0.0.0", serverPort, handlerCount, false, new Configuration()); LOG.info(nodeManaged.getClass().getSimpleName() + " server started on : " + hostName + ":" + serverPort); } catch (final BindException e) { if (serverPort - startPort < tryCount) { serverPort++; // try again } else { throw new RuntimeException("tried " + tryCount + " ports and no one is free..."); } } catch (final IOException e) { throw new RuntimeException("unable to create rpc server", e); } } rpcServer.start(); return rpcServer; }
From source file:com.datatorrent.stram.StramRecoveryTest.java
License:Apache License
@Test public void testRpcFailover() throws Exception { String appPath = testMeta.dir; Configuration conf = new Configuration(false); final AtomicBoolean timedout = new AtomicBoolean(); StreamingContainerUmbilicalProtocol impl = MockitoUtil .mockProtocol(StreamingContainerUmbilicalProtocol.class); Mockito.doAnswer(new org.mockito.stubbing.Answer<Void>() { @Override/*w w w . j av a 2 s .c om*/ public Void answer(InvocationOnMock invocation) { LOG.debug("got call: " + invocation.getMethod()); if (!timedout.get()) { try { timedout.set(true); Thread.sleep(1000); } catch (Exception e) { } //throw new RuntimeException("fail"); } return null; } }).when(impl).log("containerId", "timeout"); Server server = new RPC.Builder(conf).setProtocol(StreamingContainerUmbilicalProtocol.class) .setInstance(impl).setBindAddress("0.0.0.0").setPort(0).setNumHandlers(1).setVerbose(false).build(); server.start(); InetSocketAddress address = NetUtils.getConnectAddress(server); LOG.info("Mock server listening at " + address); int rpcTimeoutMillis = 500; int retryDelayMillis = 100; int retryTimeoutMillis = 500; FSRecoveryHandler recoveryHandler = new FSRecoveryHandler(appPath, conf); URI uri = RecoverableRpcProxy.toConnectURI(address, rpcTimeoutMillis, retryDelayMillis, retryTimeoutMillis); recoveryHandler.writeConnectUri(uri.toString()); RecoverableRpcProxy rp = new RecoverableRpcProxy(appPath, conf); StreamingContainerUmbilicalProtocol protocolProxy = rp.getProxy(); protocolProxy.log("containerId", "msg"); // simulate socket read timeout try { protocolProxy.log("containerId", "timeout"); Assert.fail("expected socket timeout"); } catch (java.net.SocketTimeoutException e) { // expected } Assert.assertTrue("timedout", timedout.get()); rp.close(); // test success on retry timedout.set(false); retryTimeoutMillis = 1500; uri = RecoverableRpcProxy.toConnectURI(address, rpcTimeoutMillis, retryDelayMillis, retryTimeoutMillis); recoveryHandler.writeConnectUri(uri.toString()); protocolProxy.log("containerId", "timeout"); Assert.assertTrue("timedout", timedout.get()); rp.close(); server.stop(); }
From source file:edu.illinois.enforcemop.examples.hadoop.TestRPC.java
License:Apache License
@Test //@Schedule(name = "slowDone", value = "slowrpcDone@SlowRPC->beforeStop@main") public void testSlowRpc() throws Exception { System.out.println("Testing Slow RPC"); // create a server with two handlers Server server = RPC.getServer(TestProtocol.class, new TestImpl(), ADDRESS, 0, 2, false, conf, null); TestProtocol proxy = null;//from w w w.j a v a 2 s . c o m try { server.start(); InetSocketAddress addr = NetUtils.getConnectAddress(server); // create a client proxy = (TestProtocol) 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("slowDone", !slowrpc.isDone()); proxy.slowPing(false); // first fast ping // verify that the first RPC is still stuck assertTrue("slowDone", !slowrpc.isDone()); proxy.slowPing(false); // second fast ping // Now the slow ping should be able to be executed //Original code : //OPWAIT while (!slowrpc.isDone()) { //OPWAIT System.out.println("Waiting for slow RPC to get done."); //OPWAIT try { // Thread.sleep(1000); //OPWAIT } catch (Exception e) {} //OPWAIT } try { Thread.sleep(1000); } catch (Exception e) { } } finally { server.stop(); if (proxy != null) { RPC.stopProxy(proxy); } System.out.println("Down slow rpc testing"); } //Interrupt thread manually Thread[] t = new Thread[2]; Thread.enumerate(t); t[1].interrupt(); }
From source file:edu.illinois.imunit.examples.hadoop.TestRPC.java
License:Apache License
@Test @Schedule(name = "slowDone", value = "slowrpcDone@SlowRPC->beforeStop@main") public void testSlowRpc() throws Exception { System.out.println("Testing Slow RPC"); // create a server with two handlers Server server = RPC.getServer(TestProtocol.class, new TestImpl(), ADDRESS, 0, 2, false, conf, null); TestProtocol proxy = null;// ww w. j av a 2s. c o m try { server.start(); InetSocketAddress addr = NetUtils.getConnectAddress(server); // create a client proxy = (TestProtocol) 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("slowDone", !slowrpc.isDone()); proxy.slowPing(false); // first fast ping // verify that the first RPC is still stuck assertTrue("slowDone", !slowrpc.isDone()); proxy.slowPing(false); // second fast ping // Now the slow ping should be able to be executed //Original code : //OPWAIT while (!slowrpc.isDone()) { //OPWAIT System.out.println("Waiting for slow RPC to get done."); //OPWAIT try { // Thread.sleep(1000); //OPWAIT } catch (Exception e) {} //OPWAIT } } finally { fireEvent("beforeStop"); server.stop(); if (proxy != null) { RPC.stopProxy(proxy); } System.out.println("Down slow rpc testing"); } //Interrupt thread manually Thread[] t = new Thread[2]; Thread.enumerate(t); t[1].interrupt(); }
From source file:net.sf.katta.node.Node.java
License:Apache License
private static Server startRPCServer(String hostName, final int startPort, IContentServer nodeManaged, int handlerCount) { int serverPort = startPort; int tryCount = 10000; Server _rpcServer = null; while (_rpcServer == null) { try {/*from w w w . j a v a 2s .c om*/ _rpcServer = RPC.getServer(nodeManaged, "0.0.0.0", serverPort, handlerCount, false, new Configuration()); LOG.info(nodeManaged.getClass().getSimpleName() + " server started on : " + hostName + ":" + serverPort); } catch (final BindException e) { if (serverPort - startPort < tryCount) { serverPort++; // try again } else { throw new RuntimeException("tried " + tryCount + " ports and no one is free..."); } } catch (final IOException e) { throw new RuntimeException("unable to create rpc server", e); } } //try { _rpcServer.start(); //} catch (final IOException e) { // throw new RuntimeException("failed to start rpc server", e); //} return _rpcServer; }
From source file:org.apache.nutch.searcher.TestDistributedSearch.java
License:Apache License
public void testDistibutedSearch() throws IOException { Configuration conf = NutchConfiguration.create(); //set up server & start it Server server = DistributedSearch.Server.getServer(conf, searchdir, conf.getInt(DISTRIBUTED_SEARCH_TEST_PORT, DEFAULT_PORT)); server.start(); int port = conf.getInt(DISTRIBUTED_SEARCH_TEST_PORT, DEFAULT_PORT); InetSocketAddress[] addresses = new InetSocketAddress[1]; addresses[0] = new InetSocketAddress("localhost", port); Client c = new DistributedSearch.Client(addresses, conf); Query query = Query.parse("apache", conf); Hits hits = c.search(query, 5, null, null, false); c.getDetails(hits.getHit(0));// w w w .j a v a 2 s. com assertTrue(hits.getTotal() > 0); if (server != null) { server.stop(); } }
From source file:org.apache.nutch.searcher.TestDistributedSearch.java
License:Apache License
public void testUpdateSegments() throws IOException { // Startup 2 search servers. One was already started in setup, start another // one at a different port Configuration conf = NutchConfiguration.create(); Server server1 = DistributedSearch.Server.getServer(conf, searchdir, conf.getInt(DISTRIBUTED_SEARCH_TEST_PORT1, DEFAULT_PORT1)); Server server2 = DistributedSearch.Server.getServer(conf, searchdir, conf.getInt(DISTRIBUTED_SEARCH_TEST_PORT2, DEFAULT_PORT2)); server1.start(); server2.start();/*from w w w .ja v a 2s . com*/ /* create a new file search-servers.txt * with 1 server at port 60000 */ FileSystem fs = FileSystem.get(conf); Path testServersPath = new Path(searchdir, "search-server.txt"); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fs.create(testServersPath, true))); bw.write("localhost " + DEFAULT_PORT1 + "\n"); bw.flush(); bw.close(); /* * Check if it found the server */ Client c = new DistributedSearch.Client(testServersPath, conf); boolean[] liveServers = c.getLiveServer(); assertEquals(liveServers.length, 1); /* Add both the servers at ports 60000 & 60005 * to the search-server.txt file */ // give the servers a little time to wait for file modification try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } bw = new BufferedWriter(new OutputStreamWriter(fs.create(testServersPath, true))); bw.write("localhost " + DEFAULT_PORT1 + "\n"); bw.write("localhost " + DEFAULT_PORT2 + "\n"); bw.flush(); bw.close(); // Check if it found both the servers c.updateSegments(); liveServers = c.getLiveServer(); assertEquals(liveServers.length, 2); if (server1 != null) { server1.stop(); } if (server2 != null) { server2.stop(); } fs.delete(testServersPath, true); }
From source file:org.apache.tajo.rpc.benchmark.BenchmarkHadoopRPC.java
License:Apache License
public static void main(String[] args) throws InterruptedException, IOException { Server server = RPC.getServer(new BenchmarkImpl(), "localhost", 15000, new Configuration()); server.start(); Thread.sleep(1000);/*ww w . j a va 2 s . co m*/ int numThreads = 1; ClientWrapper client[] = new ClientWrapper[numThreads]; for (int i = 0; i < numThreads; i++) { client[i] = new ClientWrapper(); } for (int i = 0; i < numThreads; i++) { client[i].start(); } for (int i = 0; i < numThreads; i++) { client[i].join(); } server.stop(); }
From source file:org.hdl.tensorflow.yarn.rpc.impl.TFApplicationRpcServer.java
License:Apache License
@Override public void run() { Configuration conf = new Configuration(); YarnRPC rpc = YarnRPC.create(conf);// www . j av a2 s. c o m InetSocketAddress address = new InetSocketAddress(rpcAddress, rpcPort); Server server = rpc.getServer(TensorFlowCluster.class, this, address, conf, null, conf.getInt(YarnConfiguration.RM_RESOURCE_TRACKER_CLIENT_THREAD_COUNT, YarnConfiguration.DEFAULT_RM_RESOURCE_TRACKER_CLIENT_THREAD_COUNT)); server.start(); }