ICE提纲之demo/Glacier2/callback

本例子展示了Glacier2 router的用法(没有使用Glacier2 session manager)。

如果clients与router不在同一台主机上,需要将以下地方修改为glacier2router所在机器的外部地址:

config.glacier2的Glacier2.Client.Endpoints
config.client的Ice.Default.Router和Callback.Client.Router

Glacier2router服务

启动命令

$ glacier2router --Ice.Config=config.glacier2

config.glacier2

#

# Set the instance name

#

Glacier2.InstanceName=DemoGlacier2

#

# The client-visible endpoint of Glacier2. This should be an endpoint

# visible from the public Internet, and it should be secure.

#

Glacier2.Client.Endpoints=ssl -p 4064 -h localhost

#

# The server-visible endpoint of Glacier2. This endpoint is only

# required if callbacks are needed (leave empty otherwise). This

# should be an endpoint on an internal network (like 192.168.x.x), or

# on the loopback, so that the server is not directly accessible from

# the Internet.

#

Glacier2.Server.Endpoints=tcp -h localhost

#

# For this demo, we use a null permissions verifier.

#

Glacier2.PermissionsVerifier=DemoGlacier2/NullPermissionsVerifier

#

# The timeout for inactive sessions. If any client session is inactive

# for longer than this value, the session expires and is removed. The

# unit is seconds.

#

Glacier2.SessionTimeout=30

#

# Glacier can forward requests buffered or unbuffered. Unbuffered

# means a lower resource consumption, as buffering requires one

# additional thread per connected client or server. However, without

# buffering, messages cannot be batched and message overriding doesn‘t

# work either. Also, with unbuffered request forwarding, the caller

# thread blocks for twoway requests.

# The default is to use buffering (=1), in both directions.

#Glacier2.Client.Buffered=0

#Glacier2.Server.Buffered=0

#

# These two lines instruct Glacier2 to forward contexts both for

# regular routing, as well as for callbacks (reverse routing).

#

Glacier2.Client.ForwardContext=1

Glacier2.Server.ForwardContext=1

#

# To prevent Glacier2 from being flooded with requests from or to one

# particular client, Glacier2 can be configured to sleep for a certain

# period after all current requests for this client have been

# forwarded. During this sleep period, new requests for the client are

# queued. These requests are then all sent once the sleep period is

# over. The unit is milliseconds.

#

Glacier2.Client.SleepTime=500

Glacier2.Server.SleepTime=500

#

# With the two settings below, Glacier2 can be instructed to always

# batch oneways, even if they are sent with a _fwd/o instead of a

# _fwd/O context.

# The default value for Glacier2.Client.AlwaysBatch and

# Glacier2.Server.AlwaysBatch is 0.

#Glacier2.Client.AlwaysBatch=1

#Glacier2.Server.AlwaysBatch=1

#

# Glacier2 always disables active connection management so there is no

# need to configure this manually. Connection retry does not need to

# be disabled, as it‘s safe for Glacier2 to retry outgoing connections

# to servers. Retry for incoming connections from clients must be

# disabled in the clients.

#

Slice

Callback.ice

module Demo

{

interface CallbackReceiver

{

void callback();

};

interface Callback

{

void initiateCallback(CallbackReceiver* proxy);

void shutdown();

};

};

服务器

CallbackI

void
CallbackI::initiateCallback(const CallbackReceiverPrx& proxy, const Ice::Current& current)
{
    proxy->callback();
}

void
CallbackI::shutdown(const Ice::Current& c)
{
    c.adapter->getCommunicator()->shutdown();
}

config.server

#

# The endpoint of the server‘s object adapter. This should be an

# endpoint on an internal network (like 192.168.x.x), or on the

# loopback, so that the server is not directly accessible from the

# Internet.

#

Callback.Server.Endpoints=tcp -h localhost -p 10000

Server.cpp

int

CallbackServer::run(int argc, char*[])

{

    Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("Callback.Server");

    CallbackPtr cb = new CallbackI;

    adapter->add(cb, communicator()->stringToIdentity("callback"));

    adapter->activate();

    communicator()->waitForShutdown();

}

客户端

CallbackReceiverI

void
CallbackReceiverI::callback(const Ice::Current&)
{
    cout << "received callback" << endl;
}

config.client

#

# The proxy to the Glacier2 router for all outgoing connections. This

# must match the value of Glacier2.Client.Endpoints in config.glacier2.

#

Ice.Default.Router=DemoGlacier2/router:ssl -p 4064 -h localhost

#

# We don‘t need any endpoints for the client if we use a

# router. Incoming requests are received through connections

# established from the client to the router.

#

Callback.Client.Endpoints=

#

# This must match the value of Callback.Server.Endpoints in

# config.server.

#

Callback.Proxy=callback:tcp -h localhost -p 10000

Client.cpp

Glacier2::SessionPrx
CallbackClient::createSession()
{
    Glacier2::SessionPrx session;
    cout << "This demo accepts any user-id / password combination.\n";
    string id;
    string pw;
    session = router()->createSession(id, pw);
    return session;
}

