[jboss-cvs] JBoss Messaging SVN: r7996 - branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/postoffice.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Mar 31 03:27:56 EDT 2010
Author: gaohoward
Date: 2010-03-31 03:27:55 -0400 (Wed, 31 Mar 2010)
New Revision: 7996
Modified:
branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/postoffice/GroupListener.java
branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/postoffice/GroupMember.java
branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/postoffice/MessagingPostOffice.java
Log:
JBMESSAGING-1796
Modified: branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/postoffice/GroupListener.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/postoffice/GroupListener.java 2010-03-31 07:26:27 UTC (rev 7995)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/postoffice/GroupListener.java 2010-03-31 07:27:55 UTC (rev 7996)
@@ -42,4 +42,14 @@
byte[] getState() throws Exception;
void setState(byte[] state) throws Exception;
+
+ //tell the listener that it will begin to process the view change.
+ //if the listener thinks the change cannot be made (for example
+ //shutdown has been initiated), return false. Otherwise return true.
+
+ //introduced for https://jira.jboss.org/jira/browse/JBMESSAGING-1796
+ boolean beginProcessView();
+
+ //tell the listener that the view has been processed
+ void endProcessView();
}
Modified: branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/postoffice/GroupMember.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/postoffice/GroupMember.java 2010-03-31 07:26:27 UTC (rev 7995)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/postoffice/GroupMember.java 2010-03-31 07:27:55 UTC (rev 7996)
@@ -490,6 +490,11 @@
public void viewAccepted(final View newView)
{
log.info(this + " got new view " + newView + ", old view is " + currentView);
+
+ if (!groupListener.beginProcessView())
+ {
+ return;
+ }
if (newView instanceof MergeView)
{
@@ -531,7 +536,7 @@
if (!leftNodes.isEmpty())
{
groupListener.nodesLeft(leftNodes);
- log.info("Dead members: " + leftNodes.size() + " (" + leftNodes + ")");
+ log.info("Dead members: " + leftNodes.size() + " (" + leftNodes + ")");
}
}
List nodesAdded=new ArrayList();
@@ -554,6 +559,8 @@
{
log.error("Caught Exception in MembershipListener", e);
}
+
+ groupListener.endProcessView();
}
public byte[] getState()
@@ -655,4 +662,5 @@
}
}
}
+
}
Modified: branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/postoffice/MessagingPostOffice.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/postoffice/MessagingPostOffice.java 2010-03-31 07:26:27 UTC (rev 7995)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/postoffice/MessagingPostOffice.java 2010-03-31 07:27:55 UTC (rev 7996)
@@ -240,6 +240,11 @@
private boolean useJGroupsWorkaround;
private boolean failoverOnNodeLeave;
+
+ //needed only in clustered constructor
+ private Object viewUpdateLock;
+ private boolean stopUpdate = false;
+ private boolean updateInProcess = false;
// Constructors ---------------------------------------------------------------------------------
@@ -327,6 +332,8 @@
this.clustered = true;
+ this.viewUpdateLock = new Object();
+
this.failoverOnNodeLeave = failoverOnNodeLeave;
groupMember = new GroupMember(groupName, stateTimeout, castTimeout, jChannelFactory, this, this);
@@ -407,34 +414,87 @@
log.debug(this + " started");
}
- public synchronized void stop() throws Exception
- {
- if (!started)
- {
- log.warn(this + " is not started");
-
- return;
- }
-
- if (trace) { log.trace(this + " stopping"); }
-
- super.stop();
-
- if (clustered)
- {
- //Need to send this *before* stopping
- groupMember.multicastControl(new LeaveClusterRequest(thisNodeID), true);
-
- groupMember.stop();
+ public void stop() throws Exception
+ {
+ stopViewUpdate();
+
+ synchronized (this)
+ {
+ if (!started)
+ {
+ log.warn(this + " is not started");
+
+ return;
+ }
+
+ if (trace)
+ {
+ log.trace(this + " stopping");
+ }
+
+ super.stop();
+
+ if (clustered)
+ {
+ // Need to send this *before* stopping
+ groupMember.multicastControl(new LeaveClusterRequest(thisNodeID), true);
+ groupMember.stop();
+ }
+
+ deInit();
+
+ started = false;
+
+ log.debug(this + " stopped");
}
-
- deInit();
-
- started = false;
+ }
- log.debug(this + " stopped");
+ /**
+ * This method prevents further view update before
+ * shutdown. The stop() method will call it.
+ * https://jira.jboss.org/jira/browse/JBMESSAGING-1796
+ */
+ private void stopViewUpdate()
+ {
+ if (!clustered) return;
+ synchronized (viewUpdateLock)
+ {
+ if (stopUpdate) return;
+ stopUpdate = true;
+ while (updateInProcess)
+ {
+ try
+ {
+ log.info("Waiting for view update finish before stop post office " + this);
+ viewUpdateLock.wait();
+ log.info("View update finished, stpping post office: " + this);
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+ }
}
+ public boolean beginProcessView()
+ {
+ synchronized (viewUpdateLock)
+ {
+ if (stopUpdate) return false;
+ updateInProcess = true;
+ }
+ return true;
+ }
+
+ public void endProcessView()
+ {
+ synchronized (viewUpdateLock)
+ {
+ updateInProcess = false;
+ viewUpdateLock.notify();
+ }
+ }
+
// NotificationBroadcaster implementation -------------------------------------------------------
public void addNotificationListener(NotificationListener listener,
More information about the jboss-cvs-commits
mailing list