[infinispan-commits] Infinispan SVN: r1582 - in trunk: server/core/src/main/java/org/infinispan/server/core/transport and 6 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Tue Mar 9 11:01:41 EST 2010


Author: galder.zamarreno at jboss.com
Date: 2010-03-09 11:01:38 -0500 (Tue, 09 Mar 2010)
New Revision: 1582

Added:
   trunk/server/core/src/main/java/org/infinispan/server/core/Main.java
   trunk/server/core/src/main/java/org/infinispan/server/core/Protocol.java
   trunk/server/core/src/main/java/org/infinispan/server/core/ProtocolServer.java
   trunk/server/core/src/main/java/org/infinispan/server/core/transport/Server.java
   trunk/server/core/src/main/resources/startServer.bat
   trunk/server/core/src/main/resources/startServer.sh
Removed:
   trunk/server/core/src/main/java/org/infinispan/server/core/CommandDecoder.java
   trunk/server/core/src/main/java/org/infinispan/server/core/Server.java
Modified:
   trunk/server/core/src/main/java/org/infinispan/server/core/transport/netty/NettyServer.java
   trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodServer.scala
   trunk/server/memcached/src/main/java/org/infinispan/server/memcached/Main.java
   trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextServer.java
   trunk/server/memcached/src/main/resources/sample_python_memcached_client.py
   trunk/src/main/resources/assemblies/all.xml
Log:
[ISPN-353] (Add a single shell script to handle cache server startup) Added startServer.sh/bat scripts, refactored Main into the server-core module and added server-core to the all.xml assembly.


Deleted: trunk/server/core/src/main/java/org/infinispan/server/core/CommandDecoder.java
===================================================================
--- trunk/server/core/src/main/java/org/infinispan/server/core/CommandDecoder.java	2010-03-09 14:55:47 UTC (rev 1581)
+++ trunk/server/core/src/main/java/org/infinispan/server/core/CommandDecoder.java	2010-03-09 16:01:38 UTC (rev 1582)
@@ -1,34 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.core;
-
-/**
- * CommandDecoder.
- * 
- * @author Galder Zamarreño
- * @since 4.0
- */
- at Deprecated
-public interface CommandDecoder {
-
-}

