Package eu.antidotedb.client
Class AntidoteClient
- java.lang.Object
-
- eu.antidotedb.client.AntidoteClient
-
public class AntidoteClient extends java.lang.Object
An AntidoteClient manages the connection to one or more Antidote servers.It is the main entry point for working with the client, in particular it is the source of transactions. Every operation has to be executed in the context of a transaction. See:
startTransaction()
,createStaticTransaction()
,noTransaction()
, andnewBatchRead()
.
-
-
Constructor Summary
Constructors Constructor Description AntidoteClient(PoolManager poolManager)
Instantiates a new antidote client.AntidoteClient(java.net.InetSocketAddress... inetAddrs)
Initializes an AntidoteClient with the given hosts.AntidoteClient(java.util.List<TransformerFactory> transformerFactories, java.net.InetSocketAddress... inetAddrs)
Initializes an AntidoteClient.AntidoteClient(java.util.List<TransformerFactory> transformerFactories, java.util.List<java.net.InetSocketAddress> inetAddrs)
Initializes an AntidoteClient.AntidoteClient(java.util.List<java.net.InetSocketAddress> inetAddrs)
Initializes an AntidoteClient with the given hosts.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static boolean
connectToDCs(java.net.InetSocketAddress managerNode, java.util.List<com.google.protobuf.ByteString> descriptors)
static boolean
createDC(java.net.InetSocketAddress managerNode, java.util.List<java.lang.String> nodeNames)
AntidoteStaticTransaction
createStaticTransaction()
Creates a static transaction.AntidoteStaticTransaction
createStaticTransaction(CommitInfo timestamp)
Creates a static transaction.static com.google.protobuf.ByteString
getConnectionDescriptor(java.net.InetSocketAddress managerNode)
PoolManager
getPoolManager()
Get the pool manager.protected void
init(java.util.List<TransformerFactory> transformerFactories, java.util.List<java.net.InetSocketAddress> inetAddrs)
initializes the client.BatchRead
newBatchRead()
Starts a new batch read, which allows to read several objects at once.NoTransaction
noTransaction()
Use this for executing updates and reads without a transaction context.NoTransaction
noTransaction(CommitInfo timestamp)
Use this for executing updates and reads without a transaction context.InteractiveTransaction
startTransaction()
Starts an interactive transactions.InteractiveTransaction
startTransaction(CommitInfo timestamp)
Starts an interactive transactions.
-
-
-
Constructor Detail
-
AntidoteClient
public AntidoteClient(java.net.InetSocketAddress... inetAddrs)
Initializes an AntidoteClient with the given hosts.- Parameters:
inetAddrs
- The addresses of the Antidote hosts
-
AntidoteClient
public AntidoteClient(java.util.List<java.net.InetSocketAddress> inetAddrs)
Initializes an AntidoteClient with the given hosts.- Parameters:
inetAddrs
- The addresses of the Antidote hosts
-
AntidoteClient
public AntidoteClient(java.util.List<TransformerFactory> transformerFactories, java.net.InetSocketAddress... inetAddrs)
Initializes an AntidoteClient.- Parameters:
transformerFactories
- transformers for factories (the last transformer will be at the top of the stack, so applied first)inetAddrs
- The addresses of the Antidote hosts
-
AntidoteClient
public AntidoteClient(java.util.List<TransformerFactory> transformerFactories, java.util.List<java.net.InetSocketAddress> inetAddrs)
Initializes an AntidoteClient.- Parameters:
transformerFactories
- transformers for factories (the last transformer will be at the top of the stack, so applied first)inetAddrs
- The addresses of the Antidote hosts
-
AntidoteClient
public AntidoteClient(PoolManager poolManager)
Instantiates a new antidote client.- Parameters:
poolManager
- defines where to find Antidote hosts
-
-
Method Detail
-
init
protected void init(java.util.List<TransformerFactory> transformerFactories, java.util.List<java.net.InetSocketAddress> inetAddrs)
initializes the client. Called by every constructor except forAntidoteClient(PoolManager)
.
-
startTransaction
public InteractiveTransaction startTransaction()
Starts an interactive transactions. Interactive transactions allow to mix several reads and writes in a single atomic unit.Since an interactive transaction uses database resources, you should ensure that the transaction is closed in any case. The recommended pattern is to use a try-with-resource statement and commit the transaction at the end of it:
try (InteractiveTransaction tx = antidoteClient.startTransaction()) { // updates and reads here tx.commitTransaction(); }
-
startTransaction
public InteractiveTransaction startTransaction(CommitInfo timestamp)
Starts an interactive transactions. Interactive transactions allow to mix several reads and writes in a single atomic unit.Since an interactive transaction uses database resources, you should ensure that the transaction is closed in any case. The recommended pattern is to use a try-with-resource statement and commit the transaction at the end of it:
try (InteractiveTransaction tx = antidoteClient.startTransaction()) { // updates and reads here tx.commitTransaction(); }
- Parameters:
timestamp
- The minimal timestamp that this transaction should be based on. Use the CommitInfo from the commit of a previous transaction if you want to guarantee that the new transaction sees the former one.
-
createStaticTransaction
public AntidoteStaticTransaction createStaticTransaction()
Creates a static transaction. Static transactions can be used to execute a set of updates atomically.
-
createStaticTransaction
public AntidoteStaticTransaction createStaticTransaction(CommitInfo timestamp)
Creates a static transaction. Static transactions can be used to execute a set of updates atomically.- Parameters:
timestamp
-
-
newBatchRead
public BatchRead newBatchRead()
Starts a new batch read, which allows to read several objects at once. TheBatchRead
can be committed usingBatchRead.commit(eu.antidotedb.client.TransactionWithReads)
orBatchRead.commit(TransactionWithReads)
.
-
getPoolManager
public PoolManager getPoolManager()
Get the pool manager. This can be used to configure connections at runtime.
-
noTransaction
public NoTransaction noTransaction()
Use this for executing updates and reads without a transaction context.
-
noTransaction
public NoTransaction noTransaction(CommitInfo timestamp)
Use this for executing updates and reads without a transaction context.
-
createDC
public static boolean createDC(java.net.InetSocketAddress managerNode, java.util.List<java.lang.String> nodeNames) throws java.io.IOException
- Throws:
java.io.IOException
-
getConnectionDescriptor
public static com.google.protobuf.ByteString getConnectionDescriptor(java.net.InetSocketAddress managerNode) throws java.io.IOException
- Throws:
java.io.IOException
-
connectToDCs
public static boolean connectToDCs(java.net.InetSocketAddress managerNode, java.util.List<com.google.protobuf.ByteString> descriptors) throws java.io.IOException
- Throws:
java.io.IOException
-
-