incubator-s4-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmo...@apache.org
Subject [35/50] [abbrv] git commit: moved server config to Module, moved sender/receiver out of apps loop.
Date Tue, 03 Jan 2012 14:03:28 GMT
moved server config to Module, moved sender/receiver out of apps loop.


Project: http://git-wip-us.apache.org/repos/asf/incubator-s4/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s4/commit/c20324fa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s4/tree/c20324fa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s4/diff/c20324fa

Branch: refs/heads/piper
Commit: c20324faf79a980cd4291da23b811f3624c6641a
Parents: 88c4a6d
Author: Leo Neumeyer <leo@s4.io>
Authored: Wed Oct 26 16:47:15 2011 -0700
Committer: Leo Neumeyer <leo@s4.io>
Committed: Wed Oct 26 16:47:15 2011 -0700

----------------------------------------------------------------------
 .../java/org/apache/s4/base/util/S4RLoader.java    |    2 -
 subprojects/s4-core/src/main/java/Test.java        |   17 ------
 .../src/main/java/org/apache/s4/core/Module.java   |   19 ++++---
 .../src/main/java/org/apache/s4/core/Sender.java   |   40 ++++++---------
 .../src/main/java/org/apache/s4/core/Server.java   |   26 +++++-----
 .../s4/core/gen/OverloadDispatcherGenerator.java   |    1 -
 .../s4-core/src/main/resources/s4-core.properties  |    1 +
 .../test/s4/core/apploading/AppLoadingTest.java    |   13 ++---
 8 files changed, 48 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/c20324fa/subprojects/s4-base/src/main/java/org/apache/s4/base/util/S4RLoader.java
