Package eu.mosaic_cloud.platform.interop.idl.IdlCommon

Examples of eu.mosaic_cloud.platform.interop.idl.IdlCommon.CompletionToken


  }
 
  @Override
  public CallbackCompletion<Void> add (final String key, final int exp, final TValue data)
  {
    final CompletionToken token = this.generateToken ();
    this.transcript.traceDebugging ("adding to the record with key `%s` (with request token `%s`)...", key, token.getMessageId ());
    final MemcachedPayloads.AddRequest.Builder requestBuilder = MemcachedPayloads.AddRequest.newBuilder ();
    requestBuilder.setToken (token);
    requestBuilder.setKey (key);
    requestBuilder.setExpTime (exp);
    CallbackCompletion<Void> result = null;
View Full Code Here


  }
 
  @Override
  public CallbackCompletion<Void> append (final String key, final TValue data)
  {
    final CompletionToken token = this.generateToken ();
    this.transcript.traceDebugging ("appending to the record with key `%s` (with request token `%s`)...", key, token.getMessageId ());
    final MemcachedPayloads.AppendRequest.Builder requestBuilder = MemcachedPayloads.AppendRequest.newBuilder ();
    requestBuilder.setToken (token);
    requestBuilder.setKey (key);
    CallbackCompletion<Void> result = null;
    try {
View Full Code Here

  }
 
  @Override
  public CallbackCompletion<Void> cas (final String key, final TValue data)
  {
    final CompletionToken token = this.generateToken ();
    this.transcript.traceDebugging ("cas-ing the record with key `%s` (with request token `%s`)...", key, token.getMessageId ());
    final MemcachedPayloads.CasRequest.Builder requestBuilder = MemcachedPayloads.CasRequest.newBuilder ();
    requestBuilder.setToken (token);
    requestBuilder.setKey (key);
    CallbackCompletion<Void> result = null;
    try {
View Full Code Here

  }
 
  @Override
  public CallbackCompletion<Void> prepend (final String key, final TValue data)
  {
    final CompletionToken token = this.generateToken ();
    this.transcript.traceDebugging ("prepending to the record with key `%s` (with request token `%s`)...", key, token.getMessageId ());
    final MemcachedPayloads.PrependRequest.Builder requestBuilder = MemcachedPayloads.PrependRequest.newBuilder ();
    requestBuilder.setToken (token);
    requestBuilder.setKey (key);
    CallbackCompletion<Void> result = null;
    try {
View Full Code Here

  }
 
  @Override
  public CallbackCompletion<Void> replace (final String key, final int exp, final TValue data)
  {
    final CompletionToken token = this.generateToken ();
    this.transcript.traceDebugging ("replacing the record with key `%s` (with request token `%s`)...", key, token.getMessageId ());
    final MemcachedPayloads.ReplaceRequest.Builder requestBuilder = MemcachedPayloads.ReplaceRequest.newBuilder ();
    requestBuilder.setToken (token);
    requestBuilder.setKey (key);
    requestBuilder.setExpTime (exp);
    CallbackCompletion<Void> result = null;
View Full Code Here

      throws IOException,
        ClassNotFoundException
  {
    Preconditions.checkArgument ((message.specification instanceof KeyValueMessage) || (message.specification instanceof MemcachedMessage));
    byte[] data;
    CompletionToken token;
    String key;
    int exp;
    IResult<Boolean> resultStore;
    DriverOperationFinishedHandler callback;
    final eu.mosaic_cloud.platform.interop.common.kv.KeyValueMessage messageData;
    final MemcachedDriver driver = super.getDriver (MemcachedDriver.class);
    final String mssgPrefix = "MemcachedStub - Received request for ";
    if (message.specification instanceof KeyValueMessage) {
      // NOTE: handle set with exp
      boolean handle = false;
      final KeyValueMessage kvMessage = (KeyValueMessage) message.specification;
      if (kvMessage == KeyValueMessage.SET_REQUEST) {
        final KeyValuePayloads.SetRequest setRequest = (SetRequest) message.payload;
        if (setRequest.hasExpTime ()) {
          token = setRequest.getToken ();
          key = setRequest.getKey ();
          MemcachedStub.logger.trace (mssgPrefix + " SET key: " + key + " - request id: " + token.getMessageId () + " client id: " + token.getClientId ());
          exp = setRequest.getExpTime ();
          data = setRequest.getValue ().toByteArray ();
          messageData = new eu.mosaic_cloud.platform.interop.common.kv.KeyValueMessage (key, data, setRequest.getEnvelope ().getContentEncoding (), setRequest.getEnvelope ().getContentType ());
          callback = new DriverOperationFinishedHandler (token, session, MemcachedDriver.class, MemcachedResponseTransmitter.class);
          resultStore = driver.invokeSetOperation (token.getClientId (), messageData, exp, callback);
          callback.setDetails (KeyValueOperations.SET, resultStore);
          handle = true;
        }
      } else if (kvMessage == KeyValueMessage.GET_REQUEST) {
        final KeyValuePayloads.GetRequest getRequest = (GetRequest) message.payload;
        if (getRequest.getKeyCount () > 1) {
          token = getRequest.getToken ();
          MemcachedStub.logger.trace (mssgPrefix + "GET_BULK " + " - request id: " + token.getMessageId () + " client id: " + token.getClientId ());
          callback = new DriverOperationFinishedHandler (token, session, MemcachedDriver.class, MemcachedResponseTransmitter.class);
          final EncodingMetadata expectedEncoding = new EncodingMetadata (getRequest.getEnvelope ().getContentType (), getRequest.getEnvelope ().getContentEncoding ());
          final IResult<Map<String, eu.mosaic_cloud.platform.interop.common.kv.KeyValueMessage>> resultGet = driver.invokeGetBulkOperation (token.getClientId (), getRequest.getKeyList (), expectedEncoding, callback);
          callback.setDetails (KeyValueOperations.GET_BULK, resultGet);
          handle = true;
        }
      }
      if (!handle) {
        this.handleKVOperation (message, session, driver, MemcachedResponseTransmitter.class);
      }
      return;
    }
    final MemcachedMessage mcMessage = (MemcachedMessage) message.specification;
    switch (mcMessage) {
      case ADD_REQUEST :
        final MemcachedPayloads.AddRequest addRequest = (AddRequest) message.payload;
        token = addRequest.getToken ();
        key = addRequest.getKey ();
        MemcachedStub.logger.trace (mssgPrefix + mcMessage.toString () + " key: " + key + " - request id: " + token.getMessageId () + " client id: " + token.getClientId ());
        exp = addRequest.getExpTime ();
        data = addRequest.getValue ().toByteArray ();
        messageData = new eu.mosaic_cloud.platform.interop.common.kv.KeyValueMessage (key, data, addRequest.getEnvelope ().getContentEncoding (), addRequest.getEnvelope ().getContentType ());
        callback = new DriverOperationFinishedHandler (token, session, MemcachedDriver.class, MemcachedResponseTransmitter.class);
        resultStore = driver.invokeAddOperation (token.getClientId (), messageData, exp, callback);
        callback.setDetails (KeyValueOperations.ADD, resultStore);
        break;
      case APPEND_REQUEST :
        final MemcachedPayloads.AppendRequest appendRequest = (AppendRequest) message.payload;
        token = appendRequest.getToken ();
        key = appendRequest.getKey ();
        MemcachedStub.logger.trace (mssgPrefix + mcMessage.toString () + " key: " + key + " - request id: " + token.getMessageId () + " client id: " + token.getClientId ());
        data = appendRequest.getValue ().toByteArray ();
        messageData = new eu.mosaic_cloud.platform.interop.common.kv.KeyValueMessage (key, data, appendRequest.getEnvelope ().getContentEncoding (), appendRequest.getEnvelope ().getContentType ());
        callback = new DriverOperationFinishedHandler (token, session, MemcachedDriver.class, MemcachedResponseTransmitter.class);
        resultStore = driver.invokeAppendOperation (token.getClientId (), messageData, callback);
        callback.setDetails (KeyValueOperations.APPEND, resultStore);
        break;
      case PREPEND_REQUEST :
        final MemcachedPayloads.PrependRequest prependRequest = (PrependRequest) message.payload;
        token = prependRequest.getToken ();
        key = prependRequest.getKey ();
        MemcachedStub.logger.trace (mssgPrefix + mcMessage.toString () + " key: " + key + " - request id: " + token.getMessageId () + " client id: " + token.getClientId ());
        data = prependRequest.getValue ().toByteArray ();
        messageData = new eu.mosaic_cloud.platform.interop.common.kv.KeyValueMessage (key, data, prependRequest.getEnvelope ().getContentEncoding (), prependRequest.getEnvelope ().getContentType ());
        callback = new DriverOperationFinishedHandler (token, session, MemcachedDriver.class, MemcachedResponseTransmitter.class);
        resultStore = driver.invokePrependOperation (token.getClientId (), messageData, callback);
        callback.setDetails (KeyValueOperations.PREPEND, resultStore);
        break;
      case REPLACE_REQUEST :
        final MemcachedPayloads.ReplaceRequest replaceRequest = (ReplaceRequest) message.payload;
        token = replaceRequest.getToken ();
        key = replaceRequest.getKey ();
        MemcachedStub.logger.trace (mssgPrefix + mcMessage.toString () + " key: " + key + " - request id: " + token.getMessageId () + " client id: " + token.getClientId ());
        exp = replaceRequest.getExpTime ();
        data = replaceRequest.getValue ().toByteArray ();
        messageData = new eu.mosaic_cloud.platform.interop.common.kv.KeyValueMessage (key, data, replaceRequest.getEnvelope ().getContentEncoding (), replaceRequest.getEnvelope ().getContentType ());
        callback = new DriverOperationFinishedHandler (token, session, MemcachedDriver.class, MemcachedResponseTransmitter.class);
        resultStore = driver.invokeReplaceOperation (token.getClientId (), messageData, exp, callback);
        callback.setDetails (KeyValueOperations.REPLACE, resultStore);
        break;
      case CAS_REQUEST :
        final MemcachedPayloads.CasRequest casRequest = (CasRequest) message.payload;
        token = casRequest.getToken ();
        key = casRequest.getKey ();
        MemcachedStub.logger.trace (mssgPrefix + mcMessage.toString () + " key: " + key + " - request id: " + token.getMessageId () + " client id: " + token.getClientId ());
        data = casRequest.getValue ().toByteArray ();
        messageData = new eu.mosaic_cloud.platform.interop.common.kv.KeyValueMessage (key, data, casRequest.getEnvelope ().getContentEncoding (), casRequest.getEnvelope ().getContentType ());
        callback = new DriverOperationFinishedHandler (token, session, MemcachedDriver.class, MemcachedResponseTransmitter.class);
        resultStore = driver.invokeCASOperation (token.getClientId (), messageData, callback);
        callback.setDetails (KeyValueOperations.CAS, resultStore);
        break;
      default:
        break;
    }
View Full Code Here

        ClassNotFoundException
  {
    byte[] data;
    boolean unknownMessage = false;
    final KeyValueMessage kvMessage = (KeyValueMessage) message.specification;
    CompletionToken token = null;
    String key;
    final String messagePrefix = "KeyValueStub - Received request for ";
    switch (kvMessage) {
      case ACCESS :
        KeyValueStub.logger.trace ("Received initiation message");
        final KeyValuePayloads.InitRequest initRequest = (InitRequest) message.payload;
        token = initRequest.getToken ();
        final String bucket = initRequest.getBucket ();
        driver.registerClient (token.getClientId (), bucket);
        break;
      case ABORTED :
        KeyValueStub.logger.trace ("Received termination message");
        final IdlCommon.AbortRequest abortRequest = (AbortRequest) message.payload;
        token = abortRequest.getToken ();
        driver.unregisterClient (token.getClientId ());
        break;
      case SET_REQUEST :
        final KeyValuePayloads.SetRequest setRequest = (SetRequest) message.payload;
        token = setRequest.getToken ();
        key = setRequest.getKey ();
        data = setRequest.getValue ().toByteArray ();
        final eu.mosaic_cloud.platform.interop.common.kv.KeyValueMessage messageData = new eu.mosaic_cloud.platform.interop.common.kv.KeyValueMessage (key, data, setRequest.getEnvelope ().getContentEncoding (), setRequest.getEnvelope ().getContentType ());
        KeyValueStub.logger.trace (messagePrefix + kvMessage.toString () + " key: " + key + " - request id: " + token.getMessageId () + " client id: " + token.getClientId ());
        // NOTE: execute operation
        final DriverOperationFinishedHandler setCallback = new DriverOperationFinishedHandler (token, session, driver.getClass (), transmitterClass);
        final IResult<Boolean> resultSet = driver.invokeSetOperation (token.getClientId (), messageData, setCallback);
        setCallback.setDetails (KeyValueOperations.SET, resultSet);
        break;
      case GET_REQUEST :
        final KeyValuePayloads.GetRequest getRequest = (GetRequest) message.payload;
        token = getRequest.getToken ();
        final DriverOperationFinishedHandler getCallback = new DriverOperationFinishedHandler (token, session, driver.getClass (), transmitterClass);
        if (getRequest.getKeyCount () != 1) {
          // NOTE: error - the simple driver can handle only single-key get
          KeyValueStub.logger.error ("Basic driver can handle only single-key GET.");
          driver.handleUnsupportedOperationError (kvMessage.toString (), getCallback);
          break;
        }
        key = getRequest.getKey (0);
        KeyValueStub.logger.trace (messagePrefix + kvMessage.toString () + " key: " + key + " - request id: " + token.getMessageId () + " client id: " + token.getClientId ());
        final EncodingMetadata expectedEncoding = new EncodingMetadata (getRequest.getEnvelope ().getContentType (), getRequest.getEnvelope ().getContentEncoding ());
        final IResult<eu.mosaic_cloud.platform.interop.common.kv.KeyValueMessage> resultGet = driver.invokeGetOperation (token.getClientId (), key, expectedEncoding, getCallback);
        getCallback.setDetails (KeyValueOperations.GET, resultGet);
        break;
      case DELETE_REQUEST :
        final KeyValuePayloads.DeleteRequest delRequest = (DeleteRequest) message.payload;
        token = delRequest.getToken ();
        key = delRequest.getKey ();
        KeyValueStub.logger.trace (messagePrefix + kvMessage.toString () + " key: " + key + " - request id: " + token.getMessageId () + " client id: " + token.getClientId ());
        final DriverOperationFinishedHandler delCallback = new DriverOperationFinishedHandler (token, session, driver.getClass (), transmitterClass);
        final IResult<Boolean> resultDelete = driver.invokeDeleteOperation (token.getClientId (), key, delCallback);
        delCallback.setDetails (KeyValueOperations.DELETE, resultDelete);
        break;
      case LIST_REQUEST :
        final KeyValuePayloads.ListRequest listRequest = (ListRequest) message.payload;
        token = listRequest.getToken ();
        KeyValueStub.logger.trace (messagePrefix + kvMessage.toString () + " - request id: " + token.getMessageId () + " client id: " + token.getClientId ());
        final DriverOperationFinishedHandler listCallback = new DriverOperationFinishedHandler (token, session, driver.getClass (), transmitterClass);
        final IResult<List<String>> resultList = driver.invokeListOperation (token.getClientId (), listCallback);
        listCallback.setDetails (KeyValueOperations.LIST, resultList);
        break;
      case ERROR :
        token = ((IdlCommon.Error) message.payload).getToken ();
        unknownMessage = true;
View Full Code Here

TOP

Related Classes of eu.mosaic_cloud.platform.interop.idl.IdlCommon.CompletionToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.