[infinispan-commits] Infinispan SVN: r2048 - trunk/server/core/src/main/scala/org/infinispan/server/core.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Fri Jul 16 07:37:23 EDT 2010


Author: navssurtani
Date: 2010-07-16 07:37:22 -0400 (Fri, 16 Jul 2010)
New Revision: 2048

Modified:
   trunk/server/core/src/main/scala/org/infinispan/server/core/AbstractProtocolServer.scala
   trunk/server/core/src/main/scala/org/infinispan/server/core/Main.scala
   trunk/server/core/src/main/scala/org/infinispan/server/core/ProtocolServer.scala
Log:
Updated overloaded method on AbstractProtocolServer

Modified: trunk/server/core/src/main/scala/org/infinispan/server/core/AbstractProtocolServer.scala
===================================================================
--- trunk/server/core/src/main/scala/org/infinispan/server/core/AbstractProtocolServer.scala	2010-07-16 10:27:19 UTC (rev 2047)
+++ trunk/server/core/src/main/scala/org/infinispan/server/core/AbstractProtocolServer.scala	2010-07-16 11:37:22 UTC (rev 2048)
@@ -7,8 +7,8 @@
 import org.infinispan.manager.EmbeddedCacheManager
 import org.infinispan.server.core.Main._
 import java.util.Properties
-import org.infinispan.util.Util
 import org.infinispan.util.logging.Log
