从FCS/FMS迁移到red5的指南(3)

 

 
Remoting client

远程调用客户端

RemotingClient中定义了所有需要通过远程调用协议调用的函数

下面的代码可以做为怎样使用远程调用客户端的例子:

import org.red5.server.net.remoting.RemotingClient;
 
String url = "http://server/path/to/service";
RemotingClient client = new RemotingClient(url);
Object[] args = new Object[]{"Hello world!"};
Object result = client.invokeMethod("service.remotingMethod", args);
// Now do something with the result
 
 

默认情况下,每次调用的超时时间是30秒,不过这个值能通过给构造函数传递第二个参数被改变, 而且这个最大超时间的设置单位是毫秒

The remoting headers AppendToGatewayUrlReplaceGatewayUrl andRequestPersistentHeader are handled automatically by the Red5 remoting client.

这个远程调用的消息头AppendToGatewayUrlReplaceGatewayUrl andRequestPersistentHeader 能自动被red5的远程调用客户端处理

一些在服务端被调用的函数可能耗费比较长的时间才能完成,因此最好是用异步的方式执行调用,避免在Red5线程中死锁。所以一个在IRemotingCallback中实现的对象必须被做为附件的参数传递,示例代码如下:
 
import org.red5.server.net.remoting.RemotingClient;
import org.red5.server.net.remoting.IRemotingCallback;
 
public class CallbackHandler implements IRemotingCallback {
 
  void errorReceived(RemotingClient client, String method,
                     Object[] params, Throwable error) {
      // An error occurred while performing the remoting call.
  }
  
  void resultReceived(RemotingClient client, String method,
                      Object[] params, Object result) {
      // The result was received from the server.
  }
}
 
String url = "http://server/path/to/service";
RemotingClient client = new RemotingClient(url);
Object[] args = new Object[]{"Hello world!"};
IRemotingCallback callback = new CallbackHandler();
client.invokeMethod("service.remotingMethod", args, callback);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值