Initial UUID migration

This commit is contained in:
Viktor Klang 2010-08-31 19:12:14 +02:00
parent 17143b90be
commit 3f507fb7ca
7 changed files with 23 additions and 73 deletions

View file

@ -1,59 +0,0 @@
/**
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
*/
package se.scalablesolutions.akka.util;
/**
* NOTE:
* <p/>
* This code is based on code from the [Plasmid Replication Engine] project.
* <br/>
* Licensed under [Mozilla Public License 1.0 (MPL)].
* <p/>
* Original JavaDoc:
* <p/>
* Our distributed objects are generally named most efficiently (and cleanly)
* by their UUID's. This class provides some static helpers for using UUID's.
* If it was efficient to do in Java, I would make the uuid an normal class
* and use instances of it. However, in current JVM's, we would end up using an
* Object to represent a long, which is pretty expensive. Maybe someday. ###
* <p/>
* UUID format: currently using currentTimeMillis() for the low bits. This uses
* about 40 bits for the next 1000 years, leaving 24 bits for debugging
* and consistency data. I'm using 8 of those for a magic asci 'U' byte.
* <p/>
* Future: use one instance of Uuid per type of object for better performance
* and more detailed info (instance could be matched to its uuid's via a map or
* array). This all static version bites.###
*/
public final class UUID {
public static final long UUID_NONE = 0;
public static final long UUID_WILD = -1;
public static final long UUID_MAGICMASK = 0xff << 56;
public static final long UUID_MAGIC = 'U' << 56;
protected static long lastTime;
/**
* Generate and return a new Universally Unique ID.
* Happens to be monotonically increasing.
*/
public synchronized static long newUuid() {
long time = System.currentTimeMillis();
if (time <= lastTime) {
time = lastTime + 1;
}
lastTime = time;
return UUID_MAGIC | time;
}
/**
* Returns true if uuid could have been generated by Uuid.
*/
public static boolean isValid(final long uuid) {
return (uuid & UUID_MAGICMASK) == UUID_MAGIC
&& (uuid & ~UUID_MAGICMASK) != 0;
}
}

View file

@ -0,0 +1,9 @@
/**
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
*/
package se.scalablesolutions.akka.util
object UUID {
def newUuid = new com.eaio.uuid.UUID()
}

View file

@ -31,18 +31,6 @@ import java.util.concurrent.atomic.AtomicLong
import scala.collection.mutable.{HashSet, HashMap}
import scala.reflect.BeanProperty
/**
* Atomic remote request/reply message id generator.
*
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
object RemoteRequestProtocolIdFactory {
private val nodeId = UUID.newUuid
private val id = new AtomicLong
def nextId: Long = id.getAndIncrement + nodeId
}
/**
* Life-cycle events for RemoteClient.
*/

View file

@ -10,11 +10,12 @@ import se.scalablesolutions.akka.stm.global._
import se.scalablesolutions.akka.stm.TransactionManagement._
import se.scalablesolutions.akka.stm.TransactionManagement
import se.scalablesolutions.akka.remote.protocol.RemoteProtocol._
import se.scalablesolutions.akka.remote.{RemoteServer, RemoteRequestProtocolIdFactory, MessageSerializer}
import se.scalablesolutions.akka.remote.{RemoteServer, MessageSerializer}
import se.scalablesolutions.akka.remote.protocol.RemoteProtocol.ActorType._
import se.scalablesolutions.akka.serialization.Serializer
import com.google.protobuf.ByteString
import se.scalablesolutions.akka.util.UUID
/**
* Type class definition for Actor Serialization
@ -267,7 +268,7 @@ object RemoteActorSerialization {
val actorInfo = actorInfoBuilder.build
val requestBuilder = RemoteRequestProtocol.newBuilder
.setId(RemoteRequestProtocolIdFactory.nextId)
.setId(UUID.newUuid)
.setMessage(MessageSerializer.serialize(message))
.setActorInfo(actorInfo)
.setIsOneWay(isOneWay)

Binary file not shown.

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.eaio</groupId>
<artifactId>uuid</artifactId>
<version>3.2</version>
<packaging>jar</packaging>
</project>

View file

@ -140,6 +140,8 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) {
lazy val jetty_util = "org.eclipse.jetty" % "jetty-util" % JETTY_VERSION % "compile"
lazy val jetty_xml = "org.eclipse.jetty" % "jetty-xml" % JETTY_VERSION % "compile"
lazy val uuid = "com.eaio" % "uuid" % "3.2" % "compile"
lazy val guicey = "org.guiceyfruit" % "guice-all" % "2.0" % "compile"
lazy val h2_lzf = "voldemort.store.compress" % "h2-lzf" % "1.0" % "compile"
@ -340,6 +342,7 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) {
// -------------------------------------------------------------------------------------------------------------------
class AkkaActorProject(info: ProjectInfo) extends AkkaDefaultProject(info, distPath) {
val uuid = Dependencies.uuid
val configgy = Dependencies.configgy
val hawtdispatch = Dependencies.hawtdispatch
val multiverse = Dependencies.multiverse