Package eu.mosaic_cloud.interoperability.core

Examples of eu.mosaic_cloud.interoperability.core.Message


    extends KeyValueResponseTransmitter
{
  @Override
  protected void packAndSend (final Session session, final CompletionToken token, final KeyValueOperations operation, final Object result, final boolean isError)
  {
    Message message;
    this.logger.trace ("MemcachedTransmitter: send response for " + operation + " request " + token.getMessageId () + " client id " + token.getClientId ());
    if (isError) {
      // NOTE: create error message
      final Builder errorPayload = IdlCommon.Error.newBuilder ();
      errorPayload.setToken (token);
      errorPayload.setErrorMessage (result.toString ());
      message = new Message (KeyValueMessage.ERROR, errorPayload.build ());
    } else {
      switch (operation) {
        case ADD :
        case APPEND :
        case REPLACE :
        case PREPEND :
        case CAS :
          final boolean success = (Boolean) result;
          if (success) {
            final Ok.Builder okPayload = IdlCommon.Ok.newBuilder ();
            okPayload.setToken (token);
            message = new Message (KeyValueMessage.OK, okPayload.build ());
          } else {
            final NotOk.Builder nokPayload = IdlCommon.NotOk.newBuilder ();
            nokPayload.setToken (token);
            message = new Message (KeyValueMessage.NOK, nokPayload.build ());
          }
          break;
        case GET_BULK :
          final GetReply.Builder getPayload = KeyValuePayloads.GetReply.newBuilder ();
          getPayload.setToken (token);
          @SuppressWarnings ("unchecked") final Map<String, eu.mosaic_cloud.platform.interop.common.kv.KeyValueMessage> resMap = (Map<String, eu.mosaic_cloud.platform.interop.common.kv.KeyValueMessage>) result;
          final List<KVEntry> getResults = new ArrayList<KVEntry> ();
          for (final Entry<String, eu.mosaic_cloud.platform.interop.common.kv.KeyValueMessage> entry : resMap.entrySet ()) {
            final KVEntry.Builder kvEntry = KeyValuePayloads.KVEntry.newBuilder ();
            kvEntry.setKey (entry.getKey ());
            final IdlCommon.Envelope.Builder envelope = IdlCommon.Envelope.newBuilder ();
            if (null != entry.getValue ().getContentEncoding ())
              envelope.setContentEncoding (entry.getValue ().getContentEncoding ());
            else
              envelope.setContentEncoding ("");
            if (null != entry.getValue ().getContentType ())
              envelope.setContentType (entry.getValue ().getContentType ());
            else
              envelope.setContentType ("");
            kvEntry.setEnvelope (envelope.build ());
            if (entry.getValue ().getData () == null) {
              kvEntry.setValue (ByteString.EMPTY);
            } else {
              kvEntry.setValue (ByteString.copyFrom (entry.getValue ().getData ()));
            }
            getResults.add (kvEntry.build ());
          }
          getPayload.addAllResults (getResults);
          message = new Message (KeyValueMessage.GET_REPLY, getPayload.build ());
          break;
        default:
          message = super.buildKeyValueResponse (operation, token, result);
          break;
      }
View Full Code Here


public class DFSResponseTransmitter extends ResponseTransmitter
{

  protected Message buildOperationResponse (final FilesystemOperations operation, final CompletionToken token, final Object result)
  {
    Message message = null;
    switch (operation) {
      case COPY:   
      case REMOVE_FILE:
      case REMOVE_DIR:
      case MOVE:
      case LINK:
      case MKDIR:
      case CLOSE:
         
        final boolean success = (Boolean) result;
        final SuccessResponse.Builder successPayload = DFSPayloads.SuccessResponse.newBuilder();
        successPayload.setToken (token);
        successPayload.setSuccessful(success);
        message = new Message (DFSMessage.SUCCESS, successPayload.build());
       
        break;
       
      case LIST:
        @SuppressWarnings("unchecked")
        final List<LsElement> list = (List<LsElement>) result;
        final ListResult.Builder lsPayload = DFSPayloads.ListResult.newBuilder();
        lsPayload.setToken(token);
       

        int i = 1;
        for(LsElement element:list)
        {
          ListingItem.Builder builder = DFSPayloads.ListingItem.newBuilder();
         
          builder.setFullPath(element.getPath());
          builder.setIsDirectory(element.isDirectory());
          builder.setLength(element.getLength());
          builder.setName(element.getName());
          lsPayload.addEntry(builder.build());
          i++;
        }
        message = new Message(DFSMessage.LISTING, lsPayload.build());
        break;
       
      case OPEN:
        HDFSFileDriver driver = (HDFSFileDriver) result;
        FileHandlerResponse.Builder handler = FileHandlerResponse.newBuilder();
        handler.setToken(token);
        handler.setFileHandler(driver.getHandle());
        message = new Message(DFSMessage.HANDLER, handler.build());
        break;
      default:
        break;
    }
   
View Full Code Here

  }
 
 
  protected Message buildHandlerResponse (final FileHandlerOperantions operation, final CompletionToken token, final Object result)
  {
    Message message = null;
    switch (operation) {
      case WRITE:
      case CLOSE:
      case SEEK:
      case FLUSH:
        final boolean success = (Boolean) result;
        final SuccessResponse.Builder successPayload = DFSPayloads.SuccessResponse.newBuilder();
        successPayload.setToken (token);
        successPayload.setSuccessful(success);
        message = new Message (DFSHandlerMessage.SUCCESS, successPayload.build());
       
        break;
      case READ:
       
        final byte[] bytes = (byte[]) result;
        final FileRead.Builder readPayload = FileRead.newBuilder();
        readPayload.setToken(token);
        ByteString value = ByteString.copyFrom(bytes);
        readPayload.setData(value);
        message = new Message (DFSHandlerMessage.BYTES, readPayload.build());
       
        break;
      default:
        break;
    }
View Full Code Here

    return null;
  }

  protected void sendResponse (final Session session, final CompletionToken token, final IOperationType operation, final Object result, final boolean isError)
  {
    Message message;
    if(token!=null)
      this.logger.trace ("DFSResponseTransmitter: send response for " + operation + " request " + token.getMessageId () + " client id " + token.getClientId ());
    else
      this.logger.trace ("DFSResponseTransmitter: send response for " + operation + " request " + ", null token");
    if (isError) {
      // NOTE: create error message
      final Error.Builder errorPayload = IdlCommon.Error.newBuilder ();
      errorPayload.setToken (token);
      if(result!=null)
        errorPayload.setErrorMessage (result.toString ());
      else
        errorPayload.setErrorMessage ("Unknown error");
      message = new Message (DFSMessage.ERROR, errorPayload.build ());
    } else {
      message = this.buildResponse (operation, token, result);
    }
    // NOTE: send response
    this.publishResponse (session, message);
View Full Code Here

  {
    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 (DFSMessage.ABORTED, requestBuilder.build ())));
  }
View Full Code Here

    this.transcript.traceDebugging ("Deleting file `%s` (with request token `%s`)...", fullPath, token.getMessageId ());
   
    final DFSPayloads.RemoveFile.Builder removeFileBuilder = DFSPayloads.RemoveFile.newBuilder();
    removeFileBuilder.setToken(token);
    removeFileBuilder.setFullPath(fullPath);
    final Message message = new Message(DFSMessage.REMOVE_FILE, removeFileBuilder.build());
   
    return (this.sendRequest(message, token, Void.class));
  }
View Full Code Here

    this.transcript.traceDebugging ("Deleting directory `%s` (with request token `%s`)...", fullPath, token.getMessageId ());
   
    final DFSPayloads.RemoveDir.Builder removeDirBuilder = DFSPayloads.RemoveDir.newBuilder();
    removeDirBuilder.setToken(token);
    removeDirBuilder.setFullPath(fullPath);
    final Message message = new Message(DFSMessage.REMOVE_DIR, removeDirBuilder.build());
   
    return (this.sendRequest(message, token, Void.class));
  }
View Full Code Here

    this.transcript.traceDebugging ("Making `%s` (with request token `%s`)...", dirNameFullPath, token.getMessageId ());
   
    final DFSPayloads.MakeDir.Builder makeDirBuilder = DFSPayloads.MakeDir.newBuilder();
    makeDirBuilder.setToken(token);
    makeDirBuilder.setFullPath(dirNameFullPath);
    final Message message = new Message(DFSMessage.MKDIR, makeDirBuilder.build());
   
    return (this.sendRequest(message, token, Void.class));
  }
View Full Code Here

    this.transcript.traceDebugging ("Listing `%s` (with request token `%s`)...", path, token.getMessageId ());
   
    final DFSPayloads.ListDir.Builder listDirBuilder = DFSPayloads.ListDir.newBuilder();
    listDirBuilder.setToken(token);
    listDirBuilder.setFullPath(path);
    final Message message = new Message(DFSMessage.LIST, listDirBuilder.build());
   
    return ((CallbackCompletion<List<LsElement>>) ((CallbackCompletion<?>)this.sendRequest(message, token, List.class)));
   
  }
View Full Code Here

    final DFSPayloads.OpenFile.Builder openFileBuilder = DFSPayloads.OpenFile.newBuilder();
    openFileBuilder.setToken(token);
    openFileBuilder.setFullPath(path);
    openFileBuilder.setMode(translateOpenMode(mode));
    final Message message = new Message(DFSMessage.OPEN, openFileBuilder.build());
   
    return (this.sendRequest(message, token, connectorClass));
  }
View Full Code Here

TOP

Related Classes of eu.mosaic_cloud.interoperability.core.Message

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.