Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2010-09-23 06:41:28 +0000
committerEike Stepper2010-09-23 06:41:28 +0000
commitf0507f5c7a843292f29dfd09eb6d2e75ef34b07e (patch)
tree390219e8c62e2feee0ba62d51a30fce29ef06f2b
parentf13252bac7c020a40e066c64ba836ab09c4835eb (diff)
downloadcdo-f0507f5c7a843292f29dfd09eb6d2e75ef34b07e.tar.gz
cdo-f0507f5c7a843292f29dfd09eb6d2e75ef34b07e.tar.xz
cdo-f0507f5c7a843292f29dfd09eb6d2e75ef34b07e.zip
[325928] Provide FailoverMonitor server and FailoverAgents to coordinate fail-over scenarios
https://bugs.eclipse.org/bugs/show_bug.cgi?id=325928
-rw-r--r--plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/FailoverExample.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/FailoverCDOSessionConfigurationImpl.java57
-rw-r--r--plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/net4j/CDONet4jUtil.java4
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/heartbeat/HeartBeatProtocol.java10
4 files changed, 48 insertions, 27 deletions
diff --git a/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/FailoverExample.java b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/FailoverExample.java
index 4ebfb30f27..b3cd12f2b5 100644
--- a/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/FailoverExample.java
+++ b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/FailoverExample.java
@@ -545,8 +545,8 @@ public abstract class FailoverExample
public static void main(String[] args) throws Exception
{
IManagedContainer container = createContainer();
- CDOSessionConfiguration configuration = CDONet4jUtil.createFailoverSessionConfiguration(container,
- REPOSITORY_MONITOR_HOST + ":" + REPOSITORY_MONITOR_PORT, REPOSITORY_GROUP);
+ CDOSessionConfiguration configuration = CDONet4jUtil.createFailoverSessionConfiguration(REPOSITORY_MONITOR_HOST
+ + ":" + REPOSITORY_MONITOR_PORT, REPOSITORY_GROUP, container);
CDOSession session = configuration.openSession();
session.addListener(new IListener()
diff --git a/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/FailoverCDOSessionConfigurationImpl.java b/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/FailoverCDOSessionConfigurationImpl.java
index 8db2114223..e5d4d1e2f9 100644
--- a/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/FailoverCDOSessionConfigurationImpl.java
+++ b/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/FailoverCDOSessionConfigurationImpl.java
@@ -21,8 +21,9 @@ import org.eclipse.net4j.connector.IConnector;
import org.eclipse.net4j.signal.RequestWithConfirmation;
import org.eclipse.net4j.signal.SignalProtocol;
import org.eclipse.net4j.signal.failover.IFailOverStrategy;
+import org.eclipse.net4j.signal.heartbeat.HeartBeatProtocol;
+import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.collection.Pair;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.net4j.util.container.IPluginContainer;
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
@@ -44,12 +45,16 @@ public class FailoverCDOSessionConfigurationImpl extends CDONet4jSessionConfigur
{
private String monitorConnectorDescription;
- private String repositoryGroup;
-
private IConnector monitorConnector;
private SignalProtocol<Object> monitorProtocol;
+ private String repositoryGroup;
+
+ private String repositoryConnectorDescription;
+
+ private String repositoryName;
+
public FailoverCDOSessionConfigurationImpl(String monitorConnectorDescription, String repositoryGroup)
{
this.monitorConnectorDescription = monitorConnectorDescription;
@@ -126,17 +131,18 @@ public class FailoverCDOSessionConfigurationImpl extends CDONet4jSessionConfigur
private void updateConnectorAndRepositoryName()
{
- Pair<String, String> info = queryRepositoryInfoFromMonitor();
- IConnector connector = getConnector(info.getElement1());
- String repositoryName = info.getElement2();
+ System.out.println("Querying fail-over monitor...");
+ queryRepositoryInfoFromMonitor();
- System.out.println("Connecting to " + info.getElement1() + "/" + repositoryName);
+ System.out.println("Connecting to " + repositoryConnectorDescription + "/" + repositoryName + "...");
+ IConnector connector = getConnector(repositoryConnectorDescription);
+ new HeartBeatProtocol(connector, getContainer()).start(1000L, 5000L);
uncheckedSetConnector(connector);
uncheckedSetRepositoryName(repositoryName);
}
- protected Pair<String, String> queryRepositoryInfoFromMonitor()
+ protected void queryRepositoryInfoFromMonitor()
{
if (monitorConnector == null)
{
@@ -147,22 +153,29 @@ public class FailoverCDOSessionConfigurationImpl extends CDONet4jSessionConfigur
try
{
- return new RequestWithConfirmation<Pair<String, String>>(monitorProtocol, (short)1, "QueryRepositoryInfo")
- {
- @Override
- protected void requesting(ExtendedDataOutputStream out) throws Exception
- {
- out.writeString(repositoryGroup);
- }
+ String oldRepositoryConnectorDescription = repositoryConnectorDescription;
+ String oldRepositoryName = repositoryName;
- @Override
- protected Pair<String, String> confirming(ExtendedDataInputStream in) throws Exception
+ while (ObjectUtil.equals(repositoryConnectorDescription, oldRepositoryConnectorDescription)
+ && ObjectUtil.equals(repositoryName, oldRepositoryName))
+ {
+ new RequestWithConfirmation<Boolean>(monitorProtocol, (short)1, "QueryRepositoryInfo")
{
- String connectorDescription = in.readString();
- String repositoryName = in.readString();
- return new Pair<String, String>(connectorDescription, repositoryName);
- }
- }.send();
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws Exception
+ {
+ out.writeString(repositoryGroup);
+ }
+
+ @Override
+ protected Boolean confirming(ExtendedDataInputStream in) throws Exception
+ {
+ repositoryConnectorDescription = in.readString();
+ repositoryName = in.readString();
+ return true;
+ }
+ }.send();
+ }
}
catch (Exception ex)
{
diff --git a/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/net4j/CDONet4jUtil.java b/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/net4j/CDONet4jUtil.java
index 799dd9d546..fc8a7a53dc 100644
--- a/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/net4j/CDONet4jUtil.java
+++ b/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/net4j/CDONet4jUtil.java
@@ -37,8 +37,8 @@ public final class CDONet4jUtil
/**
* @since 4.0
*/
- public static FailoverCDOSessionConfiguration createFailoverSessionConfiguration(final IManagedContainer container,
- String monitorConnectorDescription, String repositoryGroup)
+ public static FailoverCDOSessionConfiguration createFailoverSessionConfiguration(String monitorConnectorDescription,
+ String repositoryGroup, final IManagedContainer container)
{
return new FailoverCDOSessionConfigurationImpl(monitorConnectorDescription, repositoryGroup)
{
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/heartbeat/HeartBeatProtocol.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/heartbeat/HeartBeatProtocol.java
index c1cec4fad4..88d208b207 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/heartbeat/HeartBeatProtocol.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/heartbeat/HeartBeatProtocol.java
@@ -71,9 +71,17 @@ public class HeartBeatProtocol extends SignalProtocol<Object>
this(TYPE, connector, timer);
}
+ /**
+ * @since 3.1
+ */
+ public HeartBeatProtocol(IConnector connector, IManagedContainer container)
+ {
+ this(connector, getDefaultTimer(container));
+ }
+
public HeartBeatProtocol(IConnector connector)
{
- this(connector, getDefaultTimer(IPluginContainer.INSTANCE));
+ this(connector, IPluginContainer.INSTANCE);
}
public Timer getTimer()

Back to the top