Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkgilmer2005-04-23 20:53:44 +0000
committerkgilmer2005-04-23 20:53:44 +0000
commitbea8c0261730bd595bc5aa41622c5bb944cd5275 (patch)
tree51295b39bf8611c02e884535ab892c0c9eeab6cb
parent08b620133dc71fe039b33f8f453226eb27daab43 (diff)
downloadorg.eclipse.ecf-bea8c0261730bd595bc5aa41622c5bb944cd5275.tar.gz
org.eclipse.ecf-bea8c0261730bd595bc5aa41622c5bb944cd5275.tar.xz
org.eclipse.ecf-bea8c0261730bd595bc5aa41622c5bb944cd5275.zip
Initial Checkin
-rw-r--r--doc/bundles/org.eclipse.ecf.doc/html/gettingstarted/helloworld.html89
1 files changed, 89 insertions, 0 deletions
diff --git a/doc/bundles/org.eclipse.ecf.doc/html/gettingstarted/helloworld.html b/doc/bundles/org.eclipse.ecf.doc/html/gettingstarted/helloworld.html
new file mode 100644
index 000000000..95766da1c
--- /dev/null
+++ b/doc/bundles/org.eclipse.ecf.doc/html/gettingstarted/helloworld.html
@@ -0,0 +1,89 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+ <link href="default_style.css" rel=stylesheet/>
+</head>
+<body>
+<h2>The Classic Hello World Example for ECF</h2>
+<h3>Overview</h3>
+<p>As a simple first look at ECF, take a look at implementing a simple "Hello World" plugin that can send messages to other instances of the example app.
+ As a messaging application, or example is only really useful when multiple instances are running.</p>
+<h3>The Plugin Perspective</h3>
+<p>So what we are going to do is create an Eclipse plugin that contributes to the workbench via the actionSets extension point. We will create a simple action
+ that will trigger the instantiation of our Hello World client class:<br><pre>public void run(IAction action) {
+ HelloClient client = new HelloClient();
+ try {
+ client.createAndConnect(IDFactory.makeStringID("ecftcp://localhost:3282/server"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+}</pre> From the example source code provided, you can see the Eclipse plugin infrastructure
+ code in the HelloPlugin and HelloAction classes. These classes will not be discussed in this tutorial as they are not relevent to ECF.</br></p>
+<h3>The ECF Perspective</h3>
+<p>When we create our client class, HelloClient, from our action, we will provide the class with some setup information it needs to connect to an ECF server:<br><pre>public class HelloClient {
+
+ public static final String DEFAULT_CONTAINER_TYPE = "org.eclipse.ecf.provider.generic.Client";
+ public static final String SHARED_OBJECT_ID = "myobject";
+
+ public HelloClient() {
+ super();
+ }
+
+ public ISharedObjectContainer createAndConnect(ID groupID) {
+ ISharedObjectContainer container = null;
+ try {
+ // Create container instance via ECF container factory
+ container = SharedObjectContainerFactory.makeSharedObjectContainer(DEFAULT_CONTAINER_TYPE);
+ // Create ID for shared object
+ ID sharedObjectID = IDFactory.makeStringID(SHARED_OBJECT_ID);
+ // Create actual shared object
+ ISharedObject sharedObject = new HelloSharedObject();
+ // Add shared object to container
+ container.getSharedObjectManager().addSharedObject(sharedObjectID,sharedObject,new HashMap(),null);
+ // Join group identified by groupID
+ container.joinGroup(groupID,null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return container;
+ }
+}</pre></br> Note for this Hello
+ World example to be able to join a shared container, an instance of <code>org.eclipse.ecf.provider.app.ServerApplication</code> in the
+ <code>org.eclipse.ecf.example.collab</code> needs to be running on the same machine. The configuration information we are passing to the HelloClient is the following:
+ <ol>
+ <li>An ID to represent the group of contained object.<pre>client.createAndConnect(IDFactory.makeStringID("ecftcp://localhost:3282/server"));</pre>
+ <ul><li>This ID is passed into HelloClient.createAndConnect().
+ This ID is shared among all instances of our application that communicate with each other.</li><li>You may notice a URI-style protocol descriptor in our example.
+ This tells the shared container what protocol to use when adding instances of SharedObjects to the container.</li></ul>
+ </li>
+ <li>An ID to represent the particular type of shared object that is being shared.<pre>public static final String SHARED_OBJECT_ID = "myobject";</pre>
+ <ul><li>We define one of these Shared Object IDs for our application.
+ If we wanted to create another application that used the same container, but required a seperate event queue, we would define a new Shared Object ID.</li><li>For example,
+ If we wanted to create a Japanese version of Hello World, using an ID seperate from the English version would ensure that no English-only reading clients would be
+ burdened with figuring out what "Konichiwa Minasan" means.</li></ul></li>
+ <li>A classname that defines in what ways the instances of our shared objects will be able to communicate.<pre>public static final String DEFAULT_CONTAINER_TYPE = "org.eclipse.ecf.provider.generic.Client";</pre>
+ <li>For our example, we will use the org.eclipse.ecf.provider.generic.Client class. You can see an example of this class in the <code>org.eclipse.ecf.provider.comm.tcp.Client</code> class in the <code>org.eclipse.ecf.provider</code> plugin.</li></li>
+ </ol>
+ With this information, a SharedContainer is created. From there, we simply create an instance of a SharedObject, in this case the HelloSharedObject class, and join it to the group.
+ From there, all instances in the container will be able to communicate in this code block:<br><pre> public void handleEvent(Event event) {
+ if (event instanceof ISharedObjectActivatedEvent) {
+ System.out.println("HELLO WORLD "+getID()+". I'm activated!");
+ } else if (event instanceof ISharedObjectDeactivatedEvent) {
+ System.out.println("GOODBYE from "+getID()+". I'm deactivated!");
+ } else if (event instanceof ISharedObjectContainerJoinedEvent) {
+ System.out.println("Remote "+((ISharedObjectContainerJoinedEvent)event).getJoinedContainerID()+" joined!");
+ } else if (event instanceof ISharedObjectContainerDepartedEvent) {
+ System.out.println("Remote "+((ISharedObjectContainerDepartedEvent)event).getDepartedContainerID()+" departed!");
+ } else if (event instanceof ISharedObjectMessageEvent) {
+ ISharedObjectMessageEvent evt = (ISharedObjectMessageEvent) event;
+ System.out.println("Got message "+evt.getData()+" from "+evt.getSenderSharedObjectID());
+ }
+ }</pre></br>
+ </p>
+ <h3>Conclusion</h3>
+ <p>All the "application logic" of our Hello World example is defined in the HelloSharedObject class and this really is the core value that ECF provides.
+ To grow our application, there are specific parts in the framework for various logical aspects of communication. For example, to add another protocol,
+ we would only need to create a new protocol provider, and our core messaging logic would remain untouched.
+ <p>The source code used in this example may be found at [].</p>
+</body>
+</html>

Back to the top