Added: trunk/server/core/src/main/java/org/infinispan/server/core/Main.java
===================================================================
--- trunk/server/core/src/main/java/org/infinispan/server/core/Main.java	                        (rev 0)
+++ trunk/server/core/src/main/java/org/infinispan/server/core/Main.java	2010-03-09 16:01:38 UTC (rev 1582)
@@ -0,0 +1,284 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.infinispan.server.core;
+
+import gnu.getopt.Getopt;
+import gnu.getopt.LongOpt;
+import org.infinispan.Version;
+import org.infinispan.util.Util;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ThreadFactory;
+
+/**
+ * // TODO: Document this
+ *
+ * @author Galder Zamarreño
+ */
+public class Main {
+
+   private static final Log log = LogFactory.getLog(Main.class);
+   public static final String PROP_KEY_PORT = "infinispan.server.port";
+   public static final String PROP_KEY_HOST = "infinispan.server.host";
+   public static final String PROP_KEY_MASTER_THREADS = "infinispan.server.master.threads";
+   public static final String PROP_KEY_WORKER_THREADS = "infinispan.server.worker.threads";
+   public static final String PROP_KEY_CACHE_CONFIG = "infinispan.server.cache.config";
+   public static final String PROP_KEY_PROTOCOL = "infinispan.server.protocol";
+
+   public static final int PORT_DEFAULT = 11211;
+   public static final String HOST_DEFAULT = "127.0.0.1";
+   public static final int MASTER_THREADS_DEFAULT = 0;
+   public static final int WORKER_THREADS_DEFAULT = 0;
+
+   /**
+    * Server properties.  This object holds all of the required
+    * information to get the server up and running. Use System
+    * properties for defaults.
+    */
+   private Map<String, String> props = new HashMap<String, String>();
+
+   private ProtocolServer server;
+
+   /**
+    * Explicit constructor.
+    */
+   public Main() {
+      // Set default properties
+      Properties sysProps = System.getProperties();
+      for (Object propName : sysProps.keySet()) {
+         String propNameString = (String) propName;
+         String propValue = (String) sysProps.get(propNameString);
+         props.put(propNameString, propValue);
+      }
+   }
+
+   public void boot(String[] args) throws Exception {
+      // First process the command line to pickup custom props/settings
+      processCommandLine(args);
+
+      int port = props.get(PROP_KEY_PORT) == null ? PORT_DEFAULT : Integer.parseInt(props.get(PROP_KEY_PORT));
+      String host = props.get(PROP_KEY_HOST) == null ? HOST_DEFAULT : props.get(PROP_KEY_HOST);
+      int masterThreads = props.get(PROP_KEY_MASTER_THREADS) == null ? MASTER_THREADS_DEFAULT : Integer.parseInt(props.get(PROP_KEY_MASTER_THREADS));
+      if (masterThreads < 0) {
+         throw new IllegalArgumentException("Master threads can't be lower than 0: " + masterThreads);
+      }
+      int workerThreads = props.get(PROP_KEY_WORKER_THREADS) == null ? WORKER_THREADS_DEFAULT : Integer.parseInt(props.get(PROP_KEY_WORKER_THREADS));
+      if (workerThreads < 0) {
+         throw new IllegalArgumentException("Worker threads can't be lower than 0: " + masterThreads);
+      }
+      String configFile = props.get(PROP_KEY_CACHE_CONFIG);
+
+      String protocol = props.get(PROP_KEY_PROTOCOL);
+      Protocol p = protocol == null ? Protocol.HOTROD : Protocol.valueOf(protocol.toUpperCase());
+      server = (ProtocolServer) Util.getInstance(p.clazz);
+      addShutdownHook(new ShutdownHook(server)); // Make a shutdown hook
+      server.start(host, port, configFile, masterThreads, workerThreads);
+   }
+
+   private void processCommandLine(String[] args) throws Exception {
+      // set this from a system property or default to jboss
+      String programName = System.getProperty("program.name", "InfinispanServer");
+      // TODO: Since this memcached/hotrod implementation stores stuff as byte[], these could be implemented in the future:
+      // -m <num>      max memory to use for items in megabytes (default: 64 MB)
+      // -M            return error on memory exhausted (rather than removing items)
+      String sopts = "-:hD:Vp:l:m:t:c:r:";
+      LongOpt[] lopts =
+      {new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h'),
+            new LongOpt("version", LongOpt.NO_ARGUMENT, null, 'V'),
+            new LongOpt("port", LongOpt.REQUIRED_ARGUMENT, null, 'p'),
+            new LongOpt("host", LongOpt.REQUIRED_ARGUMENT, null, 'l'),
+            new LongOpt("master_threads", LongOpt.REQUIRED_ARGUMENT, null, 'm'),
+            new LongOpt("worker_threads", LongOpt.REQUIRED_ARGUMENT, null, 't'),
+            new LongOpt("cache_config", LongOpt.REQUIRED_ARGUMENT, null, 'c'),
+            new LongOpt("protocol", LongOpt.REQUIRED_ARGUMENT, null, 'r'),};
+      Getopt getopt = new Getopt(programName, args, sopts, lopts);
+
+      int code;
+      while ((code = getopt.getopt()) != -1)
+      {
+         switch (code)
+         {
+            case ':' :
+            case '?' :
+               // for now both of these should exit with error status
+               System.exit(1);
+               break; // for completeness
+            case 1 :
+               // this will catch non-option arguments
+               // (which we don't currently care about)
+               System.err.println(programName + ": unused non-option argument: " + getopt.getOptarg());
+               break; // for completeness
+            case 'h' :
+               // show command line help
+               System.out.println("usage: " + programName + " [options]");
+               System.out.println();
+               System.out.println("options:");
+               System.out.println("    -h, --help                         Show this help message");
+               System.out.println("    -V, --version                      Show version information");
+               System.out.println("    --                                 Stop processing options");
+               System.out.println("    -p, --port=<num>                   TCP port number to listen on (default: 11211)");
+               System.out.println("    -l, --host=<host or ip>            Interface to listen on (default: 127.0.0.1, localhost)");
+               System.out.println("    -m, --master_threads=<num>         Number of threads accepting incoming connections (default: unlimited while resources are available)");
+               System.out.println("    -t, --work_threads=<num>           Number of threads processing incoming requests and sending responses (default: unlimited while resources are available)");
+               System.out.println("    -c, --cache_config=<filename>      Cache configuration file (default: creates cache with default values)");
+               System.out.println("    -r, --protocol=[memcached|hotrod]  Protocol to understand by the server. Choose one of the two options");
+               System.out.println("    -D<name>[=<value>]                 Set a system property");
+               System.out.println();
+               System.exit(0);
+               break; // for completeness
+            case 'V' :
+               Version.printFullVersionInformation();
+               System.exit(0);
+               break;
+            case 'p' :
+               props.put(PROP_KEY_PORT, getopt.getOptarg());
+               break;
+            case 'l' :
+               props.put(PROP_KEY_HOST, getopt.getOptarg());
+               break;
+            case 'm' :
+               props.put(PROP_KEY_MASTER_THREADS, getopt.getOptarg());
+               break;
+            case 't' :
+               props.put(PROP_KEY_WORKER_THREADS, getopt.getOptarg());
+               break;
+            case 'c' :
+               props.put(PROP_KEY_CACHE_CONFIG, getopt.getOptarg());
+               break;
+            case 'r' :
+               props.put(PROP_KEY_PROTOCOL, getopt.getOptarg());
+               break;
+            case 'D' :
+               // set a system property
+               String arg = getopt.getOptarg();
+               String name, value;
+               int i = arg.indexOf("=");
+               if (i == -1) {
+                  name = arg;
+                  value = "true";
+               } else {
+                  name = arg.substring(0, i);
+                  value = arg.substring(i + 1, arg.length());
+               }
+               System.setProperty(name, value);
+               break;
+            default :
+               // this should not happen,
+               // if it does throw an error so we know about it
+               throw new Error("unhandled option code: " + code);
+         }
+      }
+   }
+
+   public static void main(final String[] args) throws Exception {
+      log.info("Start main with args: {0}", Arrays.toString(args));
+      Callable<Void> worker = new Callable<Void>() {
+         @Override
+         public Void call() throws Exception {
+            try {
+               Main main = new Main();
+               main.boot(args);
+            } catch (Exception e) {
+               System.err.println("Failed to boot JBoss:");
+               e.printStackTrace();
+               throw e;
+            }
+            return null;
+         }
+      };
+
+      Future<Void> f = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
+         @Override
+         public Thread newThread(Runnable r) {
+            return new Thread(r, System.getProperty("program.name") + "-main");
+         }
+      }).submit(worker);
+
+      f.get();
+   }
+
+   /**
+    * Adds the specified shutdown hook
+    *
+    * @param shutdownHook
+    */
+   static void addShutdownHook(final Thread shutdownHook) {
+      AccessController.doPrivileged(new PrivilegedAction<Void>() {
+         public Void run() {
+            Runtime.getRuntime().addShutdownHook(shutdownHook);
+            return null;
+         }
+      });
+   }
+
+   /**
+    * ShutdownHook
+    */
+   private static class ShutdownHook extends Thread {
+      private final ProtocolServer server;
+
+      ShutdownHook(ProtocolServer server) {
+         this.server = server;
+      }
+
+      @Override
+      public void run() {
+         // If we have a server
+         if (server != null) {
+            // Log out
+            System.out.println("Posting Shutdown Request to the server...");
+            // Start in new thread to give positive feedback to requesting client of success.
+            Future<Void> f = Executors.newSingleThreadExecutor().submit(new Callable<Void>() {
+               @Override
+               public Void call() throws Exception {
+                  server.stop();
+                  return null;
+               }
+            });
+
+            // Block until done
+            try {
+               f.get();
+            } catch (InterruptedException ie) {
+               // Clear the flag
+               Thread.interrupted();
+            } catch (ExecutionException e) {
+               throw new RuntimeException("Exception encountered in shutting down the server", e);
+            }
+         }
+      }
+   }
+   
+}

