Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreutarass2008-03-31 23:17:32 +0000
committereutarass2008-03-31 23:17:32 +0000
commitc3ea712c5ca2d3826ff156476ddc913ef2fb5d91 (patch)
tree46b39aacd91a4a57b6bc5856876e97d5c2691a41 /plugins
parent00d9873796602ccaeb0fd6b38bdbb60ba262407a (diff)
downloadorg.eclipse.tcf-c3ea712c5ca2d3826ff156476ddc913ef2fb5d91.tar.gz
org.eclipse.tcf-c3ea712c5ca2d3826ff156476ddc913ef2fb5d91.tar.xz
org.eclipse.tcf-c3ea712c5ca2d3826ff156476ddc913ef2fb5d91.zip
Fixed TCF channel proxying. Now Launch Configuration dialog properly shows available TCF proxies (value-add agents), as well as targets reachable through proxies.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/launch/TCFMainTab.java427
-rw-r--r--plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/local/LocatorService.java46
-rw-r--r--plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/LocatorProxy.java2
-rw-r--r--plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/core/AbstractChannel.java57
-rw-r--r--plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/protocol/IChannel.java4
-rw-r--r--plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/protocol/IPeer.java1
-rw-r--r--plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/services/ILocator.java18
-rw-r--r--plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/util/TCFTask.java2
8 files changed, 282 insertions, 275 deletions
diff --git a/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/launch/TCFMainTab.java b/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/launch/TCFMainTab.java
index 0abc2906d..07bc42b13 100644
--- a/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/launch/TCFMainTab.java
+++ b/plugins/org.eclipse.tm.tcf.debug.ui/src/org/eclipse/tm/internal/tcf/debug/ui/launch/TCFMainTab.java
@@ -54,6 +54,7 @@ import org.eclipse.tm.internal.tcf.debug.ui.Activator;
import org.eclipse.tm.tcf.protocol.IChannel;
import org.eclipse.tm.tcf.protocol.IPeer;
import org.eclipse.tm.tcf.protocol.Protocol;
+import org.eclipse.tm.tcf.protocol.IChannel.IChannelListener;
import org.eclipse.tm.tcf.services.ILocator;
@@ -66,7 +67,7 @@ public class TCFMainTab extends AbstractLaunchConfigurationTab {
private Text peer_id_text;
private Text program_text;
private Tree peer_tree;
- private PeerInfo[] peer_info;
+ private final PeerInfo peer_info = new PeerInfo();
private Display display;
private final Map<LocatorListener,ILocator> listeners = new HashMap<LocatorListener,ILocator>();
@@ -75,8 +76,12 @@ public class TCFMainTab extends AbstractLaunchConfigurationTab {
private static class PeerInfo {
PeerInfo parent;
int index;
- PeerInfo[] children;
+ String id;
Map<String,String> attrs;
+ PeerInfo[] children;
+ boolean children_pending;
+ Throwable children_error;
+ IPeer peer;
}
private class LocatorListener implements ILocator.LocatorListener {
@@ -87,41 +92,43 @@ public class TCFMainTab extends AbstractLaunchConfigurationTab {
this.parent = parent;
}
- public void peerAdded(IPeer peer) {
+ public void peerAdded(final IPeer peer) {
if (display == null) return;
- final Map<String,String> attrs = new HashMap<String,String>(peer.getAttributes());
+ final String id = peer.getID();
+ final HashMap<String,String> attrs = new HashMap<String,String>(peer.getAttributes());
display.asyncExec(new Runnable() {
public void run() {
- PeerInfo[] arr = parent == null ? peer_info : parent.children;
+ if (parent.children_error != null) return;
+ PeerInfo[] arr = parent.children;
PeerInfo[] buf = new PeerInfo[arr.length + 1];
System.arraycopy(arr, 0, buf, 0, arr.length);
PeerInfo info = new PeerInfo();
info.parent = parent;
info.index = arr.length;
+ info.id = id;
info.attrs = attrs;
+ info.peer = peer;
buf[arr.length] = info;
- if (parent == null) {
- peer_info = buf;
- }
- else {
- parent.children = buf;
- }
- updateItems();
+ parent.children = buf;
+ updateItems(parent);
}
});
}
- public void peerChanged(IPeer peer) {
+ public void peerChanged(final IPeer peer) {
if (display == null) return;
- final Map<String,String> attrs = new HashMap<String,String>(peer.getAttributes());
+ final String id = peer.getID();
+ final HashMap<String,String> attrs = new HashMap<String,String>(peer.getAttributes());
display.asyncExec(new Runnable() {
public void run() {
- String id = attrs.get(IPeer.ATTR_ID);
- PeerInfo[] arr = parent == null ? peer_info : parent.children;
+ if (parent.children_error != null) return;
+ PeerInfo[] arr = parent.children;
for (int i = 0; i < arr.length; i++) {
- if (arr[i].attrs.get(IPeer.ATTR_ID).equals(id)) {
+ if (arr[i].id.equals(id)) {
arr[i].attrs = attrs;
- updateItems();
+ arr[i].peer = peer;
+ loadChildren(arr[i]);
+ updateItems(parent);
}
}
}
@@ -132,47 +139,37 @@ public class TCFMainTab extends AbstractLaunchConfigurationTab {
if (display == null) return;
display.asyncExec(new Runnable() {
public void run() {
- PeerInfo[] arr = parent == null ? peer_info : parent.children;
+ if (parent.children_error != null) return;
+ PeerInfo[] arr = parent.children;
PeerInfo[] buf = new PeerInfo[arr.length - 1];
int j = 0;
for (int i = 0; i < arr.length; i++) {
- if (!arr[i].attrs.get(IPeer.ATTR_ID).equals(id)) {
+ if (!arr[i].id.equals(id)) {
buf[j++] = arr[i];
}
}
- if (parent == null) {
- peer_info = buf;
- }
- else {
- parent.children = buf;
- }
- updateItems();
+ parent.children = buf;
+ updateItems(parent);
}
});
}
-
- private void updateItems() {
- PeerInfo[] arr = null;
- TreeItem[] items = null;
- if (parent == null) {
- arr = peer_info;
- peer_tree.setItemCount(arr.length);
- items = peer_tree.getItems();
- }
- else {
- TreeItem item = findItem(parent);
- if (item == null) return;
- arr = parent.children;
- item.setItemCount(arr.length);
- items = item.getItems();
- }
- assert items.length == arr.length;
- for (int i = 0; i < items.length; i++) {
- fillItem(items[i], arr[i]);
- }
- String id = peer_id_text.getText();
- TreeItem item = findItem(findPeerInfo(id));
- if (item != null) peer_tree.setSelection(item);
+
+ public void peerHeartBeat(final String id) {
+ if (display == null) return;
+ display.asyncExec(new Runnable() {
+ public void run() {
+ if (parent.children_error != null) return;
+ PeerInfo[] arr = parent.children;
+ for (int i = 0; i < arr.length; i++) {
+ if (arr[i].id.equals(id)) {
+ if (arr[i].children_error != null) {
+ loadChildren(arr[i]);
+ }
+ break;
+ }
+ }
+ }
+ });
}
}
@@ -229,7 +226,7 @@ public class TCFMainTab extends AbstractLaunchConfigurationTab {
peer_label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
peer_label.setFont(font);
- if (peer_info == null) loadPeerInfo(null);
+ loadChildren(peer_info);
peer_tree = new Tree(group, SWT.VIRTUAL | SWT.BORDER | SWT.SINGLE);
GridData gd = new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1);
@@ -242,7 +239,7 @@ public class TCFMainTab extends AbstractLaunchConfigurationTab {
switch (i) {
case 0:
column.setText("Name");
- column.setWidth(120);
+ column.setWidth(160);
break;
case 1:
column.setText("OS");
@@ -265,12 +262,25 @@ public class TCFMainTab extends AbstractLaunchConfigurationTab {
peer_tree.setHeaderVisible(true);
peer_tree.setFont(font);
- peer_tree.setItemCount(peer_info.length);
peer_tree.addListener(SWT.SetData, new Listener() {
public void handleEvent(Event event) {
TreeItem item = (TreeItem)event.item;
PeerInfo info = findPeerInfo(item);
- fillItem(item, info);
+ if (info == null) {
+ PeerInfo parent = findPeerInfo(item.getParentItem());
+ if (parent == null) {
+ item.setText("Invalid");
+ }
+ else {
+ if (parent.children == null || parent.children_error != null) {
+ loadChildren(parent);
+ }
+ updateItems(parent);
+ }
+ }
+ else {
+ fillItem(item, info);
+ }
}
});
peer_tree.addSelectionListener(new SelectionListener() {
@@ -281,7 +291,7 @@ public class TCFMainTab extends AbstractLaunchConfigurationTab {
if (selections.length > 0) {
assert selections.length == 1;
PeerInfo info = findPeerInfo(selections[0]);
- peer_id_text.setText(getPath(info));
+ if (info != null) peer_id_text.setText(getPath(info));
}
}
});
@@ -331,9 +341,9 @@ public class TCFMainTab extends AbstractLaunchConfigurationTab {
program_text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
program_text.setFont(font);
program_text.addModifyListener(new ModifyListener() {
- public void modifyText(ModifyEvent e) {
+ public void modifyText(ModifyEvent e) {
updateLaunchConfigurationDialog();
- }
+ }
});
}
@@ -346,7 +356,6 @@ public class TCFMainTab extends AbstractLaunchConfigurationTab {
listeners.get(listener).removeListener(listener);
}
listeners.clear();
- peer_info = null;
display = null;
}
});
@@ -405,43 +414,148 @@ public class TCFMainTab extends AbstractLaunchConfigurationTab {
configuration.setAttribute(TCFLaunchDelegate.ATTR_PROGRAM_FILE, (String)null);
}
- private void loadPeerInfo(final PeerInfo parent) {
+ private LocatorListener createLocatorListener(PeerInfo peer, ILocator locator) {
+ assert Protocol.isDispatchThread();
+ Map<String,IPeer> map = locator.getPeers();
+ PeerInfo[] buf = new PeerInfo[map.size()];
+ int n = 0;
+ for (IPeer p : map.values()) {
+ PeerInfo info = new PeerInfo();
+ info.parent = peer;
+ info.index = n;
+ info.id = p.getID();
+ info.attrs = new HashMap<String,String>(p.getAttributes());
+ info.peer = p;
+ buf[n++] = info;
+ }
+ LocatorListener listener = new LocatorListener(peer);
+ listeners.put(listener, locator);
+ locator.addListener(listener);
+ setChildren(peer, null, buf);
+ return listener;
+ }
+
+ private boolean canHaveChildren(PeerInfo parent) {
+ return parent == peer_info || parent.attrs.get(IPeer.ATTR_PROXY) != null;
+ }
+
+ private void loadChildren(final PeerInfo parent) {
+ assert Thread.currentThread() == display.getThread();
+ if (parent.children_pending) return;
+ if (!canHaveChildren(parent)) {
+ if (parent.children == null) updateItems(parent);
+ return;
+ }
+ parent.children_pending = true;
Protocol.invokeAndWait(new Runnable() {
public void run() {
- if (parent == null) {
- ILocator locator = Protocol.getLocator();
- Map<String,IPeer> map = locator.getPeers();
- PeerInfo[] buf = new PeerInfo[map.size()];
- int n = 0;
- for (Iterator<IPeer> i = map.values().iterator(); i.hasNext();) {
- IPeer p = i.next();
- PeerInfo info = new PeerInfo();
- info.parent = parent;
- info.index = n;
- info.attrs = new HashMap<String,String>(p.getAttributes());
- buf[n++] = info;
- }
- LocatorListener listener = new LocatorListener(parent);
- listeners.put(listener, locator);
- locator.addListener(listener);
- assert peer_info == null;
- peer_info = buf;
+ if (parent == peer_info) {
+ createLocatorListener(peer_info, Protocol.getLocator());
}
else {
- PeerInfo[] buf = new PeerInfo[0];
- assert parent.children == null;
- parent.children = buf;
+ final IChannel channel = parent.peer.openChannel();
+ final LocatorListener[] listener = new LocatorListener[1];
+ channel.addChannelListener(new IChannelListener() {
+ public void congestionLevel(int level) {
+ }
+ public void onChannelClosed(Throwable error) {
+ setChildren(parent, error, new PeerInfo[0]);
+ if (listener[0] != null) listeners.remove(listener[0]);
+ }
+ public void onChannelOpened() {
+ ILocator locator = channel.getRemoteService(ILocator.class);
+ if (locator == null) {
+ channel.close();
+ }
+ else {
+ listener[0] = createLocatorListener(parent, locator);
+ }
+ }
+ });
}
}
});
}
+ private void setChildren(final PeerInfo parent, final Throwable error, final PeerInfo[] children) {
+ assert Protocol.isDispatchThread();
+ display.asyncExec(new Runnable() {
+ public void run() {
+ parent.children_pending = false;
+ parent.children = children;
+ parent.children_error = error;
+ updateItems(parent);
+ }
+ });
+ }
+
+ private void updateItems(PeerInfo parent) {
+ assert Thread.currentThread() == display.getThread();
+ if (!canHaveChildren(parent)) {
+ parent.children = new PeerInfo[0];
+ parent.children_error = null;
+ }
+ PeerInfo[] arr = parent.children;
+ TreeItem[] items = null;
+ if (arr == null || parent.children_error != null) {
+ if (parent == peer_info) {
+ peer_tree.setItemCount(1);
+ items = peer_tree.getItems();
+ }
+ else {
+ TreeItem item = findItem(parent);
+ if (item == null) return;
+ item.setItemCount(1);
+ items = item.getItems();
+ }
+ if (parent.children_pending) {
+ items[0].setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
+ items[0].setText("Loading...");
+ }
+ else if (parent.children_error != null) {
+ String msg = parent.children_error.getMessage().replace('\n', ' ');
+ items[0].setForeground(display.getSystemColor(SWT.COLOR_RED));
+ items[0].setText(msg);
+ }
+ else {
+ items[0].setForeground(display.getSystemColor(SWT.COLOR_RED));
+ items[0].setText("Invalid children list");
+ }
+ int n = peer_tree.getColumnCount();
+ for (int i = 1; i < n; i++) items[0].setText(i, "");
+ items[0].setItemCount(0);
+ }
+ else {
+ if (parent == peer_info) {
+ peer_tree.setItemCount(arr.length);
+ items = peer_tree.getItems();
+ }
+ else {
+ TreeItem item = findItem(parent);
+ if (item == null) return;
+ item.setItemCount(arr.length);
+ items = item.getItems();
+ }
+ assert items.length == arr.length;
+ for (int i = 0; i < items.length; i++) fillItem(items[i], arr[i]);
+ String id = peer_id_text.getText();
+ TreeItem item = findItem(findPeerInfo(id));
+ if (item != null) peer_tree.setSelection(item);
+ }
+ }
+
private PeerInfo findPeerInfo(TreeItem item) {
+ assert Thread.currentThread() == display.getThread();
+ if (item == null) return peer_info;
TreeItem parent = item.getParentItem();
- if (parent == null) return peer_info[peer_tree.indexOf(item)];
PeerInfo info = findPeerInfo(parent);
- if (info.children == null) loadPeerInfo(info);
- return info.children[parent.indexOf(item)];
+ if (info == null) return null;
+ if (info.children == null) return null;
+ if (info.children_error != null) return null;
+ int i = parent == null ? peer_tree.indexOf(item) : parent.indexOf(item);
+ if (i < 0 || i >= info.children.length) return null;
+ assert info.children[i].index == i;
+ return info.children[i];
}
private PeerInfo findPeerInfo(String path) {
@@ -449,26 +563,26 @@ public class TCFMainTab extends AbstractLaunchConfigurationTab {
String id = null;
PeerInfo[] arr = null;
if (i < 0) {
- if (peer_info == null) loadPeerInfo(null);
- arr = peer_info;
+ arr = peer_info.children;
id = path;
}
else {
PeerInfo p = findPeerInfo(path.substring(0, i));
if (p == null) return null;
- if (p.children == null) loadPeerInfo(p);
arr = p.children;
id = path.substring(i + 1);
}
+ if (arr == null) return null;
for (int n = 0; n < arr.length; n++) {
- if (arr[n].attrs.get(IPeer.ATTR_ID).equals(id)) return arr[n];
+ if (arr[n].id.equals(id)) return arr[n];
}
return null;
}
private TreeItem findItem(PeerInfo info) {
if (info == null) return null;
- if (info.parent == null) {
+ assert info.parent != null;
+ if (info.parent == peer_info) {
return peer_tree.getItem(info.index);
}
TreeItem i = findItem(info.parent);
@@ -477,111 +591,6 @@ public class TCFMainTab extends AbstractLaunchConfigurationTab {
return i.getItem(info.index);
}
- private interface DoneFindPeer {
- void doneFindPeer(Collection<Throwable> errors, IPeer peer);
- }
-
- private void findPeer(TreeItem item, final DoneFindPeer done) {
- assert display != null;
- assert Thread.currentThread() == display.getThread();
- final String path = getPath(findPeerInfo(item));
- Protocol.invokeLater(new Runnable() {
- public void run() {
- final Collection<Throwable> errors = new ArrayList<Throwable>();
- try {
- final int i = path.lastIndexOf('/');
- if (i < 0) {
- done.doneFindPeer(errors, Protocol.getLocator().getPeers().get(path));
- }
- else {
- openChannel(path.substring(0, i), errors, new DoneOpenChannel() {
- public void doneOpenChannel(IChannel channel) {
- IPeer peer = null;
- if (channel != null) {
- ILocator locator = channel.getRemoteService(ILocator.class);
- peer = locator.getPeers().get(path.substring(i + 1));
- channel.close();
- }
- done.doneFindPeer(errors, peer);
- }
- });
- }
- }
- catch (Throwable x) {
- errors.add(x);
- done.doneFindPeer(errors, null);
- }
- }
- });
- }
-
- private interface DoneOpenChannel {
- void doneOpenChannel(IChannel channel);
- }
-
- private static class OpenChannelListener implements IChannel.IChannelListener {
-
- private final Collection<Throwable> errors;
- private final IChannel channel;
- private final DoneOpenChannel done;
-
- OpenChannelListener(Collection<Throwable> errors, IChannel channel, DoneOpenChannel done) {
- this.errors = errors;
- this.channel = channel;
- this.done = done;
- channel.addChannelListener(this);
- }
-
- public void onChannelOpened() {
- channel.removeChannelListener(this);
- done.doneOpenChannel(channel);
- }
-
- public void congestionLevel(int level) {
- }
-
- public void onChannelClosed(Throwable e) {
- errors.add(e);
- channel.removeChannelListener(this);
- done.doneOpenChannel(null);
- }
- }
-
- private void openChannel(String path, final Collection<Throwable> errors, final DoneOpenChannel done) {
- assert Protocol.isDispatchThread();
- try {
- int i = path.lastIndexOf('/');
- if (i < 0) {
- IPeer peer = Protocol.getLocator().getPeers().get(path);
- if (peer == null) {
- errors.add(new Exception("Peer not found: " + path));
- done.doneOpenChannel(null);
- return;
- }
- new OpenChannelListener(errors, peer.openChannel(), done);
- }
- else {
- final String id = path.substring(i + 1);
- openChannel(path.substring(0, i), errors, new DoneOpenChannel() {
- public void doneOpenChannel(IChannel channel) {
- if (errors.size() > 0) {
- if (channel != null) channel.close();
- done.doneOpenChannel(null);
- }
- else {
- channel.redirect(id);
- new OpenChannelListener(errors, channel, done);
- }
- }
- });
- }
- }
- catch (Throwable x) {
- errors.add(x);
- done.doneOpenChannel(null);
- }
- }
-
private void runDiagnostics(TreeItem item, boolean loop) {
final Shell shell = new Shell(getShell(), SWT.TITLE | SWT.PRIMARY_MODAL);
GridLayout layout = new GridLayout();
@@ -660,19 +669,16 @@ public class TCFMainTab extends AbstractLaunchConfigurationTab {
});
}
};
- findPeer(item, new DoneFindPeer() {
- public void doneFindPeer(Collection<Throwable> errors, IPeer peer) {
- if (errors.size() > 0) {
- done.done(errors);
+ final PeerInfo info = findPeerInfo(item);
+ Protocol.invokeLater(new Runnable() {
+ public void run() {
+ try {
+ test[0] = new TCFSelfTest(info.peer, done);
}
- else {
- try {
- test[0] = new TCFSelfTest(peer, done);
- }
- catch (Throwable x) {
- errors.add(x);
- done.done(errors);
- }
+ catch (Throwable x) {
+ ArrayList<Throwable> errors = new ArrayList<Throwable>();
+ errors.add(x);
+ done.done(errors);
}
}
});
@@ -686,15 +692,16 @@ public class TCFMainTab extends AbstractLaunchConfigurationTab {
text[3] = info.attrs.get(IPeer.ATTR_IP_HOST);
text[4] = info.attrs.get(IPeer.ATTR_IP_PORT);
item.setText(text);
+ item.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
item.setImage(getImage(getImageName(info)));
- if (info.children == null) loadPeerInfo(info);
- item.setItemCount(info.children.length);
+ if (!canHaveChildren(info)) item.setItemCount(0);
+ else if (info.children == null || info.children_error != null) item.setItemCount(1);
+ else item.setItemCount(info.children.length);
}
private String getPath(PeerInfo info) {
- String id = info.attrs.get(IPeer.ATTR_ID);
- if (info.parent == null) return id;
- return getPath(info.parent) + "/" + id;
+ if (info.parent == peer_info) return info.id;
+ return getPath(info.parent) + "/" + info.id;
}
private Image getImage(String name) {
diff --git a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/local/LocatorService.java b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/local/LocatorService.java
index c08b5ad4d..ace101013 100644
--- a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/local/LocatorService.java
+++ b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/local/LocatorService.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.tm.internal.tcf.services.local;
-import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
@@ -19,7 +18,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import org.eclipse.tm.internal.tcf.core.LocalPeer;
@@ -68,6 +66,7 @@ public class LocatorService implements ILocator {
};
private Thread input_thread = new Thread() {
+ // TODO: implement discovery in slave mode (not needed for Windows)
public void run() {
for (;;) {
try {
@@ -111,33 +110,17 @@ public class LocatorService implements ILocator {
assert peers.get(peer.getID()) == null;
if (peer instanceof LocalPeer) local_peer = (LocalPeer)peer;
peers.put(peer.getID(), peer);
- for (Iterator<LocatorListener> i = listeners.iterator(); i.hasNext(); ) {
- i.next().peerAdded(peer);
- }
+ for (LocatorListener l : listeners) l.peerAdded(peer);
}
public static void removePeer(IPeer peer) {
assert peers.get(peer.getID()) == peer;
peers.remove(peer);
String id = peer.getID();
- for (Iterator<LocatorListener> i = listeners.iterator(); i.hasNext(); ) {
- i.next().peerRemoved(id);
- }
- }
-
- private void notifyPeer(IPeer peer) {
- assert peers.get(peer.getID()) == peer;
- for (Iterator<LocatorListener> i = listeners.iterator(); i.hasNext(); ) {
- i.next().peerChanged(peer);
- }
+ for (LocatorListener l : listeners) l.peerRemoved(id);
}
public static void channelStarted(final AbstractChannel channel) {
- channel.addEventListener(locator, new IChannel.IEventListener() {
- public void event(String name, byte[] data) {
- locator.event(channel, name, data);
- }
- });
channel.addCommandServer(locator, new IChannel.ICommandServer() {
public void command(IToken token, String name, byte[] data) {
locator.command(channel, token, name, data);
@@ -145,19 +128,6 @@ public class LocatorService implements ILocator {
});
}
- @SuppressWarnings("unchecked")
- private void event(AbstractChannel channel, String name, byte[] data) {
- try {
- if (name.equals("Hello")) {
- Collection<String> c = (Collection<String>)JSON.parseSequence(data)[0];
- channel.onLocatorHello(c);
- }
- }
- catch (IOException e) {
- channel.terminate(e);
- }
- }
-
private void command(AbstractChannel channel, IToken token, String name, byte[] data) {
try {
if (name.equals("redirect")) {
@@ -169,6 +139,11 @@ public class LocatorService implements ILocator {
else if (name.equals("sync")) {
channel.sendResult(token, null);
}
+ else if (name.equals("publishPeer")) {
+ // TODO: handle "publishPeer" command from discovery master
+ channel.sendResult(token, JSON.toJSONSequence(new Object[]{
+ new Integer(0), null, new Integer(0) }));
+ }
else {
channel.terminate(new Exception("Illegal command: " + name));
}
@@ -299,7 +274,10 @@ public class LocatorService implements ILocator {
IPeer peer = peers.get(id);
if (peer instanceof RemotePeer) {
if (((RemotePeer)peer).updateAttributes(map)) {
- notifyPeer(peer);
+ for (LocatorListener l : listeners) l.peerChanged(peer);
+ }
+ else {
+ for (LocatorListener l : listeners) l.peerHeartBeat(id);
}
}
else {
diff --git a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/LocatorProxy.java b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/LocatorProxy.java
index 436c93678..c2304c2c9 100644
--- a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/LocatorProxy.java
+++ b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/internal/tcf/services/remote/LocatorProxy.java
@@ -68,7 +68,7 @@ public class LocatorProxy implements ILocator {
public IChannel openChannel() {
assert Protocol.isDispatchThread();
IChannel c = channel.getRemotePeer().openChannel();
- c.redirect(getID());
+ c.redirect(this);
return c;
}
};
diff --git a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/core/AbstractChannel.java b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/core/AbstractChannel.java
index fa974f8fa..0dcd50ac9 100644
--- a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/core/AbstractChannel.java
+++ b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/core/AbstractChannel.java
@@ -101,7 +101,7 @@ public abstract class AbstractChannel implements IChannel {
private static IChannelListener[] listeners_array = new IChannelListener[64];
- private final LinkedList<String> redirect_queue = new LinkedList<String>();
+ private final LinkedList<IPeer> redirect_queue = new LinkedList<IPeer>();
private final Map<Class<?>,IService> local_service_by_class = new HashMap<Class<?>,IService>();
private final Map<Class<?>,IService> remote_service_by_class = new HashMap<Class<?>,IService>();
private final Map<String,IService> local_service_by_name = new HashMap<String,IService>();
@@ -337,17 +337,28 @@ public abstract class AbstractChannel implements IChannel {
LocatorService.channelStarted(this);
}
- public void redirect(String peer_id) {
+ public void redirect(IPeer peer) {
assert Protocol.isDispatchThread();
if (state == STATE_OPENNING) {
assert redirect_command == null;
- redirect_queue.add(peer_id);
+ redirect_queue.add(peer);
}
else {
assert state == STATE_OPEN;
- state = STATE_OPENNING;
try {
- onLocatorHello(new ArrayList<String>());
+ ILocator l = (ILocator)remote_service_by_class.get(ILocator.class);
+ if (l == null) throw new IOException("Peer " + peer.getID() + " has no locator service");
+ this.peer = peer;
+ redirect_command = l.redirect(peer.getID(), new ILocator.DoneRedirect() {
+ public void doneRedirect(IToken token, Exception x) {
+ assert redirect_command == token;
+ state = STATE_OPENNING;
+ redirect_command = null;
+ remote_congestion_level = 0;
+ if (x != null) terminate(x);
+ // Wait for next "Hello"
+ }
+ });
}
catch (Throwable x) {
terminate(x);
@@ -356,7 +367,7 @@ public abstract class AbstractChannel implements IChannel {
}
@SuppressWarnings("unchecked")
- public void onLocatorHello(Collection<String> c) throws IOException {
+ private void onLocatorHello(Collection<String> c) throws IOException {
if (state != STATE_OPENNING) throw new IOException("Invalid event: Locator.Hello");
remote_service_by_class.clear();
String pkg_name = LocatorProxy.class.getPackage().getName();
@@ -377,26 +388,12 @@ public abstract class AbstractChannel implements IChannel {
remote_service_by_name.put(service_name, service);
}
}
+ state = STATE_OPEN;
assert redirect_command == null;
if (redirect_queue.size() > 0) {
- String id = redirect_queue.removeFirst();
- ILocator l = (ILocator)remote_service_by_class.get(ILocator.NAME);
- if (l == null) throw new IOException("Peer " + peer.getID() + " has no locator service");
- peer = l.getPeers().get(id);
- if (peer == null) throw new IOException("Unknown peer ID: " + id);
- redirect_command = l.redirect(id, new ILocator.DoneRedirect() {
- public void doneRedirect(IToken token, Exception x) {
- assert redirect_command == token;
- assert state == STATE_OPENNING;
- redirect_command = null;
- remote_congestion_level = 0;
- if (x != null) terminate(x);
- // Wait for next "Hello"
- }
- });
+ redirect(redirect_queue.removeFirst());
}
else {
- state = STATE_OPEN;
notifying_channel_opened = true;
Transport.channelOpened(this);
listeners_array = channel_listeners.toArray(listeners_array);
@@ -667,6 +664,7 @@ public abstract class AbstractChannel implements IChannel {
addToOutQueue(msg);
}
+ @SuppressWarnings("unchecked")
private void handleInput(Message msg) {
assert Protocol.isDispatchThread();
synchronized (out_queue) {
@@ -711,13 +709,18 @@ public abstract class AbstractChannel implements IChannel {
token.getListener().result(token, msg.data);
break;
case 'E':
- list = event_listeners.get(msg.service);
- if (list != null) {
- for (int i = 0; i < list.length; i++) {
- list[i].event(msg.name, msg.data);
+ if (msg.service.equals(ILocator.NAME) && msg.name.equals("Hello")) {
+ onLocatorHello((Collection<String>)JSON.parseSequence(msg.data)[0]);
+ }
+ else {
+ list = event_listeners.get(msg.service);
+ if (list != null) {
+ for (int i = 0; i < list.length; i++) {
+ list[i].event(msg.name, msg.data);
+ }
}
+ sendCongestionLevel();
}
- sendCongestionLevel();
break;
case 'F':
remote_congestion_level = Integer.parseInt(new String(msg.data, "UTF8"));
diff --git a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/protocol/IChannel.java b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/protocol/IChannel.java
index 158bd80ae..3a8b4e52c 100644
--- a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/protocol/IChannel.java
+++ b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/protocol/IChannel.java
@@ -266,7 +266,7 @@ public interface IChannel {
/**
* Redirect this channel to given peer using this channel remote peer locator service as a proxy.
- * @param peer_id - peer that will become new remote communication endpoint of this channel
+ * @param peer - peer that will become new remote communication endpoint of this channel
*/
- void redirect(String peer_id);
+ void redirect(IPeer peer);
}
diff --git a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/protocol/IPeer.java b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/protocol/IPeer.java
index aa3b1290e..9a49685c3 100644
--- a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/protocol/IPeer.java
+++ b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/protocol/IPeer.java
@@ -29,6 +29,7 @@ public interface IPeer {
ATTR_NAME = "Name",
ATTR_OS_NAME = "OSName",
ATTR_TRANSPORT_NAME = "TransportName",
+ ATTR_PROXY = "Proxy",
ATTR_IP_HOST = "Host",
ATTR_IP_ALIASES = "Aliases",
ATTR_IP_ADDRESSES = "Addresses",
diff --git a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/services/ILocator.java b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/services/ILocator.java
index de04a7c3a..243c16a88 100644
--- a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/services/ILocator.java
+++ b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/services/ILocator.java
@@ -91,10 +91,28 @@ public interface ILocator extends IService {
void removeListener(LocatorListener listener);
interface LocatorListener {
+ /**
+ * A new peer is added into locator peer table.
+ * @param peer
+ */
void peerAdded(IPeer peer);
+ /**
+ * Peer attributes have changed.
+ * @param peer
+ */
void peerChanged(IPeer peer);
+ /**
+ * A peer is removed from locator peer table.
+ * @param id - peer ID
+ */
void peerRemoved(String id);
+
+ /**
+ * Peer heart beat detected.
+ * @param id - peer ID
+ */
+ void peerHeartBeat(String id);
}
} \ No newline at end of file
diff --git a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/util/TCFTask.java b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/util/TCFTask.java
index 160cab4ea..02c21b7d0 100644
--- a/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/util/TCFTask.java
+++ b/plugins/org.eclipse.tm.tcf/src/org/eclipse/tm/tcf/util/TCFTask.java
@@ -103,7 +103,7 @@ public abstract class TCFTask<V> implements Runnable, Future<V> {
public synchronized V get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
unit.toNanos(timeout);
- // TODO Auto-generated method stub
+ // TODO: implement TCFTask.get() with timeout
assert false;
return null;
}

Back to the top