您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)如何實(shí)現(xiàn)RPC實(shí)驗(yàn),小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
package com.rpc; import java.io.IOException; import org.apache.hadoop.ipc.VersionedProtocol; public interface MyRPCProtocol extends VersionedProtocol { public static final long versionID = 4L; String hello(String name); } class MyRPCProtocolImpl implements MyRPCProtocol { @Override public long getProtocolVersion(String arg0, long arg1) throws IOException { return MyRPCProtocol.versionID; } @Override public String hello(String name) { return "hello " + name; } }
package com.rpc; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.ipc.RPC; import org.apache.hadoop.ipc.RPC.Server; public class MyServer { public static int PORT = 3333; public static void main(String[] args) throws Exception { final Server server = RPC.getServer(new MyRPCProtocolImpl(), "localhost", MyServer.PORT, new Configuration()); server.start(); } }
package com.rpc; import java.net.InetSocketAddress; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.ipc.RPC; public class MyClient { public static void main(String[] args) throws Exception { final InetSocketAddress inetSocketAddress = new InetSocketAddress("localhost", MyServer.PORT); MyRPCProtocol rpc = (MyRPCProtocol)RPC.getProxy(MyRPCProtocol.class, MyRPCProtocol.versionID, inetSocketAddress, new Configuration()); String str = rpc.hello("習(xí)大大"); System.out.println(str); RPC.stopProxy(rpc); } }
依賴包:hadoop-core-1.2.1、commons-configuration-1.6、commons-lang-2.4、commons-logging-1.1.1
關(guān)于“如何實(shí)現(xiàn)RPC實(shí)驗(yàn)”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。