Added: trunk/server/core/src/main/java/org/infinispan/server/core/Protocol.java
===================================================================
--- trunk/server/core/src/main/java/org/infinispan/server/core/Protocol.java	                        (rev 0)
+++ trunk/server/core/src/main/java/org/infinispan/server/core/Protocol.java	2010-03-09 16:01:38 UTC (rev 1582)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.infinispan.server.core;
+
+/**
+ * // TODO: Document this
+ *
+ * @author Galder Zamarreño
+ */
+public enum Protocol {
+   MEMCACHED("org.infinispan.server.memcached.Main"),
+   HOTROD("org.infinispan.server.hotrod.Main"),
+   ;
+
+   final String clazz;
+
+   private Protocol(String clazz) {
+      this.clazz = clazz;
+   }
+}

Added: trunk/server/core/src/main/java/org/infinispan/server/core/ProtocolServer.java
===================================================================
--- trunk/server/core/src/main/java/org/infinispan/server/core/ProtocolServer.java	                        (rev 0)
+++ trunk/server/core/src/main/java/org/infinispan/server/core/ProtocolServer.java	2010-03-09 16:01:38 UTC (rev 1582)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.infinispan.server.core;
+
+/**
+ * // TODO: Document this
+ *
+ * @author Galder Zamarreño
+ */
+public interface ProtocolServer {
+
+   void start(String host, int port, String configFile, int masterThreads, int workerThreads) throws Exception;
+
+   void stop();
+
+}

