You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by gt...@apache.org on 2015/02/06 23:53:42 UTC

svn commit: r1657983 - in /river/river-examples/river-examples/trunk/hello-client: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/river/ src/main/java/org/apache/river/examples/ src/main/java/org/...

Author: gtrasuk
Date: Fri Feb  6 22:53:42 2015
New Revision: 1657983

URL: http://svn.apache.org/r1657983
Log:
The set of examples is complete, including the client.  To use the project, follow the instructions starting in README.md.

Added:
    river/river-examples/river-examples/trunk/hello-client/   (with props)
    river/river-examples/river-examples/trunk/hello-client/pom.xml
    river/river-examples/river-examples/trunk/hello-client/src/
    river/river-examples/river-examples/trunk/hello-client/src/main/
    river/river-examples/river-examples/trunk/hello-client/src/main/java/
    river/river-examples/river-examples/trunk/hello-client/src/main/java/org/
    river/river-examples/river-examples/trunk/hello-client/src/main/java/org/apache/
    river/river-examples/river-examples/trunk/hello-client/src/main/java/org/apache/river/
    river/river-examples/river-examples/trunk/hello-client/src/main/java/org/apache/river/examples/
    river/river-examples/river-examples/trunk/hello-client/src/main/java/org/apache/river/examples/hello/
    river/river-examples/river-examples/trunk/hello-client/src/main/java/org/apache/river/examples/hello/client/
    river/river-examples/river-examples/trunk/hello-client/src/main/java/org/apache/river/examples/hello/client/App.java

Propchange: river/river-examples/river-examples/trunk/hello-client/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Feb  6 22:53:42 2015
@@ -0,0 +1 @@
+target

Added: river/river-examples/river-examples/trunk/hello-client/pom.xml
URL: http://svn.apache.org/viewvc/river/river-examples/river-examples/trunk/hello-client/pom.xml?rev=1657983&view=auto
==============================================================================
--- river/river-examples/river-examples/trunk/hello-client/pom.xml (added)
+++ river/river-examples/river-examples/trunk/hello-client/pom.xml Fri Feb  6 22:53:42 2015
@@ -0,0 +1,67 @@
+<?xml version="1.0"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.river.examples</groupId>
+        <artifactId>river-examples</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <groupId>org.apache.river.examples</groupId>
+    <artifactId>hello-client</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <name>hello-client</name>
+    <url>http://maven.apache.org</url>
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+    <dependencies>
+        <!-- Note that the versions for these are specified in the parent
+        pom's dependency management section. 
+        -->
+        <dependency>
+            <groupId>net.jini</groupId>
+            <artifactId>jsk-platform</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>net.jini</groupId>
+            <artifactId>jsk-lib</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>net.jini</groupId>
+            <artifactId>jsk-resources</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.river</groupId>
+            <artifactId>start</artifactId>
+            <version>2.2.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.river.examples</groupId>
+            <artifactId>hello-api</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+    </dependencies>
+    
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                
+                <configuration>
+                    <archive>
+                        <manifest>
+                            <addClasspath>true</addClasspath>
+                            <classpathLayoutType>custom</classpathLayoutType>
+                            <customClasspathLayout>
+                                ${artifact.artifactId}.${artifact.extension}
+                            </customClasspathLayout>
+                        </manifest>
+                    </archive>
+                </configuration>
+               
+            </plugin>
+        </plugins>
+    </build>
+</project>

Added: river/river-examples/river-examples/trunk/hello-client/src/main/java/org/apache/river/examples/hello/client/App.java
URL: http://svn.apache.org/viewvc/river/river-examples/river-examples/trunk/hello-client/src/main/java/org/apache/river/examples/hello/client/App.java?rev=1657983&view=auto
==============================================================================
--- river/river-examples/river-examples/trunk/hello-client/src/main/java/org/apache/river/examples/hello/client/App.java (added)
+++ river/river-examples/river-examples/trunk/hello-client/src/main/java/org/apache/river/examples/hello/client/App.java Fri Feb  6 22:53:42 2015
@@ -0,0 +1,67 @@
+package org.apache.river.examples.hello.client;
+
+import com.sun.jini.start.LifeCycle;
+import java.util.Scanner;
+import net.jini.config.Configuration;
+import net.jini.config.ConfigurationProvider;
+import net.jini.core.entry.Entry;
+import net.jini.core.lookup.ServiceItem;
+import net.jini.core.lookup.ServiceTemplate;
+import net.jini.lookup.ServiceDiscoveryManager;
+import net.jini.security.ProxyPreparer;
+import org.apache.river.examples.hello.api.Greeter;
+
+/**
+ * Hello world!
+ *
+ */
+public class App {
+
+    private static final String MODULE=App.class.getPackage().getName();
+    
+    public App(final String[] args, LifeCycle lc) {
+        main(args);
+    }
+    
+    public static synchronized void main(String[] args) {
+        try {
+            // Get the config
+            Configuration config = ConfigurationProvider.getInstance(args);
+            // From the config, get the ServiceDiscoveryManager
+            ServiceDiscoveryManager sdm=
+                    (ServiceDiscoveryManager) 
+                    config.getEntry(MODULE, "sdm", ServiceDiscoveryManager.class);
+            // We'll also need a proxy preparer.
+            ProxyPreparer preparer=(ProxyPreparer) config.getEntry(MODULE, 
+                    "greeterPreparer", ProxyPreparer.class);
+            // While the sdm is finding registrars, let's ask the user for their
+            // name.
+            Scanner in = new Scanner(System.in);
+            System.out.println("Please enter your name:");
+            String name = in.nextLine();
+            // Query the sdm for Greeter services.
+            ServiceTemplate template=new ServiceTemplate(
+                    null,
+                    new Class[] { Greeter.class },
+                    new Entry[0]
+            );
+            ServiceItem[] serviceItems=sdm.lookup(template, 5, null);
+            if (serviceItems.length==0) {
+                System.out.println("We didn't find any greeter services.");
+                System.exit(0);
+            }
+            // Pick a service item
+            ServiceItem chosen=serviceItems[0];
+            // Prepare the proxy.
+            Greeter greeter=(Greeter) preparer.prepareProxy(chosen.service);
+            // Make the call
+            String message=greeter.sayHello(name);
+            // Print the result
+            System.out.println("Greeter replied '" + message + "'.");
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        } finally {
+            System.exit(0);
+        }
+    }
+}