Esempio n. 1
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
  * @see #testAndSet(OtpErlangString, OtpErlangObject, OtpErlangObject)
  * @since 3.9
  */
 public <OldT, NewT> void testAndSet(final String key, final OldT oldValue, final NewT newValue)
     throws ConnectionException, TimeoutException, NotFoundException, KeyChangedException,
         UnknownException {
   testAndSet(
       new OtpErlangString(key),
       ErlangValue.convertToErlang(oldValue),
       ErlangValue.convertToErlang(newValue));
 }
Esempio n. 2
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
  * @see #addDelOnList(OtpErlangObject, OtpErlangList, OtpErlangList)
  * @since 3.9
  */
 public <T> void addDelOnList(final String key, final List<T> toAdd, final List<T> toRemove)
     throws ConnectionException, TimeoutException, NotAListException, UnknownException {
   OtpErlangList toAddErl;
   OtpErlangList toRemoveErl;
   try {
     toAddErl = (OtpErlangList) ErlangValue.convertToErlang(toAdd);
     toRemoveErl = (OtpErlangList) ErlangValue.convertToErlang(toRemove);
   } catch (final ClassCastException e) {
     // one of the parameters was no list
     // note: a ClassCastException inside ErlangValue.convertToErlang is
     // converted to an UnknownException
     throw new NotAListException(e);
   }
   addDelOnList(new OtpErlangString(key), toAddErl, toRemoveErl);
 }
Esempio n. 3
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(OtpErlangObject, OtpErlangLong)
  * @see #addOnNr(OtpErlangObject, OtpErlangDouble)
  * @since 3.9
  */
 public <T> void addOnNr(final String key, final T toAdd)
     throws ConnectionException, TimeoutException, NotANumberException, UnknownException {
   final OtpErlangObject toAddErl = ErlangValue.convertToErlang(toAdd);
   if (toAddErl instanceof OtpErlangLong) {
     addOnNr(new OtpErlangString(key), (OtpErlangLong) toAddErl);
   } else if (toAddErl instanceof OtpErlangDouble) {
     addOnNr(new OtpErlangString(key), (OtpErlangDouble) toAddErl);
   } else {
     throw new NotANumberException(toAddErl);
   }
 }
Esempio n. 4
0
 /**
  * Stores the given <code>key</code>/<code>value</code> pair.
  *
  * @param <T> the type of the <tt>value</tt>
  * @param key the key to store the value for
  * @param value 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 UnknownException if any other error occurs
  * @see #write(OtpErlangString, OtpErlangObject)
  * @since 2.9
  */
 public <T> void write(final String key, final T value)
     throws ConnectionException, TimeoutException, UnknownException {
   write(new OtpErlangString(key), ErlangValue.convertToErlang(value));
 }