Deleted: trunk/server/core/src/main/java/org/infinispan/server/core/Server.java
===================================================================
--- trunk/server/core/src/main/java/org/infinispan/server/core/Server.java	2010-03-09 14:55:47 UTC (rev 1581)
+++ trunk/server/core/src/main/java/org/infinispan/server/core/Server.java	2010-03-09 16:01:38 UTC (rev 1582)
@@ -1,34 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
- * individual contributors as indicated by the @author tags. See the
- * copyright.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.server.core;
-
-/**
- * ChannelFactory.
- * 
- * @author Galder Zamarreño
- * @since 4.0
- */
-public interface Server {
-   void start();
-   void stop();
-}

Copied: trunk/server/core/src/main/java/org/infinispan/server/core/transport/Server.java (from rev 1566, trunk/server/core/src/main/java/org/infinispan/server/core/Server.java)
===================================================================
--- trunk/server/core/src/main/java/org/infinispan/server/core/transport/Server.java	                        (rev 0)
+++ trunk/server/core/src/main/java/org/infinispan/server/core/transport/Server.java	2010-03-09 16:01:38 UTC (rev 1582)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and
+ * individual contributors as indicated by the @author tags. See the
+ * copyright.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.server.core.transport;
+
+/**
+ * ChannelFactory.
+ * 
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+public interface Server {
+   void start();
+   void stop();
+}

Modified: trunk/server/core/src/main/java/org/infinispan/server/core/transport/netty/NettyServer.java
===================================================================
--- trunk/server/core/src/main/java/org/infinispan/server/core/transport/netty/NettyServer.java	2010-03-09 14:55:47 UTC (rev 1581)
+++ trunk/server/core/src/main/java/org/infinispan/server/core/transport/netty/NettyServer.java	2010-03-09 16:01:38 UTC (rev 1582)
@@ -30,7 +30,7 @@
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.infinispan.server.core.CommandHandler;
-import org.infinispan.server.core.Server;
+import org.infinispan.server.core.transport.Server;
 import org.infinispan.util.logging.Log;
 import org.infinispan.util.logging.LogFactory;
 import org.jboss.netty.bootstrap.ServerBootstrap;

Added: trunk/server/core/src/main/resources/startServer.bat
===================================================================
--- trunk/server/core/src/main/resources/startServer.bat	                        (rev 0)
+++ trunk/server/core/src/main/resources/startServer.bat	2010-03-09 16:01:38 UTC (rev 1582)
@@ -0,0 +1,16 @@
+ at echo off
+
+setlocal enabledelayedexpansion
+
+set LIB=
+for %%f in (..\lib\*.jar) do set LIB=!LIB!;%%f
+for %%f in (..\modules\memcached\lib\*.jar) do set LIB=!LIB!;%%f
+rem echo libs: %LIB%
+
+set CP=%LIB%;..\infinispan-core.jar;..\modules\core\infinispan-server-memcached.jar;%CP%
+set CP=%LIB%;..\modules\memcached\infinispan-server-memcached.jar;%CP%
+set CP=%LIB%;..\modules\hotrod\infinispan-server-hotrod.jar;%CP%
+
+java -classpath "%CP%" -Dbind.address=127.0.0.1 -Djava.net.preferIPv4Stack=true -Dlog4j.configuration=..\etc\log4j.xml org.infinispan.server.core.Main %*
+
+:fileEnd
\ No newline at end of file

Added: trunk/server/core/src/main/resources/startServer.sh
===================================================================
--- trunk/server/core/src/main/resources/startServer.sh	                        (rev 0)
+++ trunk/server/core/src/main/resources/startServer.sh	2010-03-09 16:01:38 UTC (rev 1582)
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+DIRNAME=`dirname $0`
+
+# Setup ISPN_HOME
+if [ "x$ISPN_HOME" = "x" ]; then
+    # get the full path (without any relative bits)
+    ISPN_HOME=`cd $DIRNAME/..; pwd`
+fi
+export ISPN_HOME
+
+CP=${CP}:${ISPN_HOME}/infinispan-core.jar
+
+if [ -e ${ISPN_HOME}/lib ]
+then
+   for JAR in ${ISPN_HOME}/lib/*
+   do
+      CP=$CP:$JAR
+   done
+fi
+
+CP=${CP}:${ISPN_HOME}/modules/core/infinispan-server-core.jar
+
+if [ -e ${ISPN_HOME}/modules/core/lib ]
+then
+   for JAR in ${ISPN_HOME}/modules/core/lib/*
+   do
+      CP=$CP:$JAR
+   done
+fi
+
+CP=${CP}:${ISPN_HOME}/modules/memcached/infinispan-server-memcached.jar
+
+if [ -e ${ISPN_HOME}/modules/memcached/lib ]
+then
+   for JAR in ${ISPN_HOME}/modules/memcached/lib/*
+   do
+      CP=$CP:$JAR
+   done
+fi
+
+CP=${CP}:${ISPN_HOME}/modules/hotrod/infinispan-server-hotrod.jar
+
+if [ -e ${ISPN_HOME}/modules/hotrod/lib ]
+then
+   for JAR in ${ISPN_HOME}/modules/hotrod/lib/*
+   do
+      CP=$CP:$JAR
+   done
+fi
+
+JVM_PARAMS="${JVM_PARAMS} -Dbind.address=127.0.0.1 -Djava.net.preferIPv4Stack=true  -Dlog4j.configuration=file:${ISPN_HOME}/etc/log4j.xml"
+
+# Sample JPDA settings for remote socket debuging
+#JVM_PARAMS="$JVM_PARAMS -Xrunjdwp:transport=dt_socket,address=8686,server=y,suspend=n"
+
+java -cp $CP ${JVM_PARAMS} org.infinispan.server.core.Main ${*}
\ No newline at end of file


Property changes on: trunk/server/core/src/main/resources/startServer.sh
___________________________________________________________________
Name: svn:executable
   + *

Modified: trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodServer.scala
===================================================================
--- trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodServer.scala	2010-03-09 14:55:47 UTC (rev 1581)
+++ trunk/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodServer.scala	2010-03-09 16:01:38 UTC (rev 1582)
@@ -2,8 +2,8 @@
 
 import org.infinispan.manager.CacheManager
 import java.net.InetSocketAddress
-import org.infinispan.server.core.Server
 import org.infinispan.server.core.transport.netty.{NettyNoStateDecoder, NettyEncoder, NettyServer, NettyDecoder}
+import org.infinispan.server.core.transport.Server
 
 /**
  * // TODO: Document this

Modified: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/Main.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/Main.java	2010-03-09 14:55:47 UTC (rev 1581)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/Main.java	2010-03-09 16:01:38 UTC (rev 1582)
@@ -22,257 +22,27 @@
  */
 package org.infinispan.server.memcached;
 
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.ThreadFactory;
+import org.infinispan.server.core.ProtocolServer;
 
