Slice Compilation

Slice Compilation

Compilation
A Slice compiler produces source files that must be combined with application code to produce client and server executables.

Slice 编译器生成的源文件必须与应用程序代码组合才能生成客户端和服务器可执行文件。

Single Development Environment for Client and Server

The figure below shows the situation when both client and server are developed in C++. The Slice compiler generates two files from a Slice definition in a source file Printer.ice: a header file (Printer.h) and a source file (Printer.cpp)

下图展示了客户端和服务器端均采用C++开发时的情况。 Slice 编译器根据源文件 Printer.ice 中的 Slice 定义生成两个文件:头文件 (Printer.h) 和源文件 (Printer.cpp)

Alt text

Development process if client and server share the same development environment.

The Printer.h header file contains definitions that correspond to the types used in the Slice definition. It is included in the source code of both client and server to ensure that client and server agree about the types and interfaces used by the application.
The Printer.cpp source file provides an API to the client for sending messages to remote objects. The client source code (Client.cpp, written by the client developer) contains the client-side application logic. The generated source code and the client code are compiled and linked into the client executable.

客户端和服务器共享相同开发环境的开发流程。

Printer.h 头文件包含与 Slice 定义中使用的类型相对应的定义。 它包含在客户端和服务器的源代码中,以确保客户端和服务器就应用程序使用的类型和接口达成一致。
Printer.cpp 源文件向客户端提供 API,用于将消息发送到远程对象。 客户端源代码(Client.cpp,由客户端开发人员编写)包含客户端应用程序逻辑。 生成的源代码和客户端代码被编译并链接到客户端可执行文件中。

The Printer.cpp source file also contains source code that provides an up-call interface from the Ice run time into the server code written by the developer and provides the connection between the networking layer of Ice and the application code. The server implementation file (Server.cpp, written by the server developer) contains the server-side application logic (the object implementations, properly termed servants). The generated source code and the implementation source code are compiled and linked into the server executable.

Printer.cpp 源文件还包含源代码,该源代码提供从 Ice 运行时到开发人员编写的服务器代码的上行调用接口,并提供 Ice 网络层和应用程序代码之间的连接。 服务器实现文件(Server.cpp,由服务器开发人员编写)包含服务器端应用程序逻辑(对象实现,正确称为servants)。 生成的源代码和实现源代码被编译并链接到服务器可执行文件中。

Both client and server also link with an Ice library that provides the necessary run-time support.

客户端和服务器还与提供必要的运行时支持的 Ice 库链接。

You are not limited to a single implementation of a client or server. For example, you can build multiple servers, each of which implements the same interfaces but uses different implementations (for example, with different performance characteristics). Multiple such server implementations can coexist in the same system. This arrangement provides one fundamental scalability mechanism in Ice: if you find that a server process starts to bog down as the number of objects increases, you can run an additional server for the same interfaces on a different machine. Such federated servers provide a single logical service that is distributed over a number of processes on different machines. Each server in the federation implements the same interfaces but hosts different object instances. (Of course, federated servers must somehow ensure consistency of any databases they share across the federation.)

您不限于客户端或服务器的单一实现。 例如,您可以构建多个服务器,每个服务器都实现相同的接口,但使用不同的实现(例如,具有不同的性能特征)。 多个此类服务器实现可以共存于同一系统中。 这种安排在 Ice 中提供了一种基本的可扩展性机制:如果您发现服务器进程随着对象数量的增加而开始陷入困境,您可以为不同机器上的相同接口运行额外的服务器。 此类联合服务器提供分布在不同机器上的多个进程上的单一逻辑服务。 联合中的每个服务器都实现相同的接口,但托管不同的对象实例。 (当然,联合服务器必须以某种方式确保它们在联合中共享的任何数据库的一致性。)

Ice also provides support for replicated servers. Replication permits multiple servers to each implement the same set of object instances. This improves performance and scalability (because client load can be shared over a number of servers) as well as redundancy (because each object is implemented in more than one server).

Ice 还提供对复制服务器的支持。 复制允许多个服务器各自实现同一组对象实例。 这提高了性能和可伸缩性(因为客户端负载可以在多个服务器上共享)以及冗余(因为每个对象都在多个服务器中实现)。

Different Development Environments for Client and Server

Client and server cannot share any source or binary components if they are developed in different languages. For example, a client written in Java cannot include a C++ header file.

如果客户端和服务器使用不同语言开发,则不能共享任何源代码或二进制组件。 例如,用 Java 编写的客户端不能包含 C++ 头文件。

This figure shows the situation when a client written in Java and the corresponding server is written in C++. In this case, the client and server developers are completely independent, and each uses his or her own development environment and language mapping. The only link between client and server developers is the Slice definition each one uses.

该图显示了当客户端用Java编写而相应的服务器用C++编写时的情况。 在这种情况下,客户端和服务器开发人员是完全独立的,并且各自使用自己的开发环境和语言映射。 客户端和服务器开发人员之间的唯一联系是各自使用的 Slice 定义。

Alt text

Development process for different development environments.

For Java, the slice compiler creates a number of files whose names depend on the names of various Slice constructs. (These files are collectively referred to as *.java in the above figure.)

针对不同开发环境的开发流程。

对于 Java,slice编译器创建许多文件,其名称取决于各种 Slice 构造的名称。 (这些文件在上图中统称为*.java。)

Slice Compilation and your Build Environment

One way to integrate Slice compilation in your build system is to compile your Slice files manually, and then keep (check-in) the generated files like other source files. Later on, each time you change a Slice file, you have to remember to recompile this Slice file and update the generated files. While simple, this approach can lead to inconsistencies and bugs if you forget to recompile a modified Slice file.

将 Slice 编译集成到构建系统中的一种方法是手动编译 Slice 文件,然后像其他源文件一样保留(签入)生成的文件。 以后,每次更改 Slice 文件时,都必须记住重新编译该 Slice 文件并更新生成的文件。 虽然简单,但如果您忘记重新编译修改后的 Slice 文件,这种方法可能会导致不一致和错误。

We recommend you use instead an Ice Builder for your build environment to manage the compilation of your Slice files. An Ice Builder is a simple plug-in or task for your build environment that compiles or recompiles Slice files when it detects the corresponding generated files are missing or out of date. A Builder performs this Slice compilation by invoking the Slice compiler for the target programming language–it does compile the files itself and usually supports several versions of Ice.

我们建议您在构建环境中使用 Ice Builder 来管理 Slice 文件的编译。 Ice Builder 是一个适用于构建环境的简单插件或任务,当它检测到相应的生成文件丢失或过期时,它会编译或重新编译 Slice 文件。 Builder 通过调用目标编程语言的 Slice 编译器来执行此 Slice 编译 - 它本身会编译文件,并且通常支持多个版本的 Ice。