Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Schwarz2014-08-12 04:55:10 -0400
committerTobias Schwarz2014-08-12 04:55:54 -0400
commit03d305d35e754a3e85808ee2828bf0a2d81ff6a4 (patch)
treeb0652fac2682c3c6bb2aa19f15568d65d30936fc
parent4c5a11fffa9cbfc5476124997884385635ee23a5 (diff)
downloadorg.eclipse.tcf-03d305d35e754a3e85808ee2828bf0a2d81ff6a4.tar.gz
org.eclipse.tcf-03d305d35e754a3e85808ee2828bf0a2d81ff6a4.tar.xz
org.eclipse.tcf-03d305d35e754a3e85808ee2828bf0a2d81ff6a4.zip
Target Explorer: add peer version and migration
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/IPeerProperties.java10
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/IPeerModelMigrationDelegate.java34
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/PeerPersistableURIProvider.java25
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelRefreshService.java47
4 files changed, 109 insertions, 7 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/IPeerProperties.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/IPeerProperties.java
index 7852e3bf1..c464a8715 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/IPeerProperties.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/IPeerProperties.java
@@ -22,4 +22,14 @@ public interface IPeerProperties {
* must be decoded using {@link PeerDataHelper#decodePeerList(String)}.
*/
public static final String PROP_PROXIES = "Proxies"; //$NON-NLS-1$
+
+ /**
+ * Property: The version of the connection.
+ */
+ public static final String PROP_VERSION = "Version"; //$NON-NLS-1$
+
+ /**
+ * Property: <code>true</code> if this connection was already migrated to a higher version.
+ */
+ public static final String PROP_MIGRATED = "Migrated"; //$NON-NLS-1$
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/IPeerModelMigrationDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/IPeerModelMigrationDelegate.java
new file mode 100644
index 000000000..31e078254
--- /dev/null
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/IPeerModelMigrationDelegate.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Wind River Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the terms
+ * of the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tcf.te.tcf.locator.interfaces;
+
+import org.eclipse.tcf.protocol.IPeer;
+import org.osgi.framework.Version;
+
+/**
+ * IPeerModelMigrationDelegate
+ */
+public interface IPeerModelMigrationDelegate {
+
+ /**
+ * Get the active version for peers handled by this delegate.
+ * @return The active version.
+ */
+ public Version getVersion();
+
+ /**
+ * Migrate the given peer to the active version.
+ *
+ * @param peer The peer to migrate.
+ * @return The migrated peer or <code>null</code> if nothing to migrate.
+ */
+ public IPeer migrate(IPeer peer);
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/PeerPersistableURIProvider.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/PeerPersistableURIProvider.java
index 4836c2827..c3b951af8 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/PeerPersistableURIProvider.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/PeerPersistableURIProvider.java
@@ -9,6 +9,7 @@
*******************************************************************************/
package org.eclipse.tcf.te.tcf.locator.internal.adapters;
+import java.io.File;
import java.net.URI;
import java.util.concurrent.atomic.AtomicReference;
@@ -18,9 +19,11 @@ import org.eclipse.tcf.protocol.IPeer;
import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.te.core.adapters.ModelNodePersistableURIProvider;
import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNodeProperties;
+import org.eclipse.tcf.te.tcf.core.interfaces.IPeerProperties;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProvider;
import org.eclipse.tcf.te.tcf.locator.model.ModelLocationUtil;
+import org.osgi.framework.Version;
/**
* Persistable implementation handling peer attributes.
@@ -62,6 +65,7 @@ public class PeerPersistableURIProvider extends ModelNodePersistableURIProvider
if (peer != null) {
// Get the URI the peer model has been created from
final AtomicReference<URI> nodeURI = new AtomicReference<URI>();
+ final AtomicReference<Version> version = new AtomicReference<Version>();
Runnable runnable = new Runnable() {
@Override
public void run() {
@@ -69,6 +73,8 @@ public class PeerPersistableURIProvider extends ModelNodePersistableURIProvider
if (value != null && !"".equals(value.trim())) { //$NON-NLS-1$
nodeURI.set(URI.create(value.trim()));
}
+ value = peer.getAttributes().get(IPeerProperties.PROP_VERSION);
+ version.set(value != null ? new Version(value.trim()) : Version.emptyVersion);
}
};
if (Protocol.isDispatchThread()) {
@@ -89,8 +95,23 @@ public class PeerPersistableURIProvider extends ModelNodePersistableURIProvider
}
name = makeValidFileSystemName(name);
// Get the URI from the name
- uri = getRoot().append(name).toFile().toURI();
-
+ uri = getRoot().append(name+".peer").toFile().toURI(); //$NON-NLS-1$
+ try {
+ File file = new File(uri.normalize());
+ if (file.exists()) {
+ name = makeValidFileSystemName(name + "_" + version.toString()); //$NON-NLS-1$
+ uri = getRoot().append(name+".peer").toFile().toURI(); //$NON-NLS-1$
+ }
+ file = new File(uri.normalize());
+ int i = 1;
+ while (file.exists()) {
+ name = makeValidFileSystemName(name + "_" + i); //$NON-NLS-1$
+ uri = getRoot().append(name+".peer").toFile().toURI(); //$NON-NLS-1$
+ i++;
+ }
+ }
+ catch (Exception e) {
+ }
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelRefreshService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelRefreshService.java
index 507b4306b..732b92b60 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelRefreshService.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelRefreshService.java
@@ -11,7 +11,6 @@ package org.eclipse.tcf.te.tcf.locator.services;
import java.io.File;
import java.io.FileFilter;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -29,8 +28,12 @@ import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback;
import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNodeProperties;
import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService;
import org.eclipse.tcf.te.runtime.services.ServiceManager;
+import org.eclipse.tcf.te.runtime.services.interfaces.IDelegateService;
+import org.eclipse.tcf.te.runtime.services.interfaces.IService;
import org.eclipse.tcf.te.tcf.core.Tcf;
+import org.eclipse.tcf.te.tcf.core.interfaces.IPeerProperties;
import org.eclipse.tcf.te.tcf.core.peers.Peer;
+import org.eclipse.tcf.te.tcf.locator.interfaces.IPeerModelMigrationDelegate;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode;
import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProperties;
@@ -39,6 +42,7 @@ import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelRefreshServi
import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelUpdateService;
import org.eclipse.tcf.te.tcf.locator.model.ModelLocationUtil;
import org.eclipse.tcf.te.tcf.locator.nodes.PeerNode;
+import org.osgi.framework.Version;
/**
@@ -209,12 +213,45 @@ public class PeerModelRefreshService extends AbstractPeerModelService implements
}
attrs.put(IPeer.ATTR_ID, id);
}
-
// Construct the peer from the attributes
IPeer peer = new Peer(attrs);
- // Add the constructed peer to the peers map
- peers.put(peer.getID(), peer);
- } catch (IOException e) {
+
+ IPeerModelMigrationDelegate delegate = null;
+ for (IService delegateService : ServiceManager.getInstance().getServices(peer, IDelegateService.class, false)) {
+ delegate = ((IDelegateService)delegateService).getDelegate(peer, IPeerModelMigrationDelegate.class);
+ if (delegate != null) break;
+ }
+ if (delegate != null) {
+ Version activeVersion = delegate.getVersion();
+ String version = attrs.get(IPeerProperties.PROP_VERSION);
+ String value = attrs.get(IPeerProperties.PROP_MIGRATED);
+ boolean migrated = value != null && Boolean.parseBoolean(value);
+ Version peerVersion = version != null ? new Version(version.trim()) : Version.emptyVersion;
+ if (peerVersion.compareTo(activeVersion) == 0) {
+ // Add the peer to the peers map
+ peers.put(peer.getID(), peer);
+ }
+ else if (!migrated) {
+ IPeer migratedPeer = delegate.migrate(peer);
+ if (migratedPeer != null) {
+ attrs.put(IPeerProperties.PROP_MIGRATED, Boolean.TRUE.toString());
+ service.write(new Peer(attrs), null);
+
+ attrs = new HashMap<String, String>(migratedPeer.getAttributes());
+ attrs.put(IPersistableNodeProperties.PROPERTY_URI, null);
+ attrs.put(IPeerProperties.PROP_VERSION, activeVersion.toString());
+ peer = new Peer(attrs);
+ service.write(peer, null);
+ // Add the migrated peer to the peers map
+ peers.put(peer.getID(), peer);
+ }
+ }
+ }
+ else {
+ // Add the peer to the peers map
+ peers.put(peer.getID(), peer);
+ }
+ } catch (Throwable e) {
/* ignored on purpose */
}
}

Back to the top