-import gnu.getopt.Getopt;
-import gnu.getopt.LongOpt;
-
-import org.infinispan.Version;
-import org.infinispan.util.logging.Log;
-import org.infinispan.util.logging.LogFactory;
-
 /**
  * Main.
  * 
  * @author Galder Zamarreño
  * @since 4.1
  */
-public class Main {
+public class Main implements ProtocolServer {
 
-   private static final Log log = LogFactory.getLog(Main.class);
-   public static final String PROP_KEY_PORT = "infinispan.memcached.port";
-   public static final String PROP_KEY_HOST = "infinispan.memcached.host";
-   public static final String PROP_KEY_MASTER_THREADS = "infinispan.memcached.master.threads";
-   public static final String PROP_KEY_WORKER_THREADS = "infinispan.memcached.worker.threads";
-   public static final String PROP_KEY_CACHE_CONFIG = "infinispan.memcached.cache.config";
-
-   public static final int PORT_DEFAULT = 11211;
-   public static final String HOST_DEFAULT = "127.0.0.1";
-   public static final int MASTER_THREADS_DEFAULT = 0;
-   public static final int WORKER_THREADS_DEFAULT = 0;
-
-   /**
-    * Server properties.  This object holds all of the required
-    * information to get the server up and running. Use System
-    * properties for defaults.
-    */
-   private Map<String, String> props = new HashMap<String, String>();
-
    private TextServer server;
 
-   /**
-    * Explicit constructor.
-    */
-   public Main() {
-      // Set default properties
-      Properties sysProps = System.getProperties();
-      for (Object propName : sysProps.keySet()) {
-         String propNameString = (String) propName;
-         String propValue = (String) sysProps.get(propNameString);
-         props.put(propNameString, propValue);
-      }
-   }
-
-   public void boot(String[] args) throws Exception {
-      // First process the command line to pickup custom props/settings
-      processCommandLine(args);
-
-      int port = props.get(PROP_KEY_PORT) == null ? PORT_DEFAULT : Integer.parseInt(props.get(PROP_KEY_PORT));
-      String host = props.get(PROP_KEY_HOST) == null ? HOST_DEFAULT : props.get(PROP_KEY_HOST);
-      int masterThreads = props.get(PROP_KEY_MASTER_THREADS) == null ? MASTER_THREADS_DEFAULT : Integer.parseInt(props.get(PROP_KEY_MASTER_THREADS));
-      if (masterThreads < 0) {
-         throw new IllegalArgumentException("Master threads can't be lower than 0: " + masterThreads);
-      }
-      int workerThreads = props.get(PROP_KEY_WORKER_THREADS) == null ? WORKER_THREADS_DEFAULT : Integer.parseInt(props.get(PROP_KEY_WORKER_THREADS));
-      if (workerThreads < 0) {
-         throw new IllegalArgumentException("Worker threads can't be lower than 0: " + masterThreads);
-      }
-      String configFile = props.get(PROP_KEY_CACHE_CONFIG);
-
+   @Override
+   public void start(String host, int port, String configFile, int masterThreads, int workerThreads) throws Exception {
       server = new TextServer(host, port, configFile, masterThreads, workerThreads);
-      // Make a shutdown hook
-      addShutdownHook(new ShutdownHook(server));
-
       server.start();
    }
 
-   private void processCommandLine(String[] args) throws Exception {
-      // set this from a system property or default to jboss
-      String programName = System.getProperty("program.name", "memcached");
-      // TODO: Since this memcached implementation stores stuff as byte[], these could be implemented in the future:
-      // -m <num>      max memory to use for items in megabytes (default: 64 MB)
-      // -M            return error on memory exhausted (rather than removing items)
-      String sopts = "-:hD:Vp:l:m:t:c:";
-      LongOpt[] lopts =
-      {new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h'),
-            new LongOpt("version", LongOpt.NO_ARGUMENT, null, 'V'),
-            new LongOpt("port", LongOpt.REQUIRED_ARGUMENT, null, 'p'),
-            new LongOpt("host", LongOpt.REQUIRED_ARGUMENT, null, 'l'),
-            new LongOpt("master_threads", LongOpt.REQUIRED_ARGUMENT, null, 'm'),
-            new LongOpt("worker_threads", LongOpt.REQUIRED_ARGUMENT, null, 't'),
-            new LongOpt("cache_config", LongOpt.REQUIRED_ARGUMENT, null, 'c'),};
-      Getopt getopt = new Getopt(programName, args, sopts, lopts);
-
-      int code;
-      while ((code = getopt.getopt()) != -1)
-      {
-         switch (code)
-         {
-            case ':' :
-            case '?' :
-               // for now both of these should exit with error status
-               System.exit(1);
-               break; // for completeness
-            case 1 :
-               // this will catch non-option arguments
-               // (which we don't currently care about)
-               System.err.println(programName + ": unused non-option argument: " + getopt.getOptarg());
-               break; // for completeness
-            case 'h' :
-               // show command line help
-               System.out.println("usage: " + programName + " [options]");
-               System.out.println();
-               System.out.println("options:");
-               System.out.println("    -h, --help                     Show this help message");
-               System.out.println("    -V, --version                  Show version information");
-               System.out.println("    --                             Stop processing options");
-               System.out.println("    -p, --port=<num>               TCP port number to listen on (default: 11211)");
-               System.out.println("    -l, --host=<host or ip>        Interface to listen on (default: 127.0.0.1, localhost)");
-               System.out.println("    -m, --master_threads=<num>     Number of threads accepting incoming connections. (default: unlimited while resources are available)");
-               System.out.println("    -t, --work_threads=<num>       Number of threads processing incoming requests and sending responses. (default: unlimited while resources are available)");
-               System.out.println("    -c, --cache_config=<filename>  Cache configuration file (default: creates cache with default values)");
-               System.out.println("    -D<name>[=<value>]             Set a system property");
-               System.out.println();
-               System.exit(0);
-               break; // for completeness
-            case 'V' :
-               Version.printFullVersionInformation();
-               System.exit(0);
-               break;
-            case 'p' :
-               props.put(PROP_KEY_PORT, getopt.getOptarg());
-               break;
-            case 'l' :
-               props.put(PROP_KEY_HOST, getopt.getOptarg());
-               break;
-            case 'm' :
-               props.put(PROP_KEY_MASTER_THREADS, getopt.getOptarg());
-               break;
-            case 't' :
-               props.put(PROP_KEY_WORKER_THREADS, getopt.getOptarg());
-               break;
-            case 'c' :
-               props.put(PROP_KEY_CACHE_CONFIG, getopt.getOptarg());
-               break;
-            case 'D' :
-               // set a system property
-               String arg = getopt.getOptarg();
-               String name, value;
-               int i = arg.indexOf("=");
-               if (i == -1) {
-                  name = arg;
-                  value = "true";
-               } else {
-                  name = arg.substring(0, i);
-                  value = arg.substring(i + 1, arg.length());
-               }
-               System.setProperty(name, value);
-               break;
-            default :
-               // this should not happen,
-               // if it does throw an error so we know about it
-               throw new Error("unhandled option code: " + code);
-         }
-      }
+   @Override
+   public void stop() {
+      server.stop();
    }
 
-   public static void main(final String[] args) throws Exception {
-      log.info("Start main with args: {0}", Arrays.toString(args));
-      Callable<Void> worker = new Callable<Void>() {
-         @Override
-         public Void call() throws Exception {
-            try {
-               Main main = new Main();
-               main.boot(args);
-            } catch (Exception e) {
-               System.err.println("Failed to boot JBoss:");
-               e.printStackTrace();
-               throw e;
-            }
-            return null;
-         }
-      };
-
-      Future<Void> f = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
-         @Override
-         public Thread newThread(Runnable r) {
-            return new Thread(r, System.getProperty("program.name") + "-main");
-         }
-      }).submit(worker);
-
-      f.get();
-   }
-
-   /**
-    * Adds the specified shutdown hook
-    * 
-    * @param shutdownHook
-    */
-   static void addShutdownHook(final Thread shutdownHook) {
-      AccessController.doPrivileged(new PrivilegedAction<Void>() {
-         public Void run() {
-            Runtime.getRuntime().addShutdownHook(shutdownHook);
-            return null;
-         }
-      });
-   }
-
-   /**
-    * ShutdownHook
-    */
-   private static class ShutdownHook extends Thread {
-      private final TextServer server;
-
-      ShutdownHook(TextServer server) {
-         this.server = server;
-      }
-
-      @Override
-      public void run() {
-         // If we have a server
-         if (server != null) {
-            // Log out
-            System.out.println("Posting Shutdown Request to the memcached server...");
-            // Start in new thread to give positive feedback to requesting client of success.
-            Future<Void> f = Executors.newSingleThreadExecutor().submit(new Callable<Void>() {
-               @Override
-               public Void call() throws Exception {
-                  server.stop();
-                  return null;
-               }
-            });
-
-            // Block until done
-            try {
-               f.get();
-            } catch (InterruptedException ie) {
-               // Clear the flag
-               Thread.interrupted();
-            } catch (ExecutionException e) {
-               throw new RuntimeException("Exception encountered in shutting down the server", e);
-            }
-         }
-      }
-   }
-
 }

Modified: trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextServer.java
===================================================================
--- trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextServer.java	2010-03-09 14:55:47 UTC (rev 1581)
+++ trunk/server/memcached/src/main/java/org/infinispan/server/memcached/TextServer.java	2010-03-09 16:01:38 UTC (rev 1582)
@@ -29,7 +29,7 @@
 
 import org.infinispan.Cache;
 import org.infinispan.manager.DefaultCacheManager;
-import org.infinispan.server.core.Server;
+import org.infinispan.server.core.transport.Server;
 import org.infinispan.server.core.transport.netty.NettyDecoder;
 import org.infinispan.server.core.transport.netty.NettyServer;
 import org.infinispan.server.memcached.transport.TextDecoder;

Modified: trunk/server/memcached/src/main/resources/sample_python_memcached_client.py
===================================================================
--- trunk/server/memcached/src/main/resources/sample_python_memcached_client.py	2010-03-09 14:55:47 UTC (rev 1581)
+++ trunk/server/memcached/src/main/resources/sample_python_memcached_client.py	2010-03-09 16:01:38 UTC (rev 1582)
@@ -9,7 +9,7 @@
 import time
 
 ip = "127.0.0.1"
-port = "12211"
+port = "11211"
 ipaddress = ip + ':' + port
 mc = memcache.Client([ipaddress], debug=1)
 

Modified: trunk/src/main/resources/assemblies/all.xml
===================================================================
--- trunk/src/main/resources/assemblies/all.xml	2010-03-09 14:55:47 UTC (rev 1581)
+++ trunk/src/main/resources/assemblies/all.xml	2010-03-09 16:01:38 UTC (rev 1582)
@@ -146,6 +146,7 @@
             <include>org.infinispan:infinispan-tree</include>
             <include>org.infinispan:infinispan-query</include>
             <include>org.infinispan:infinispan-server-rest</include>
+            <include>org.infinispan:infinispan-server-core</include>            
             <include>org.infinispan:infinispan-server-memcached</include>
             <include>org.infinispan:infinispan-server-hotrod</include>
             <include>org.infinispan:infinispan-lucene-directory</include>



More information about the infinispan-commits mailing list