Class CGThriftServerHandler

  • All Implemented Interfaces:
    org.wso2.carbon.cloud.gateway.common.thrift.gen.CloudGatewayService.Iface

    public class CGThriftServerHandler
    extends Object
    implements org.wso2.carbon.cloud.gateway.common.thrift.gen.CloudGatewayService.Iface
    This implements the handler for Thrift server. This uses static objects(for buffers) in order to make sure that standalone deployment and Stratos based deployment will work. Since static objects can be accessed from anywhere make sure to review (in order to avoid stealing from this buffers) any custom code deployed into the same JVM.
    • Constructor Detail

      • CGThriftServerHandler

        public CGThriftServerHandler​(org.apache.axis2.transport.base.threads.WorkerPool workerPool)
    • Method Detail

      • login

        public String login​(String userName,
                            String password,
                            String queueName)
                     throws org.wso2.carbon.cloud.gateway.common.thrift.gen.NotAuthorizedException,
                            org.apache.thrift.TException
        Allow access to user userName for the buffer queueName and return the token or throw exception if user can't allow access to the buffer
        Specified by:
        login in interface org.wso2.carbon.cloud.gateway.common.thrift.gen.CloudGatewayService.Iface
        Parameters:
        userName - user name of the client
        password - password of the client
        queueName - the name of the buffer to use should allow access to
        Returns:
        a token to use for server buffer access
        Throws:
        org.wso2.carbon.cloud.gateway.common.thrift.gen.NotAuthorizedException - throws in case of illegal access
        org.apache.thrift.TException - throws in case of an connection error
      • exchange

        public List<org.wso2.carbon.cloud.gateway.common.thrift.gen.Message> exchange​(List<org.wso2.carbon.cloud.gateway.common.thrift.gen.Message> responseMessageList,
                                                                                      int blockSize,
                                                                                      String token)
                                                                               throws org.wso2.carbon.cloud.gateway.common.thrift.gen.NotAuthorizedException,
                                                                                      org.apache.thrift.TException
        This will perform the exchange of data buffers between the client and the server. This must do it's all operations without blocking as much as possible.
        Specified by:
        exchange in interface org.wso2.carbon.cloud.gateway.common.thrift.gen.CloudGatewayService.Iface
        Parameters:
        responseMessageList - The response buffer from thrift client
        blockSize - size of the message bulk that need to return client
        token - the token to authorize the exchange operation
        Returns:
        a message bulk of size, 'size' if possible
        Throws:
        org.wso2.carbon.cloud.gateway.common.thrift.gen.NotAuthorizedException - in case the provided token is invalid
        org.apache.thrift.TException - in case of an error
      • addRequestMessage

        public static void addRequestMessage​(org.wso2.carbon.cloud.gateway.common.thrift.gen.Message msg,
                                             String token)
                                      throws org.apache.axis2.AxisFault
        Add a message into the server's request buffer, wait if the buffer is full.
        Parameters:
        msg - the new Thrift message
        token - the token to look up the real buffer
        Throws:
        org.apache.axis2.AxisFault - in case of an error - for e.g. out of space in the queue
      • getResponseMessage

        public static org.wso2.carbon.cloud.gateway.common.thrift.gen.Message getResponseMessage()
        Return the head of the response buffer, not that if there are no message it'll block if no messages available.

        Note that since the buffers are static objects anybody has the access to buffers (and the data inside them) but before deploy any custom be warned to review them!

        Returns:
        the message if there is any or null in case of this thread is interrupted
      • getRequestBuffer

        public BlockingQueue<org.wso2.carbon.cloud.gateway.common.thrift.gen.Message> getRequestBuffer​(String token)
        Return the request message buffer

        Note that since the buffers are static objects anybody has the access to buffers (and the data inside them) but before deploy any custom be warned to review them!

        Parameters:
        token - the token to the buffer is bound to
        Returns:
        request message buffer
      • getSecureUUID

        public static String getSecureUUID​(String queueName)
        Return the token give the queue name
        Parameters:
        queueName - queue name
        Returns:
        the secure token that this queue is bound
      • getRequestBuffers

        public static Map<String,​BlockingQueue<org.wso2.carbon.cloud.gateway.common.thrift.gen.Message>> getRequestBuffers()
        Return the list of request buffers

        Note that since the buffers are static objects anybody has the access to buffers (and the data inside them) but before deploy any custom be warned to review them!

        Returns:
        request buffer list
      • addNewRequestBuffer

        public static void addNewRequestBuffer​(String token)
        Add a new request buffer to the list of request buffers
        Parameters:
        token - the token for the new buffer
      • getMiddleBuffer

        public static Map<String,​org.wso2.carbon.cloud.gateway.common.thrift.gen.Message> getMiddleBuffer()