abstract class CassandraSequenceFactory extends SequenceFactory with AppLogging
A sequence factory using Cassandra
Overview
- Manage sequences using (
seqId
,subId
) as a key - Reduce overhead by generating and persisting sequence beforehand
- For each key (
seqId
,subId
), hold the next IDs in memory
seqID
concept is introduced by this implementation.
It can be thought of as a sub-namespace.
Details
Define an increment value as max server count (name it n
) beforehand.
Assign the different initial values (that is in the range [1 to n
]) to each server.
We can generate a unique ID using the above condition.
For example, suppose we have 3 servers initially and scale it out to 5 servers in the future.
Assign initial values as follows
- Server A: (Assign an initial value = 1)
- Server B: (Assign an initial value = 2)
- Server C: (Assign an initial value = 3)
Each server generates a sequence like the below
- Server A generates a sequence 1, 6, 11, ...,
Ai = 1 + n * i
- Server B generates a sequence 2, 7, 12, ...,
Bi = 2 + n * i
- Server C generates a sequence 3, 8, 13, ...,
Ci = 3 + n * i
In the future, we can add two servers (named Server D and Server E).
- Server D is assigned 4 as an initial value.
It generates a sequence 4, 9, 14, ...,
Di = 4 + n * i
. - Server E is assigned 5 as an initial value.
It generates a sequence 5, 10, 15, ...,
Ei = 5 + n * i
.
Therefore, as we see the above, we can generate unique IDs.
- Annotations
- @SuppressWarnings()
- Alphabetic
- By Inheritance
- CassandraSequenceFactory
- AppLogging
- SequenceFactory
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new CassandraSequenceFactory()
Abstract Value Members
-
abstract
val
config: Config
The configuration that is used for reading settings
-
abstract
def
maxSequence: BigInt
The maximum ID that can be generated
-
abstract
def
seqId: String
The sequence ID for this factory
The sequence ID for this factory
- returns
The sequence ID
-
abstract
def
sequenceCacheSize: Int
The number of IDs that the factory generates before it receives a generating request
-
abstract
def
supportedTenants: Seq[Tenant]
List of supported tenants.
List of supported tenants.
Used to create SequenceFactorySupervisor at initialization. If a numbering request is made for a tenant not included in this list,
Future.failed(new IllegalArgumentException)
will be returned. -
abstract
val
system: ActorSystem
The actor system that is used for creating internal actors
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
lazy val
logger: AppLogger
- Definition Classes
- AppLogging
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
nextId(subId: Option[String])(implicit tenant: Tenant): Future[BigInt]
Generate the next ID for the given sub ID
Generate the next ID for the given sub ID
- subId
The namespace. If it is scala.None, a default sub ID is used.
- returns
A scala.concurrent.Future containing the generated ID
- Definition Classes
- CassandraSequenceFactory → SequenceFactory
-
final
def
nextId()(implicit tenant: Tenant): Future[BigInt]
Generate the next ID for a default sub ID
-
final
def
nextId(subId: String)(implicit tenant: Tenant): Future[BigInt]
Generate the next ID for the given sub ID
Generate the next ID for the given sub ID
- subId
The sub ID
- returns
A scala.concurrent.Future containing the generated ID
- Definition Classes
- SequenceFactory
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()