diff options
author | slewis | 2006-03-07 07:12:16 +0000 |
---|---|---|
committer | slewis | 2006-03-07 07:12:16 +0000 |
commit | 608cd8119ce59d2bc3883ec73d6b0e6ab4bc967b (patch) | |
tree | fcbc45e18f14f2fa48d3cccaca581a4c6c18c53b /doc | |
parent | 4192e5aa84c6307fb32e96fd246026d90f39b7f0 (diff) | |
download | org.eclipse.ecf-608cd8119ce59d2bc3883ec73d6b0e6ab4bc967b.tar.gz org.eclipse.ecf-608cd8119ce59d2bc3883ec73d6b0e6ab4bc967b.tar.xz org.eclipse.ecf-608cd8119ce59d2bc3883ec73d6b0e6ab4bc967b.zip |
Enhanced and simplified new datashare client 2
Diffstat (limited to 'doc')
2 files changed, 12 insertions, 8 deletions
diff --git a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/datashare/DsClient2.java b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/datashare/DsClient2.java index 6414c9b1c..f7d98fe2c 100644 --- a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/datashare/DsClient2.java +++ b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/datashare/DsClient2.java @@ -30,13 +30,16 @@ public class DsClient2 { protected static final String TARGET_SERVER = "ecftcp://localhost:3282/server"; IContainer container = null; IChannel channel = null; + protected IChannel createChannel(IContainer container) throws ECFException { + // Get IChannelContainer adapter IChannelContainer channelContainer = (IChannelContainer) container .getAdapter(IChannelContainer.class); + // Check it's valid, throw if not if (channelContainer == null) throw new NullPointerException( "cannot get channel container adapter"); - // Create channel ID + // Create channel ID with fixed name 'channel2' final ID channelID = IDFactory.getDefault().createID( channelContainer.getChannelNamespace(), "channel2"); // Setup listener so then when channelmessageevents are received that @@ -46,9 +49,7 @@ public class DsClient2 { if (event instanceof IChannelMessageEvent) { IChannelMessageEvent msg = (IChannelMessageEvent) event; showMessageInUI(new String(msg.getData())); - } else { - System.out.println("got channel event " + event); - } + } else System.out.println("got channel event " + event); } }; // Create channel config information @@ -58,6 +59,7 @@ public class DsClient2 { // Create and return new channel return channelContainer.createChannel(config); } + protected void showMessageInUI(final String message) { Display.getDefault().asyncExec(new Runnable() { public void run() { @@ -73,9 +75,8 @@ public class DsClient2 { // create channel channel = createChannel(container); // create target ID - ID targetID = IDFactory.getDefault().createID( - container.getConnectNamespace(), TARGET_SERVER); // connect container to target - container.connect(targetID, null); + container.connect(IDFactory.getDefault().createID( + container.getConnectNamespace(), TARGET_SERVER), null); } } diff --git a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/datashare/MyChannel.java b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/datashare/MyChannel.java index d64b52761..40205a027 100644 --- a/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/datashare/MyChannel.java +++ b/doc/bundles/org.eclipse.ecf.tutorial/src/org/eclipse/ecf/tutorial/datashare/MyChannel.java @@ -27,15 +27,17 @@ public class MyChannel extends BaseChannel { protected void initialize() throws SharedObjectInitException { super.initialize(); - + // Add event processor that responds to IContainerConnectedEvent messages addEventProcessor(new IEventProcessor() { public boolean acceptEvent(Event event) { if (event instanceof IContainerConnectedEvent) return true; return false; } public Event processEvent(Event event) { + // If event is IContainerConnectedEvent if (event instanceof IContainerConnectedEvent) { IContainerConnectedEvent ccevent = (IContainerConnectedEvent) event; + // Check to make sure it's a client...not the groupID if (!ccevent.getTargetID().equals(getGroupID())) sendHelloMessage(); } return event; @@ -44,6 +46,7 @@ public class MyChannel extends BaseChannel { protected void sendHelloMessage() { try { + // send message this.sendMessage(("hello from "+getHomeContainerID().getName()).getBytes()); } catch (ECFException e) { e.printStackTrace(); |