Union Platform(7) Union Server Module作成準備

本エントリーでは、Server ModuleとRoom Moduleを作成する際の準備方法を紹介します。UnionのバージョンはUnion alpha3を使用します。

Union ServerはJAVA言語で記述されているため、Server Module、Room ModuleともにJAVA言語で作成します。JAVA言語での開発にはeclipseを使うと便利です。

eclipeを使ったModule作成の準備

eclipseを使ってModuleを作成する際の準備方法を簡単に紹介します。

eclipseのインストール

eclipseを未だインストールしていない場合は、elipseの公式サイトからアーカイブをダウンロードしインストールします。ダウンロードして来たeclipse-SDK-3.5-win32.zipを解凍しお好きな場所へ配置します。

今回はWindowsにインストールする例ですが、Mac OS Xでもほとんど同じです。
以下のように配置しました。これらのパスはご自身の環境に合わせて読み替えて頂ければと思います。

  • e:\eclipse
  • e:\workspace
  • e:\union

プロジェクトの作成

プロジェクトの作成
  1. [File] -> [new] -> [Java Project]を選択します。
  2. Project nameはお好きな名前で良いですが、今回はunion_platform等と入力します。
  3. ContentsはCreate project from existing sourceを選択します。
  4. Directory: に e:¥union と入力します。これはunion serverのディレクトリを指定して下さい。
  5. [Next]をクリックします。
  6. [Finish]をクリックします。

これでUnion ServerのModuleを作成するProjectが作成出来ました。

Source Folderの作成

.javaファイルを格納するSource Folderを作成します。
Source Folderの作成

  1. Package Explorerでunion_platform(プロジェクト名)からコンテキストメニューを表示します。
  2. [New] -> [Source Folder]を選択します。
  3. Folder name: に src と入力します。
  4. [Finish]をクリックします。

e:¥union¥srcが作成されていれば成功です。ソース格納場所が出来上がりました。次はここにクラスを作成して行きます。

Classの作成

Classの作成
  1. Package Explorerでunion_platform(プロジェクト名)からコンテキストメニューを表示します。
  2. [New] -> [Class]を選択します。
  3. Package:に作成したいパッケージ名を入力します。今回は、com.asmple.server.union.module.serverとしました。
  4. Name:にPackageに所属させるクラス名を入力します。今回は、ServerModuleSampleとしました。
  5. Interfaces:の横の[Add]をクリックします。
  6. Choose interfaces: に Moduleと入力します。
  7. Matching intems: に Module – net.user1.union.api と表示されるので、選択して[OK]をクリックします。
  8. [Finish]をクリックします。

e:¥union¥src¥com¥asmple¥server¥union¥module¥server¥ServerModuleSample.javaが作成されていれば成功です。

ServerModuleSampleの編集

さて、以下のようなjavaファイルが自動で生成されますが、L:11のreturnをtrueに変更します。ここでtrueをreturnしておかないとModuleの初期化に失敗してしまいますので注意しましょう。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.asmple.server.union.module.server;
 
import net.user1.union.api.Module;
import net.user1.union.core.context.ModuleContext;
 
public class ServerModuleSample implements Module {
 
	@Override
	public boolean init(ModuleContext arg0) {
		// TODO Auto-generated method stub
		return false;
	}
 
	@Override
	public void shutdown() {
		// TODO Auto-generated method stub
 
	}
 
}

L:11を以下のように変更。

11
		return true;

build.xmlの作成

antツールを使って、jarファイルを作成する準備をします。モジュールをいくつも作成した際に、jarにまとめてしまおうという考えです。以下のようなe:¥union¥build.xmを作成します。

1
2
3
4
5
6
<?xml version="1.0" encoding="Shift_JIS"?>
<project name="com_asmple_union_server_module" default="jar" basedir="." >
	<target name="jar">
		<jar basedir="./bin" jarfile="lib/com-asmple-server-union-module.jar" />
	</target>
