java thrift 教程_RPC学习----Thrift快速入门和Java简单示例

一.什么是RPC?

RPC(Remote Procedure Call Protocol)——远程过程调用协议,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议。

RPC协议假定某些传输协议的存在,如TCP或UDP,为通信程序之间携带信息数据。在OSI网络通信模型中,RPC跨越了传输层和应用层。RPC使得开发包括网络分布式多程序在内的应用程序更加容易。

二.什么是Thrift?

thrift是一个软件框架,用来进行可扩展且跨语言的服务的开发。它结合了功能强大的软件堆栈和代码生成引擎,以构建在 C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, and OCaml 这些编程语言间无缝结合的、高效的服务。

thrift最初由facebook开发,07年四月开放源码,08年5月进入apache孵化器。

三.下载,安装,配置Thrift

本机环境:ubuntu 12.04 (64bit)

1.下载:

2.安装,配置Thrift

Building from source

First make sure your system meets all necessary Apache Thrift Requirements

If you are building from the first time out of the source repository, you will need to generate the configure scripts. (This is not necessary if you downloaded areleased tarball.) From the top directory, do:

./bootstrap.sh

Once the configure scripts are generated, thrift can be configured. From the top directory, do:

./configure

Disable a language:

./configure --without-java

You may need to specify the location of the boost files explicitly. If you installed boost in /usr/local, you would run configure as follows:

./configure --with-boost=/usr/local

If you want to override the logic of the detection of the Java SDK, use the JAVAC environment variable:

./configure JAVAC=/usb/bin/javac

Note that by default the thrift C++ library is typically built with debugging symbols included. If you want to customize these options you should use the CXXFLAGS option in configure, as such:

./configure CXXFLAGS='-g -O2'./configure CFLAGS='-g -O2'./configure CPPFLAGS='-DDEBUG_MY_FEATURE'

To see other configuration options run

./configure --help

Once you have run configure you can build Thrift via make:

make

and

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
(self.model.predict(next_state[np.newaxis])) target_f = self.model.predict(state[np.newaxis]) target_f[0][np.argmax(action)] = target self.model.fit(state[np.newaxis], target_f, epochs=1, verbose=0) state = next_stateJavaRPC(远程过程调用)可以通过使用Java RMI或Apache Thrift框架来实现。这里 total_reward += reward self.epsilon = max(self.epsilon_min, self.epsilon * self.epsilon_decay) print('Episode {}:提供一个简单Java RMI示例: 1. 定义接口 ``` public interface MyService extends Remote { total reward = {}, epsilon = {}'.format(episode, total_reward, self.epsilon)) if save_path is not None: self.model public String sayHello(String name) throws RemoteException; } ``` 2. 实现接口 ``` public class MyServiceImpl extends Unicast.save(save_path) def predict(self, state): return self.model.predict(state[np.newaxis])[0] ``` 在上面的RemoteObject implements MyService { public MyServiceImpl() throws RemoteException { super(); } public String sayHello(String name) throws代码中,我们定义了一个强化学习代理类StocksAgent,该类用于训练和保存模型。 RemoteException { return "Hello " + name; } } ``` 3. 启动服务 ``` public class Server { public在初始化方法中,我们传入股票环境和模型等参数,并定义了一个神经网络模型,用于 static void main(String[] args) throws RemoteException, MalformedURLException { MyService service = new MyServiceImpl(); Naming.rebind("r估计动作的价值。在act方法中,我们根据当前状态选择动作,有一定的随机性mi://localhost:1099/MyService", service); System.out.println("Server started"); } } ``` 4. 客户,即以epsilon的概率随机选择动作。在train方法中,我们训练模型,并记录每个episode的端调用 ``` public class Client { public static void main(String[] args) throws RemoteException, NotBoundException, MalformedURLException { MyService service = (MyService) Naming.lookup("rmi://localhost:1099/MyService"); String result = service总奖励和当前epsilon值。在predict方法中,我们根据当前状态预测动作的价值。 最后,.sayHello("World"); System.out.println(result); } } ``` 这个示例演示了如何使用Java RMI我们定义一个主函数,用于实例化股票环境和强化学习代理,并训练模型: ```框架实现RPC。当客户端调用远程方法时,底层框架会自动处理网络通信和python if __name__ == '__main__': stock_codes = ['sh600000', 'sh600519', 'sh601318',序列化等问题,使得远程调用看起来像是本地调用一样简单

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值