pekko/kernel/src/main/scala/Kernel.scala

198 lines
7.4 KiB
Scala
Raw Normal View History

/**
* Copyright (C) 2009 Scalable Solutions.
*/
2009-03-23 19:17:49 +01:00
package se.scalablesolutions.akka.kernel
//import org.apache.zookeeper.jmx.ManagedUtil
//import org.apache.zookeeper.server.persistence.FileTxnSnapLog
//import org.apache.zookeeper.server.ServerConfig
//import org.apache.zookeeper.server.NIOServerCnxn
2009-03-10 00:56:42 +01:00
//import voldemort.client.{SocketStoreClientFactory, StoreClient, StoreClientFactory}
//import voldemort.server.{VoldemortConfig, VoldemortServer}
//import voldemort.versioning.Versioned
2009-03-10 00:56:42 +01:00
import com.sun.grizzly.http.SelectorThread
import com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory
2009-03-10 00:56:42 +01:00
import java.io.IOException
import java.net.URI
import java.util.{Map, HashMap}
2009-03-10 00:56:42 +01:00
import java.io.{File, IOException}
import javax.ws.rs.core.UriBuilder
2009-03-10 00:56:42 +01:00
import javax.management.JMException
2009-03-10 00:56:42 +01:00
/**
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
object Kernel extends Logging {
2009-03-10 00:56:42 +01:00
val SERVER_URL = "localhost"
2009-04-19 10:58:20 +02:00
2009-03-10 00:56:42 +01:00
val JERSEY_SERVER_URL = "http://" + SERVER_URL + "/"
val JERSEY_SERVER_PORT = 9998
2009-03-23 19:17:49 +01:00
val JERSEY_REST_CLASSES_ROOT_PACKAGE = "se.scalablesolutions.akka.kernel"
2009-03-10 00:56:42 +01:00
val JERSEY_BASE_URI = UriBuilder.fromUri(JERSEY_SERVER_URL).port(getPort(JERSEY_SERVER_PORT)).build()
/*
2009-03-10 00:56:42 +01:00
val VOLDEMORT_SERVER_URL = "tcp://" + SERVER_URL
val VOLDEMORT_SERVER_PORT = 6666
2009-03-15 08:35:37 +01:00
val VOLDEMORT_BOOTSTRAP_URL = VOLDEMORT_SERVER_URL + ":" + VOLDEMORT_SERVER_PORT
2009-03-10 00:56:42 +01:00
val ZOO_KEEPER_SERVER_URL = SERVER_URL
val ZOO_KEEPER_SERVER_PORT = 9898
private[this] var storageFactory: StoreClientFactory = _
private[this] var storageServer: VoldemortServer = _
*/
2009-04-19 10:58:20 +02:00
def main(args: Array[String]): Unit = {
2009-04-19 10:58:20 +02:00
log.info("Starting Akka kernel...")
startCassandra
cassandraBenchmark
2009-03-10 00:56:42 +01:00
//val threadSelector = startJersey
// TODO: handle shutdown of Jersey in separate thread
// TODO: spawn main in new thread an communicate using socket
//System.in.read
//threadSelector.stopEndpoint
//startZooKeeper
//startVoldemort
2009-03-10 00:56:42 +01:00
}
private[akka] def startJersey: SelectorThread = {
val initParams = new java.util.HashMap[String, String]
initParams.put(
"com.sun.jersey.config.property.packages",
JERSEY_REST_CLASSES_ROOT_PACKAGE)
GrizzlyWebContainerFactory.create(JERSEY_BASE_URI, initParams)
}
2009-04-19 10:58:20 +02:00
private[akka] def startCassandra = {
CassandraNode.start
2009-03-10 00:56:42 +01:00
}
2009-04-19 10:58:20 +02:00
private def cassandraBenchmark = {
val NR_ENTRIES = 100000
println("=================================================")
var start = System.currentTimeMillis
for (i <- 1 to NR_ENTRIES) CassandraNode.insertMapStorageEntryFor("test", i.toString, "data")
var end = System.currentTimeMillis
println("Writes per second: " + NR_ENTRIES / ((end - start).toDouble / 1000))
/*
FIXME: batch_insert fails with the following exception:
ERROR - Exception was generated at : 04/27/2009 15:26:35 on thread main
[B cannot be cast to org.apache.cassandra.db.WriteResponse
java.lang.ClassCastException: [B cannot be cast to org.apache.cassandra.db.WriteResponse
at org.apache.cassandra.service.WriteResponseResolver.resolve(WriteResponseResolver.java:50)
at org.apache.cassandra.service.WriteResponseResolver.resolve(WriteResponseResolver.java:31)
at org.apache.cassandra.service.QuorumResponseHandler.get(QuorumResponseHandler.java:101)
at org.apache.cassandra.service.StorageProxy.insertBlocking(StorageProxy.java:135)
at org.apache.cassandra.service.CassandraServer.batch_insert_blocking(CassandraServer.java:489)
at se.scalablesolutions.akka.kernel.CassandraNode$.insertHashEntries(CassandraNode.scala:59)
at se.scalablesolutions.akka.kernel.Kernel$.cassandraBenchmark(Kernel.scala:91)
at se.scalablesolutions.akka.kernel.Kernel$.main(Kernel.scala:52)
at se.scalablesolutions.akka.kernel.Kernel.main(Kernel.scala)
println("=================================================")
var start = System.currentTimeMillis
println(start)
val entries = new scala.collection.mutable.ArrayBuffer[Tuple2[String, String]]
for (i <- 1 to NR_ENTRIES) entries += (i.toString, "data")
CassandraNode.insertHashEntries("test", entries.toList)
var end = System.currentTimeMillis
println("Writes per second - batch: " + NR_ENTRIES / ((end - start).toDouble / 1000))
*/
println("=================================================")
start = System.currentTimeMillis
for (i <- 1 to NR_ENTRIES) CassandraNode.getMapStorageEntryFor("test", i.toString)
end = System.currentTimeMillis
println("Reads per second: " + NR_ENTRIES / ((end - start).toDouble / 1000))
System.exit(0)
}
2009-04-19 10:58:20 +02:00
// private[akka] def startVoldemort = {
// // Start Voldemort server
// val config = VoldemortConfig.loadFromVoldemortHome(Boot.HOME)
// storageServer = new VoldemortServer(config)
// storageServer.start
// log.info("Replicated persistent storage server started at %s", VOLDEMORT_BOOTSTRAP_URL)
//
// // Create Voldemort client factory
// val numThreads = 10
// val maxQueuedRequests = 10
// val maxConnectionsPerNode = 10
// val maxTotalConnections = 100
// storageFactory = new SocketStoreClientFactory(
// numThreads,
// numThreads,
// maxQueuedRequests,
// maxConnectionsPerNode,
// maxTotalConnections,
// VOLDEMORT_BOOTSTRAP_URL)
//
// val name = this.getClass.getName
// val storage = getStorageFor("actors")
//// val value = storage.get(name)
// val value = new Versioned("state")
// //value.setObject("state")
// storage.put(name, value)
// }
//
// private[akka] def getStorageFor(storageName: String): StoreClient[String, String] =
// storageFactory.getStoreClient(storageName)
2009-03-15 08:35:37 +01:00
2009-03-10 00:56:42 +01:00
// private[akka] def startZooKeeper = {
// try {
// ManagedUtil.registerLog4jMBeans
// ServerConfig.parse(args)
2009-04-19 10:58:20 +02:00
// } catch {
2009-03-10 00:56:42 +01:00
// case e: JMException => log.warning("Unable to register log4j JMX control: s%", e)
2009-04-19 10:58:20 +02:00
// case e => log.fatal("Error in ZooKeeper config: s%", e)
2009-03-10 00:56:42 +01:00
// }
// val factory = new ZooKeeperServer.Factory() {
// override def createConnectionFactory = new NIOServerCnxn.Factory(ServerConfig.getClientPort)
// override def createServer = {
// val server = new ZooKeeperServer
// val txLog = new FileTxnSnapLog(
2009-04-19 10:58:20 +02:00
// new File(ServerConfig.getDataLogDir),
2009-03-10 00:56:42 +01:00
// new File(ServerConfig.getDataDir))
// server.setTxnLogFactory(txLog)
// server
// }
// }
// try {
// val zooKeeper = factory.createServer
// zooKeeper.startup
// log.info("ZooKeeper started")
// // TODO: handle clean shutdown as below in separate thread
// // val cnxnFactory = serverFactory.createConnectionFactory
// // cnxnFactory.setZooKeeperServer(zooKeeper)
// // cnxnFactory.join
// // if (zooKeeper.isRunning) zooKeeper.shutdown
2009-04-19 10:58:20 +02:00
// } catch { case e => log.fatal("Unexpected exception: s%",e) }
2009-03-10 00:56:42 +01:00
// }
private def getPort(defaultPort: Int) = {
val port = System.getenv("JERSEY_HTTP_PORT")
if (null != port) Integer.parseInt(port)
else defaultPort;
}
2009-03-10 00:56:42 +01:00
}
2009-03-12 00:33:18 +01:00
//import javax.ws.rs.{Produces, Path, GET}
// @GET
// @Produces("application/json")
// @Path("/network/{id: [0-9]+}/{nid}")
// def getUserByNetworkId(@PathParam {val value = "id"} id: Int, @PathParam {val value = "nid"} networkId: String): User = {
// val q = em.createQuery("SELECT u FROM User u WHERE u.networkId = :id AND u.networkUserId = :nid")
// q.setParameter("id", id)
// q.setParameter("nid", networkId)
// q.getSingleResult.asInstanceOf[User]
// }