helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zzh...@apache.org
Subject git commit: refactor config-accessor, add external-command
Date Wed, 03 Apr 2013 22:44:42 GMT
Updated Branches:
  refs/heads/master de5dcd293 -> d59b78570


refactor config-accessor, add external-command


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

Branch: refs/heads/master
Commit: d59b78570c15105c258c5fa9abc8b6874b4b8c4f
Parents: de5dcd2
Author: zzhang <zzhang5@uci.edu>
Authored: Wed Apr 3 15:44:23 2013 -0700
Committer: zzhang <zzhang5@uci.edu>
Committed: Wed Apr 3 15:44:23 2013 -0700

----------------------------------------------------------------------
 .../main/java/org/apache/helix/ConfigAccessor.java |   78 +++-
 .../java/org/apache/helix/ExternalCommand.java     |  401 +++++++++++++++
 .../participant/statemachine/StateModelParser.java |    4 +-
 .../java/org/apache/helix/ExternalCommand.java     |  400 --------------
 .../helix/integration/TestMessageThrottle.java     |    2 +-
 5 files changed, 471 insertions(+), 414 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/d59b7857/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java b/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java
index aefb2be..ffe4778 100644
--- a/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java
+++ b/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java
@@ -22,7 +22,9 @@ package org.apache.helix;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.TreeMap;
 
 import org.apache.helix.model.ConfigScope;