</project>
antに登録
antに登録
  1. [Window] -> [Show View] -> Antを選択します。
  2. Ant Viewの左のボタン(Add Buildfiles)をクリックします。
  3. union_platform(プロジェクト名)配下のbuild.xml(先ほど作成したもの)を選択します。
  4. Ant Viewに新しいBuildファイルが追加されます。
  5. com_asmple_union_server_moduleを選択して、右から3番目の矢印アイコン(Run)をクリックします。

e:¥union¥lib¥com-asmple-server-union-module.jar が出来上がっていれば成功。これでClassファイルを更新した際には、AntのRunを実行することで、jarファイルを更新できます。

startup.bat(.sh)の編集

Windows環境の場合はstartup.batを編集します。

java -cp lib\union.jar;lib\stax-api-1.0.1.jar;lib\wstx-asl-3.2.6.jar net.user1.union.core.UnionMain start

lib\wstx-asl-3.2.6.jarの後ろに以下を追記します。

;lib\com-asmple-server-union-module.jar

Mac OS X, Linux環境の場合はstartup.shを編集します。

#!/bin/sh
java -cp lib/union.jar:lib/stax-api-1.0.1.jar:lib/wstx-asl-3.2.6.jar net.user1.union.core.UnionMain start &

lib/wstx-asl-3.2.6.jarの後ろに以下を追記します。

:lib/com-asmple-server-union-module.jar

union.xmlの編集

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<union>
    <server>
        <admin>
            <port>9110</port>
    	    <password>password</password>
        </admin>
        <client_timeout>30</client_timeout>
    </server>
    <gateways>
	    <gateway id="IOGateway" type="flash:io">
	    	<port>9100</port>
            <policy_file>policy.xml</policy_file>
	    </gateway>  
        <gateway id="NIOGateway" type="flash:nio">
            <port>9101</port>
            <policy_file>policy.xml</policy_file>
        </gateway>         	    
    </gateways>
    <modules>
        <module>
            <id>serverStatsServerModule</id>
            <source type="class">net.user1.union.servermodule.ServerStatsServerModule</source>
            <attributes>
                <attribute name="interval">300</attribute>
            </attributes>
        </module>   
    </modules>
</union>

L:26の下に以下を追加

        <module>
            <id>serverModuleSample</id>
            <source type="class">com.asmple.server.union.module.server.ServerModuleSample</source>
        </module>

Union Server起動

startup.bat(.sh)を実行して下記のようなログが出力されれば、新しいServer Moduleのロードは成功です。

2009-09-05 16:22:52,046 INFO  - Loaded module type [class] with code [com.asmple.server.union.module.server.ServerModuleSample]
2009-09-05 16:22:52,046 WARN  - Server module [serverModuleSample] loaded.

まとめ

今回はeclipseを使って、Union ServerのModuleを作成する準備をしてきました。私自身普段はeclipseもJAVAも触らないのですが、大分効率化出来そうですね。もっと良い方法などありましたら、是非ともご教授下さい。

では、次回は実際にModuleを作成してみようと思います。

関連記事

  1. UnionPlatform (1) 概要
  2. UnionPlatform (2) 概念
  3. Union Platform(3) 情報の共有化
  4. Union Platform(4) Reactorのイベント
  5. Union Platform(5) チャットを作る
  6. Union Platform(6) Union Server入門
  7. Union Platform(7) Union Server Module作成準備
  8. Union Platform(8) Moduleサンプル
 

Comments: 3

Leave a reply »

 
 
 

[...] 前回のstartup.bat(.sh)に追記していきます。前回の記事をお読みでない方は、Union Platform(7) Union Server Module作成準備を参照して下さい。 [...]

 
 

[...] Union Platform(7) Union Server Module作成準備 Tags [...]

 
 

[...] Union Platform(7) Union Server Module作成準備 [...]

 
 
Leave a Reply
 
  (will not be published)