Class CGThriftServerHandler
- java.lang.Object
-
- org.wso2.carbon.cloud.gateway.transport.server.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 Summary
Constructors Constructor Description CGThriftServerHandler(org.apache.axis2.transport.base.threads.WorkerPool workerPool)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
addNewRequestBuffer(String token)
Add a new request buffer to the list of request buffersstatic void
addRequestMessage(org.wso2.carbon.cloud.gateway.common.thrift.gen.Message msg, String token)
Add a message into the server's request buffer, wait if the buffer is full.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)
This will perform the exchange of data buffers between the client and the server.static Map<String,org.wso2.carbon.cloud.gateway.common.thrift.gen.Message>
getMiddleBuffer()
BlockingQueue<org.wso2.carbon.cloud.gateway.common.thrift.gen.Message>
getRequestBuffer(String token)
Return the request message bufferstatic Map<String,BlockingQueue<org.wso2.carbon.cloud.gateway.common.thrift.gen.Message>>
getRequestBuffers()
Return the list of request buffersstatic 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.static String
getSecureUUID(String queueName)
Return the token give the queue namestatic Map<String,Semaphore>
getSemaphoreMap()
String
login(String userName, String password, String queueName)
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
-
-
-
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 interfaceorg.wso2.carbon.cloud.gateway.common.thrift.gen.CloudGatewayService.Iface
- Parameters:
userName
- user name of the clientpassword
- password of the clientqueueName
- 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 accessorg.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 interfaceorg.wso2.carbon.cloud.gateway.common.thrift.gen.CloudGatewayService.Iface
- Parameters:
responseMessageList
- The response buffer from thrift clientblockSize
- size of the message bulk that need to return clienttoken
- 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 invalidorg.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 messagetoken
- 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
-
-