@@ -80,13 +82,27 @@ public class ConfigAccessor
    */
   public String get(ConfigScope scope, String key)
   {
+    Map<String, String> map = get(scope, Arrays.asList(key));
+    return map.get(key);
+  }
+  
+  /**
+   * get config values
+   * 
+   * @param scope
+   * @param keys
+   * @return
+   */
+  public Map<String, String> get(ConfigScope scope, List<String> keys)
+  {
     if (scope == null || scope.getScope() == null)
     {
       LOG.error("Scope can't be null");
       return null;
     }
 
-    String value = null;
+    // String value = null;
+    Map<String, String> map = new HashMap<String, String>();
     String clusterName = scope.getClusterName();
     if (!ZKUtil.isClusterSetup(clusterName, zkClient))
     {
@@ -102,28 +118,48 @@ public class ConfigAccessor
     {
       if (splits.length == 1)
       {
-        value = record.getSimpleField(key);
+        for (String key : keys) {
+          if (record.getSimpleFields().containsKey(key)) {
+            map.put(key, record.getSimpleField(key));
+          }
+        }
       }
       else if (splits.length == 2)
       {
         if (record.getMapField(splits[1]) != null)
         {
-          value = record.getMapField(splits[1]).get(key);
+          for (String key : keys) {
+            if (record.getMapField(splits[1]).containsKey(key)) {
+              map.put(key, record.getMapField(splits[1]).get(key));
+            }
+          }
         }
       }
     }
-    return value;
+    return map;
 
   }
 
   /**
-   * Set a config value
+   * Set a config value, create if doesn't exist
    * 
    * @param scope
    * @param key
    * @param value
    */
-  public void set(ConfigScope scope, String key, String value)
+  public void set(ConfigScope scope, String key, String value) {
+    Map<String, String> map = new HashMap<String, String>();
+    map.put(key, value);
+    set(scope, map);
+  }
+  
+  /**
+   * Set config values, create if doesn't exist
+   *
+   * @param scope
+   * @param keyValueMap
+   */
+  public void set(ConfigScope scope, Map<String, String> keyValueMap)
   {
     if (scope == null || scope.getScope() == null)
     {
@@ -153,7 +189,10 @@ public class ConfigAccessor
     ZNRecord update = new ZNRecord(id);
     if (splits.length == 1)
     {
-      update.setSimpleField(key, value);
+      for (String key: keyValueMap.keySet()) {
+        String value = keyValueMap.get(key);
+        update.setSimpleField(key, value);
+      }
     }
     else if (splits.length == 2)
     {
@@ -161,7 +200,10 @@ public class ConfigAccessor
       {
         update.setMapField(splits[1], new TreeMap<String, String>());
       }
-      update.getMapField(splits[1]).put(key, value);
+      for (String key: keyValueMap.keySet()) {
+        String value = keyValueMap.get(key);
+        update.getMapField(splits[1]).put(key, value);
+      }
     }
     ZKUtil.createOrUpdate(zkClient, splits[0], update, true, true);
     return;
@@ -173,7 +215,17 @@ public class ConfigAccessor
    * @param scope
    * @param key
    */
-  public void remove(ConfigScope scope, String key)
+  public void remove(ConfigScope scope, String key) {
+    remove(scope, Arrays.asList(key));
+  }
+  
+  /**
+   * remove config values
+   * 
+   * @param scope
+   * @param keys
+   */
+  public void remove(ConfigScope scope, List<String> keys)
   {
     if (scope == null || scope.getScope() == null)
     {
@@ -195,7 +247,9 @@ public class ConfigAccessor
     if (splits.length == 1)
     {
       // subtract doesn't care about value, use empty string
-      update.setSimpleField(key, "");
+      for (String key : keys) {
+        update.setSimpleField(key, "");
+      }
     }
     else if (splits.length == 2)
     {
@@ -204,7 +258,9 @@ public class ConfigAccessor
         update.setMapField(splits[1], new TreeMap<String, String>());
       }
       // subtract doesn't care about value, use empty string
-      update.getMapField(splits[1]).put(key, "");
+      for (String key : keys) {
+        update.getMapField(splits[1]).put(key, "");
+      }
     }
 
     ZKUtil.subtract(zkClient, splits[0], update);

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/d59b7857/helix-core/src/main/java/org/apache/helix/ExternalCommand.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/ExternalCommand.java b/helix-core/src/main/java/org/apache/helix/ExternalCommand.java
new file mode 100644
index 0000000..5c9d716
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/ExternalCommand.java
@@ -0,0 +1,401 @@
+package org.apache.helix;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeoutException;
+
+import org.apache.log4j.Logger;
+
+public class ExternalCommand
+{
+  public static final String MODULE = ExternalCommand.class.getName();
+  public static final Logger LOG = Logger.getLogger(MODULE);
+
+  private final ProcessBuilder _processBuilder;
+
+  private Process _process;
+  private InputReader _out;
+  private InputReader _err;
+
+  private static class InputReader extends Thread
+  {
+    private static final int BUFFER_SIZE = 2048;
+
+    private final InputStream _in;
+    private final ByteArrayOutputStream _out;
+    private boolean _running = false;
+
+    InputReader(InputStream in)
+    {
+      _in = in;
+      _out = new ByteArrayOutputStream();
+    }
+
+    @Override
+    public void run()
+    {
+      _running = true;
+
+      byte[] buf = new byte[BUFFER_SIZE];
+      int n = 0;
+      try
+      {
+        while((n = _in.read(buf)) != -1)
+          _out.write(buf, 0, n);
+      }
+      catch(IOException e)
+      {
+        LOG.error("error while reading external command", e);
+      }
+
+      _running = false;
+    }
+
+    public byte[] getOutput()
+    {
+      if(_running)
+        throw new IllegalStateException("wait for process to be completed");
+
+      return _out.toByteArray();
+    }
+  }
+  /**
+* Constructor */
+  public ExternalCommand(ProcessBuilder processBuilder)
+  {
+    _processBuilder = processBuilder;
+  }
+
+  /**
+* After creating the command, you have to start it...
+*
+* @throws IOException
+*/
+  public void start() throws IOException
+  {
+    _process = _processBuilder.start();
+    _out = new InputReader(new BufferedInputStream(_process.getInputStream()));
+    _err = new InputReader(new BufferedInputStream(_process.getErrorStream()));
+
+    _out.start();
+    _err.start();
+  }
+
+  /**
+* @see ProcessBuilder
+*/
+  public Map<String, String> getEnvironment()
+  {
+    return _processBuilder.environment();
+  }
+
+  /**
+* @see ProcessBuilder
+*/
+  public File getWorkingDirectory()
+  {
+    return _processBuilder.directory();
+  }
+
+  /**
+* @see ProcessBuilder
+*/
+  public void setWorkingDirectory(File directory)
+  {
+    _processBuilder.directory(directory);
+  }
+
+  /**
+* @see ProcessBuilder
+*/
+  public boolean getRedirectErrorStream()
+  {
+    return _processBuilder.redirectErrorStream();
+  }
+
+  /**
+* @see ProcessBuilder
+*/
+  public void setRedirectErrorStream(boolean redirectErrorStream)
+  {
+    _processBuilder.redirectErrorStream(redirectErrorStream);
+  }
+
+  public byte[] getOutput() throws InterruptedException
+  {
+    waitFor();
+    return _out.getOutput();
+  }
+
+  public byte[] getError() throws InterruptedException
+  {
+    waitFor();
+    return _err.getOutput();
+  }
+
+  /**
+* Returns the output as a string.
+*
+* @param encoding
+* @return encoded string
+* @throws InterruptedException
+* @throws UnsupportedEncodingException
+*/
+  public String getStringOutput(String encoding) throws InterruptedException,
+                                                        UnsupportedEncodingException
+  {
+    return new String(getOutput(), encoding);
+  }
+
+  /**
+* Returns the output as a string. Uses encoding "UTF-8".
+*
+* @return utf8 encoded string
+* @throws InterruptedException
+*/
+  public String getStringOutput() throws InterruptedException
+  {
+    try
+    {
+      return getStringOutput("UTF-8");
+    }
+    catch(UnsupportedEncodingException e)
+    {
+      // should not happen
+      throw new RuntimeException(e);
+    }
+  }
+
+  /**
+* Returns the error as a string.
+*
+* @param encoding
+* @return error as string
+* @throws InterruptedException
+* @throws UnsupportedEncodingException
+*/
+  public String getStringError(String encoding) throws InterruptedException,
+                                                       UnsupportedEncodingException
+  {
+    return new String(getError(), encoding);
+  }
+
+  /**
+* Returns the error as a string. Uses encoding "UTF-8".
+*
+* @return error as string
+* @throws InterruptedException
+*/
+  public String getStringError() throws InterruptedException
+  {
+    try
+    {
+      return getStringError("UTF-8");
+    }
+    catch(UnsupportedEncodingException e)
+    {
+      // should not happen
+      throw new RuntimeException(e);
+    }
+  }
+
+  /**
+* Properly waits until everything is complete: joins on the thread that
+* reads the output, joins on the thread that reads the error and finally
+* wait for the process to be finished.
+* @return the status code of the process.
+*
+* @throws InterruptedException
+*/
+  public int waitFor() throws InterruptedException
+  {
+    if(_process == null)
+      throw new IllegalStateException("you must call start first");
+
+    _out.join();
+    _err.join();
+    return _process.waitFor();
+  }
+
+  /**
+* Properly waits until everything is complete: joins on the thread that
+* reads the output, joins on the thread that reads the error and finally
+* wait for the process to be finished.
+* If the process has not completed before the timeout, throws a
+* {@link TimeoutException}
+* @return the status code of the process.
+*
+* @throws TimeoutException
+* @throws InterruptedException
+*/
+  public int waitFor(long timeout) throws InterruptedException, TimeoutException
+  {
+    if(_process == null)
+      throw new IllegalStateException("you must call start first");
+
+//    Chronos c = new Chronos();
+    _out.join(timeout);
+//    timeout -= c.tick();
+    if (timeout <= 0)
+      throw new TimeoutException("Wait timed out");
+    _err.join(timeout);
+//    timeout -= c.tick();
+    if (timeout <= 0)
+      throw new TimeoutException("Wait timed out");
+
+    // there is no timeout in this API, not much we can do here
+    // waiting on the other two threads should give us some safety
+    return _process.waitFor();
+  }
+
+  public int exitValue()
+  {
+    if(_process == null)
+      throw new IllegalStateException("you must call start first");
+
+    return _process.exitValue();
+  }
+
+  public void destroy()
+  {
+    if(_process == null)
+      throw new IllegalStateException("you must call start first");
+
+    _process.destroy();
+  }
+
+  /**
+* Creates an external process from the command. It is not started and you have to call
+* start on it!
+*
+* @param commands the command to execute
+* @return the process */
+  public static ExternalCommand create(String... commands)
+  {
+    ExternalCommand ec = new ExternalCommand(new ProcessBuilder(commands));
+    return ec;
+  }
+
+  /**
+* Creates an external process from the command. It is not started and you have to call
+* start on it!
+*
+* @param commands the command to execute
+* @return the process */
+  public static ExternalCommand create(List<String> commands)
+  {
+    ExternalCommand ec = new ExternalCommand(new ProcessBuilder(commands));
+    return ec;
+  }
+
+  /**
+* Creates an external process from the command. The command is executed.
+*
+* @param commands the commands to execute
+* @return the process
+* @throws IOException if there is an error */
+  public static ExternalCommand start(String... commands) throws IOException
+  {
+    ExternalCommand ec = new ExternalCommand(new ProcessBuilder(commands));
+    ec.start();
+    return ec;
+  }
+
+  /**
+    * Executes the external command in the given working directory and waits for it to be
+    * finished.
+    *
+    * @param workingDirectory the root directory from where to run the command
+    * @param command the command to execute (should be relative to the working directory
+    * @param args the arguments to the command
+    * @return the process 
+    */
+  public static ExternalCommand execute(File workingDirectory,
+                                        String command,
+                                        String... args)
+      throws IOException, InterruptedException
+  {
+    try
+    {
+      return executeWithTimeout(workingDirectory, command, 0, args);
+    }
+    catch (TimeoutException e)
+    {
+      // Can't happen!
+      throw new IllegalStateException(MODULE + ".execute: Unexpected timeout occurred!");
+    }
+  }
+
+/**
+  * Executes the external command in the given working directory and waits (until timeout
+  * is elapsed) for it to be finished.
+  *
+  * @param workingDirectory
+  * the root directory from where to run the command
+  * @param command
+  * the command to execute (should be relative to the working directory
+  * @param timeout
+  * the maximum amount of time to wait for this external command (in ms). If
+  * this value is less than or equal to 0, timeout is ignored
+  * @param args
+  * the arguments to the command
+  * @return the process
+  */
+  public static ExternalCommand executeWithTimeout(File workingDirectory,
+                                                   String command,
+                                                   long timeout,
+                                                   String... args)
+      throws IOException, InterruptedException, TimeoutException
+  {
+    List<String> arguments = new ArrayList<String>(args.length + 1);
+
+    arguments.add(new File(workingDirectory, command).getAbsolutePath());
+    arguments.addAll(Arrays.asList(args));
+
+    ExternalCommand cmd = ExternalCommand.create(arguments);
+
+    cmd.setWorkingDirectory(workingDirectory);
+
+    cmd.setRedirectErrorStream(true);
+
+    cmd.start();
+
+    /* Use timeout if it is a valid value! */
+    if (timeout <= 0)
+      cmd.waitFor();
+    else
+      cmd.waitFor(timeout);
+
+    if (LOG.isDebugEnabled())
+      LOG.debug(cmd.getStringOutput());
+
+    return cmd;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/d59b7857/helix-core/src/main/java/org/apache/helix/participant/statemachine/StateModelParser.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/participant/statemachine/StateModelParser.java
b/helix-core/src/main/java/org/apache/helix/participant/statemachine/StateModelParser.java
index b7c7c3a..10fd259 100644
--- a/helix-core/src/main/java/org/apache/helix/participant/statemachine/StateModelParser.java
+++ b/helix-core/src/main/java/org/apache/helix/participant/statemachine/StateModelParser.java
@@ -115,8 +115,8 @@ public class StateModelParser
 					Transition annotation = method.getAnnotation(Transition.class);
 					if (annotation != null)
 					{
-						boolean matchesFrom = annotation.from().equalsIgnoreCase(fromState);
-						boolean matchesTo = annotation.to().equalsIgnoreCase(toState);
+						boolean matchesFrom = "*".equals(annotation.from()) || annotation.from().equalsIgnoreCase(fromState);
+						boolean matchesTo = "*".equals(annotation.to()) || annotation.to().equalsIgnoreCase(toState);
 						boolean matchesParamTypes = Arrays.equals(paramTypes,
 						    method.getParameterTypes());
 						if (matchesFrom && matchesTo && matchesParamTypes)

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/d59b7857/helix-core/src/test/java/org/apache/helix/ExternalCommand.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/ExternalCommand.java b/helix-core/src/test/java/org/apache/helix/ExternalCommand.java
deleted file mode 100644
index 63ea6c8..0000000
--- a/helix-core/src/test/java/org/apache/helix/ExternalCommand.java
+++ /dev/null
@@ -1,400 +0,0 @@
-package org.apache.helix;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeoutException;
-
-import org.apache.log4j.Logger;
-
-public class ExternalCommand
-{
-  public static final String MODULE = ExternalCommand.class.getName();
-  public static final Logger LOG = Logger.getLogger(MODULE);
-
-  private final ProcessBuilder _processBuilder;
-
-  private Process _process;
-  private InputReader _out;
-  private InputReader _err;
-
-  private static class InputReader extends Thread
-  {
-    private static final int BUFFER_SIZE = 2048;
-
-    private final InputStream _in;
-    private final ByteArrayOutputStream _out;
-    private boolean _running = false;
-
-    InputReader(InputStream in)
-    {
-      _in = in;
-      _out = new ByteArrayOutputStream();
-    }
-
-    @Override
-    public void run()
-    {
-      _running = true;
-
-      byte[] buf = new byte[BUFFER_SIZE];
-      int n = 0;
-      try
-      {
-        while((n = _in.read(buf)) != -1)
-          _out.write(buf, 0, n);
-      }
-      catch(IOException e)
-      {
-        LOG.error("error while reading external command", e);
-      }
-
-      _running = false;
-    }
-
-    public byte[] getOutput()
-    {
-      if(_running)
-        throw new IllegalStateException("wait for process to be completed");
-
-      return _out.toByteArray();
-    }
-  }
-  /**
-* Constructor */
-  public ExternalCommand(ProcessBuilder processBuilder)
-  {
-    _processBuilder = processBuilder;
-  }
-
-  /**
-* After creating the command, you have to start it...
-*
-* @throws IOException
-*/
-  public void start() throws IOException
-  {
-    _process = _processBuilder.start();
-    _out = new InputReader(new BufferedInputStream(_process.getInputStream()));
-    _err = new InputReader(new BufferedInputStream(_process.getErrorStream()));
-
-    _out.start();
-    _err.start();
-  }
-
-  /**
-* @see ProcessBuilder
-*/
-  public Map<String, String> getEnvironment()
-  {
-    return _processBuilder.environment();
-  }
-
-  /**
-* @see ProcessBuilder
-*/
-  public File getWorkingDirectory()
-  {
-    return _processBuilder.directory();
-  }
-
-  /**
-* @see ProcessBuilder
-*/
-  public void setWorkingDirectory(File directory)
-  {
-    _processBuilder.directory(directory);
-  }
-
-  /**
-* @see ProcessBuilder
-*/
-  public boolean getRedirectErrorStream()
-  {
-    return _processBuilder.redirectErrorStream();
-  }
-
-  /**
-* @see ProcessBuilder
-*/
-  public void setRedirectErrorStream(boolean redirectErrorStream)
-  {
-    _processBuilder.redirectErrorStream(redirectErrorStream);
-  }
-
-  public byte[] getOutput() throws InterruptedException
-  {
-    waitFor();
-    return _out.getOutput();
-  }
-
-  public byte[] getError() throws InterruptedException
-  {
-    waitFor();
-    return _err.getOutput();
-  }
-
-  /**
-* Returns the output as a string.
-*
-* @param encoding
-* @return encoded string
-* @throws InterruptedException
-* @throws UnsupportedEncodingException
-*/
-  public String getStringOutput(String encoding) throws InterruptedException,
-                                                        UnsupportedEncodingException
-  {
-    return new String(getOutput(), encoding);
-  }
-
-  /**
-* Returns the output as a string. Uses encoding "UTF-8".
-*
-* @return utf8 encoded string
-* @throws InterruptedException
-*/
-  public String getStringOutput() throws InterruptedException
-  {
-    try
-    {
-      return getStringOutput("UTF-8");
-    }
-    catch(UnsupportedEncodingException e)
-    {
-      // should not happen
-      throw new RuntimeException(e);
-    }
-  }
-
-  /**
-* Returns the error as a string.
-*
-* @param encoding
-* @return error as string
-* @throws InterruptedException
-* @throws UnsupportedEncodingException
-*/
-  public String getStringError(String encoding) throws InterruptedException,
-                                                       UnsupportedEncodingException
-  {
-    return new String(getError(), encoding);
-  }
-
-  /**
-* Returns the error as a string. Uses encoding "UTF-8".
-*
-* @return error as string
-* @throws InterruptedException
-*/
-  public String getStringError() throws InterruptedException
-  {
-    try
-    {
-      return getStringError("UTF-8");
-    }
-    catch(UnsupportedEncodingException e)
-    {
-      // should not happen
-      throw new RuntimeException(e);
-    }
-  }
-
-  /**
-* Properly waits until everything is complete: joins on the thread that
-* reads the output, joins on the thread that reads the error and finally
-* wait for the process to be finished.
-* @return the status code of the process.
-*
-* @throws InterruptedException
-*/
-  public int waitFor() throws InterruptedException
-  {
-    if(_process == null)
-      throw new IllegalStateException("you must call start first");
-
-    _out.join();
-    _err.join();
-    return _process.waitFor();
-  }
-
-  /**
-* Properly waits until everything is complete: joins on the thread that
-* reads the output, joins on the thread that reads the error and finally
-* wait for the process to be finished.
-* If the process has not completed before the timeout, throws a
-* {@link TimeoutException}
-* @return the status code of the process.
-*
-* @throws TimeoutException
-* @throws InterruptedException
-*/
-  public int waitFor(long timeout) throws InterruptedException, TimeoutException
-  {
-    if(_process == null)
-      throw new IllegalStateException("you must call start first");
-
-//    Chronos c = new Chronos();
-    _out.join(timeout);
-//    timeout -= c.tick();
-    if (timeout <= 0)
-      throw new TimeoutException("Wait timed out");
-    _err.join(timeout);
-//    timeout -= c.tick();
-    if (timeout <= 0)
-      throw new TimeoutException("Wait timed out");
-
-    // there is no timeout in this API, not much we can do here
-    // waiting on the other two threads should give us some safety
-    return _process.waitFor();
-  }
-
-  public int exitValue()
-  {
-    if(_process == null)
-      throw new IllegalStateException("you must call start first");
-
-    return _process.exitValue();
-  }
-
-  public void destroy()
-  {
-    if(_process == null)
-      throw new IllegalStateException("you must call start first");
-
-    _process.destroy();
-  }
-
-  /**
-* Creates an external process from the command. It is not started and you have to call
-* start on it!
-*
-* @param commands the command to execute
-* @return the process */
-  public static ExternalCommand create(String... commands)
-  {
-    ExternalCommand ec = new ExternalCommand(new ProcessBuilder(commands));
-    return ec;
-  }
-
-  /**
-* Creates an external process from the command. It is not started and you have to call
-* start on it!
-*
-* @param commands the command to execute
-* @return the process */
-  public static ExternalCommand create(List<String> commands)
-  {
-    ExternalCommand ec = new ExternalCommand(new ProcessBuilder(commands));
-    return ec;
-  }
-
-  /**
-* Creates an external process from the command. The command is executed.
-*
-* @param commands the commands to execute
-* @return the process
-* @throws IOException if there is an error */
-  public static ExternalCommand start(String... commands) throws IOException
-  {
-    ExternalCommand ec = new ExternalCommand(new ProcessBuilder(commands));
-    ec.start();
-    return ec;
-  }
-
-  /**
-* Executes the external command in the given working directory and waits for it to be
-* finished.
-*
-* @param workingDirectory the root directory from where to run the command
-* @param command the command to execute (should be relative to the working directory
-* @param args the arguments to the command
-* @return the process */
-  public static ExternalCommand execute(File workingDirectory,
-                                        String command,
-                                        String... args)
-      throws IOException, InterruptedException
-  {
-    try
-    {
-      return executeWithTimeout(workingDirectory, command, 0, args);
-    }
-    catch (TimeoutException e)
-    {
-      // Can't happen!
-      throw new IllegalStateException(MODULE + ".execute: Unexpected timeout occurred!");
-    }
-  }
-
-/**
-* Executes the external command in the given working directory and waits (until timeout
-* is elapsed) for it to be finished.
-*
-* @param workingDirectory
-* the root directory from where to run the command
-* @param command
-* the command to execute (should be relative to the working directory
-* @param timeout
-* the maximum amount of time to wait for this external command (in ms). If
-* this value is less than or equal to 0, timeout is ignored
-* @param args
-* the arguments to the command
-* @return the process
-*/
-  public static ExternalCommand executeWithTimeout(File workingDirectory,
-                                                   String command,
-                                                   long timeout,
-                                                   String... args)
-      throws IOException, InterruptedException, TimeoutException
-  {
-    List<String> arguments = new ArrayList<String>(args.length + 1);
-
-    arguments.add(new File(workingDirectory, command).getAbsolutePath());
-    arguments.addAll(Arrays.asList(args));
-
-    ExternalCommand cmd = ExternalCommand.create(arguments);
-
-    cmd.setWorkingDirectory(workingDirectory);
-
-    cmd.setRedirectErrorStream(true);
-
-    cmd.start();
-
-    /* Use timeout if it is a valid value! */
-    if (timeout <= 0)
-      cmd.waitFor();
-    else
-      cmd.waitFor(timeout);
-
-    if (LOG.isDebugEnabled())
-      LOG.debug(cmd.getStringOutput());
-
-    return cmd;
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/d59b7857/helix-core/src/test/java/org/apache/helix/integration/TestMessageThrottle.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestMessageThrottle.java
b/helix-core/src/test/java/org/apache/helix/integration/TestMessageThrottle.java
index 4cf8c80..39c75fc 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestMessageThrottle.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestMessageThrottle.java
@@ -80,7 +80,7 @@ public class TestMessageThrottle extends ZkIntegrationTestBase
     HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
     ConstraintItemBuilder builder = new ConstraintItemBuilder();
     builder.addConstraintAttribute("MESSAGE_TYPE", "STATE_TRANSITION")
-           .addConstraintAttribute("InSTANCE", ".*")
+           .addConstraintAttribute("INSTANCE", ".*")
            .addConstraintAttribute("CONSTRAINT_VALUE", "1");
     
 //    Map<String, String> constraints = new TreeMap<String, String>();


Mime
View raw message