Package eu.mosaic_cloud.drivers.kvstore

Examples of eu.mosaic_cloud.drivers.kvstore.MemcachedDriver


    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


      stub = MemcachedStub.stubs.get (cData);
      try {
        if (stub == null) {
          MemcachedStub.logger.trace ("MemcachedStub: create new stub.");
          final MemcachedResponseTransmitter transmitter = new MemcachedResponseTransmitter ();
          final MemcachedDriver driver = MemcachedDriver.create (config, threading);
          stub = new MemcachedStub (config, transmitter, driver, channel);
          MemcachedStub.stubs.put (cData, stub);
          AbstractDriverStub.incDriverReference (stub);
          channel.accept (KeyValueSession.DRIVER, stub);
          channel.accept (MemcachedSession.DRIVER, stub);
View Full Code Here

  {
    MemcachedStub stub;
    try {
      MemcachedStub.logger.trace ("MemcachedStub: create new stub.");
      final MemcachedResponseTransmitter transmitter = new MemcachedResponseTransmitter ();
      final MemcachedDriver driver = MemcachedDriver.create (config, threading);
      stub = new MemcachedStub (config, transmitter, driver, channel);
      AbstractDriverStub.incDriverReference (stub);
      channel.accept (KeyValueSession.DRIVER, stub);
      channel.accept (MemcachedSession.DRIVER, stub);
    } catch (final Exception e) {
View Full Code Here

TOP

Related Classes of eu.mosaic_cloud.drivers.kvstore.MemcachedDriver

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.