예제 #1
0
 /**
  * Changes the list stored at the given key, i.e. first adds all items in <tt>toAdd</tt> then
  * removes all items in <tt>toRemove</tt>. Assumes en empty list if no value exists at
  * <tt>key</tt>.
  *
  * @param key the key to write the value to
  * @param toAdd a list of values to add to a list
  * @param toRemove a list of values to remove from a list
  * @throws 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
  * @throws TimeoutException if a timeout occurred while trying to write the value
  * @throws NotAListException if the previously stored value was no list
  * @throws UnknownException if any other error occurs
  * @since 3.9
  */
 public void addDelOnList(
     final OtpErlangObject key, final OtpErlangList toAdd, final OtpErlangList toRemove)
     throws ConnectionException, TimeoutException, NotAListException, UnknownException {
   try {
     final RequestList reqs = new RequestList();
     reqs.addAddDelOnList(key, toAdd, toRemove);
     final ResultList result = req_list(reqs);
     if (result.size() == 1) {
       result.processAddDelOnListAt(0);
     } else {
       throw new UnknownException(result.getResults());
     }
   } catch (final AbortException e) {
     // should not occur (we did not commit anything)
     throw new UnknownException(e);
   }
 }
예제 #2
0
 /**
  * Stores the given <tt>key</tt>/<tt>new_value</tt> pair if the old value at <tt>key</tt> is
  * <tt>old_value</tt> (atomic test_and_set).
  *
  * @param key the key to store the value for
  * @param oldValue the old value to check
  * @param newValue the value to store
  * @throws 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
  * @throws TimeoutException if a timeout occurred while trying to write the value
  * @throws NotFoundException if the requested key does not exist
  * @throws KeyChangedException if the key did not match <tt>old_value</tt>
  * @throws UnknownException if any other error occurs
  * @since 3.9
  */
 public void testAndSet(
     final OtpErlangString key, final OtpErlangObject oldValue, final OtpErlangObject newValue)
     throws ConnectionException, TimeoutException, NotFoundException, KeyChangedException,
         UnknownException {
   try {
     final RequestList reqs = new RequestList();
     reqs.addTestAndSet(key, oldValue, newValue);
     final ResultList result = req_list(reqs);
     if (result.size() == 1) {
       result.processTestAndSetAt(0);
     } else {
       throw new UnknownException(result.getResults());
     }
   } catch (final AbortException e) {
     // should not occur (we did not commit anything)
     throw new UnknownException(e);
   }
 }
예제 #3
0
 /**
  * Executes all requests in <code>req</code>.
  *
  * <p>The transaction's log is reset if a commit in the request list was successful, otherwise it
  * still retains in the transaction which must be successfully committed, aborted or reset in
  * order to be (re-)used for another request.
  *
  * @param req the requests to issue
  * @return results of all requests in the same order as they appear in <code>req</code>
  * @throws 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
  * @throws TimeoutException if a timeout occurred while trying to write the value
  * @throws AbortException if the commit failed
  * @throws UnknownException if any other error occurs
  */
 public ResultList req_list(final RequestList req)
     throws ConnectionException, TimeoutException, AbortException, UnknownException {
   if (req.isEmpty()) {
     return new ResultList(new OtpErlangList());
   }
   OtpErlangObject received_raw = null;
   final OtpErlangList erlangReqList = req.getErlangReqList();
   if (transLog == null) {
     received_raw = connection.doRPC("api_tx", "req_list", new OtpErlangObject[] {erlangReqList});
   } else {
     received_raw =
         connection.doRPC("api_tx", "req_list", new OtpErlangObject[] {transLog, erlangReqList});
   }
   try {
     /*
      * possible return values:
      *  {tx_tlog:tlog(), [{ok} | {ok, Value} | {fail, abort | timeout | not_found}]}
      */
     final OtpErlangTuple received = (OtpErlangTuple) received_raw;
     transLog = received.elementAt(0);
     if (received.arity() == 2) {
       final ResultList result = new ResultList((OtpErlangList) received.elementAt(1));
       if (req.isCommit()) {
         if (result.size() >= 1) {
           result.processCommitAt(result.size() - 1);
           // transaction was successful: reset transaction log
           transLog = null;
         } else {
           throw new UnknownException(result.getResults());
         }
       }
       return result;
     }
     throw new UnknownException(received_raw);
   } catch (final ClassCastException e) {
     // e.printStackTrace();
     throw new UnknownException(e, received_raw);
   }
 }
예제 #4
0
 /**
  * Changes the number stored at the given key, i.e. adds some value. Assumes <tt>0</tt> if no
  * value exists at <tt>key</tt>.
  *
  * @param key the key to write the value to
  * @param toAdd the number to add to the number stored at key (may also be negative)
  * @throws 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
  * @throws TimeoutException if a timeout occurred while trying to write the value
  * @throws NotANumberException if the previously stored value was no number
  * @throws UnknownException if any other error occurs
  * @see #addOnNr_(RequestList)
  * @since 3.9
  */
 public void addOnNr(final OtpErlangObject key, final OtpErlangDouble toAdd)
     throws ConnectionException, TimeoutException, NotANumberException, UnknownException {
   final RequestList reqs = new RequestList();
   reqs.addAddOnNr(key, toAdd);
   addOnNr_(reqs);
 }