summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-04-12 03:40:37 (EDT)
committerEike Stepper2008-04-12 03:40:37 (EDT)
commitf8db92014f016c5901a406fc9d93384cd5b5c368 (patch)
treeaba8ce130121e306f915a2fb4595f5fc097aeaaa
parentdecf18a8ba3fbae5ff3bac83bdb4aeb686e2be54 (diff)
downloadcdo-f8db92014f016c5901a406fc9d93384cd5b5c368.zip
cdo-f8db92014f016c5901a406fc9d93384cd5b5c368.tar.gz
cdo-f8db92014f016c5901a406fc9d93384cd5b5c368.tar.bz2
[226793] Provide an ECHOProtocol example
https://bugs.eclipse.org/bugs/show_bug.cgi?id=226793
-rw-r--r--plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/echo/EchoProtocol.java21
-rw-r--r--plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/echo/client/EchoClient.java65
2 files changed, 86 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/echo/EchoProtocol.java b/plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/echo/EchoProtocol.java
new file mode 100644
index 0000000..87a2dbb
--- /dev/null
+++ b/plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/echo/EchoProtocol.java
@@ -0,0 +1,21 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.examples.echo;
+
+/**
+ * @author Eike Stepper
+ */
+public interface EchoProtocol
+{
+ public static final String PROTOCOL_NAME = "echo";
+
+ public static final short ECHO_SIGNAL = 1;
+}
diff --git a/plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/echo/client/EchoClient.java b/plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/echo/client/EchoClient.java
new file mode 100644
index 0000000..ee907dc
--- /dev/null
+++ b/plugins/org.eclipse.net4j.examples/src/org/eclipse/net4j/examples/echo/client/EchoClient.java
@@ -0,0 +1,65 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.examples.echo.client;
+
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.examples.echo.EchoProtocol;
+import org.eclipse.net4j.internal.util.om.log.PrintLogHandler;
+import org.eclipse.net4j.internal.util.om.trace.PrintTraceHandler;
+import org.eclipse.net4j.tcp.TCPUtil;
+import org.eclipse.net4j.util.container.ContainerUtil;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.OMPlatform;
+
+/**
+ * @author Eike Stepper
+ */
+public class EchoClient
+{
+ public static void main(String[] args) throws Exception
+ {
+ // Send all traces and logs to the console
+ OMPlatform.INSTANCE.setDebugging(true);
+ OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);
+ OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
+
+ // Use this container to create and wire the components
+ IManagedContainer container = ContainerUtil.createContainer();
+
+ try
+ {
+ Net4jUtil.prepareContainer(container);
+ TCPUtil.prepareContainer(container);
+ container.registerFactory(new EchoClientProtocol.Factory());
+ LifecycleUtil.activate(container);
+
+ // Start a connector
+ IConnector connector = (IConnector)container.getElement("org.eclipse.net4j.connectors", "tcp", "localhost:2036");
+
+ // Open a virtual channel with the ECHO protocol, send an ECHO request and close the channel
+ IChannel channel = connector.openChannel(EchoProtocol.PROTOCOL_NAME, null);
+ EchoRequest request = new EchoRequest(channel, "My cool message");
+ String echo = request.send();
+ channel.close();
+
+ System.out.println();
+ System.out.println("ECHO: " + echo);
+ System.out.println();
+ }
+ finally
+ {
+ LifecycleUtil.deactivate(container);
+ }
+ }
+}