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

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


 
  @Override
  public CallbackCompletion<Void> moveFile(String sourceFullPath,
      String destinationFullPath) {
   
    final CompletionToken token = this.generateToken();
    this.transcript.traceDebugging ("Moving `%s` to `%s`(with request token `%s`)...",
        sourceFullPath, destinationFullPath, token.getMessageId ());
   
    final DFSPayloads.MoveFile.Builder moveFileBuilder = DFSPayloads.MoveFile.newBuilder();
    moveFileBuilder.setToken(token);
    moveFileBuilder.setFromPath(sourceFullPath);
    moveFileBuilder.setToPath(destinationFullPath);
View Full Code Here


    return (this.sendRequest(message, token, Void.class));
  }
 
  public CallbackCompletion<Void> seek(String fileHandlerUUID, long position) {
   
    final CompletionToken token = this.generateToken();
    this.transcript.traceDebugging ("Seeking file with fileHandler `%s` (with request token `%s`)...",
        fileHandlerUUID, token.getMessageId ());
   
    final DFSPayloads.SeekFile.Builder seekFileBuilder = DFSPayloads.SeekFile.newBuilder();
    seekFileBuilder.setToken(token);
    seekFileBuilder.setFileHandler(fileHandlerUUID);
    seekFileBuilder.setPosition(position);
View Full Code Here

   
  }

  public CallbackCompletion<Void> flush(String fileHandlerUUID) {
   
    final CompletionToken token = this.generateToken();
    this.transcript.traceDebugging ("Flushing file with fileHandler `%s` (with request token `%s`)...",
        fileHandlerUUID, token.getMessageId ());
   
    final DFSPayloads.FlushFile.Builder flushFileBuilder = DFSPayloads.FlushFile.newBuilder();
    flushFileBuilder.setToken(token);
    flushFileBuilder.setFileHandler(fileHandlerUUID);
    final Message message = new Message(DFSHandlerMessage.FLUSH, flushFileBuilder.build());
View Full Code Here

      throws IOException,
        ClassNotFoundException
  {
    Preconditions.checkArgument (message.specification instanceof AmqpMessage);
    final AmqpMessage amqpMessage = (AmqpMessage) message.specification;
    CompletionToken token;
    IResult<Boolean> resultBool;
    IResult<String> resultString;
    String queue;
    String exchange;
    boolean durable;
    boolean autoDelete;
    boolean passive;
    boolean autoAck;
    boolean exclusive;
    String consumer;
    String routingKey;
    byte[] dataBytes;
    final AmqpDriver driver = super.getDriver (AmqpDriver.class);
    switch (amqpMessage) {
      case ACCESS :
        AmqpStub.logger.trace ("Received initiation message"); // $NON-NLS-1$
        break;
      case ABORTED :
        AmqpStub.logger.trace ("Received termination message"); // $NON-NLS-1$
        break;
      case DECL_EXCHANGE_REQUEST :
        final AmqpPayloads.DeclareExchangeRequest declExchange = (DeclareExchangeRequest) message.payload;
        token = declExchange.getToken ();
        exchange = declExchange.getExchange ();
        final ExchangeType type = declExchange.getType ();
        durable = declExchange.getDurable ();
        autoDelete = declExchange.getAutoDelete ();
        passive = declExchange.getPassive ();
        AmqpStub.logger.trace ("AmqpStub - Received request for DECLARE EXCHANGE "); // $NON-NLS-1$
        // NOTE: execute operation
        final DriverOperationFinishedHandler exchHandler = new DriverOperationFinishedHandler (token, session);
        resultBool = driver.declareExchange (token.getClientId (), exchange, AmqpExchangeType.valueOf (type.toString ().toUpperCase ()), durable, autoDelete, passive, exchHandler);
        exchHandler.setDetails (AmqpOperations.DECLARE_EXCHANGE, resultBool);
        break;
      case DECL_QUEUE_REQUEST :
        final AmqpPayloads.DeclareQueueRequest declQueue = (DeclareQueueRequest) message.payload;
        token = declQueue.getToken ();
        queue = declQueue.getQueue ();
        exclusive = declQueue.getExclusive ();
        durable = declQueue.getDurable ();
        autoDelete = declQueue.getAutoDelete ();
        passive = declQueue.getPassive ();
        AmqpStub.logger.trace ("AmqpStub - Received request for DECLARE QUEUE"); // $NON-NLS-1$
        // NOTE: execute operation
        final DriverOperationFinishedHandler queueHandler = new DriverOperationFinishedHandler (token, session);
        resultBool = driver.declareQueue (token.getClientId (), queue, exclusive, durable, autoDelete, passive, queueHandler);
        queueHandler.setDetails (AmqpOperations.DECLARE_QUEUE, resultBool);
        break;
      case BIND_QUEUE_REQUEST :
        final AmqpPayloads.BindQueueRequest bindQueue = (BindQueueRequest) message.payload;
        token = bindQueue.getToken ();
        exchange = bindQueue.getExchange ();
        queue = bindQueue.getQueue ();
        routingKey = bindQueue.getRoutingKey ();
        AmqpStub.logger.trace ("AmqpStub - Received request for BIND QUEUE"); // $NON-NLS-1$
        // NOTE: execute operation
        final DriverOperationFinishedHandler bindHandler = new DriverOperationFinishedHandler (token, session);
        resultBool = driver.bindQueue (token.getClientId (), exchange, queue, routingKey, bindHandler);
        bindHandler.setDetails (AmqpOperations.BIND_QUEUE, resultBool);
        break;
      case PUBLISH_REQUEST :
        final AmqpPayloads.PublishRequest publish = (PublishRequest) message.payload;
        token = publish.getToken ();
        dataBytes = publish.getData ().toByteArray ();
        durable = publish.getDurable ();
        exchange = publish.getExchange ();
        final boolean immediate = publish.getImmediate ();
        final boolean mandatory = publish.getMandatory ();
        routingKey = publish.getRoutingKey ();
        String correlationId = null;
        String replyTo = null;
        final Envelope envelope = publish.getEnvelope ();
        if (publish.hasCorrelationId ()) {
          correlationId = publish.getCorrelationId ();
        }
        if (publish.hasReplyTo ()) {
          replyTo = publish.getReplyTo ();
        }
        final AmqpOutboundMessage mssg = new AmqpOutboundMessage (exchange, routingKey, dataBytes, mandatory, immediate, durable, replyTo, envelope.getContentEncoding (), envelope.getContentType (), correlationId, null);
        AmqpStub.logger.trace ("AmqpStub - Received request for PUBLISH"); // $NON-NLS-1$
        // NOTE: execute operation
        final DriverOperationFinishedHandler pubHandler = new DriverOperationFinishedHandler (token, session);
        resultBool = driver.basicPublish (token.getClientId (), mssg, pubHandler);
        pubHandler.setDetails (AmqpOperations.PUBLISH, resultBool);
        break;
      case CONSUME_REQUEST :
        final AmqpPayloads.ConsumeRequest cop = (ConsumeRequest) message.payload;
        token = cop.getToken ();
        queue = cop.getQueue ();
        consumer = cop.getConsumer ();
        exclusive = cop.getExclusive ();
        autoAck = cop.getAutoAck ();
        AmqpStub.logger.trace ("AmqpStub - Received request for CONSUME"); // $NON-NLS-1$
        // NOTE: execute operation
        final DriverOperationFinishedHandler consHandler = new DriverOperationFinishedHandler (token, session);
        final IAmqpConsumer consumeCallback = new ConsumerHandler (session);
        resultString = driver.basicConsume (queue, consumer, exclusive, autoAck, consumeCallback, consHandler);
        consHandler.setDetails (AmqpOperations.CONSUME, resultString);
        break;
      case GET_REQUEST :
        final AmqpPayloads.GetRequest gop = (GetRequest) message.payload;
        token = gop.getToken ();
        queue = gop.getQueue ();
        autoAck = gop.getAutoAck ();
        AmqpStub.logger.trace ("AmqpStub - Received request for GET"); // $NON-NLS-1$
        // NOTE: execute operation
        final DriverOperationFinishedHandler getHandler = new DriverOperationFinishedHandler (token, session);
        resultBool = driver.basicGet (token.getClientId (), queue, autoAck, getHandler);
        getHandler.setDetails (AmqpOperations.GET, resultBool);
        break;
      case CANCEL_REQUEST :
        final AmqpPayloads.CancelRequest clop = (CancelRequest) message.payload;
        token = clop.getToken ();
        consumer = clop.getConsumer ();
        AmqpStub.logger.trace ("AmqpStub - Received request for CANCEL"); // $NON-NLS-1$
        // NOTE: execute operation
        final DriverOperationFinishedHandler cancelHandler = new DriverOperationFinishedHandler (token, session);
        resultBool = driver.basicCancel (consumer, cancelHandler);
        cancelHandler.setDetails (AmqpOperations.CANCEL, resultBool);
        break;
      case ACK :
        final AmqpPayloads.Ack aop = (Ack) message.payload;
        token = aop.getToken ();
        final long delivery = aop.getDelivery ();
        final boolean multiple = aop.getMultiple ();
        AmqpStub.logger.trace ("AmqpStub - Received  ACK "); // $NON-NLS-1$
        // NOTE: execute operation
        final DriverOperationFinishedHandler ackHandler = new DriverOperationFinishedHandler (token, session);
        resultBool = driver.basicAck (token.getClientId (), delivery, multiple, ackHandler);
        ackHandler.setDetails (AmqpOperations.ACK, resultBool);
        break;
      default:
        final DriverOperationFinishedHandler errHandler = new DriverOperationFinishedHandler (null, session);
        driver.handleUnsupportedOperationError (amqpMessage.toString (), errHandler);
View Full Code Here

  }
 
  @Override
  public CallbackCompletion<Void> delete (final String key)
  {
    final CompletionToken token = this.generateToken ();
    this.transcript.traceDebugging ("deleting the record with key `%s` (with request token `%s`)...", key, token.getMessageId ());
    final DeleteRequest.Builder requestBuilder = DeleteRequest.newBuilder ();
    requestBuilder.setToken (token);
    requestBuilder.setKey (key);
    final Message message = new Message (KeyValueMessage.DELETE_REQUEST, requestBuilder.build ());
    return this.sendRequest (message, token, Void.class);
View Full Code Here

 
  @Override
  public CallbackCompletion<Void> destroy ()
  {
    this.transcript.traceDebugging ("destroying the proxy...");
    final CompletionToken token = this.generateToken ();
    final AbortRequest.Builder requestBuilder = AbortRequest.newBuilder ();
    requestBuilder.setToken (token);
    return (this.disconnect (new Message (KeyValueMessage.ABORTED, requestBuilder.build ())));
  }
View Full Code Here

 
  @Override
  @SuppressWarnings ("unchecked")
  public CallbackCompletion<List<String>> list ()
  {
    final CompletionToken token = this.generateToken ();
    this.transcript.traceDebugging ("listing the keys (with request token `%s`)...", token.getMessageId ());
    final ListRequest.Builder requestBuilder = ListRequest.newBuilder ();
    requestBuilder.setToken (token);
    final Message message = new Message (KeyValueMessage.LIST_REQUEST, requestBuilder.build ());
    return ((CallbackCompletion<List<String>>) ((CallbackCompletion<?>) this.sendRequest (message, token, List.class)));
  }
View Full Code Here

  {
    final KeyValueMessage kvMessage = (KeyValueMessage) message.specification;
    switch (kvMessage) {
      case OK : {
        final IdlCommon.Ok okPayload = (Ok) message.payload;
        final CompletionToken token = okPayload.getToken ();
        this.transcript.traceDebugging ("processing the success (OK) response for pending request with token `%s`...", token.getMessageId ());
        this.pendingRequests.succeed (token.getMessageId (), null);
      }
        break;
      case NOK : {
        final IdlCommon.NotOk nokPayload = (NotOk) message.payload;
        final CompletionToken token = nokPayload.getToken ();
        this.transcript.traceDebugging ("processing the failure (NOK) response for pending request with token `%s`...", token.getMessageId ());
        this.pendingRequests.fail (token.getMessageId (), new Exception ("request failed"));
      }
        break;
      case ERROR : {
        final IdlCommon.Error errorPayload = (Error) message.payload;
        final CompletionToken token = errorPayload.getToken ();
        this.transcript.traceDebugging ("processing the failure (error) response for pending request with token `%s` with message `%s`...", token.getMessageId (), errorPayload.getErrorMessage ());
        this.pendingRequests.fail (token.getMessageId (), new Exception (errorPayload.getErrorMessage ()));
      }
        break;
      case LIST_REPLY : {
        final KeyValuePayloads.ListReply listPayload = (ListReply) message.payload;
        final CompletionToken token = listPayload.getToken ();
        this.transcript.traceDebugging ("processing the success (list reply) response for pending request with token `%s`...", token.getMessageId ());
        this.pendingRequests.succeed (token.getMessageId (), listPayload.getKeysList ());
      }
        break;
      case GET_REPLY : {
        final KeyValuePayloads.GetReply getPayload = (GetReply) message.payload;
        final CompletionToken token = getPayload.getToken ();
        final List<KVEntry> resultEntries = getPayload.getResultsList ();
        this.transcript.traceDebugging ("processing the success (get reply) response (with `%d` entries) for pending request with token `%s`...", Integer.valueOf (resultEntries.size ()), token.getMessageId ());
        final Class<?> outcomeClass = this.pendingRequests.peek (token.getMessageId ()).future.outcomeClass;
        final Object outcome;
        if (outcomeClass == Map.class) {
          final Map<String, TValue> values = new HashMap<String, TValue> ();
          for (final KVEntry entry : resultEntries) {
            final Envelope envelope = entry.getEnvelope ();
            final EncodingMetadata encodingMetadata = new EncodingMetadata (envelope.getContentType (), envelope.getContentEncoding ());
            final TValue value;
            final byte[] rawValue = resultEntries.get (0).getValue ().toByteArray ();
            if ((rawValue != null) && (rawValue.length > 0)) {
              try {
                value = this.encoder.decode (rawValue, encodingMetadata);
              } catch (final EncodingException exception) {
                this.exceptions.traceDeferredException (exception, "decoding the value for record failed; deferring!");
                this.pendingRequests.fail (token.getMessageId (), exception);
                break;
              }
            } else {
              value = null;
            }
            values.put (entry.getKey (), value);
          }
          outcome = values;
        } else if (outcomeClass == Object.class) {
          final TValue value;
          if (!resultEntries.isEmpty ()) {
            final byte[] rawValue = resultEntries.get (0).getValue ().toByteArray ();
            if ((rawValue != null) && (rawValue.length > 0)) {
              final Envelope envelope = resultEntries.get (0).getEnvelope ();
              final EncodingMetadata encodingMetadata = new EncodingMetadata (envelope.getContentType (), envelope.getContentEncoding ());
              try {
                value = this.encoder.decode (rawValue, encodingMetadata);
              } catch (final EncodingException exception) {
                this.exceptions.traceDeferredException (exception, "decoding the value for record failed; deferring!");
                this.pendingRequests.fail (token.getMessageId (), exception);
                break;
              }
            } else {
              value = null;
            }
          } else {
            value = null;
          }
          outcome = value;
        } else {
          this.pendingRequests.fail (token.getMessageId (), new AssertionError ());
          break;
        }
        this.pendingRequests.succeed (token.getMessageId (), outcome);
      }
        break;
      default: {
        this.transcript.traceWarning ("processing unexpected message of type `%s`; ignoring...", message.specification);
      }
View Full Code Here

    }
  }
 
  protected <TOutcome> CallbackCompletion<TOutcome> sendGetRequest (final List<String> keys, final Class<TOutcome> outcomeClass)
  {
    final CompletionToken token = this.generateToken ();
    this.transcript.traceDebugging ("getting the record with key `%s` (and `%d` other keys) (with request token `%s`)...", keys.get (0), Integer.valueOf (keys.size () - 1), token.getMessageId ());
    final GetRequest.Builder requestBuilder = GetRequest.newBuilder ();
    requestBuilder.setToken (token);
    requestBuilder.addAllKey (keys);
    final EncodingMetadata encodingMetadata = this.encoder.getExpectedEncodingMetadata ();
    requestBuilder.setEnvelope (this.buildEnvelope (encodingMetadata));
View Full Code Here

    return (this.sendRequest (message, token, outcomeClass));
  }
 
  protected CallbackCompletion<Void> sendSetRequest (final String key, final TValue data, final int exp)
  {
    final CompletionToken token = this.generateToken ();
    this.transcript.traceDebugging ("setting the record with key `%s` (with request token `%s`)...", key, token.getMessageId ());
    final SetRequest.Builder requestBuilder = SetRequest.newBuilder ();
    requestBuilder.setToken (token);
    requestBuilder.setKey (key);
    requestBuilder.setExpTime (exp);
    CallbackCompletion<Void> result = null;
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.