From cdf606ecf2353025e480ed01c1805babe210cd9e Mon Sep 17 00:00:00 2001
From: Jeffrey Jia <jiefengjia@gmail.com>
Date: Tue, 17 Jul 2012 22:51:48 +0800
Subject: [PATCH] add node server entry point

---
 server/node/pom.xml                                |   50 +++++++++++++
 .../main/java/org/infinispan/server/node/Main.java |   77 ++++++++++++++++++++
 server/node/src/main/resources/node.xml            |   42 +++++++++++
 server/node/src/main/resources/startNode.bat       |   18 +++++
 server/node/src/main/resources/startNode.sh        |   26 +++++++
 5 files changed, 213 insertions(+)
 create mode 100644 server/node/pom.xml
 create mode 100644 server/node/src/main/java/org/infinispan/server/node/Main.java
 create mode 100644 server/node/src/main/resources/node.xml
 create mode 100644 server/node/src/main/resources/startNode.bat
 create mode 100755 server/node/src/main/resources/startNode.sh

diff --git a/server/node/pom.xml b/server/node/pom.xml
new file mode 100644
index 0000000..fa1f6fd
--- /dev/null
+++ b/server/node/pom.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ JBoss, Home of Professional Open Source
+  ~ Copyright 2012 Red Hat Inc. and/or its affiliates and other
+  ~ contributors as indicated by the @author tags. All rights reserved.
+  ~ See the copyright.txt 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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+   <modelVersion>4.0.0</modelVersion>
+   <parent>
+      <groupId>org.infinispan</groupId>
+      <artifactId>infinispan-server-parent</artifactId>
+      <version>5.2.0-SNAPSHOT</version>
+      <relativePath>../pom.xml</relativePath>
+   </parent>
+
+   <artifactId>infinispan-server-node</artifactId>
+   <packaging>jar</packaging>
+   <name>Infinispan Node Server</name>
+   <description>Infinispan Node Server</description>
+
+   <dependencies>
+      <dependency>
+         <groupId>${project.groupId}</groupId>
+         <artifactId>infinispan-core</artifactId>
+      </dependency>
+   </dependencies>
+
+   <build>
+      <finalName>infinispan-server-node</finalName>
+   </build>
+</project>
diff --git a/server/node/src/main/java/org/infinispan/server/node/Main.java b/server/node/src/main/java/org/infinispan/server/node/Main.java
new file mode 100644
index 0000000..647ff9e
--- /dev/null
+++ b/server/node/src/main/java/org/infinispan/server/node/Main.java
@@ -0,0 +1,77 @@
+/* 
+ * JBoss, Home of Professional Open Source
+ * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
+ * as indicated by the @author tags. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+package org.infinispan.server.node;
+
+import java.io.IOException;
+
+import org.infinispan.Cache;
+import org.infinispan.manager.DefaultCacheManager;
+
+/**
+ * The main entry point of Infinispan Node when run as a Server on the command line.
+ * 
+ * @author Jeffrey Jia (<a href="mailto:jiefengjia@gmail.com">jiefengjia@gmail.com</a>)
+ * @since 5.2
+ */
+public class Main {
+
+   public static void main(String[] args) throws IOException {
+
+      String cache_config = "node.xml";
+      final int argsLen = args.length;
+      for (int i = 0, argsLength = argsLen; i < argsLength; i++) {
+         final String arg = args[i];
+
+         try {
+            if ("-h".equals(arg) || "--help".equals(arg)) {
+               usage();
+               return;
+            } else if ("-c".equals(arg) || "--cache_config".equals(arg)) {
+               cache_config = args[i + 1];
+               break;
+            } else {
+               usage();
+               System.exit(1);
+            }
+
+         } catch (IndexOutOfBoundsException e) {
+            System.err.printf("Argument expected for option %s\n", arg);
+            usage();
+            System.exit(1);
+         }
+
+      }
+      DefaultCacheManager cacheManager = new DefaultCacheManager(cache_config);
+      Cache<String, String> cache = cacheManager.getCache();
+      cache.start();
+      System.out.println("Infinispan Node Server started on " + cacheManager.getAddress());
+
+   }
+
+   private static void usage() {
+
+      System.out.println("usage: startNode [options]");
+      System.out.println("");
+      System.out.println("options:");
+      System.out.println("    -h, --help                         Show this help message");
+      System.out
+            .println("    -c, --cache_config=<filename>      Cache configuration file (default: creates cache with default values)");
+   }
+
+}
diff --git a/server/node/src/main/resources/node.xml b/server/node/src/main/resources/node.xml
new file mode 100644
index 0000000..b43a94c
--- /dev/null
+++ b/server/node/src/main/resources/node.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ JBoss, Home of Professional Open Source
+  ~ Copyright 2009 Red Hat Inc. and/or its affiliates and other
+  ~ contributors as indicated by the @author tags. All rights reserved.
+  ~ See the copyright.txt 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.
+  -->
+<infinispan
+      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+      xsi:schemaLocation="urn:infinispan:config:5.1 http://www.infinispan.org/schemas/infinispan-config-5.1.xsd"
+      xmlns="urn:infinispan:config:5.1">
+   
+   <global>
+      <transport clusterName="demoCluster"/>
+      <globalJmxStatistics enabled="true"/>
+   </global>
+
+   <default>
+      <jmxStatistics enabled="true"/>
+      <clustering mode="distribution">
+         <l1 enabled="true" lifespan="60000"/>
+         <hash numOwners="2" rehashRpcTimeout="120000"/>
+         <sync/>
+      </clustering>
+   </default>
+</infinispan>
diff --git a/server/node/src/main/resources/startNode.bat b/server/node/src/main/resources/startNode.bat
new file mode 100644
index 0000000..1f4ed78
--- /dev/null
+++ b/server/node/src/main/resources/startNode.bat
@@ -0,0 +1,18 @@
+@echo off
+
+setlocal enabledelayedexpansion
+set ISPN_HOME=%~dp0
+set ISPN_HOME="%ISPN_HOME%.."
+
+set /p CP=<%ISPN_HOME%\modules\demos\gui\runtime-classpath.txt
+set CP=%CP::=;%
+set CP=%CP:$ISPN_HOME=!ISPN_HOME!%
+set CP=%ISPN_HOME%\modules\demos\gui\infinispan-gui-demo.jar;%CP%
+rem echo libs: %CP%
+
+:test
+set /a "TESTPORT=%RANDOM%+2000"
+netstat -an | findstr ":%TESTPORT% "
+if %ERRORLEVEL%==0 goto test
+
+java -cp "%CP%" -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=%TESTPORT% -Djgroups.bind_addr=127.0.0.1 -Djava.net.preferIPv4Stack=true -Dlog4j.configuration=%ISPN_HOME%\etc\log4j.xml -Dsun.nio.ch.bugLevel="" org.infinispan.server.node.Main
diff --git a/server/node/src/main/resources/startNode.sh b/server/node/src/main/resources/startNode.sh
new file mode 100755
index 0000000..5fb5ce4
--- /dev/null
+++ b/server/node/src/main/resources/startNode.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+source "`dirname "$0"`/functions.sh"
+
+add_classpath "${ISPN_HOME}"/*.jar
+add_classpath "${ISPN_HOME}/lib"
+add_classpath "${ISPN_HOME}/modules/node"
+
+add_jvm_args $JVM_PARAMS
+add_jvm_args '-Djgroups.bind_addr=127.0.0.1'
+add_jvm_args '-Djava.net.preferIPv4Stack=true'
+
+# RHQ monitoring options
+add_jvm_args '-Dcom.sun.management.jmxremote.ssl=false'
+add_jvm_args '-Dcom.sun.management.jmxremote.authenticate=false'
+add_jvm_args -Dcom.sun.management.jmxremote.port=$(find_tcp_port)
+
+# Workaround for JDK6 NPE: http://bugs.sun.com/view_bug.do?bug_id=6427854
+add_jvm_args '-Dsun.nio.ch.bugLevel=""'
+
+# Sample JPDA settings for remote socket debugging
+#add_jvm_args "-Xrunjdwp:transport=dt_socket,address=8686,server=y,suspend=n"
+
+add_program_args $@
+
+start org.infinispan.server.node.Main
-- 
1.7.10.4