int
CallbackClient::runWithSession(int argc, char*[])
{
    Ice::Identity callbackReceiverIdent = createCallbackIdentity("callbackReceiver");

    Ice::ObjectPrx base = communicator()->propertyToProxy("Callback.Proxy");
    CallbackPrx twoway = CallbackPrx::checkedCast(base);

    objectAdapter()->add(new CallbackReceiverI, callbackReceiverIdent);

    CallbackReceiverPrx twowayR = CallbackReceiverPrx::uncheckedCast(objectAdapter()->createProxy(callbackReceiverIdent));

    string override;

    char c;
    do
    {
        cin >> c;
        if(c == ‘t‘)
        {
            Ice::Context context;
            context["_fwd"] = "t";
            if(!override.empty())
            {
                context["_ovrd"] = override;
            }
            twoway->initiateCallback(twowayR, context);
        }
        else if(c == ‘v‘)
        {
            if(override.empty())
            {
                override = "some_value";
            }
            else
            {
                override.clear();
            }
        }
        else if(c == ‘s‘)
        {
            twoway->shutdown();
        }
    }
    while(1);
}

ICE提纲之demo/Glacier2/callback

时间: 2024-10-28 20:20:20

ICE提纲之demo/Glacier2/callback的相关文章

ICE提纲之demo/IceStorm/clock

ICE发布者/订阅者的一个最简单例子 IceStorm服务 config.icebox # # The IceBox server endpoint configuration. This endpoint is only used # to communicate with the IceBox ServiceManager object (such as when # using iceboxadmin to shutdown the server). # # The IceStorm se

ICE中间件介绍以及demo

一:基本开发步骤 根据业务编写slice:写任何ICE应用的第一步都要编写一个slice定义,其中包含了这个应用的所有接口 编写实现接口代码:命名规则就是接口的名字加上I 编写server端代码 写配置文件,部署服务 编写client端代码 先启动server端服务,然后启动client端服务 二:demo(安装ice服务) 定义一个接口,建立一个Printer.ice文件 moudle Demo{     interface Printer{ void printString(string s

ICE安装及使用示例

ICE是什么 ZeroC ICE 是指ZeroC公司的ICE(Internet Communications Engine)中间件平台. Ice 应用适合于异构平台环境中使用:客户和服务器可以采用不同的编程语言,可以运行在不同的操作系统和机器架构上,并且可以使用多种网络技术进行通信.无论部署环境如何,这些应用的源码都是可移植的. 其采用C/S 模式结构,支持同步调用方式和异步调用方式,异步派发调用方式.支持跨语言的对象调用.多种语言之间采用共同的Slice(Specification Langu

ice安装以及简单使用

ICE(Internet Communications Engine)是一个中间件平台.作为一个高性能的互联网通信平台,ICE包含了很多分层的服务和插件(Plug-ins),并且简单.高效和强大. ICE当前支持C++.Java.C#.Visual Basic.Python和PHP编程语言,并支持在多种操作系统上运行.更多的操作系统和编程语言将会在以后的发布中支持. 1:下载安装包:http://www.zeroc.com/download.html 2:安装ice并在环境变量中配置ice的安装

KDevelop

ctags+vim还是太累了,还是使用IDE好,尤其是c++模板.KDevelop就不错,符号智能推导以及cmake项目管理和配置,还是挺好用的. Android端的ndk开发使用Android Studio,服务端开发就用KDevelop,谁让我用了Ice. KDevelop不用编译,不用yum或apt,就连安装rpm或deb也不用,下载来就一个文件直接运行,到官方网下载就可以了. 以编译Ice一个demo为例,浏览一遍使用. 新建一个项目 我们要的就是 simple CMake 然后在终端

ES6新特性:Javascript中Generator(生成器)

ES6的很多特性都跟Generator扯上关系,而且实际用处比较广, 包含了任何需要异步的模块, 比如ajax, filesystem, 或者数组对象遍历等都可以用到: Generator的使用: Generator函数和普通的函数区别有两个, 1:function和函数名之间有一个*号, 2:函数体内部使用了yield表达式:比如这样: function* gen() { yield "1"; yield "2" } 这个玩意儿如果运行的话,会返回一个Iterat

DOM事件简介

Click.touch.load.drag.change.input.error.risize — 这些都是冗长的DOM(文档对象模型)事件列表的一部分.事件可以在文档(Document)结构的任何部分被触发,触发者可以是用户操作,也可以是浏览器本身.事件并不是只是在一处被触发和终止:他们在整个document中流动,拥有它们自己的生命周期.而这个生命周期让DOM事件有更多的用途和可扩展性. 作为一个开发人员,我们必须要理解DOM事件是如何工作的,然后才能更好的驾驭它,利用它们潜在的优势,开发出

dubbu 官方参考手册~备案(防止哪天阿里一生气把dubbo给删除了)

首页  ||  下载  ||  用户指南  ||  开发者指南  ||  管理员指南  ||  培训文档  ||  常见问题解答  ||  发布记录  ||  发展路线  ||  社区 English | 中文 用户指南 入门 背景 需求 架构 用法 快速启动 服务提供者 服务消费者 依赖 必需依赖 缺省依赖 可选依赖 成熟度 功能成熟度 策略成熟度 配置 Xml配置 属性配置 注解配置 API配置 示例 启动时检查 集群容错 负载均衡 线程模型 直连提供者 只订阅 只注册 静态服务 多协议 多

JavaScript 数组基本操作

简介 数组操作无论是在JavaScript中还是在其他语言中都是很常见.经常会用到的,现在我把JavaScript 数组基本操作整理一下,供大家参考学习.里边包含我自己的见解以及案例,希望能够帮助大家,使用的是ECMAScript 5. 字符串与数组转换 有时候我们需要把字符串进行转换为数组,则需要split方法,把数组转换为字符串则需要join方法 var star="js,php,java,c++"; star=star.split(","); console.