Oracle Coherence 内存网格
安装和配置开发环境

作者:金辉 (Oracle)

2016 年 5 月 16 日发布


右箭头 第 1 章 — 漫说内存网格
右箭头 第 2&3 章 — 安装和配置开发环境
右箭头 第 4 章 — 开始第一个Coherence程序
右箭头 第 5 章 — 在 Coherence 中使用 POF 对象
右箭头 第 6 章 — 分布式内存集群的数据灌注、查询和统计
右箭头 第 7 章 — 监听器处理内存集群中变化的对象
右箭头 第 8 章 — 使用 ZFS 加密
右箭头 第 9 章 — 内存集群与数据库的互操作
右箭头 第 10 章 — Coherence 内存集群的安全访问
右箭头 第 11 章 — 基于内存集群的事件处理

第 2 章 — Coherence 安装

 

Coherence 的安装介质,既有独立下载,也有集成在 WebLogic 的下载介质当中。独立的介质,通常是包含在压缩文件中的 jar 文件,解压缩到具体目录,运行 java –jar 执行安装即可。集成在 WebLogic 当中的,则可在安装 WebLogic 时同步安装 Coherence,并能在 FMW_HOME 的目录下,看到 coherence 安装目录,类似如:

figure-01

第 3 章 — 配置 Coherence 的开发环境

 

本章节介绍使用 Oracle WebLogic 12.1.2 的完整安装包里的 Oracle Enterprise Pack for Eclipse 开发基于 Coherence 的 Java 应用。

3.1 安装 Eclipse 和 OEPE

 

读者可以通过到如下地址,下载和安装 OEPE 的完整安装包:

http://www.oracle.com/technetwork/developer-tools/eclipse/overview/index.html

系列环境中,OEPE 安装在如下目录:

C:\Oracle\wls1212.32\oepe

 

3.2 在 Oracle Eclipse 中配置 Coherence 开发环境

 

安装完成 OEPE 之后,需要配置相关的环境变量来支持在 OEPE 环境里进行 Coherence 的开发。比如配置一些 Coherence 库变量。

figure-02

在 Eclipse 启动完成后,如下图选择“Java EE perspective”

figure-03

然后在菜单栏里选择“Java EE perspective”图标

figure-04

3.3 为开发工程配置必要的库和软件包

 

在 Eclipse IDE 中创建工程遵循如下步骤:

1. 打开文件->新建-> Application Client Project。

figure-05

2. 在弹出的“New Application Client Project”对话框中,输入项目名称:chapter03_07,如下图:

figure-06

3. 在 Configuration 选项中,选择 Modify

在弹出的 Project Facets 对话框中,选中 Oracle Coherence 选项;

并且从下拉列表中选择版本 12.1.2。如下图。

figure-07

添加 Oracle Coherence 扩展,将把 coherence.jar 自动加入工程的 class path 当中。完成之后,项目将能能够自动在 Project Explorer 产生如下的相关配置文件:

 coherence-cache-config.xml  默认的缓存配置文件
 pof-config.xml  Portable Object Format序列化配置文件
 tangosol-coherence-override.xml  用于重载Coherence的操作与运行时的配置文件

 

4. 点击 Save As,并且在 Save Preset 对话框中输入一个名称,比如 CoherenceConfig,及其描述信息,如下图:

figure-08

然后点击 OK 关闭 Save Preset 对话框,点击 OK 关闭 Project Facets 对话框。

figure-09

5. 选择 Next,在 New Application Client Project 的 Java 配置项中,继续选择默认的下一步;

figure-10

6. 在 Application Client Module,取消“Create a default Main class”,选择下一步

figure-11

7. 在 Coherence 配置中,将要添加 Coherence12.1.2 作为 User Library 到当前工程项目当中

A. 点击 Manage Libraries,在 Preferences 中点击 New

figure-12

B. 在 New User Library 对话框中,输入 Enter Coherence12.1.2,

C. 选择 System library (added to the boot class path) 选项,

D. 点 OK 关闭 New User Library 对话框。

figure-13

E. 在 Preferences 对话框中,点 Add External JARs,增加 coherence.jar 到库中:在你的文件系统中找到 coherence.jar。

完成后如下图:

figure-14

8. 在 Coherence 配置中,选中 Coherence12.1.2,然后点击 Finish。

figure-15

这时一个Coherence工程创建完成。

3.4 在Eclipse IDE中运行Cache服务器

 

1. 在 Eclipse IDE 中鼠标右键点击工程。选 Run As->Run Configurations。在 Run Configurations 对话框中,选择 Oracle Coherence,创建新 New 配置。输入 chapter03CacheServer 作为名称。

figure-16

2. 在 Project 下,选择 Browse,选中 chapter03_07;

3. 在 Main class 下,选中 Include system libraries when searching for a main class 选项,点击 Search 图标,输入 DefaultCacheServer,选中 com.tangosol.net.DefaultCacheServer,并点击 OK。

figure-17

4. 在 Coherence 选项页中,选择 General 选项页。如果 Cache configuration descriptor 没有,则选择旁边的 Browse 图标,导航到项目中的 cache configuration 配置文件。local storage,选择 Enabled (cache server)。

figure-18

托动右侧滑块,集群端口改成 3155,点 Apply。

figure-19

5. 打开 Arguments 选卡,在 VM 参数中,输入 -showversion,点 Apply。

figure-20

6. 打开 Common 选卡,点击 Shared file,并确保右侧项目为 chapter03_07,点 Apply

figure-21

7. 点 Run,启动 Cache Server。

figure-22

至此,一个 OEPE 中的 Coherence 开发环境配置完成。

3.5 IDE 中的基础操作

 

本节包含三部分内容

  • 创建 Coherence Java 类
  • 创建 Coherence Client 运行配置环境
  • 停止 CacheServer

3.5.1 创建一个Coherence Java 类

 

在 Eclipse IDE 中创建新 Coherence Client Java 类的步骤如下:

1. 鼠标右键点击项目,选择 New->Class;

2. 在 New Java Class 对话框中,输入 package 名称,比如 com.oracle.handson.chapter03

3. 输入 MyFirstCoherenceSample 作为 Class 名。

4. Under Which method stubs would you like to create?

  • 选择 public static void main(String[]args),如果需要运行这个类;
  • 选择 Constructors from superclass,如果需要重写集成的构造函数;
  • 默认选择 Inherited abstract methods,如果继承的方法或需要待实现的接口。

5. 点 OK 创建新 Java Class

figure-23

 

3.5.2 创建 Coherence 运行时配置

 

创建 Coherence 运行时的配置按照如下步骤:

1. 右键选择项目,选择 Run As->Run Configurations;

2. 点击 Oracle Coherence,选择 New;

3. 新的运行配置名称比如 chapter03CacheClient,在 Project 里,选择当前的工程:chapter03_07。Main Class 选择刚才 3.5.1 里创建的 Java 类,点 Apply。

figure-24

4. 点 Coherence 选卡,按照如下进行初步配置

figure-25

3.5.3 在 Eclipse IDE 中停止 CacheServer

 

在 Eclipse IDE 中,可以点击 Terminate 停止 CacheServer。

figure-26

关于作者

 niehao

金辉,在 Oracle 负责云和中间件产品的资深售前顾问和团队经理,有十多年的中间件和项目管理经验,专注在企业云构建,企业集成解决方案领域,熟悉业内主要的 SOA 集成产品。参加过北京马拉松和 TNF50 越野比赛。你可以通过邮件 arthur.jin@oracle.com 与他联系。