+import org.infinispan.util.{TypedProperties, Util}
 
 /**
  * // TODO: Document this
@@ -24,47 +24,44 @@
    protected var cacheManager: EmbeddedCacheManager = _
 
    def start(properties: Properties, cacheManager: EmbeddedCacheManager, defaultPort: Int) {
-      this.host = properties.getProperty(PROP_KEY_HOST, HOST_DEFAULT)
-      this.port = properties.getProperty(PROP_KEY_PORT, defaultPort.toString).toInt
-      this.masterThreads = properties.getProperty(PROP_KEY_MASTER_THREADS, MASTER_THREADS_DEFAULT).toInt
-      if (masterThreads < 0)
-         throw new IllegalArgumentException("Master threads can't be lower than 0: " + masterThreads)
+      val typedProps = TypedProperties.toTypedProperties(properties)
+      val toStart = typedProps.getBooleanProperty("enabled", false)
 
-      this.workerThreads = properties.getProperty(PROP_KEY_WORKER_THREADS, WORKER_THREADS_DEFAULT).toInt
-      if (workerThreads < 0)
-         throw new IllegalArgumentException("Worker threads can't be lower than 0: " + masterThreads)
+      if (toStart) {
+         this.host = typedProps.getProperty(PROP_KEY_HOST, HOST_DEFAULT)
+         this.port = typedProps.getIntProperty(PROP_KEY_PORT, defaultPort)
+         this.masterThreads = typedProps.getIntProperty(PROP_KEY_MASTER_THREADS, MASTER_THREADS_DEFAULT)
+         if (masterThreads < 0)
+            throw new IllegalArgumentException("Master threads can't be lower than 0: " + masterThreads)
 
-      this.cacheManager = cacheManager
-      val idleTimeout = properties.getProperty(PROP_KEY_IDLE_TIMEOUT, IDLE_TIMEOUT_DEFAULT).toInt
-      if (idleTimeout < -1)
-         throw new IllegalArgumentException("Idle timeout can't be lower than -1: " + idleTimeout)
+         this.workerThreads = typedProps.getIntProperty(PROP_KEY_WORKER_THREADS, WORKER_THREADS_DEFAULT)
+         if (workerThreads < 0)
+            throw new IllegalArgumentException("Worker threads can't be lower than 0: " + masterThreads)
 
-      val tcpNoDelayString = properties.getProperty(PROP_KEY_TCP_NO_DELAY, TCP_NO_DELAY_DEFAULT)
-      val tcpNoDelay =
-      try {
-         tcpNoDelayString.toBoolean
-      } catch {
-         case n: NumberFormatException => {
-            throw new IllegalArgumentException("TCP no delay flag switch must be a boolean: " + tcpNoDelayString)
+         this.cacheManager = cacheManager
+         val idleTimeout = typedProps.getIntProperty(PROP_KEY_IDLE_TIMEOUT, IDLE_TIMEOUT_DEFAULT)
+         if (idleTimeout < -1)
+            throw new IllegalArgumentException("Idle timeout can't be lower than -1: " + idleTimeout)
+
+         val tcpNoDelay = typedProps.getBooleanProperty(PROP_KEY_TCP_NO_DELAY, TCP_NO_DELAY_DEFAULT)
+
+         val sendBufSize = typedProps.getIntProperty(PROP_KEY_SEND_BUF_SIZE, SEND_BUF_SIZE_DEFAULT)
+         if (sendBufSize < 0) {
+            throw new IllegalArgumentException("Send buffer size can't be lower than 0: " + sendBufSize)
          }
-      }
 
-      val sendBufSize = properties.getProperty(PROP_KEY_SEND_BUF_SIZE, SEND_BUF_SIZE_DEFAULT).toInt
-      if (sendBufSize < 0) {
-         throw new IllegalArgumentException("Send buffer size can't be lower than 0: " + sendBufSize)
-      }
+         val recvBufSize = typedProps.getIntProperty(PROP_KEY_RECV_BUF_SIZE, RECV_BUF_SIZE_DEFAULT)
+         if (recvBufSize < 0) {
+            throw new IllegalArgumentException("Send buffer size can't be lower than 0: " + sendBufSize)
+         }
 
-      val recvBufSize = properties.getProperty(PROP_KEY_RECV_BUF_SIZE, RECV_BUF_SIZE_DEFAULT).toInt
-      if (recvBufSize < 0) {
-         throw new IllegalArgumentException("Send buffer size can't be lower than 0: " + sendBufSize)
+         // Register rank calculator before starting any cache so that we can capture all view changes
+         cacheManager.addListener(getRankCalculatorListener)
+         // Start default cache
+         startDefaultCache
+         val address = new InetSocketAddress(host, port)
+         startTransport(address, idleTimeout, tcpNoDelay, sendBufSize, recvBufSize)
       }
-
-      // Register rank calculator before starting any cache so that we can capture all view changes
-      cacheManager.addListener(getRankCalculatorListener)
-      // Start default cache
-      startDefaultCache
-      val address = new InetSocketAddress(host, port)
-      startTransport(address, idleTimeout, tcpNoDelay, sendBufSize, recvBufSize)
    }
 
    def startTransport(address: InetSocketAddress, idleTimeout: Int, tcpNoDelay: Boolean, sendBufSize: Int, recvBufSize: Int) {
@@ -77,15 +74,10 @@
 
 
    def start(propertiesFileName: String, cacheManager: EmbeddedCacheManager) {
-      val propsObject = new Properties()
+      val propsObject = new TypedProperties()
       val stream = Util.loadResourceAsStream(propertiesFileName)
       propsObject.load(stream)
-
-      if (propsObject.getProperty("isEnabled").equals("true")) {
-         start(propsObject, cacheManager)
-      }
-
-
+      start(propsObject, cacheManager)
    }
 
    override def stop {

Modified: trunk/server/core/src/main/scala/org/infinispan/server/core/Main.scala
===================================================================
--- trunk/server/core/src/main/scala/org/infinispan/server/core/Main.scala	2010-07-16 10:27:19 UTC (rev 2047)
+++ trunk/server/core/src/main/scala/org/infinispan/server/core/Main.scala	2010-07-16 11:37:22 UTC (rev 2048)
@@ -34,12 +34,12 @@
    val PROP_KEY_PROXY_HOST = "infinispan.server.proxy_host"
    val PROP_KEY_PROXY_PORT = "infinispan.server.proxy_port"
    val HOST_DEFAULT = "127.0.0.1"
-   val MASTER_THREADS_DEFAULT = "0"
-   val WORKER_THREADS_DEFAULT = "0"
-   val IDLE_TIMEOUT_DEFAULT = "-1"
-   val TCP_NO_DELAY_DEFAULT = "true"
-   val SEND_BUF_SIZE_DEFAULT = "0"
-   val RECV_BUF_SIZE_DEFAULT = "0"
+   val MASTER_THREADS_DEFAULT = 0
+   val WORKER_THREADS_DEFAULT = 0
+   val IDLE_TIMEOUT_DEFAULT = -1
+   val TCP_NO_DELAY_DEFAULT = true
+   val SEND_BUF_SIZE_DEFAULT = 0
+   val RECV_BUF_SIZE_DEFAULT = 0
 
    /**
     * Server properties.  This object holds all of the required

Modified: trunk/server/core/src/main/scala/org/infinispan/server/core/ProtocolServer.scala
===================================================================
--- trunk/server/core/src/main/scala/org/infinispan/server/core/ProtocolServer.scala	2010-07-16 10:27:19 UTC (rev 2047)
+++ trunk/server/core/src/main/scala/org/infinispan/server/core/ProtocolServer.scala	2010-07-16 11:37:22 UTC (rev 2048)
@@ -20,8 +20,15 @@
    def start(properties: Properties, cacheManager: EmbeddedCacheManager)
 
    /**
-    * Stops the server
+    * Overloaded method that starts the server by using a properties file. This is particularly useful if trying to
+    * start the cache through a beans.xml file or similar.
     */
+   def start(propertiesFileName: String, cacheManager: EmbeddedCacheManager)
+
+
+   /**
+    *  Stops the server
+    */
    def stop
 
    /**



More information about the infinispan-commits mailing list