Hi. leehui. This is old issue. But I have another opinion about this. I am sorry for replying too late.
first,
--------------------------
Shreedhar Ganapathy wrote:
The join() call is a blocking call in that it returns only after group
join has occurred. So you should be able to call GroupHandle's apis
without any waiting.
--------------------------
--> I could not agree Shreedhar Ganapathy's comment. When join() is called, MasterDiscovery's logic is executed at new thread. So GroupHandle.isGroupLeader() and GroupHandle.getGroupLeader() API is not safe.
--------------------------
leehui wrote:
"Why isGroupLeader() returns false? I think it should return true"
--------------------------
--> I think GroupHandle.isGroupLeader() have meaning when all members agree or after finishing MasterDiscovery.
Before finishing MasterDiscovery, We can not know who is group leader. So, I think isGroupLeader() can return false before finishing MasterDiscovery.
At the following sample code, GroupHandler.isGroupLeader() returns false for a while. But after finishing MasterDiscovery (MasterAssigned == true, "every group member first elects himself as group leader"), GroupHandler.isGroupLeader() returns true if there is only one member.
...
while( true ) {
System.out.println(groupHandle.isGroupLeader());
System.out.println(groupHandle.getGroupLeader());
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
...
GroupHandle.isGroupLeader() will call ClusterManager.isMaster() finally. see following code.
--------------------------
ClusterManager.java
...
public boolean isMaster() {
return clusterViewManager.isMaster() && masterNode.isMasterAssigned();
}
--------------------------
I think GroupHandler.getGroupLeader() is strange instead.
I think if master is not assigned(e.g. before finishing MasterDiscovery, masterNode.isMasterAssigned() == false), GroupHandler.getGroupLeader() must not return own name. e.g. return unknown state?
Thanks.
--
Bongjae Chang
----- Original Message -----
From: "leehui" <leehui70_at_gmail.com>
To: "dev" <dev_at_shoal.dev.java.net>
Sent: Wednesday, April 30, 2008 3:55 PM
Subject: [Shoal-Dev] GroupLeader Test
> Hi,
>
> I write a simple class to test shoal's GroupLeader functions. The codes like this:
>
> import java.util.UUID;
>
> import com.sun.enterprise.ee.cms.core.GMSException;
> import com.sun.enterprise.ee.cms.core.GMSFactory;
> import com.sun.enterprise.ee.cms.core.GroupHandle;
> import com.sun.enterprise.ee.cms.core.GroupManagementService;
> import com.sun.enterprise.ee.cms.core.GroupManagementService.MemberType;
>
>
> public class SimpleTest {
>
> /**
> * @param args
> */
> public static void main(String[] args) {
>
>
> String serverToken = UUID.randomUUID().toString();
> GroupManagementService gms = (GroupManagementService) GMSFactory.startGMSModule(serverToken, "DemoGroup", MemberType.CORE, null);
> try {
> gms.join();
> } catch (GMSException e) {
> e.printStackTrace();
> }
>
> GroupHandle groupHandle = gms.getGroupHandle();
> System.out.println(groupHandle.isGroupLeader());
> System.out.println(groupHandle.getGroupLeader());
>
> try {
> Thread.sleep(2000);
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
>
> System.out.println(groupHandle.isGroupLeader());
> System.out.println(groupHandle.getGroupLeader());
>
>
> }
>
> }
>
> When I run it, the console prints:
>
> false
> e2fed556-ff76-4a38-9645-c1f6160dc07f
> 2008-4-30 14:29:33 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow getMemberTokens
> 信息: GMS View Change Received for group DemoGroup : Members in view for (before change analysis) are :
> 1: MemberId: e2fed556-ff76-4a38-9645-c1f6160dc07f, MemberType: CORE, Address: urn:jxta:uuid-289CBAB1836A4A009242B36E1509E49AE78AB5C0E6B94A499134E1DEA803497203
>
> 2008-4-30 14:29:33 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow newViewObserved
> 信息: Analyzing new membership snapshot received as part of event : MASTER_CHANGE_EVENT
> false
> e2fed556-ff76-4a38-9645-c1f6160dc07f
>
> (1) Why isGroupLeader() returns false? I think it should return true.
>
>
> Then, I start another instance of SimpleTest, the console prints:
>
> false
> 836f3c91-a20a-4edf-a13c-326028990a8e
> 2008-4-30 14:29:46 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow getMemberTokens
> 信息: GMS View Change Received for group DemoGroup : Members in view for (before change analysis) are :
> 1: MemberId: 836f3c91-a20a-4edf-a13c-326028990a8e, MemberType: CORE, Address: urn:jxta:uuid-289CBAB1836A4A009242B36E1509E49A428F46CA05A349DBA7A9B02FEBDB344803
>
> 2008-4-30 14:29:47 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow newViewObserved
> 信息: Analyzing new membership snapshot received as part of event : MASTER_CHANGE_EVENT
> 2008-4-30 14:29:47 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow getMemberTokens
> 信息: GMS View Change Received for group DemoGroup : Members in view for (before change analysis) are :
> 1: MemberId: 836f3c91-a20a-4edf-a13c-326028990a8e, MemberType: CORE, Address: urn:jxta:uuid-289CBAB1836A4A009242B36E1509E49A428F46CA05A349DBA7A9B02FEBDB344803
> 2: MemberId: e2fed556-ff76-4a38-9645-c1f6160dc07f, MemberType: CORE, Address: urn:jxta:uuid-289CBAB1836A4A009242B36E1509E49AE78AB5C0E6B94A499134E1DEA803497203
>
> 2008-4-30 14:29:47 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow newViewObserved
> 信息: Analyzing new membership snapshot received as part of event : MASTER_CHANGE_EVENT
> 2008-4-30 14:29:47 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow getMemberTokens
> 信息: GMS View Change Received for group DemoGroup : Members in view for (before change analysis) are :
> 1: MemberId: 836f3c91-a20a-4edf-a13c-326028990a8e, MemberType: CORE, Address: urn:jxta:uuid-289CBAB1836A4A009242B36E1509E49A428F46CA05A349DBA7A9B02FEBDB344803
> 2: MemberId: e2fed556-ff76-4a38-9645-c1f6160dc07f, MemberType: CORE, Address: urn:jxta:uuid-289CBAB1836A4A009242B36E1509E49AE78AB5C0E6B94A499134E1DEA803497203
>
> 2008-4-30 14:29:47 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow newViewObserved
> 信息: Analyzing new membership snapshot received as part of event : ADD_EVENT
> false
> e2fed556-ff76-4a38-9645-c1f6160dc07f
>
> (2) The first isGroupLeader() prints false. I think it should be true. Just like my question (1).
> (3) Form above console's info, it seems that every group member first elects himself as group leader, then communicate others to update group leader' info.
> As there is no change notification of group leader, I think it may be better to return the true group leader after gms.join(). Otherwise, the shoal should
> provide some callbacks. Am I right?
>
> When you run SimpleTest serveral times, the console may prints:
>
> false
> Exception in thread "main" java.lang.NullPointerException
> at com.sun.enterprise.ee.cms.impl.jxta.GroupCommunicationProviderImpl.getGroupLeader(GroupCommunicationProviderImpl.java:281)
> at com.sun.enterprise.ee.cms.impl.jxta.GroupHandleImpl.getGroupLeader(GroupHandleImpl.java:398)
> at SimpleTest.main(SimpleTest.java:28)
> 2008-4-30 14:51:16 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow getMemberTokens
> 信息: GMS View Change Received for group DemoGroup : Members in view for (before change analysis) are :
> 1: MemberId: ab6418c9-84bc-49a8-af4c-d6e5b6127de4, MemberType: CORE, Address: urn:jxta:uuid-289CBAB1836A4A009242B36E1509E49A1B75978AE67A4B04A022C83142739EC103
>
> 2008-4-30 14:51:16 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow newViewObserved
> 信息: Analyzing new membership snapshot received as part of event : MASTER_CHANGE_EVENT
>
> (4) This exception occurs occasionally. But I don't know when and why it occurs. How to handle it?
>
> (5) Does shoal plan to expose MASTER_CHANGE_EVENT callback in future?
>
> Thank you in advance for your reply.
>
> --------------
> leehui
> 2008-04-30
>