|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.zib.scalaris.AbstractTransaction<TransactionSingleOp.RequestList,TransactionSingleOp.ResultList>
de.zib.scalaris.TransactionSingleOp
public class TransactionSingleOp
Provides methods to read and write key/value pairs to/from a scalaris ring.
Each operation is a single transaction. If you are looking for more
transactions, use the Transaction
class instead.
Instances of this class can be generated using a given connection to a
scalaris node (TransactionSingleOp(Connection)
) or without a
connection (TransactionSingleOp()
) in which case a new connection
is created using ConnectionFactory.createConnection()
.
There are two paradigms for reading and writing values:
AbstractTransaction.read(OtpErlangString)
,
AbstractTransaction.write(OtpErlangString, OtpErlangObject)
AbstractTransaction.read(String)
, AbstractTransaction.write(String, Object)
These types can be accessed from any Scalaris API and translate to
each language's native types, e.g. String and OtpErlangString.
A list of supported types can be found in the ErlangValue
class which will perform the conversion.
Additional (custom) types can be used by providing a class that
extends the ErlangValue
class.
The user can specify custom behaviour but the correct
handling of these values is at the user's hand.
An example using erlang objects to improve performance for
inserting strings is provided by
ErlangValueFastString
and can be
tested by FastStringBenchmark
.
String key;
OtpErlangString otpKey;
TransactionSingleOp sc = new TransactionSingleOp();
String value = sc.read(key).stringValue(); // AbstractTransaction.read(String)
OtpErlangObject optValue = sc.read(otpKey).value(); // AbstractTransaction.read(OtpErlangString)
For the full example, see
TransactionSingleOpReadExample
String key;
String value;
OtpErlangString otpKey;
OtpErlangString otpValue;
TransactionSingleOp sc = new TransactionSingleOp();
sc.write(key, value); // AbstractTransaction.write(String, Object)
sc.writeObject(otpKey, otpValue); // AbstractTransaction.write(OtpErlangString, OtpErlangObject)
For the full example, see
TransactionSingleOpWriteExample
ConnectionPolicy
that has been set when the connection
was created. By default, ConnectionFactory
uses
DefaultConnectionPolicy
which implements automatic connection
retries by classifying nodes as good or bad depending on their previous
state. The number of automatic retries is adjustable (default: 3).
Nested Class Summary | |
---|---|
static class |
TransactionSingleOp.RequestList
Encapsulates requests that can be used for transactions in req_list(RequestList) . |
static class |
TransactionSingleOp.ResultList
Encapsulates a list of results as returned by req_list(RequestList) . |
Constructor Summary | |
---|---|
TransactionSingleOp()
Constructor, uses the default connection returned by ConnectionFactory.createConnection() . |
|
TransactionSingleOp(Connection conn)
Constructor, uses the given connection to an erlang node. |
Method Summary | |
---|---|
TransactionSingleOp.ResultList |
req_list(TransactionSingleOp.RequestList req)
Executes all requests in req and commits each one of them in
a single transaction. |
TransactionSingleOp.ResultList |
req_list(TransactionSingleOpOperation op)
Executes the given operation. |
Methods inherited from class de.zib.scalaris.AbstractTransaction |
---|
addDelOnList, addDelOnList, addOnNr, addOnNr, addOnNr, closeConnection, isCompressed, read, read, setCompressed, testAndSet, testAndSet, write, write |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TransactionSingleOp() throws ConnectionException
ConnectionFactory.createConnection()
.
ConnectionException
- if the connection failspublic TransactionSingleOp(Connection conn)
conn
- connection to use for the transactionMethod Detail |
---|
public TransactionSingleOp.ResultList req_list(TransactionSingleOpOperation op) throws ConnectionException, UnknownException
op
- the operation to execute
ConnectionException
- if the connection is not active or a communication error
occurs or an exit signal was received or the remote node
sends a message containing an invalid cookie
UnknownException
- if any other error occursreq_list(RequestList)
public TransactionSingleOp.ResultList req_list(TransactionSingleOp.RequestList req) throws ConnectionException, UnknownException
req
and commits each one of them in
a single transaction.
NOTE: The execution order of multiple requests on the same key is
undefined!
req_list
in class AbstractTransaction<TransactionSingleOp.RequestList,TransactionSingleOp.ResultList>
req
- the requests to issue
req
ConnectionException
- if the connection is not active or a communication error
occurs or an exit signal was received or the remote node
sends a message containing an invalid cookie
UnknownException
- if any other error occurs
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |