検証用Protocolを実装
少しだけ時間が取れたのでJGroupsの一人ソース輪読会の続きをやった.
がしかし,読んでいてこんがらかってきたので,ある手法で動きを調べてみることに.
ある手法とは,こんな感じのSystem.out.println()ログ出力プロトコルを実装してJGroupsを動かしてみること.
public class MIR extends Protocol {
public String getName() {
return "MIR";
}
public void destroy() {
System.out.println("MIR.destroy()");
super.destroy();
}
public void down(Event evt) {
System.out.println("MIR.down(" + evt + ")");
super.down(evt);
}
public Protocol getDownProtocol() {
System.out.println("MIR.getDownProtocol() returns " + super.getDownProtocol());
return super.getDownProtocol();
}
...略
}呼び出し元のmainメソッドは以下.
public static final String STACK2 =
"UDP(mcast_addr=228.1.2.3;mcast_port=45566;ip_ttl=32):" +
"MIR";
public static void main(String[] args) throws Exception {
System.out.println("\n----- start new JChannel() -----\n");
JChannel channel = new JChannel(STACK2);
System.out.println("\n----- start channel.connect() -----\n");
channel.connect("demo-group");
System.out.println("\n----- start channel.disconnect() -----\n");
channel.disconnect();
System.out.println("\n----- start channel.close() -----\n");
channel.close();
System.out.println("\n----- main method end -----\n");
}最下層レイヤーにはUDPのようなProtocolを設定しておかないと上手く動かないので,MIR+UDPの2層構成にて.
設定ファイル上での上下関係は動作時の上下関係とは逆になる.
以下のログが出力された.
----- start new JChannel() -----
MIR.setProtocolStack(org.jgroups.stack.ProtocolStack@32fb4f)
MIR.setProperties({}) returns true
MIR.setPropertiesInternal({}) returns true
MIR.init()
MIR.requiredUpServices() returns null
MIR.requiredDownServices() returns null
MIR.providedUpServices() returns null
MIR.providedDownServices() returns null
MIR.setDownProtocol(Protocol UDP(local address: null))
MIR.setUpProtocol(org.jgroups.stack.ProtocolStack@32fb4f)
MIR.getDownProtocol() returns Protocol UDP(local address: null)
MIR.startDownHandler()
MIR.startUpHandler()
MIR.getUpProtocol() returns org.jgroups.stack.ProtocolStack@32fb4f
----- start channel.connect() -----
MIR.(protected) receiveDownEvent(Event[type=START, arg=null])
MIR.(protected) handleSpecialDownEvent(Event[type=START, arg=null])
MIR.start()
MIR.down(Event[type=START, arg=null])
MIR.passDown(Event[type=START, arg=null])
MIR.(protected) receiveUpEvent(Event[type=SET_LOCAL_ADDRESS, arg=192.168.1.100:2319])
MIR.up(Event[type=SET_LOCAL_ADDRESS, arg=192.168.1.100:2319])
MIR.passUp(Event[type=SET_LOCAL_ADDRESS, arg=192.168.1.100:2319])
MIR.(protected) receiveUpEvent(Event[type=START_OK, arg=true])
MIR.up(Event[type=START_OK, arg=true])
MIR.passUp(Event[type=START_OK, arg=true])
MIR.(protected) receiveDownEvent(Event[type=CONNECT, arg=demo-group])
MIR.down(Event[type=CONNECT, arg=demo-group])
MIR.passDown(Event[type=CONNECT, arg=demo-group])
MIR.(protected) receiveUpEvent(Event[type=CONNECT_OK, arg=null])
MIR.up(Event[type=CONNECT_OK, arg=null])
MIR.passUp(Event[type=CONNECT_OK, arg=null])
----- start channel.disconnect() -----
MIR.(protected) receiveDownEvent(Event[type=DISCONNECT, arg=192.168.1.100:2319])
MIR.down(Event[type=DISCONNECT, arg=192.168.1.100:2319])
MIR.passDown(Event[type=DISCONNECT, arg=192.168.1.100:2319])
MIR.(protected) receiveUpEvent(Event[type=DISCONNECT_OK, arg=null])
MIR.up(Event[type=DISCONNECT_OK, arg=null])
MIR.passUp(Event[type=DISCONNECT_OK, arg=null])
MIR.(protected) receiveDownEvent(Event[type=STOP_QUEUEING, arg=null])
MIR.(protected) receiveDownEvent(Event[type=STOP, arg=null])
MIR.down(Event[type=STOP_QUEUEING, arg=null])
MIR.passDown(Event[type=STOP_QUEUEING, arg=null])
MIR.(protected) handleSpecialDownEvent(Event[type=STOP, arg=null])
MIR.stop()
MIR.down(Event[type=STOP, arg=null])
MIR.passDown(Event[type=STOP, arg=null])
MIR.(protected) receiveUpEvent(Event[type=STOP_OK, arg=true])
MIR.up(Event[type=STOP_OK, arg=true])
MIR.passUp(Event[type=STOP_OK, arg=true])
----- start channel.close() -----
MIR.stopInternal()
MIR.destroy()
MIR.getDownProtocol() returns Protocol UDP(local address: 192.168.1.100:2319)
----- main method end -----続きはまた後日.