----------------------------------------------------------------------
diff --git a/subprojects/s4-base/src/main/java/org/apache/s4/base/util/S4RLoader.java b/subprojects/s4-base/src/main/java/org/apache/s4/base/util/S4RLoader.java
index 0d54454..4fd110d 100644
--- a/subprojects/s4-base/src/main/java/org/apache/s4/base/util/S4RLoader.java
+++ b/subprojects/s4-base/src/main/java/org/apache/s4/base/util/S4RLoader.java
@@ -8,8 +8,6 @@ import java.util.Map;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 
-import com.google.common.collect.MapMaker;
-
 /**
  * 
  * CREDITS

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/c20324fa/subprojects/s4-core/src/main/java/Test.java
----------------------------------------------------------------------
diff --git a/subprojects/s4-core/src/main/java/Test.java b/subprojects/s4-core/src/main/java/Test.java
deleted file mode 100644
index bc73b8f..0000000
--- a/subprojects/s4-core/src/main/java/Test.java
+++ /dev/null
@@ -1,17 +0,0 @@
-import java.net.URL;
-
-
-public class Test {
-
-    /**
-     * @param args
-     */
-    public static void main(String[] args) {
-
-        /* Get the URL for a resource. */
-        Object o = new Object();
-        URL url = o.getClass().getResource("/apps/HelloApp.jar");
-        System.out.println("URL: " + url.toString());
-        System.out.println("Filename: " + url.getFile().toString());
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/c20324fa/subprojects/s4-core/src/main/java/org/apache/s4/core/Module.java
----------------------------------------------------------------------
diff --git a/subprojects/s4-core/src/main/java/org/apache/s4/core/Module.java b/subprojects/s4-core/src/main/java/org/apache/s4/core/Module.java
index 27fb386..799cff8 100644
--- a/subprojects/s4-core/src/main/java/org/apache/s4/core/Module.java
+++ b/subprojects/s4-core/src/main/java/org/apache/s4/core/Module.java
@@ -1,5 +1,6 @@
 package org.apache.s4.core;
 
+import java.io.File;
 import java.io.InputStream;
 
 import org.apache.commons.configuration.ConfigurationConverter;
@@ -23,8 +24,7 @@ public class Module extends AbstractModule {
     private void loadProperties(Binder binder) {
 
         try {
-            InputStream is = this.getClass().getResourceAsStream(
-                    "/s4-core.properties");
+            InputStream is = this.getClass().getResourceAsStream("/s4-core.properties");
             config = new PropertiesConfiguration();
             config.load(is);
 
@@ -32,8 +32,7 @@ public class Module extends AbstractModule {
             // TODO - validate properties.
 
             /* Make all properties injectable. Do we need this? */
-            Names.bindProperties(binder,
-                    ConfigurationConverter.getProperties(config));
+            Names.bindProperties(binder, ConfigurationConverter.getProperties(config));
         } catch (ConfigurationException e) {
             binder.addError(e);
             e.printStackTrace();
@@ -46,8 +45,14 @@ public class Module extends AbstractModule {
             loadProperties(binder());
 
         bind(Server.class).asEagerSingleton();
-//        bind(String.class).annotatedWith(Names.named("core.module"))
-//                .toInstance(config.getString("core.module"));
+
+        /*
+         * Apps dir is searched as follows: The s4.apps.path property in the properties file.
The user's current working
+         * directory under the subdirectory /bin/apps.
+         */
+        String appsDir = config.getString("s4.apps.path", System.getProperty("user.dir")
+ File.separator + "bin"
+                + File.separator + "apps");
+        bind(String.class).annotatedWith(Names.named("appsDir")).toInstance(appsDir);
     }
 
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/c20324fa/subprojects/s4-core/src/main/java/org/apache/s4/core/Sender.java
----------------------------------------------------------------------
diff --git a/subprojects/s4-core/src/main/java/org/apache/s4/core/Sender.java b/subprojects/s4-core/src/main/java/org/apache/s4/core/Sender.java
index 66e1298..dcac5d4 100644
--- a/subprojects/s4-core/src/main/java/org/apache/s4/core/Sender.java
+++ b/subprojects/s4-core/src/main/java/org/apache/s4/core/Sender.java
@@ -6,26 +6,24 @@ import org.apache.s4.base.Hasher;
 import org.apache.s4.base.SerializerDeserializer;
 
 import com.google.inject.Inject;
-
+import com.google.inject.Singleton;
 
 /**
- * The {@link Sender} and its counterpart {@link Receiver} are the top level
- * classes of the communication layer.
+ * The {@link Sender} and its counterpart {@link Receiver} are the top level classes of the
communication layer.
  * <p>
- * {@link Sender} is responsible for sending an event to a
- * {@link ProcessingElement} instance using a hashKey.
+ * {@link Sender} is responsible for sending an event to a {@link ProcessingElement} instance
using a hashKey.
  * <p>
- * Details on how the cluster is partitioned and how events are serialized and
- * transmitted to its destination are hidden from the application developer.
+ * Details on how the cluster is partitioned and how events are serialized and transmitted
to its destination are hidden
+ * from the application developer.
  */
+@Singleton
 public class Sender {
     final private Emitter emitter;
     final private SerializerDeserializer serDeser;
     final private Hasher hasher;
 
     /*
-     * If the local partition id is not initialized, always use the comm layer
-     * to send events.
+     * If the local partition id is not initialized, always use the comm layer to send events.
      */
     private int localPartitionId = -1;
 
@@ -39,30 +37,25 @@ public class Sender {
      *            a hashing function to map keys to partition IDs.
      */
     @Inject
-    public Sender(Emitter emitter, SerializerDeserializer serDeser,
-            Hasher hasher) {
+    public Sender(Emitter emitter, SerializerDeserializer serDeser, Hasher hasher) {
         this.emitter = emitter;
         this.serDeser = serDeser;
         this.hasher = hasher;
     }
 
     /**
-     * This method attempts to send an event to a remote partition. If the
-     * destination is local, the method does not send the event and returns
-     * true. The caller is expected to put the event in a local queue instead.
+     * This method attempts to send an event to a remote partition. If the destination is
local, the method does not
+     * send the event and returns true. The caller is expected to put the event in a local
queue instead.
      * 
      * @param hashKey
-     *            the string used to map the value of a key to a specific
-     *            partition.
+     *            the string used to map the value of a key to a specific partition.
      * @param event
-     *            the event to be delivered to a {@link ProcessingElement}
-     *            instance.
+     *            the event to be delivered to a {@link ProcessingElement} instance.
      * @return true if the event is not sent because the destination is local.
      * 
      */
     public boolean sendAndCheckIfLocal(String hashKey, Event event) {
-        int partition = (int) (hasher.hash(hashKey) % emitter
-                .getPartitionCount());
+        int partition = (int) (hasher.hash(hashKey) % emitter.getPartitionCount());
 
         if (partition == localPartitionId) {
             /* Hey we are in the same JVM, don't use the network. */
@@ -79,12 +72,11 @@ public class Sender {
     }
 
     /**
-     * Send an event to all the remote partitions in the cluster. The caller is
-     * expected to also put the event in a local queue.
+     * Send an event to all the remote partitions in the cluster. The caller is expected
to also put the event in a
+     * local queue.
      * 
      * @param event
-     *            the event to be delivered to {@link ProcessingElement}
-     *            instances.
+     *            the event to be delivered to {@link ProcessingElement} instances.
      */
     public void sendToRemotePartitions(Event event) {
 

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/c20324fa/subprojects/s4-core/src/main/java/org/apache/s4/core/Server.java
----------------------------------------------------------------------
diff --git a/subprojects/s4-core/src/main/java/org/apache/s4/core/Server.java b/subprojects/s4-core/src/main/java/org/apache/s4/core/Server.java
index 20a2e52..fa11979 100644
--- a/subprojects/s4-core/src/main/java/org/apache/s4/core/Server.java
+++ b/subprojects/s4-core/src/main/java/org/apache/s4/core/Server.java
@@ -21,9 +21,8 @@ import com.google.inject.Injector;
 import com.google.inject.name.Named;
 
 /**
- * The Server instance coordinates activities in a cluster node including
- * loading and unloading of applications and instantiating the communication
- * layer.
+ * The Server instance coordinates activities in a cluster node including loading and unloading
of applications and
+ * instantiating the communication layer.
  */
 public class Server {
 
@@ -32,19 +31,20 @@ public class Server {
     final private String commModuleName;
     final private String logLevel;
     public static final String MANIFEST_S4_APP_CLASS = "S4-App-Class";
-    // NOTE: currently we use a directory, but this will be changed by a URL (ref to zookeeper?),

+    // NOTE: currently we use a directory, but this will be changed by a URL (ref to zookeeper?),
     // so that applications can be downloaded from a remote repository
-    final private static String S4_APPS_PATH = System.getProperty("s4.apps.path", System.getProperty("user.dir")
-            + "/bin/apps");
+    final private String appsDir;
     List<App> apps = new ArrayList<App>();
 
     /**
      * 
      */
     @Inject
-    public Server(@Named("comm.module") String commModuleName, @Named("s4.logger_level")
String logLevel) {
+    public Server(@Named("comm.module") String commModuleName, @Named("s4.logger_level")
String logLevel,
+            @Named("appsDir") String appsDir) {
         this.commModuleName = commModuleName;
         this.logLevel = logLevel;
+        this.appsDir = appsDir;
     }
 
     public void start() throws Exception {
@@ -67,9 +67,12 @@ public class Server {
         /* After some indirection we get the injector. */
         injector = Guice.createInjector(module);
 
-        File[] s4rFiles = new File(S4_APPS_PATH).listFiles(new PatternFilenameFilter("\\w+\\.s4r"));
+        Sender sender = injector.getInstance(Sender.class);
+        Receiver receiver = injector.getInstance(Receiver.class);
+
+        File[] s4rFiles = new File(appsDir).listFiles(new PatternFilenameFilter("\\w+\\.s4r"));
         for (File s4rFile : s4rFiles) {
-            loadApp(injector, s4rFile);
+            loadApp(sender, receiver, s4rFile);
         }
 
         // now init + start apps
@@ -80,10 +83,9 @@ public class Server {
         }
 
         logger.info("Completed applications startup");
-
     }
 
-    private void loadApp(Injector injector, File s4r) {
+    private void loadApp(Sender sender, Receiver receiver, File s4r) {
 
         S4RLoader cl = new S4RLoader(s4r.getAbsolutePath());
         try {
@@ -108,8 +110,6 @@ public class Server {
                 return;
             }
 
-            Sender sender = injector.getInstance(Sender.class);
-            Receiver receiver = injector.getInstance(Receiver.class);
             app.setCommLayer(sender, receiver);
             apps.add(app);
         } catch (IOException e) {

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/c20324fa/subprojects/s4-core/src/main/java/org/apache/s4/core/gen/OverloadDispatcherGenerator.java
----------------------------------------------------------------------
diff --git a/subprojects/s4-core/src/main/java/org/apache/s4/core/gen/OverloadDispatcherGenerator.java
b/subprojects/s4-core/src/main/java/org/apache/s4/core/gen/OverloadDispatcherGenerator.java
index 5e2fdec..cfaa6c2 100644
--- a/subprojects/s4-core/src/main/java/org/apache/s4/core/gen/OverloadDispatcherGenerator.java
+++ b/subprojects/s4-core/src/main/java/org/apache/s4/core/gen/OverloadDispatcherGenerator.java
@@ -26,7 +26,6 @@ import java.util.List;
 import java.util.Random;
 
 import org.apache.s4.base.Event;
-import org.apache.s4.base.util.MultiClassLoader;
 import org.apache.s4.base.util.S4RLoader;
 import org.apache.s4.core.ProcessingElement;
 import org.objectweb.asm.ClassWriter;

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/c20324fa/subprojects/s4-core/src/main/resources/s4-core.properties
----------------------------------------------------------------------
diff --git a/subprojects/s4-core/src/main/resources/s4-core.properties b/subprojects/s4-core/src/main/resources/s4-core.properties
index 1a075f4..7db6157 100644
--- a/subprojects/s4-core/src/main/resources/s4-core.properties
+++ b/subprojects/s4-core/src/main/resources/s4-core.properties
@@ -1,4 +1,5 @@
 comm.module = org.apache.s4.comm.Module
 s4.logger_level = TRACE
+#s4.apps.path = /My/Apps/Dir
 
 

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/c20324fa/subprojects/s4-core/src/test/java/test/s4/core/apploading/AppLoadingTest.java
----------------------------------------------------------------------
diff --git a/subprojects/s4-core/src/test/java/test/s4/core/apploading/AppLoadingTest.java
b/subprojects/s4-core/src/test/java/test/s4/core/apploading/AppLoadingTest.java
index d0cf3a8..e88aedf 100644
--- a/subprojects/s4-core/src/test/java/test/s4/core/apploading/AppLoadingTest.java
+++ b/subprojects/s4-core/src/test/java/test/s4/core/apploading/AppLoadingTest.java
@@ -12,7 +12,6 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.jar.JarEntry;
 import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
 
 import org.apache.s4.core.Server;
 import org.apache.zookeeper.ZooKeeper;
@@ -63,7 +62,8 @@ public class AppLoadingTest {
     public void testA() throws Exception, InterruptedException {
 
         // add all classes from counter app
-        File rootAppDir = new File ( new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath()+"/s4-example/bin");
+        File rootAppDir = new File(new File(System.getProperty("user.dir")).getParentFile().getAbsolutePath()
+                + "/s4-example/bin");
         File appFilesDir = new File(rootAppDir, "org/apache/s4/example/counter");
         generateS4RFromDirectoryContents(rootAppDir, appFilesDir, "counterExample",
                 "org.apache.s4.example.counter.MyApp");
@@ -118,16 +118,15 @@ public class AppLoadingTest {
 
     /**
      * 
-     * 1. generates an s4r package from classes in the apploading package (TODO process still
to be improved), 
-     * 2. deploys it to bin/apps 
-     * 3. starts a forked S4 node, which loads apps from bin/apps
-     * 4. verifies app is working (s4 app started, event correctly processed)
+     * 1. generates an s4r package from classes in the apploading package (TODO process still
to be improved), 2.
+     * deploys it to bin/apps 3. starts a forked S4 node, which loads apps from bin/apps
4. verifies app is working (s4
+     * app started, event correctly processed)
      * 
      * NOTE: we'll need to add an automatic test for which we make sure code cannot be in
the classpath
      */
     @Test
     public void testAppLoading() throws Exception {
-        
+
         // TODO fix paths
 
         final ZooKeeper zk = TestUtils.createZkClient();


Mime
View raw message